| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- Lib::loadClass('HttpException');
- 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();
- return $route;
- } else {
- throw new HttpException("Not found", 404);
- }
- }
- }
|