diff options
| author | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 13:58:36 -0400 |
|---|---|---|
| committer | Kevin J Hoerr <kjhoerr@protonmail.com> | 2017-07-08 13:58:36 -0400 |
| commit | 692a4a48d5f8f74a06d0b5890e31887a76a903f3 (patch) | |
| tree | 9fc39dc20be3b8a442031b85beffc7baa583143b /index.php | |
| parent | 0364d790e9764d91489db21805064ceeb23e3e22 (diff) | |
| download | august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.gz august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.tar.bz2 august-offensive-692a4a48d5f8f74a06d0b5890e31887a76a903f3.zip | |
Improve exception handling, introduce autoloading
Diffstat (limited to 'index.php')
| -rw-r--r-- | index.php | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -4,21 +4,38 @@ declare(strict_types=1); namespace AugustOffensive; -// y u no autoload -include 'private/Model/Connection.php'; -include 'private/Model/Query.php'; -include 'private/Model/Result.php'; -include 'private/View/Main.php'; -include 'private/Controller/Controller.php'; +// Borrowed and modified from PSR-4 Closure Example +spl_autoload_register( + function ($class) { + $prefix = 'AugustOffensive\\'; + $relative_class = substr($class, strlen($prefix)); + + // find file in /private/ in respective namespace path + $file = __DIR__ . '/private/' . str_replace('\\', '/', $relative_class) . '.php'; + + // if the file exists, require it + if (file_exists($file)) { + require $file; + } + } +); use AugustOffensive\View; -use AugustOffensive\Model; +use AugustOffensive\Controller; + +try { + // initiate connection and build front-end + $connection = Controller\Controller::initiateConnection(); + $view = new View\Main($connection); -// initiate connection and build front-end -$connection = new Model\Connection(); -$view = new View\Main($connection); + // get results of query from front-end + $result = $view->generateResult(); -// get results of query from front-end -$result = $view->generateResult(); + echo $result; +} catch (\Exception $err) { + // catch all exceptions and let the controller generate the error + $error = Controller\Controller::errorResult($err); -echo $result; + // pass generated error result to output + echo View\Main::generateOutput($error); +} |
