Example #1
0
    /**
     * Render an exception
     *
     * @param object $exception the exception instance
     * @param int    $index     index of the current exception
     * @param int    $total     total number of exceptions
     * @return string html
     */
    public function renderException($exception, $index, $total)
    {
        $trace = $exception->getTrace();
        $isMain = 0 === $index;
        $number = $index + 1;
        $message = '';
        $info = '';
        $title = Debug::getExceptionName($exception);
        $titleTag = $isMain ? 'h1' : 'h2';
        $message = '<p class="message">' . nl2br($this->escape($exception->getMessage()), false) . '</p>';
        $info = "\n<p>in <em>" . $this->renderFilePath($exception->getFile()) . "</em> on line <em>" . $exception->getLine() . "</em></p>";
        // title, message, file
        $html = <<<HTML
<div class="group exception">
<i class="icon icon-warning"></i>
<div class="section major">
    <{$titleTag}><em>{$number}/{$total}</em> {$title}</{$titleTag}>
    {$message}{$info}
</div>

HTML;
        // code preview
        $codePreview = $this->renderCodePreview($exception->getFile(), $exception->getLine(), $isMain ? 5 : 3);
        if (null !== $codePreview) {
            $html .= "\n<div class=\"section\">{$codePreview}</div>\n";
            $codePreview = null;
        }
        // trace
        if ($trace) {
            $html .= $this->renderTrace($trace);
        }
        // context
        if ($exception instanceof ContextualErrorException) {
            $html .= $this->renderContext($exception->getContext());
        }
        $html .= "</div>\n";
        return $html;
    }