public final function traverse($URL) { $pages = $this->getPages(); if (!is_null($pages) and $pages !== false) { foreach ($pages as $Page) { if (!is_null($Page) && $Page instanceof Page && $Page->isMatch($URL)) { try { $Page->run($this); $Page->show($this); return null; } catch (Exception $e) { ErrorHandler::primitiveError(500, "Page script error", $e->getMessage()); } } } } ErrorHandler::primitiveError(404, "Page not found", "Cannot find any pages with this URL."); }
ob_clean(); $errorCase = array(E_WARNING => "Warning!", E_ERROR => "Error!", E_USER_ERROR => "User Error", E_USER_WARNING => "User Warning", E_USER_NOTICE => "User Notice"); self::primitiveError(500, array_key_exists($errno, $errorCase) ? $errorCase[$errno] : "An unknown error occurred", $errstr . "<br/>Line " . $errline . " in " . $errfile); } public static function fatalHandler() { $error = error_get_last(); if (self::$Enabled && $error !== null) { $errorMsg = $error['message'] . ' on line ' . $error['line'] . "<br/>(" . $error['file'] . ")"; self::primitiveError(500, "Fatal error occurred", $errorMsg); } } private static $Enabled = false; public static function start() { error_reporting(0); self::$Enabled = true; set_error_handler(__CLASS__ . '::exceptionHandler', E_ALL); register_shutdown_function(__CLASS__ . '::fatalHandler'); } public static function stop() { self::$Enabled = false; error_reporting(E_ALL); restore_error_handler(); register_shutdown_function("exit"); } } ErrorHandler::start(); @(include_once "engine/Engine.php") or ErrorHandler::primitiveError(500, "Missing Engine class."); $engine = new Engine();
public function run() { try { //Traverse the Template if possible, otherwise the template is null; if (is_null(self::$currentTemplate)) { throw new Exception("No template found."); } else { $url = $this->fixPath(isset($_GET["current_engine_page"]) ? $_GET["current_engine_page"] : ""); self::$currentTemplate->traverse($url); } } catch (Exception $e) { ErrorHandler::primitiveError(500, "Cannot run Engine", $e->getMessage()); } }