public function 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

1 call to ExceptionHandler::getContent()
ExceptionHandler::createResponse in drupal/core/vendor/symfony/debug/Symfony/Component/Debug/ExceptionHandler.php
Creates the error Response associated with the given Exception.

File

drupal/core/vendor/symfony/debug/Symfony/Component/Debug/ExceptionHandler.php, line 125

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
          ->abbrClass($e['class']);
        $message = nl2br($e['message']);
        $content .= sprintf(<<<EOF
                        <div class="block_exception clear_fix">
                            <h2><span>%d/%d</span> %s: %s</h2>
                        </div>
                        <div class="block">
                            <ol class="traces list_exception">

EOF
, $ind, $total, $class, $message);
        foreach ($e['trace'] as $trace) {
          $content .= '       <li>';
          if ($trace['function']) {
            $content .= sprintf('at %s%s%s(%s)', $this
              ->abbrClass($trace['class']), $trace['type'], $trace['function'], $this
              ->formatArgs($trace['args']));
          }
          if (isset($trace['file']) && isset($trace['line'])) {
            if ($linkFormat = ini_get('xdebug.file_link_format')) {
              $link = str_replace(array(
                '%f',
                '%l',
              ), array(
                $trace['file'],
                $trace['line'],
              ), $linkFormat);
              $content .= sprintf(' in <a href="%s" title="Go to source">%s line %s</a>', $link, $trace['file'], $trace['line']);
            }
            else {
              $content .= sprintf(' in %s line %s', $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($exception), $exception
          ->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;
}