|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FOSRestBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace FOS\RestBundle\Exception; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Debug\Exception\FlattenException as LegacyFlattenException; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; |
|
16
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
17
|
|
|
|
|
18
|
|
|
if (method_exists(LegacyFlattenException::class, 'createFromThrowable')) { |
|
19
|
|
|
/** |
|
20
|
|
|
* @internal |
|
21
|
|
|
*/ |
|
22
|
|
|
class FlattenException extends LegacyFlattenException |
|
|
|
|
|
|
23
|
|
|
{ |
|
24
|
|
|
} |
|
25
|
|
|
} else { |
|
26
|
|
|
/** |
|
27
|
|
|
* @internal |
|
28
|
|
|
*/ |
|
29
|
|
|
class FlattenException extends LegacyFlattenException |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
private $traceAsString; |
|
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return static |
|
35
|
|
|
*/ |
|
36
|
|
|
public static function createFromThrowable(\Throwable $exception, int $statusCode = null, array $headers = []) |
|
37
|
|
|
{ |
|
38
|
|
|
$e = new static(); |
|
39
|
|
|
$e->setMessage($exception->getMessage()); |
|
40
|
|
|
$e->setCode($exception->getCode()); |
|
41
|
|
|
|
|
42
|
|
|
if ($exception instanceof HttpExceptionInterface) { |
|
43
|
|
|
$statusCode = $exception->getStatusCode(); |
|
44
|
|
|
$headers = array_merge($headers, $exception->getHeaders()); |
|
45
|
|
|
} elseif ($exception instanceof RequestExceptionInterface) { |
|
46
|
|
|
$statusCode = 400; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (null === $statusCode) { |
|
50
|
|
|
$statusCode = 500; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$e->setStatusCode($statusCode); |
|
54
|
|
|
$e->setHeaders($headers); |
|
55
|
|
|
$e->setTraceFromThrowable($exception); |
|
56
|
|
|
$e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception)); |
|
|
|
|
|
|
57
|
|
|
$e->setFile($exception->getFile()); |
|
58
|
|
|
$e->setLine($exception->getLine()); |
|
59
|
|
|
|
|
60
|
|
|
$previous = $exception->getPrevious(); |
|
61
|
|
|
|
|
62
|
|
|
if ($previous instanceof \Throwable) { |
|
63
|
|
|
$e->setPrevious(static::createFromThrowable($previous)); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
return $e; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function setTraceFromThrowable(\Throwable $throwable) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->traceAsString = $throwable->getTraceAsString(); |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
return $this->setTrace($throwable->getTrace(), $throwable->getFile(), $throwable->getLine()); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.