load disqus only on request
[mdref/mdref] / public / index.php
index 853c0916398ec77e7878c34c8ec99ff8d5aaa2e0..e6d0f75a4ce4a9fe449d1cd92c8f81c97b9c7570 100644 (file)
@@ -9,19 +9,22 @@ use http\Env\Request;
 use http\Env\Response;
 
 define("ROOT", dirname(__DIR__));
+define("REFS", getenv("REFPATH") ?: implode(PATH_SEPARATOR, glob(ROOT."/refs/*")));
 
-#ini_set("open_basedir", ROOT.":".REFS);
+ini_set("open_basedir", ROOT.PATH_SEPARATOR.REFS);
 
-$loader = require ROOT . "/vendor/autoload.php";
-/* @var $loader \Composer\Autoload\ClassLoader */
-$loader->add("mdref", ROOT);
+if (!ini_get("date.timezone")) {
+       date_default_timezone_set("UTC");
+}
 
-new ExceptionHandler;
+spl_autoload_register(function($c) {
+       if (!strncmp($c, "mdref\\", 6)) {
+               return require ROOT . "/" . strtr($c, "\\", "/") . ".php";
+       }
+});
 
-$reference = new Reference(($refs = getenv("REFPATH")) ? explode(PATH_SEPARATOR, $refs) : glob(ROOT."/refs/*"));
-$action = new Action($reference, new Request, new Response, new BaseUrl);
-
-ob_start($response);
+$response = new Response;
+$ehandler = new ExceptionHandler($response);
+$reference = new Reference(explode(PATH_SEPARATOR, REFS));
+$action = new Action($reference, new Request, $response, new BaseUrl);
 $action->handle();
-ob_end_flush();
-$response->send();