-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.php
31 lines (24 loc) · 943 Bytes
/
router.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
<?php
// requires php with gd or imagick (php, php-gd or php-imagick, php-curl packages and php-pgsql if db loader is used)
// use this to serve for development purposes:
// php -S localhost:8000 router.php
spl_autoload_register(function ($class_name) {
$class_path = str_replace("\\", "/", $class_name);
$filename = __DIR__ . "/src/" . $class_path . ".php";
if (file_exists($filename)) require $filename;
});
$settings = OsmMetaEmitter\Settings::read();
if (php_sapi_name() == "cli-server") {
$root = "/";
} else {
if (preg_match("{(.*/)[^/]*\.php$}", $_SERVER["SCRIPT_NAME"], $matches)) {
$root = $matches[1];
} else {
$root = "/";
}
}
if (substr($_SERVER['REQUEST_URI'], 0, strlen($root)) == $root) {
$request = substr($_SERVER['REQUEST_URI'], strlen($root));
}
$router = OsmMetaEmitter\Router::fromSettings($settings, (@$_SERVER['HTTPS'] ? "https" : "http") . "://$_SERVER[HTTP_HOST]${root}");
$router->route($request);