You are here

public function ExceptionHandler::getContent in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/debug/ExceptionHandler.php \Symfony\Component\Debug\ExceptionHandler::getContent()

Gets the HTML content associated with the given exception.

Parameters

FlattenException $exception A FlattenException instance:

Return value

string The content as a string

File

vendor/symfony/debug/ExceptionHandler.php, line 222

Class

ExceptionHandler
ExceptionHandler converts an exception to a Response object.

Namespace

Symfony\Component\Debug

Code

public function getContent(FlattenException $exception) {
  switch ($exception
    ->getStatusCode()) {
    case 404:
      $title = 'Sorry, the page you are looking for could not be found.';
      break;
    default:
      $title = 'Whoops, looks like something went wrong.';
  }
  $content = '';
  if ($this->debug) {
    try {
      $count = count($exception
        ->getAllPrevious());
      $total = $count + 1;
      foreach ($exception
        ->toArray() as $position => $e) {
        $ind = $count - $position + 1;
        $class = $this
          ->formatClass($e['class']);
        $message = nl2br($this
          ->escapeHtml($e['message']));
        $content .= sprintf(<<<EOF
                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">%d/%d</span>
                            <span class="exception_title">%s%s:</span>
                            <span class="exception_message">%s</span>
                        </h2>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $this
          ->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
        foreach ($e['trace'] as $trace) {
          $content .= '       <li>';
          if ($trace['function']) {
            $content .= sprintf('at %s%s%s(%s)', $this
              ->formatClass($trace['class']), $trace['type'], $trace['function'], $this
              ->formatArgs($trace['args']));
          }
          if (isset($trace['file']) && isset($trace['line'])) {
            $content .= $this
              ->formatPath($trace['file'], $trace['line']);
          }
          $content .= "</li>\n";
        }
        $content .= "    </ol>\n</div>\n";
      }
    } catch (\Exception $e) {

      // something nasty happened and we cannot throw an exception anymore
      if ($this->debug) {
        $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this
          ->escapeHtml($e
          ->getMessage()));
      }
      else {
        $title = 'Whoops, looks like something went wrong.';
      }
    }
  }
  return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{<span class="php-variable">$title</span>}</h1>
                {<span class="php-variable">$content</span>}
            </div>
EOF;
}