示例#1
0
 /**
  * Request dispatcher.
  *
  * @return mixed Controller/action response
  *
  */
 private function dispatch()
 {
     if ($this->route->isActionClosure()) {
         $controller = 'ClosureContext';
         $action = 'bind';
     } else {
         $controller = $this->route->controller();
         $controller = $controller . Configuration::CONTROLLER_NAME_SUFFIX;
         $action = $this->route->action();
     }
     if (class_exists($controller, true)) {
         // Load reflection of controller/class
         $this->container->reflectionLoad($controller);
         $withConstructor = false;
         $dependencies = array();
         $constructor = $this->container->reflectionGetConstructor();
         // Check if class has a contructor method (either "__construct" or method that is the same name as its class)
         if (isset($constructor->name)) {
             $dependencies = $this->container->reflectionGetMethodDependencies($constructor->name);
             if ($constructor->name == '__construct') {
                 // $skipReflection = true;
                 $withConstructor = true;
             }
         }
         // Create class instance (object)
         $obj = $this->container->reflectionCreateInstance($dependencies, $withConstructor);
         // Prepare/set Closure function
         if ($this->route->isActionClosure()) {
             $obj->set($this->route->getClosure());
         }
         // Check if object method exists
         if (method_exists($obj, $action)) {
             // Check if action method needs dependency
             $dependencies = $this->container->reflectionGetMethodDependencies($action);
             // Call the controller's action method
             call_user_func_array(array($obj, $action), $dependencies);
         } else {
             // No action method found!
             if (!$this->config->application['production']) {
                 $this->http->header($this->http->getValue('SERVER_PROTOCOL') . ' 404 Not Found', true, 404);
                 throw new Exception('Cannot find method "' . $action . '" in controller class "' . $controller . '"');
             } else {
                 $this->view->layout('error')->page('error.404')->render();
             }
         }
     } else {
         // No controller class found!
         if (!$this->config->application['production']) {
             $this->http->header($this->http->getValue('SERVER_PROTOCOL') . ' 404 Not Found', true, 404);
             throw new Exception('Cannot find controller class "' . $controller . '"');
         } else {
             $this->view->layout('error')->page('error.404')->render();
         }
     }
 }
示例#2
0
 /**
  * Request dispatcher.
  *
  * @return mixed Controller/action response
  *
  */
 private function dispatch()
 {
     if ($this->route->isActionClosure()) {
         $controller = 'ClosureContext';
         $action = 'bind';
     } else {
         $controller = $this->route->controller();
         $controller = $controller . Configuration::COMMAND_NAME_SUFFIX;
         $action = $this->route->action();
     }
     if (class_exists($controller, true)) {
         // Load reflection of controller/class
         $this->container->reflectionLoad($controller);
         $withConstructor = false;
         $dependencies = array();
         $constructor = $this->container->reflectionGetConstructor();
         // Check if class has a contructor method (either "__construct" or method that is the same name as its class)
         if (isset($constructor->name)) {
             $dependencies = $this->container->reflectionGetMethodDependencies($constructor->name);
             if ($constructor->name == '__construct') {
                 // $skipReflection = true;
                 $withConstructor = true;
             }
         }
         // Create class instance (object)
         $obj = $this->container->reflectionCreateInstance($dependencies, $withConstructor);
         // Prepare/set Closure function
         if ($this->route->isActionClosure()) {
             $obj->set($this->route->getClosure());
         }
         // Check if object method exists
         if (method_exists($obj, $action)) {
             // Check if action method needs dependency
             $dependencies = $this->container->reflectionGetMethodDependencies($action);
             // Call the controller's action method
             return call_user_func_array(array($obj, $action), $dependencies);
         } else {
             // No action method found!
             throw new Exception('Cannot find method "' . $action . '" in controller class "' . $controller . '"');
         }
     } else {
         // No controller class found!
         throw new Exception('Cannot find controller class "' . $controller . '"');
     }
 }
示例#3
0
文件: View.php 项目: rawswift/orinoco
 /**
  * Render action (presentation) content.
  *
  * @return boolean Whether or not view/content file exists
  *
  */
 public function renderContent()
 {
     $contentViewName = null;
     // Check if page view is specified or not
     if (!isset($this->pageView)) {
         $contentView = $this->viewBase . DIRECTORY_SEPARATOR . trim($this->config->view['template']['page'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->route->controller() . DIRECTORY_SEPARATOR . $this->route->action() . $this->config->PHP_FILE_EXTENSION;
         $contentViewName = $this->route->controller() . '.' . $this->route->action();
     } else {
         $contentView = $this->viewBase . DIRECTORY_SEPARATOR . trim($this->config->view['template']['page'], DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->pageView['controller'] . DIRECTORY_SEPARATOR . $this->pageView['action'] . $this->config->PHP_FILE_EXTENSION;
         $contentViewName = $this->pageView['controller'] . '.' . $this->pageView['action'];
     }
     if (!file_exists($contentView)) {
         if (!$this->config->application['production']) {
             throw new RuntimeException('View "' . $contentView . '" not found or does not exists.');
         } else {
             print 'View "' . $contentViewName . '" not found or does not exists.';
         }
     }
     include $contentView;
 }