Beispiel #1
0
 /**
  * Handler to catch uncaught exception.
  * @param  \Exception|\Throwable
  * @return void
  * @internal
  */
 public static function exceptionHandler($exception, $exit = TRUE)
 {
     if (self::$done) {
         return;
     }
     self::$done = TRUE;
     if (!headers_sent()) {
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
         $code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== FALSE ? 503 : 500;
         header("{$protocol} {$code}", TRUE, $code);
         if (self::isHtmlMode()) {
             header('Content-Type: text/html; charset=UTF-8');
         }
     }
     if (self::$productionMode) {
         try {
             self::log($exception, self::EXCEPTION);
         } catch (\Exception $e) {
         }
         if (self::isHtmlMode()) {
             $logged = empty($e);
             require self::$errorTemplate ?: __DIR__ . '/assets/Debugger/error.500.phtml';
         } elseif (PHP_SAPI === 'cli') {
             fwrite(STDERR, 'ERROR: application encountered an error and can not continue. ' . (isset($e) ? "Unable to log error.\n" : "Error was logged.\n"));
         }
     } elseif (!connection_aborted() && self::isHtmlMode()) {
         self::getBlueScreen()->render($exception);
         self::getBar()->render();
     } else {
         self::fireLog($exception);
         try {
             $file = self::log($exception, self::EXCEPTION);
             if ($file && !headers_sent()) {
                 header("X-Tracy-Error-Log: {$file}");
             }
             echo "{$exception}\n" . ($file ? "(stored in {$file})\n" : '');
             if ($file && self::$browser) {
                 exec(self::$browser . ' ' . escapeshellarg($file));
             }
         } catch (\Exception $e) {
             echo "{$exception}\nUnable to log error: {$e->getMessage()}\n";
         }
     }
     try {
         foreach (self::$onFatalError as $handler) {
             call_user_func($handler, $exception);
         }
     } catch (\Exception $e) {
         try {
             self::log($e, self::EXCEPTION);
         } catch (\Exception $e) {
         }
     }
     if ($exit) {
         exit(254);
     }
 }
Beispiel #2
0
 /**
  * Handler to catch uncaught exception.
  * @return void
  * @internal
  */
 public static function exceptionHandler(\Exception $exception, $exit = TRUE)
 {
     if (self::$done) {
         return;
     }
     self::$done = TRUE;
     if (!headers_sent()) {
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
         $code = isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE ') !== FALSE ? 503 : 500;
         header("{$protocol} {$code}", TRUE, $code);
         if (self::isHtmlMode()) {
             header('Content-Type: text/html; charset=UTF-8');
         }
     }
     $logMsg = 'Unable to log error. Check if directory is writable and path is absolute.';
     if (self::$productionMode) {
         try {
             self::log($exception, self::EXCEPTION);
         } catch (\Exception $e) {
         }
         $error = isset($e) ? $logMsg : NULL;
         if (self::isHtmlMode()) {
             require __DIR__ . '/templates/error.phtml';
         } else {
             echo "ERROR: application encountered an error and can not continue.\n{$error}\n";
         }
     } elseif (!connection_aborted() && self::isHtmlMode()) {
         self::getBlueScreen()->render($exception);
         self::getBar()->render();
     } elseif (connection_aborted() || !self::fireLog($exception)) {
         try {
             $file = self::log($exception, self::EXCEPTION);
             if ($file && !headers_sent()) {
                 header("X-Tracy-Error-Log: {$file}");
             }
             echo "{$exception}\n" . ($file ? "(stored in {$file})\n" : '');
             if ($file && self::$browser) {
                 exec(self::$browser . ' ' . escapeshellarg($file));
             }
         } catch (\Exception $e) {
             echo "{$exception}\n{$logMsg} {$e->getMessage()}\n";
         }
     }
     try {
         foreach (self::$onFatalError as $handler) {
             call_user_func($handler, $exception);
         }
     } catch (\Exception $e) {
         try {
             self::log($e, self::EXCEPTION);
         } catch (\Exception $e) {
         }
     }
     if ($exit) {
         exit(254);
     }
 }