Exemplo n.º 1
0
Arquivo: N2nVars.php Projeto: n2n/n2n
 public static function getMimeTypeDetector()
 {
     if (!isset(self::$mimeTypeDetector)) {
         self::$mimeTypeDetector = new MimeTypeDetector(N2N::getVarStore()->requestFileFsPath(VarStore::CATEGORY_ETC, N2N::NS, null, self::MIMETYPES_ETC_FILE));
     }
     return self::$mimeTypeDetector;
 }
Exemplo n.º 2
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);
 }
Exemplo n.º 3
0
 /**
  * 
  * @param string $typeName
  * @throws TypeLoaderErrorException
  */
 public static function load($typeName)
 {
     try {
         self::requireScript(self::getFilePathOfTypeWihtoutCheck($typeName), $typeName);
         return true;
     } catch (TypeNotFoundException $e) {
         $lutp = N2N::getLastUserTracePoint();
         self::$latestException = new TypeLoaderErrorException($typeName, $e->getMessage(), 0, E_ERROR, $lutp['file'], $lutp['line']);
         return false;
     }
     /*catch (\Exception $e) {
     			self::$exceptionHandler->handleThrowable($e);
     			die();
     		}*/
     return false;
 }
Exemplo n.º 4
0
Arquivo: N2N.php Projeto: n2n/n2n
 /**
  * 
  */
 public static function shutdown()
 {
     self::$exceptionHandler->checkForFatalErrors();
     if (!self::$exceptionHandler->isStable()) {
         return;
     }
     try {
         if (!N2N::isInitialized()) {
             return;
         }
         if (N2N::isHttpContextAvailable()) {
             N2N::getCurrentResponse()->flush();
         }
     } catch (\Throwable $t) {
         self::$exceptionHandler->handleThrowable($t);
     }
 }