/** * Determines the current route and runs it. */ public static function run() { // Pull the current path out of the get arguments directly $length = strlen(APP_RELATIVE_URL) == 0 ? 0 : strlen(APP_RELATIVE_URL) + 1; $path = substr(urldecode(parse_url(filter_input(INPUT_SERVER, 'REQUEST_URI'), PHP_URL_PATH)), $length); try { // Get the appropriate route for the path $route = Routes::get($path); // If our route is null, we should 404 if ($route == null) { header('Status: 404 Not Found', true, 404); View::renderView('404'); return; } // See whther or not we have to check the token if ($route->isTokenNeeded()) { Auth::checkToken(); } // Get the current path variables self::$currentPathVariables = self::pullVariables($path, $route); // Run the route $route->run(); // See if the last rendered path variable needs to be set if (View::hasRenderedView()) { Session::set(self::LAST_RENDERED_PATH_KEY, $path); } } catch (Exception $ex) { View::renderJson($ex->getMessage(), false); exit; } }
/** * Renders a view given a view name and context. Prints to the screen. * @param string $name The name of the view. * @param mixed $context The context to use in compilation. */ public static function renderView($name, $context = null) { $compiled = self::compileView($name, $context); Log::clearNoticesAndAlerts(); self::$hasRenderedView = true; echo $compiled; }