コード例 #1
0
ファイル: Kernel.php プロジェクト: avalonphp/avalon
 /**
  * Route the request and execute the controller.
  */
 public static function process()
 {
     Request::init();
     $route = Router::process();
     if (!$route) {
         $route = Router::getRoute('404');
     }
     if ($route) {
         list($class, $method) = explode('::', $route->controller);
         $action = "{$method}Action";
         Request::$properties->set(['controller' => $class, 'action' => $method]);
         if (!class_exists($class)) {
             throw new Exception("Controller class [{$class}] not found");
         }
         if (!method_exists($class, $action)) {
             throw new Exception("Controller action [{$route->controller}Action] not found");
         }
         $controller = new $class();
         $response = static::runFilters('before', $controller, $method);
         if (!$response) {
             $response = call_user_func_array([$controller, $action], $route->actionParams());
         }
         static::runFilters('after', $controller, $method);
         if (!$response instanceof Response) {
             throw new Exception("The controller returned an invalid response");
         }
         return $response;
     } else {
         throw new Exception(sprintf("No route matches [%s %s] and no 404 controller set", Request::$method, Request::$pathInfo));
     }
 }