/** * Initialize the DisplayController class */ public function init() { try { parent::init(); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant le chargement du module: ' . $e->getMessage()); } if (file_exists(_CONTROLLERS_DIR_ . '/Tools.php')) { $url = Tools::getInstance()->request_url; $url .= '&id=ukn'; $controller = Tools::getInstance()->getUrl_controller($url); if ($controller == 'Display404Controller') { if (file_exists(_ERRORS_VIEWS_ . '/' . $this->view_name . '.tpl')) { try { echo $this->twig->render($this->view_name . '.tpl', array('bootstrapPath' => _BOOTSTRAP_FILE_)); } catch (Exception $e) { throw new Exception('Une erreur est survenue durant la récupération des données: ' . $e->getMessage()); } } else { throw new Exception('Le template "' . $this->view_name . '" n\'existe pas dans "' . _ERRORS_VIEWS_ . '"!'); } } else { throw new Exception('Une erreur est survenue durant la phase de routage!'); } } else { throw new Exception('L\'URL n\'est pas évaluable!'); } }
/** * 框架调用:异常统一处理,并且根据配置决定处理方式 * * @param object $exception */ public static function _exception($exception) { // APP的配置 $appCfg = QP_Sys::getAppCfg(); // 得到异常代码 $code = $exception->getCode(); // 永远抛出的异常 $allowException = array(QP_Exception::EXCEPTION_NO_CONTROLLER, QP_Exception::EXCEPTION_NO_ACTION); // 如果设置为显示异常 或 为永远抛出的异常则调用 Error 控制器 if (in_array($code, $allowException) || $appCfg['display_exception']) { // 调用 ErrorController 并且执行它 require APPLICATION_PATH . '/Controllers/ErrorController.php'; $errorController = new ErrorController(); $errorController->init(); $errorController->errorAction($exception); // 是否自动解析视图 if ($errorController->viewIsAutoRender()) { $errorController->view->setPath('Error'); echo $errorController->view->render('Error.html'); } } else { // 写日志 $msg = 'Exception Message:' . $exception->getMessage() . PHP_EOL; $msg .= 'Stack Trace:' . $exception->getTraceAsString() . PHP_EOL; self::log($msg, 'app'); } }