예제 #1
0
파일: Router.php 프로젝트: fant0m/VAII
 public static function dispatch()
 {
     $path = str_replace(PATH, '', $_SERVER['REQUEST_URI']);
     $method = $_SERVER["REQUEST_METHOD"];
     foreach (self::$routes as $route) {
         if ($route['path'] == $path && $route['method'] == $method) {
             $name = 'controllers\\' . $route['controller'];
             $controller = new $name();
             if ($method == 'POST') {
                 $postdata = file_get_contents("php://input");
                 $request = json_decode($postdata);
                 return $controller->{$route}['action']($request);
             } else {
                 return $controller->{$route}['action']();
             }
         } elseif (strpos($path, $route['path']) !== false && $route['method'] == $method && array_key_exists('param', $route)) {
             $name = 'controllers\\' . $route['controller'];
             $controller = new $name();
             $param = str_replace($route['path'] . '/', '', $path);
             return $controller->{$route}['action']($param);
         }
     }
     $controller = new controllers\BaseController();
     return $controller->notFound();
 }