load disqus only on request
[mdref/mdref] / public / index.php
index 23a1be2cf1a8595337669918a3438a80f4ef27fe..e6d0f75a4ce4a9fe449d1cd92c8f81c97b9c7570 100644 (file)
@@ -1,27 +1,30 @@
 <?php
 
-define("ROOT", dirname(__DIR__));
-define("REFS", getenv("REFPATH") ?: implode(PATH_SEPARATOR, glob(ROOT."/refs/*")));
+use mdref\Action;
+use mdref\BaseUrl;
+use mdref\Reference;
+use mdref\ExceptionHandler;
 
-ini_set("open_basedir", ROOT.":".REFS);
+use http\Env\Request;
+use http\Env\Response;
 
-$loader = require ROOT . "/vendor/autoload.php";
-/* @var $loader \Composer\Autoload\ClassLoader */
-$loader->add("mdref", ROOT);
+define("ROOT", dirname(__DIR__));
+define("REFS", getenv("REFPATH") ?: implode(PATH_SEPARATOR, glob(ROOT."/refs/*")));
 
-use http\Controller;
-use http\Controller\Url;
-use http\Controller\Observer\Layout;
+ini_set("open_basedir", ROOT.PATH_SEPARATOR.REFS);
 
-use mdref\ExceptionHandler;
-use mdref\Action;
+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";
+       }
+});
 
-$ctl = new Controller;
-$ctl->setDependency("baseUrl", new Url)
-       ->attach(new Action)
-       ->attach(new Layout)
-       ->notify()
-       ->getResponse()
-       ->send();
+$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();