getAllPrevious() public method

public getAllPrevious ( )
コード例 #1
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     *
     * @return string The content as a string
     */
    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>{$title}</h1>
                {$content}
            </div>
EOF;
    }
コード例 #2
0
ファイル: ExceptionHandler.php プロジェクト: keboola/syrup
    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;
                $truncated = 0;
                foreach ($exception->toArray() as $position => $e) {
                    if (mb_strlen($content, '8bit') > 12 * 1024 * 1024) {
                        $truncated++;
                        continue;
                    }
                    $ind = $count - $position + 1;
                    $class = $this->formatClass($e['class']);
                    $message = nl2br($this->escapeHtml($e['message']));
                    $contentTemplate = <<<EOF
                        <h2 class="block_exception clear_fix">
                            <span class="exception_counter">%d/%d</span>
                            <span class="exception_title">%s (%d)%s:</span>
                            <span class="exception_message">%s</span>
                        </h2>
                        <div class="block">
EOF;
                    $content .= sprintf($contentTemplate, $ind, $total, $class, empty($e['code']) ? 0 : $e['code'], $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']), $message);
                    if (!empty($e['data'])) {
                        $content .= '<h2>Data</h2>';
                        $content .= '<pre>' . json_encode($e['data'], JSON_PRETTY_PRINT) . '</pre>';
                    }
                    $content .= '<h2 style="margin-top:10px">Trace</h2>';
                    $content .= '<ol class="traces list_exception">';
                    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";
                }
                $content .= sprintf('<div class="block">%s exceptions truncated</div>', $truncated);
            } 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), $e->getMessage());
                } else {
                    $title = 'Whoops, looks like something went wrong.';
                }
            }
        }
        return <<<EOF
            <div id="sf-resetcontent" class="sf-reset">
                <h1>{$title}</h1>
                {$content}
            </div>
EOF;
    }
コード例 #3
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     *
     * @return string The content as a string
     */
    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>{$title}</h1>
                {$content}
            </div>
EOF;
    }
コード例 #4
0
    /**
     * Gets the HTML content associated with the given exception.
     *
     * @param FlattenException $exception A FlattenException instance
     * @param bool             $showAll   Show all exceptions or just the last one
     *
     * @return string The content as a string
     */
    public function getContent(FlattenException $exception, $showAll = true)
    {
        switch ($exception->getStatusCode()) {
            case 404:
                $title = "The page you are looking for could not be found";
                break;
            default:
                $title = "Oh noes, something's broken";
        }
        $content = '';
        if ($this->debug) {
            try {
                $exceptions = $exception->toArray();
                if (false === $showAll) {
                    $exceptions = array_slice($exceptions, -1, 1);
                    $count = 1;
                    $total = 1;
                } else {
                    $count = count($exception->getAllPrevious());
                    $total = $count + 1;
                }
                foreach ($exceptions as $position => $e) {
                    $i = 0;
                    $class = $this->abbrClass($e['class']);
                    $message = nl2br($e['message']);
                    if (false === $showAll) {
                        $content .= sprintf(<<<EOT
                        <div>
                            <h3 class="alert alert-error">%s: %s</h3>
                        </div>
EOT
, $class, $message);
                    } else {
                        $ind = $count - $position + 1;
                        $content .= sprintf(<<<EOT
                        <div>
                            <h3 class="alert alert-error">%d/%d %s: %s</h3>
                        </div>
EOT
, $ind, $total, $class, $message);
                    }
                    $content .= <<<EOT
                        <div>
                            <table class="table table-bordered table-striped"><tbody>
EOT;
                    foreach ($e['trace'] as $trace) {
                        $i++;
                        $content .= '       <tr><td>' . $i . '</td><td>';
                        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 .= "</td</tr>\n";
                    }
                    $content .= "    </tbody></table>\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 = "Uh oh something's broken";
                }
            }
        }
        list($quote, $author) = $this->getQuote();
        $statusCode = $exception->getStatusCode();
        $ppiLogo = $this->getPpiLogo();
        return <<<EOF
            <div class="page-header well">
                <h1 title="An exception has occurred - Code {$statusCode}"><img src="{$ppiLogo}" height="56" width="89">&nbsp;{$title}.</h1>
                <p class="muted quote"><i>"{$quote}"</i> &mdash; {$author}</p>
            </div>
            <div class="ppi-container well">
                {$content}
            </div>
EOF;
    }