当前位置: 首页>>代码示例>>PHP>>正文


PHP FlattenException::toArray方法代码示例

本文整理汇总了PHP中Symfony\Component\Debug\Exception\FlattenException::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException::toArray方法的具体用法?PHP FlattenException::toArray怎么用?PHP FlattenException::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Debug\Exception\FlattenException的用法示例。


在下文中一共展示了FlattenException::toArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: showAction

 /**
  * Converts an Exception to a Response.
  *
  * A "showException" request parameter can be used to force display of an error page (when set to false) or
  * the exception page (when true). If it is not present, the "debug" value passed into the constructor will
  * be used.
  *
  * @param Request              $request   The request
  * @param FlattenException     $exception A FlattenException instance
  * @param DebugLoggerInterface $logger    A DebugLoggerInterface instance
  *
  * @return Response
  *
  * @throws \InvalidArgumentException When the exception template does not exist
  */
 public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
 {
     $showException = $request->attributes->get('showException', $this->debug);
     // As opposed to an additional parameter, this maintains BC
     $code = $exception->getStatusCode();
     $response = ['error' => $code, 'message' => isset(Response::$statusTexts[$code]) ? Response::$statusTexts[$code] : ''];
     if ($showException) {
         $response['exception'] = $exception->toArray();
     }
     return new JsonResponse($response, $code);
 }
开发者ID:e-moe,项目名称:data-service,代码行数:26,代码来源:ExceptionController.php

示例2: getContent

    /**
     * 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;
    }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:64,代码来源:ExceptionHandler.php

示例3: getContent

    /**
     * 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;
    }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:67,代码来源:ExceptionHandler.php

示例4: getTrace

 private function getTrace(FlattenException $exception)
 {
     $all = $exception->toArray();
     $str = '';
     foreach ($all as $e) {
         $traces = $e['trace'];
         foreach ($traces as $trace) {
             $str .= "in file " . $trace['file'] . " on line " . $trace['line'] . PHP_EOL;
         }
     }
     return $str;
 }
开发者ID:keboola,项目名称:syrup,代码行数:12,代码来源:ExceptionHandler.php

示例5: getContent

    public function getContent(FlattenException $exception)
    {
        $content = '';
        $title = 'Exception Report';
        try {
            foreach ($exception->toArray() as $position => $e) {
                $class = $this->formatClass($e['class']);
                $message = nl2br($this->escapeHtml($e['message']));
                $content .= sprintf(<<<EOF
                    <h2>%s</h2>
                    <h3>Type: %s</h3>
                    <div style="margin-bottom: 50px;">
                        <ol>

EOF
, $message, $class, $this->formatPath($e['trace'][0]['file'], $e['trace'][0]['line']));
                foreach ($e['trace'] as $trace) {
                    $content .= '       <li style="border-bottom: 1px solid ' . $this->colors['trace_item_delimiter'] . '; padding: 5px 0 9px 0; margin: 0;">';
                    if (isset($trace['file']) && isset($trace['line'])) {
                        $content .= '<p>' . $this->formatPath($trace['file'], $trace['line']) . '</p>';
                    }
                    if ($trace['function']) {
                        $content .= sprintf('<p>at %s<span style="color: ' . $this->colors['error_position'] . '">%s%s</span>( %s )</p>', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
                    }
                    unset($trace['file'], $trace['line'], $trace['short_class'], $trace['namespace']);
                    if (empty($trace['class'])) {
                        unset($trace['class']);
                        if (empty($trace['type'])) {
                            unset($trace['type']);
                        }
                    }
                    //$content .= '<pre>' . json_encode($trace, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . '</pre>';
                    $content .= "</li>\n";
                }
                $content .= "    </ol>\n</div>";
            }
        } catch (\Exception $e) {
            // something nasty happened and we cannot throw an exception anymore
            $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
        }
        return <<<EOF
            <h1>{$title}</h1>
            {$content}
EOF;
    }
开发者ID:swayok,项目名称:laravel-extended-errors,代码行数:45,代码来源:ExceptionRenderer.php

示例6: getContent

    /**
     * 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;
    }
开发者ID:dragoonis,项目名称:framework,代码行数:93,代码来源:ExceptionHandler.php


注:本文中的Symfony\Component\Debug\Exception\FlattenException::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。