2020-05-17 22:30:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require '../main.php';
|
|
|
|
|
|
|
|
// very basic routing
|
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);
|
|
|
|
|
|
|
|
Container::$routeCollection->get('index', '', [MapGuesser\Controller\HomeController::class, 'getIndex']);
|
|
|
|
Container::$routeCollection->get('maps', 'maps', [MapGuesser\Controller\MapsController::class, 'getMaps']);
|
|
|
|
Container::$routeCollection->group('game', function (MapGuesser\Routing\RouteCollection $routeCollection) {
|
|
|
|
$routeCollection->get('game', '{mapId}', [MapGuesser\Controller\GameController::class, 'getGame']);
|
|
|
|
$routeCollection->get('game-json', '{mapId}/json', [MapGuesser\Controller\GameController::class, 'getGameJson']);
|
|
|
|
$routeCollection->get('position-json', '{mapId}/position.json', [MapGuesser\Controller\PositionController::class, 'getPosition']);
|
|
|
|
$routeCollection->post('guess-json', '{mapId}/guess.json', [MapGuesser\Controller\PositionController::class, 'evaluateGuess']);
|
|
|
|
});
|
2020-06-01 21:13:02 +02:00
|
|
|
Container::$routeCollection->group('admin', function (MapGuesser\Routing\RouteCollection $routeCollection) {
|
|
|
|
$routeCollection->get('admin.maps', 'maps', [MapGuesser\Controller\MapAdminController::class, 'getMaps']);
|
|
|
|
$routeCollection->get('admin.mapEditor', 'mapEditor/{mapId}', [MapGuesser\Controller\MapAdminController::class, 'getMapEditor']);
|
|
|
|
});
|
2020-05-17 22:30:22 +02:00
|
|
|
|
2020-05-31 20:44:45 +02:00
|
|
|
$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-05-31 20:44:45 +02:00
|
|
|
$response = $route->callController($params);
|
|
|
|
|
|
|
|
if ($response instanceof MapGuesser\Interfaces\Response\IContent) {
|
|
|
|
header('Content-Type: ' . $response->getContentType() . '; charset=UTF-8');
|
|
|
|
echo $response->render();
|
|
|
|
} elseif ($response instanceof MapGuesser\Interfaces\Response\IRedirect) {
|
|
|
|
header('Location: ' . $host . '/' . $response->getUrl(), true, $response->getHttpCode());
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
header('Content-Type: text/html; charset=UTF-8', true, 404);
|
|
|
|
require ROOT . '/views/error/404.php';
|
|
|
|
}
|