Exemplo n.º 1
0
 /**
  * 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);
 }