本文整理汇总了PHP中Symfony\Component\Debug\Exception\FlattenException::getTraceAsString方法的典型用法代码示例。如果您正苦于以下问题:PHP FlattenException::getTraceAsString方法的具体用法?PHP FlattenException::getTraceAsString怎么用?PHP FlattenException::getTraceAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Debug\Exception\FlattenException
的用法示例。
在下文中一共展示了FlattenException::getTraceAsString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendPhpResponse
/**
* Sends the error associated with the given Exception as a plain PHP response. This method uses plain PHP
* functions like header() and echo to output the response.
*
* Note that this will just generate pure JSON response of an error.
*
* @param \Exception|FlattenException $exception An \Exception or FlattenException instance
*
* @return void
*/
public function sendPhpResponse($exception)
{
// Store trace string
$traceString = $exception->getTraceAsString();
// Flatten current Exception
if (!$exception instanceof FlattenException) {
$exception = FlattenException::create($exception);
}
// Set headers, if those aren't yet set
if (!headers_sent()) {
header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
foreach ($exception->getHeaders() as $name => $value) {
header($name . ': ' . $value, false);
}
header('Content-Type: application/json; charset=UTF-8');
}
// Basic error data
$error = ['message' => $exception->getMessage(), 'status' => $exception->getStatusCode(), 'code' => $exception->getCode()];
// If we're running application in debug mode, attach some extra information about actual error
if ($this->debug) {
$error += ['debug' => ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTrace(), 'traceString' => $traceString]];
}
echo json_encode($error);
}