Ejemplo n.º 1
0
 public function exceptionDispatch(Exception $ex)
 {
     try {
         if (Hayate_Event::run('hayate.exception', array($this, $ex))) {
             return;
         }
         // try to dispatch to the current module error.php controller
         $module = $this->module();
         $filepath = $this->modulesPath . $module . '/controllers/error.php';
         // if the error controller does not exists in the current module
         // look in the default module
         if (!is_file($filepath)) {
             $module = Hayate_Config::getInstance()->get('default_module', 'default');
             $filepath = $this->modulesPath . $module . '/controllers/error.php';
         }
         if (is_file($filepath)) {
             require_once $filepath;
             $classname = ucfirst($module) . '_ErrorController';
             $rfc = new ReflectionClass($classname);
             if ($rfc->isSubclassOf('Hayate_Controller') && $rfc->isInstantiable()) {
                 $controller = $rfc->newInstance();
                 $action = $rfc->hasMethod('index') ? $rfc->getMethod('index') : $rfc->getMethod('__call');
                 if ($action->isPublic()) {
                     $action->invokeArgs($controller, array($ex));
                 }
             }
         } else {
             $display_errors = Hayate_Config::getInstance()->get('display_errors', false);
             if ($display_errors && $this->errorReporter) {
                 Hayate_Event::remove('hayate.send_headers');
                 Hayate_Event::remove('hayate.render');
                 $this->errorReporter->setException($ex);
                 echo $this->errorReporter->report();
             }
         }
     } catch (Exception $ex) {
     }
 }