當前位置: 首頁>>代碼示例>>PHP>>正文


PHP FlattenException::getTraceAsString方法代碼示例

本文整理匯總了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);
 }
開發者ID:tarlepp,項目名稱:silex-backend,代碼行數:34,代碼來源:ExceptionHandler.php


注:本文中的Symfony\Component\Debug\Exception\FlattenException::getTraceAsString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。