diff --git a/.gitmodules b/.gitmodules index 2a24f2a9..4aee5fd7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "chibi-core"] - path = chibi-core + path = lib/chibi-core url = https://github.com/rr-/chibi-core.git [submodule "php-markdown"] - path = php-markdown + path = lib/php-markdown url = https://github.com/michelf/php-markdown.git [submodule "redbean"] - path = redbean + path = lib/redbean url = https://github.com/gabordemooij/redbean.git diff --git a/chibi-core b/chibi-core deleted file mode 160000 index f409272c..00000000 --- a/chibi-core +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f409272ce5b9856c8765dc8b9b68349efde71b0c diff --git a/lib/chibi-core b/lib/chibi-core new file mode 160000 index 00000000..84882328 --- /dev/null +++ b/lib/chibi-core @@ -0,0 +1 @@ +Subproject commit 8488232806fd5ceecb25af39036f250b081ada3d diff --git a/php-markdown b/lib/php-markdown similarity index 100% rename from php-markdown rename to lib/php-markdown diff --git a/redbean b/lib/redbean similarity index 100% rename from redbean rename to lib/redbean diff --git a/public_html/dispatch.php b/public_html/dispatch.php index c2ae4340..da58de54 100644 --- a/public_html/dispatch.php +++ b/public_html/dispatch.php @@ -1,21 +1,12 @@ config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/'; - R::setup('sqlite:' . $this->config->main->dbPath); - $workCallback(); - } -} - $query = $_SERVER['REQUEST_URI']; $configPaths = [ diff --git a/src/Bootstrap.php b/src/Bootstrap.php new file mode 100644 index 00000000..09ad82f1 --- /dev/null +++ b/src/Bootstrap.php @@ -0,0 +1,33 @@ +context->layoutName = isset($_GET['json']) + ? 'layout-json' + : 'layout-normal'; + $this->context->transport = new StdClass; + $this->context->transport->success = null; + + $this->config->chibi->baseUrl = 'http://' . rtrim($_SERVER['HTTP_HOST'], '/') . '/'; + R::setup('sqlite:' . $this->config->main->dbPath); + if (empty($this->context->route)) + { + $this->context->viewName = 'error-404'; + (new \Chibi\View())->renderFile($this->context->layoutName); + return; + } + + try + { + $workCallback(); + } + catch (Exception $e) + { + $this->context->exception = $e; + $this->context->viewName = 'error-exception'; + (new \Chibi\View())->renderFile($this->context->layoutName); + } + } +} diff --git a/src/Controllers/AbstractController.php b/src/Controllers/AbstractController.php index 0b4268b8..2e7e8a6e 100644 --- a/src/Controllers/AbstractController.php +++ b/src/Controllers/AbstractController.php @@ -21,13 +21,6 @@ abstract class AbstractController public function workWrapper($workCallback) { - session_start(); - $this->context->layoutName = isset($_GET['json']) - ? 'layout-json' - : 'layout-normal'; - $this->context->transport = new StdClass; - $this->context->transport->success = null; - $this->attachUser(); try @@ -40,10 +33,5 @@ abstract class AbstractController $this->context->transport->exception = $e; $this->context->transport->success = false; } - catch (Exception $e) - { - $this->context->exception = $e; - $this->context->viewName = 'error-exception'; - } } } diff --git a/src/Views/error-404.phtml b/src/Views/error-404.phtml new file mode 100644 index 00000000..f75ab2ae --- /dev/null +++ b/src/Views/error-404.phtml @@ -0,0 +1,2 @@ +