本文整理匯總了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);
}