Exemplo n.º 1
0
 /**
  * Handler to catch uncaught exception.
  * @param  \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';
         } elseif (PHP_SAPI === 'cli') {
             fwrite(STDERR, "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);
     }
 }
Exemplo n.º 2
0
 /**
  * @return ILogger
  */
 public static function getFireLogger()
 {
     if (!self::$fireLogger) {
         self::$fireLogger = new FireLogger();
     }
     return self::$fireLogger;
 }
Exemplo n.º 3
0
 /**
  * Handler to catch uncaught exception.
  * @param  \Exception
  * @return void
  * @internal
  */
 public static function _exceptionHandler(\Exception $exception, $exit = TRUE)
 {
     if (!self::$enabled) {
         return;
     }
     self::$enabled = FALSE;
     // prevent double rendering
     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);
     }
     try {
         if (self::$productionMode) {
             try {
                 self::log($exception, self::EXCEPTION);
             } catch (\Exception $e) {
                 echo 'FATAL ERROR: unable to log error';
             }
             if (self::isHtmlMode()) {
                 require __DIR__ . '/templates/error.phtml';
             } else {
                 echo "ERROR: the server encountered an internal error and was unable to complete your request.\n";
             }
         } else {
             if (!connection_aborted() && self::isHtmlMode()) {
                 self::getBlueScreen()->render($exception);
                 self::getBar()->render();
             } elseif (connection_aborted() || !self::fireLog($exception)) {
                 $file = self::log($exception, self::ERROR);
                 if (!headers_sent()) {
                     header("X-Tracy-Error-Log: {$file}");
                 }
                 echo "{$exception}\n" . ($file ? "(stored in {$file})\n" : '');
                 if (self::$browser) {
                     exec(self::$browser . ' ' . escapeshellarg($file));
                 }
             }
         }
         foreach (self::$onFatalError as $handler) {
             call_user_func($handler, $exception);
         }
     } catch (\Exception $e) {
         if (self::$productionMode) {
             echo self::isHtmlMode() ? '<meta name=robots content=noindex>FATAL ERROR' : 'FATAL ERROR';
         } else {
             echo 'FATAL ERROR: thrown ', get_class($e), ': ', $e->getMessage(), "\nwhile processing ", get_class($exception), ': ', $exception->getMessage(), "\n";
         }
     }
     if ($exit) {
         exit(254);
     }
 }