/** * 启动控制器 * * @param string $uri 路径 * * @return Controller */ public static function run($uri) { $c = new self($uri); $c->cutURI(); $c->dispatch(); try { $c->execute(); } catch (\Exception $e) { Error::exceptionHandler($e); } finally { if ($c->outputAllow) { Responder::write(); } } return $c; }
/** * 捕获到的错误 * * @param $code * @param string $msg * @param bool $fatal 是否致命错误 * @param array $param 传递的其它参数 */ protected static function error($code, $msg, $fatal, $param = []) { if ($fatal) { $method = '_' . $code; } else { $method = 'client_error'; } $action = self::getAction($method); $action->header('code', $code); $action->header('msg', $msg); if (Controller::current()->getMime() === 'html') { $action->out('title', $action->getFromData('title') ?: '有错误发生'); $action->out('code', $code); $action->out('msg', $msg); Controller::current()->setTemplate('error/error'); } if ($fatal && RUN_MODE === 'develop') { $action->out('trace', self::getTrace()); } $action->{$method}(...$param); Responder::write(); //致命错误 //if($fatal){ die; //} }