Esempio n. 1
0
 public function dispatch($controller = null, $action = null, $params = array())
 {
     $this->setHelpersPath();
     $controller = $controller ? $controller : $this->getRequest()->getController();
     $response = JO_Response::getInstance();
     if (!$this->isDispatchable($controller) && $this->isDispatchable('error')) {
         $controller = 'error';
         $action = 'error404';
     }
     if ($this->isDispatchable($controller)) {
         JO_Loader::setIncludePaths(array($this->getDispatchDirectory()));
         $className = $this->formatControllerName($controller);
         JO_Loader::loadFile($this->classToFilename($className), null, true);
         $controller_instance = new $className($this->getRequest());
         if (!$controller_instance instanceof JO_Action) {
             require_once 'JO/Exception.php';
             throw new JO_Exception('Controller "' . $className . '" is not an instance of JO_Action');
         }
         $action = $action ? $action : $this->getRequest()->getAction();
         // by default, buffer output
         $disableOb = $this->getParam('disableOutputBuffering');
         $obLevel = ob_get_level();
         if (empty($disableOb)) {
             ob_start();
         }
         try {
             $controller_instance->dispatch($controller, $action, $params);
         } catch (Exception $e) {
             // Clean output buffer on error
             $curObLevel = ob_get_level();
             if ($curObLevel > $obLevel) {
                 do {
                     ob_get_clean();
                     $curObLevel = ob_get_level();
                 } while ($curObLevel > $obLevel);
             }
             throw $e;
         }
         if (empty($disableOb)) {
             $content = ob_get_clean();
             $response->appendBody($content);
         }
         // Destroy the page controller instance and reflection objects
         $controller_instance = null;
     } else {
         $controller_instance = new JO_Action();
         $controller_instance->dispatch($controller, 'error404');
         // Destroy the page controller instance and reflection objects
         $controller_instance = null;
         //			require_once 'JO/Exception.php';
         //			throw new JO_Exception(
         //				'Controller "' . $controller . '" is not found'
         //			);
     }
 }