本文整理汇总了PHP中Symfony\Component\HttpKernel\Exception\FlattenException::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException::toArray方法的具体用法?PHP FlattenException::toArray怎么用?PHP FlattenException::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\HttpKernel\Exception\FlattenException
的用法示例。
在下文中一共展示了FlattenException::toArray方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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)
{
$title = '';
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 {
$message = nl2br($exception->getMessage());
$class = $this->abbrClass($exception->getClass());
$count = count($exception->getAllPrevious());
$content = '';
foreach ($exception->toArray() as $position => $e) {
$ind = $count - $position + 1;
$total = $count + 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 $i => $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;
}