/** * Executes the router * * @return boolean */ public static function start() { $request = Request::path(); //allow method spoofing $post = Request::$post; if (isset($post['_method'])) { Request::method($post['_method']); } //check home route if (isset(self::$_home) && self::$_home->match($request)) { self::$_home->execute(); return true; } //check any routes foreach (self::$_any as $handle => $route_obj) { if ($route_obj->match($request)) { $route_obj->execute(); return true; } } //check for method routes | POST or GET $relevant_requests; if (Request::method() == "POST") { $relevant_requests = self::$_post; } elseif (Request::method() == "GET") { $relevant_requests = self::$_get; } elseif (Request::method() == "PUT") { $relevant_requests = self::$_put; } elseif (Request::method() == "DELETE") { $relevant_requests = self::$_delete; } elseif (Request::method() == "PATCH") { $relevant_requests = self::$_patch; } elseif (Request::method() == "OPTIONS") { $relevant_requests = self::$_options; } //check the releavant requests foreach ($relevant_requests as $handle => $route_obj) { if ($route_obj->match($request)) { $route_obj->execute(); return true; } } //no routes have been executed here //check for error page if (isset(self::$_default)) { self::$_default->execute(); return true; } App::throw(0x194); return false; }
/** * Throws an application error and sets an HTTP code * * @param integer $code * * @return boolean */ public static function throw($code) { header("HTTP/1.0 {$code}"); $error = StatusCodeHandler::find($code); if ($error instanceof StatusCode) { LogHandler::write($error, Request::path() . "\t" . $_SERVER["REMOTE_ADDR"]); return Router::throw($code); } return false; }