2020-05-17 22:30:22 +02:00
|
|
|
<?php
|
|
|
|
|
2020-06-13 20:42:07 +02:00
|
|
|
require '../web.php';
|
2020-05-17 22:30:22 +02:00
|
|
|
|
2020-06-01 22:44:44 +02:00
|
|
|
$host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['HTTP_HOST'];
|
2020-05-31 20:44:45 +02:00
|
|
|
$method = strtolower($_SERVER['REQUEST_METHOD']);
|
|
|
|
$url = substr($_SERVER['REQUEST_URI'], strlen('/'));
|
2020-05-25 18:52:31 +02:00
|
|
|
if (($pos = strpos($url, '?')) !== false) {
|
|
|
|
$url = substr($url, 0, $pos);
|
|
|
|
}
|
2020-05-31 20:44:45 +02:00
|
|
|
$url = rawurldecode($url);
|
|
|
|
|
|
|
|
$match = Container::$routeCollection->match($method, explode('/', $url));
|
2020-05-19 03:19:23 +02:00
|
|
|
|
2020-05-31 20:44:45 +02:00
|
|
|
if ($match !== null) {
|
|
|
|
list($route, $params) = $match;
|
2020-05-19 03:19:23 +02:00
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
$request = new MapGuesser\Request\Request($_GET, $params, $_POST, $_SESSION);
|
2020-05-31 20:44:45 +02:00
|
|
|
|
2020-06-09 00:56:00 +02:00
|
|
|
$handler = $route->getHandler();
|
|
|
|
$controller = new $handler[0]($request);
|
2020-06-07 23:37:01 +02:00
|
|
|
|
|
|
|
if ($controller instanceof MapGuesser\Interfaces\Authorization\ISecured) {
|
|
|
|
$authorized = $controller->authorize();
|
|
|
|
} else {
|
|
|
|
$authorized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($authorized) {
|
2020-06-09 00:56:00 +02:00
|
|
|
$response = call_user_func([$controller, $handler[1]]);
|
2020-06-07 23:37:01 +02:00
|
|
|
|
|
|
|
if ($response instanceof MapGuesser\Interfaces\Response\IContent) {
|
|
|
|
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
|
|
|
|
echo $response->render();
|
|
|
|
|
|
|
|
return;
|
|
|
|
} elseif ($response instanceof MapGuesser\Interfaces\Response\IRedirect) {
|
|
|
|
header('Location: ' . $host . '/' . $response->getUrl(), true, $response->getHttpCode());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2020-05-31 20:44:45 +02:00
|
|
|
}
|
|
|
|
}
|
2020-06-07 23:37:01 +02:00
|
|
|
|
|
|
|
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
|
|
|
require ROOT . '/views/error/404.php';
|