/**
  * @return array
  */
 public function display()
 {
     $hide = true;
     if (Ip::isAdmin() || Ip::isLocal()) {
         $hide = false;
     }
     if ($this->code == 500 && $hide) {
         return ['status' => $this->code, 'message' => 'Internal server error'];
     }
     $return = ['status' => $this->code, 'message' => $this->message];
     if ($this->getPrevious()) {
         if (isset($return['message'])) {
             $message = $return['message'];
         }
         $return = array_merge($return, $this->export($this->getPrevious()));
         if (isset($message) && $message) {
             $return['message'] = $message;
         }
         if ($this->getPrevious()->getPrevious()) {
             $return['previous'] = $this->export($this->getPrevious()->getPrevious());
         }
     }
     return $return;
 }
Esempio n. 2
0
 /**
  * @param \Throwable $exception
  *
  * @return bool
  */
 public static function exceptionHandler(\Throwable $exception)
 {
     // This error code is not included in error_reporting
     if (!error_reporting() || $exception->getLine() == 0) {
         return;
     }
     if ('cli' === PHP_SAPI || isset($_SERVER['HTTP_USER_AGENT']) && stripos($_SERVER['HTTP_USER_AGENT'], 'curl') !== false) {
         $formatterClass = '\\Cawa\\Error\\Formatter\\CliFormatter';
     } else {
         $formatterClass = '\\Cawa\\Error\\Formatter\\HtmlFormatter';
     }
     if (AbstractApp::isInit() && AbstractApp::instance() instanceof HttpApp) {
         self::log($exception);
         self::response()->setStatus(500);
         if (AbstractApp::env() != AbstractApp::PROD || Ip::isAdmin()) {
             $formatter = new $formatterClass();
             self::render($formatter, $exception);
         } else {
             self::clearAllBuffer();
             echo self::router()->returnError(500);
         }
         AbstractApp::instance()->end();
     } else {
         if (!headers_sent()) {
             header('HTTP/1.1 500 Internal Server Error');
         }
         if (AbstractApp::env() != AbstractApp::PROD) {
             $formatter = new $formatterClass();
             self::render($formatter, $exception);
         } else {
             self::clearAllBuffer();
             echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . "\n" . '<html><head>' . "\n" . '<title>' . self::response()->getStatusString(500) . '</title>' . "\n" . '</head><body>' . "\n" . '<h1>' . self::response()->getStatusString(500) . '</h1>' . "\n" . '</body></html>';
         }
     }
 }