/**
  * {@inheritdoc}
  */
 public function render($debug, $type, array $error, $exception = null, $outputBuffer = null)
 {
     echo "\n";
     if ($debug) {
         if ($exception instanceof DebugException) {
             // debug exception
             echo "[Debug";
             if (null !== $exception->getTitle()) {
                 echo ': ', $exception->getTitle();
             }
             echo "]\n\n", $exception->getMessage();
         } else {
             // error or exception
             echo '[', ErrorHandler::getErrorTypeName($type), "]\n\n";
             if (null === $exception) {
                 // error
                 echo DebugUtil::formatArray($error, ' > ');
             } else {
                 // exception
                 echo DebugUtil::formatException($exception, ' > ');
             }
         }
     } else {
         // non-debug
         echo 'Internal application error';
     }
 }
Пример #2
0
 /**
  * Handle fatal error
  *
  * @param int             $type      error type (ErrorHandler::ERROR_X)
  * @param array           $error     error parameters (message, file, line, [code])
  * @param object|null $exception exception instance if available
  */
 protected function onFatalError($type, array $error, $exception = null)
 {
     if ($this->handlingFatalError) {
         return;
     }
     $this->handlingFatalError = true;
     $isCli = 'cli' === PHP_SAPI;
     $headersSent = true;
     $additionalException = null;
     try {
         // fix working directory
         if (null !== $this->root) {
             chdir($this->root);
         }
         // attempt to replace current headers and clean buffers
         if (!$isCli) {
             $headersSent = !DebugUtil::replaceHeaders(array('HTTP/1.1 500 Internal Server Error'));
         }
         $outputBuffer = DebugUtil::cleanBuffers(true);
         // dispatch event
         if (null !== $this->eventDispatcher) {
             $event = $this->eventDispatcher->dispatch('error_handler.fatal', new Event(array('type' => $type, 'error' => $error, 'exception' => $exception, 'output_buffer' => $outputBuffer, 'is_cli' => $isCli)));
             if ($event->isPropagationStopped()) {
                 // return if the propagation has been stopped
                 return;
             }
         }
         // render error
         $this->getErrorRenderer($isCli ? ErrorRendererInterface::INTERFACE_CLI : ErrorRendererInterface::INTERFACE_WEB)->render($this->debug, $type, $error, $exception, $outputBuffer);
     } catch (\Exception $additionalException) {
     } catch (\Throwable $additionalException) {
     }
     if ($additionalException) {
         // something went terribly wrong
         // additional exception occured when handling the error
         if ($this->debug) {
             // detailed information in debug
             if (!$headersSent) {
                 header('Content-Type: text/plain; charset=UTF-8');
             }
             if ($isCli) {
                 echo "\n";
             }
             echo "Fatal error handler state. Additional exception occured:\n\n";
             $padding = ' > ';
             // additional exception
             echo DebugUtil::formatException($additionalException, $padding);
             // original error
             echo "\n\nOriginal error:\n\n";
             if (null !== $exception) {
                 echo DebugUtil::formatException($exception, $padding);
             } else {
                 echo DebugUtil::formatArray($error, $padding);
             }
         } else {
             // plain message in production
             echo 'Internal server error';
         }
     }
     $this->handlingFatalError = false;
 }
 /**
  * Render arguments
  *
  * @param  array  $args array of arguments
  * @return string html
  */
 public function renderArguments(array $args)
 {
     $html = "<table class=\"argumentList\"><tbody>\n";
     for ($i = 0, $argCount = sizeof($args); $i < $argCount; ++$i) {
         $html .= "<tr><th>{$i}</th><td><pre>" . $this->escape(DebugUtil::getDump($args[$i])) . "</pre></td></tr>\n";
     }
     $html .= "</tbody></table>\n";
     return $html;
 }