You are here

public static function FlattenException::create in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/debug/Exception/FlattenException.php \Symfony\Component\HttpKernel\Exception\FlattenException::create()

File

vendor/symfony/debug/Exception/FlattenException.php, line 76

Class

FlattenException
FlattenException wraps a PHP Exception to be able to serialize it.

Namespace

Symfony\Component\HttpKernel\Exception

Code

public static function create(\Exception $exception, $statusCode = null, array $headers = array()) {
  $e = new static();
  $e
    ->setMessage($exception
    ->getMessage());
  $e
    ->setCode($exception
    ->getCode());
  if ($exception instanceof HttpExceptionInterface) {
    $statusCode = $exception
      ->getStatusCode();
    $headers = array_merge($headers, $exception
      ->getHeaders());
  }
  if (null === $statusCode) {
    $statusCode = 500;
  }
  $e
    ->setStatusCode($statusCode);
  $e
    ->setHeaders($headers);
  $e
    ->setTraceFromException($exception);
  $e
    ->setClass(get_class($exception));
  $e
    ->setFile($exception
    ->getFile());
  $e
    ->setLine($exception
    ->getLine());
  if ($exception
    ->getPrevious()) {
    $e
      ->setPrevious(static::create($exception
      ->getPrevious()));
  }
  return $e;
}