Example #1
0
 public function start()
 {
     try {
         //TODO: add more customization capabilities.
         // Check for custom application configuration in resources->config
         $router_config = $this->_resources->has('config') && $this->_resources->get('config')->has('router') ? $this->_resources->get('config')->get('router') : array();
         if (is_array($router_config)) {
             $router_config = DataObject::from_array($router_config);
         }
         // Prepare router
         $router = new Router($this->_application_path, $this->_uri->get_main_params(), $router_config->to_array());
         $router->set_base_url($this->_uri->get_website_base_url());
         $this->_resources->set('router', $router);
         // Prepare the view object
         $view = new View(array('path' => $router->get_path('view'), 'layoutPath' => $router->get_path('layout')));
         $view->add_view_helper(new HtmlHelper($router));
         $this->_resources->set('view', $view);
         // Authorisation check: authentications, Acl, security token ... (possible 401: Unauthorised access)
         $this->_events->trigger('checkers', $this);
         // Prepare Action and check existance of ressource uried (possible 404: Ressource not found)
         Controller::inject($this->_resources->to_array());
         $action = Controller::action_factory($router->get_class_path('controller'), $this->_uri->get_param('action'));
         // Execute Action
         $contents = Controller::act($action);
     } catch (Exception $e) {
         if (!$this->_exception_controller || !file_exists($router->get_path("controller") . DS . $this->_exception_controller)) {
             throw $e;
         }
         $params["e"] = $e;
         Controller::inject($this->_resources);
         $action = Controller::action_factory($router->get_path("controller") . DS . $this->_exception_controller, "index");
         $contents = Controller::act($action);
     }
     // TOTHINK: For better performances and more flexibility, filter should be added from outside the app
     //$this->addFilter(new Incube_Filter_Tag($view));
     $this->_events->trigger('render', $this, array('contents' => $contents));
     if (is_string($contents) && !empty($contents)) {
         echo $contents;
     }
     // TODO: manage rendering
     //echo $view->render();
 }