Ejemplo n.º 1
0
 public function start()
 {
     try {
         // call the router and check whether the given url can be matched to any route
         $this->router = Router::getInstance();
         // fill in the parameters
         $params = Params::getInstance();
         $params->setRequest(Request::getInstance());
         $params->setRouter(Router::getInstance());
         // call the given controllers given action
         $controllerName = $this->router->getController();
         $actionName = $this->router->getAction();
         // instantiate the controller
         if (class_exists($controllerName)) {
             $controller = new $controllerName();
         } else {
             throw new \Exception("The class '{$controllerName}' in routing configuration isn't exists", 404);
         }
         // call the given action and get the viewmodel from it
         if (in_array($actionName, get_class_methods($controllerName))) {
             $controller->onDispatch($this);
             $view = $controller->{$actionName}();
         } else {
             throw new \Exception("The method '{$actionName}' isn't a callable!", 404);
         }
         if (is_object($view) && in_array('System\\StdLib\\View\\ViewInterface', class_implements($view))) {
             $controller->getLayout()->render($view);
         } else {
             throw new \Exception("No valid viewmodels returned. Returned viewmodels should implement 'System\\StdLib\\View\\ViewInterface'");
         }
     } catch (\Exception $e) {
         die($e->getMessage());
         $this->displayFatalErrors($e);
     }
     // end
 }
 /**
  * @return \System\StdLib\Controller\Plugin\Params
  */
 protected function params()
 {
     return Params::getInstance();
 }