route(); } catch (HttpException $e) { Http::sendHeaderByCode($e->getCode()); die($e->getMessage()); } catch (Exception $e) { die($e->getMessage()); } exit; } public static function handleAuth($route) { if (empty($route)) return; try { $route = self::getRoute($route); $route->handleAuth(); } catch (HttpException $e) { Http::sendHeaderByCode($e->getCode()); die($e->getMessage()); } catch (Exception $e) { die($e->getMessage()); } } public static function getRoute($route) { static $_routeInstances = null; if (!is_array($_routeInstances)) $_routeInstances = array(); if (empty($route)) return; if (array_key_exists($route, $_routeInstances)) return $_routeInstances[$route]; $routeClassName = "Route_{$route}"; if (Lib::tryLoadClass($routeClassName)) { $_routeInstances[$route] = new $routeClassName(); return $_routeInstances[$route]; } else { throw new HttpException("Not found", 404); } } }