fix PHP-7.4 compat
[mdref/mdref] / public / index.php
1 <?php
2
3 namespace mdref;
4
5 use http\Env\Request;
6 use http\Env\Response;
7 use function ini_get;
8 use function ini_set;
9 use function spl_autoload_register;
10 use function strncmp;
11 use function strtr;
12 use const GLOB_ONLYDIR;
13 use const PATH_SEPARATOR;
14 use const REFS;
15 use const ROOT;
16
17 define("ROOT", dirname(__DIR__));
18 define("REFS", getenv("REFPATH") ?: implode(PATH_SEPARATOR, glob(ROOT."/refs/*", GLOB_ONLYDIR)));
19
20 ini_set("open_basedir", ROOT.PATH_SEPARATOR.REFS);
21
22 if (!ini_get("date.timezone")) {
23 date_default_timezone_set("UTC");
24 }
25
26 spl_autoload_register(function($c) {
27 if (!strncmp($c, "mdref\\", 6)) {
28 return require ROOT . "/" . strtr($c, "\\", "/") . ".php";
29 }
30 });
31
32 $response = new Response;
33 $ehandler = new ExceptionHandler($response);
34 $reference = new Reference(explode(PATH_SEPARATOR, REFS));
35 $action = new Action($reference, new Request, $response, new BaseUrl);
36 $action->handle();