/** * Sends a nice detailed view to the Response * * @param \Exception $e */ private function renderBeautifulExceptionView(\Throwable $e) { $request = N2N::getCurrentRequest(); $response = N2N::getCurrentResponse(); $status = null; $viewName = null; if ($e instanceof StatusException) { $status = $e->getStatus(); } else { $status = Response::STATUS_500_INTERNAL_SERVER_ERROR; } $throwableModel = null; // if ($e instanceof StatusException && isset($viewName)) { // $throwableModel = new ThrowableModel($e, null); // } else { $throwableModel = new ThrowableModel($e); $this->pendingOutputs[] = $response->fetchBufferedOutput(false); $that = $this; $throwableModel->setOutputCallback(function () use($that) { $output = implode('', $this->pendingOutputs); $this->pendingOutputs = array(); return $output; }); // } $viewName = N2N::getAppConfig()->error()->getErrorViewName($status); if ($viewName === null) { if (!N2N::isDevelopmentModeOn()) { $viewName = self::DEFAULT_STATUS_LIVE_VIEW; } else { if ($status == Response::STATUS_500_INTERNAL_SERVER_ERROR) { $viewName = self::DEFAULT_500_DEV_VIEW; } else { $viewName = self::DEFAULT_STATUS_DEV_VIEW; } } } $view = N2N::getN2nContext()->lookup(ViewFactory::class)->create($viewName, array('throwableModel' => $throwableModel)); $view->setControllerContext(new ControllerContext($request->getCmdPath(), $request->getCmdContextPath())); $response->reset(); $response->setStatus($status); $response->send($view); }
/** * @param string $publicDirPath * @param string $varDirPath * @param array $moduleDirPaths */ public static function initialize(string $publicDirPath, string $varDirPath, N2nCache $n2nCache, ModuleFactory $moduleFactory = null) { mb_internal_encoding(self::CHARSET); // ini_set('default_charset', self::CHARSET); self::$exceptionHandler = new ExceptionHandler(N2N::isDevelopmentModeOn()); register_shutdown_function(array('n2n\\core\\N2N', 'shutdown')); self::$n2n = new N2N(new FsPath(IoUtils::realpath($publicDirPath)), new FsPath(IoUtils::realpath($varDirPath))); if ($moduleFactory === null) { $moduleFactory = new EtcModuleFactory(); } self::$n2n->initModules($moduleFactory); self::$n2n->init($n2nCache); self::$initialized = true; self::initLogging(self::$n2n); self::$exceptionHandler->checkForStartupErrors(); }