2020-05-17 22:30:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require '../main.php';
|
|
|
|
|
|
|
|
// very basic routing
|
2020-05-30 15:33:28 +02:00
|
|
|
$host = $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'];
|
2020-05-17 22:30:22 +02:00
|
|
|
$url = $_SERVER['REQUEST_URI'];
|
2020-05-25 18:52:31 +02:00
|
|
|
if (($pos = strpos($url, '?')) !== false) {
|
|
|
|
$url = substr($url, 0, $pos);
|
|
|
|
}
|
2020-05-17 22:30:22 +02:00
|
|
|
switch($url) {
|
2020-05-30 15:37:26 +02:00
|
|
|
case '/maps':
|
|
|
|
$controller = new MapGuesser\Controller\MapsController();
|
|
|
|
break;
|
2020-05-19 16:13:57 +02:00
|
|
|
case '/game':
|
2020-05-30 15:33:28 +02:00
|
|
|
$mapId = isset($_GET['map']) ? (int) $_GET['map'] : 0;
|
|
|
|
$controller = new MapGuesser\Controller\GameController($mapId);
|
2020-05-17 22:30:22 +02:00
|
|
|
break;
|
2020-05-26 23:19:23 +02:00
|
|
|
case '/game.json':
|
2020-05-30 15:33:28 +02:00
|
|
|
$mapId = isset($_GET['map']) ? (int) $_GET['map'] : 0;
|
|
|
|
$controller = new MapGuesser\Controller\GameController($mapId, true);
|
2020-05-26 23:19:23 +02:00
|
|
|
break;
|
2020-05-25 19:46:31 +02:00
|
|
|
case '/position.json':
|
2020-05-30 15:33:28 +02:00
|
|
|
$mapId = isset($_GET['map']) ? (int) $_GET['map'] : 0;
|
|
|
|
$controller = new MapGuesser\Controller\PositionController($mapId);
|
2020-05-19 03:19:23 +02:00
|
|
|
break;
|
2020-05-20 13:06:40 +02:00
|
|
|
case '/':
|
2020-05-30 15:37:26 +02:00
|
|
|
header('Location: ' . $host . '/maps', true, 302);
|
2020-05-20 13:06:40 +02:00
|
|
|
die;
|
2020-05-17 22:30:22 +02:00
|
|
|
default:
|
|
|
|
echo 'Error 404';
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
|
2020-05-19 03:19:23 +02:00
|
|
|
$view = $controller->run();
|
|
|
|
|
|
|
|
header('Content-Type: ' . $view->getContentType() . '; charset=UTF-8');
|
|
|
|
|
|
|
|
echo $view->render();
|