forked from phpmyadmin/phpmyadmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
66 lines (58 loc) · 1.9 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* Main loader script
*/
declare(strict_types=1);
use FastRoute\Dispatcher;
use PhpMyAdmin\Message;
use PhpMyAdmin\Response;
use function FastRoute\simpleDispatcher;
if (! defined('ROOT_PATH')) {
// phpcs:disable PSR1.Files.SideEffects
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
// phpcs:enable
}
global $containerBuilder, $route;
/** @var string $route */
$route = $_GET['route'] ?? $_POST['route'] ?? '/';
/**
* See FAQ 1.34.
*
* @see https://docs.phpmyadmin.net/en/latest/faq.html#faq1-34
*/
if (($route === '/' || $route === '') && isset($_GET['db']) && mb_strlen($_GET['db']) !== 0) {
$route = '/database/structure';
if (isset($_GET['table']) && mb_strlen($_GET['table']) !== 0) {
$route = '/sql';
}
}
if ($route === '/import-status') {
// phpcs:disable PSR1.Files.SideEffects
define('PMA_MINIMUM_COMMON', true);
// phpcs:enable
}
require_once ROOT_PATH . 'libraries/common.inc.php';
$routes = require ROOT_PATH . 'libraries/routes.php';
$dispatcher = simpleDispatcher($routes);
$routeInfo = $dispatcher->dispatch(
$_SERVER['REQUEST_METHOD'],
rawurldecode($route)
);
if ($routeInfo[0] === Dispatcher::NOT_FOUND) {
/** @var Response $response */
$response = $containerBuilder->get(Response::class);
$response->setHttpResponseCode(404);
Message::error(sprintf(
__('Error 404! The page %s was not found.'),
'<code>' . $route . '</code>'
))->display();
} elseif ($routeInfo[0] === Dispatcher::METHOD_NOT_ALLOWED) {
/** @var Response $response */
$response = $containerBuilder->get(Response::class);
$response->setHttpResponseCode(405);
Message::error(__('Error 405! Request method not allowed.'))->display();
} elseif ($routeInfo[0] === Dispatcher::FOUND) {
[$controllerName, $action] = $routeInfo[1];
$controller = $containerBuilder->get($controllerName);
$controller->$action($routeInfo[2]);
}