|
|
@@ -7,20 +7,41 @@ class Router {
|
|
|
public static function route($route) {
|
|
|
if (empty($route)) return;
|
|
|
|
|
|
+ try {
|
|
|
+ $route = self::getRoute($route);
|
|
|
+ $route->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) {
|
|
|
+ if (empty($route)) return;
|
|
|
+
|
|
|
$routeClassName = "Route_{$route}";
|
|
|
if (Lib::tryLoadClass($routeClassName)) {
|
|
|
$route = new $routeClassName();
|
|
|
- try {
|
|
|
- $route->route();
|
|
|
- } catch (HttpException $e) {
|
|
|
- Http::sendHeaderByCode($e->getCode());
|
|
|
- die($e->getMessage());
|
|
|
- } catch (Exception $e) {
|
|
|
- die($e->getMessage());
|
|
|
- }
|
|
|
- exit;
|
|
|
+ return $route;
|
|
|
} else {
|
|
|
- die("Route '{$route}' not exists");
|
|
|
+ throw new HttpException("Not found", 404);
|
|
|
}
|
|
|
}
|
|
|
|