/** * serve * initialize front controller. * * @param string application path * * @return object Viloveul\Core\Application */ public static function serve($path) { $realpath = realpath($path); if (false === $realpath) { die('Application path does not appear.'); } $realpath = rtrim(str_replace('\\', '/', $realpath), '/'); $basepath = rtrim(str_replace('\\', '/', realpath($_SERVER['SCRIPT_FILENAME'])), '/'); if (is_file($realpath . '/configs.php')) { $configs = (include $realpath . '/configs.php'); is_array($configs) and Core\Configure::write($configs); } Core\Debugger::registerErrorHandler(); Core\Debugger::registerExceptionHandler(); register_shutdown_function(function () { $error = error_get_last(); if (isset($error) && $error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)) { Core\Debugger::handleError($error['type'], $error['message'], $error['file'], $error['line']); } }); return new Core\Application($realpath, $basepath); }
/* |-------------------------------------------------------------------------- | Share the Singleton $app with the Template Files |-------------------------------------------------------------------------- | | Eliminate complexity, get the job done. | */ Core\Sharer::share('app', $app); /* |-------------------------------------------------------------------------- | Dispatch the Router |-------------------------------------------------------------------------- | | Ta Da! We can see something now! | */ include DSS_PATH . 'app/routes.php'; Core\Router::dispatch(); /* |-------------------------------------------------------------------------- | Display the Execution Time |-------------------------------------------------------------------------- | | Show the time taken to complete execution up till this far. (See the file | config/env.php) | */ if (getenv('SHOW_EXECUTION_TIME')) { Core\Debugger::exec_time(); }
|-------------------------------------------------------------------------- | Register the Autoloader |-------------------------------------------------------------------------- | | Composer is our best friend. He maintains our dependencies and manage | the autoloader very well. Good guy Composer. | */ require __DIR__ . '/../vendor/autoload.php'; /* |-------------------------------------------------------------------------- | Register the Environment Variables |-------------------------------------------------------------------------- | | Reads the config file (config/env.php) and register it in using the | putenv() function. Configurations are retreivable using the getenv() | function everywhere in the project. | */ Core\Config::setEnv(); /* |-------------------------------------------------------------------------- | Register the Error Handler |-------------------------------------------------------------------------- | | The debugging tool will register the error handler based on your | configuration (located at config/env.php). | */ Core\Debugger::start();