Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@0
|
4 * This file is part of the Symfony package.
|
Chris@0
|
5 *
|
Chris@0
|
6 * (c) Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
7 *
|
Chris@0
|
8 * For the full copyright and license information, please view the LICENSE
|
Chris@0
|
9 * file that was distributed with this source code.
|
Chris@0
|
10 */
|
Chris@0
|
11
|
Chris@0
|
12 namespace Symfony\Component\HttpKernel\DataCollector;
|
Chris@0
|
13
|
Chris@0
|
14 use Symfony\Component\Debug\Exception\FlattenException;
|
Chris@0
|
15 use Symfony\Component\HttpFoundation\Request;
|
Chris@0
|
16 use Symfony\Component\HttpFoundation\Response;
|
Chris@0
|
17
|
Chris@0
|
18 /**
|
Chris@0
|
19 * ExceptionDataCollector.
|
Chris@0
|
20 *
|
Chris@0
|
21 * @author Fabien Potencier <fabien@symfony.com>
|
Chris@0
|
22 */
|
Chris@0
|
23 class ExceptionDataCollector extends DataCollector
|
Chris@0
|
24 {
|
Chris@0
|
25 /**
|
Chris@0
|
26 * {@inheritdoc}
|
Chris@0
|
27 */
|
Chris@0
|
28 public function collect(Request $request, Response $response, \Exception $exception = null)
|
Chris@0
|
29 {
|
Chris@0
|
30 if (null !== $exception) {
|
Chris@0
|
31 $this->data = array(
|
Chris@0
|
32 'exception' => FlattenException::create($exception),
|
Chris@0
|
33 );
|
Chris@0
|
34 }
|
Chris@0
|
35 }
|
Chris@0
|
36
|
Chris@0
|
37 /**
|
Chris@0
|
38 * Checks if the exception is not null.
|
Chris@0
|
39 *
|
Chris@0
|
40 * @return bool true if the exception is not null, false otherwise
|
Chris@0
|
41 */
|
Chris@0
|
42 public function hasException()
|
Chris@0
|
43 {
|
Chris@0
|
44 return isset($this->data['exception']);
|
Chris@0
|
45 }
|
Chris@0
|
46
|
Chris@0
|
47 /**
|
Chris@0
|
48 * Gets the exception.
|
Chris@0
|
49 *
|
Chris@0
|
50 * @return \Exception The exception
|
Chris@0
|
51 */
|
Chris@0
|
52 public function getException()
|
Chris@0
|
53 {
|
Chris@0
|
54 return $this->data['exception'];
|
Chris@0
|
55 }
|
Chris@0
|
56
|
Chris@0
|
57 /**
|
Chris@0
|
58 * Gets the exception message.
|
Chris@0
|
59 *
|
Chris@0
|
60 * @return string The exception message
|
Chris@0
|
61 */
|
Chris@0
|
62 public function getMessage()
|
Chris@0
|
63 {
|
Chris@0
|
64 return $this->data['exception']->getMessage();
|
Chris@0
|
65 }
|
Chris@0
|
66
|
Chris@0
|
67 /**
|
Chris@0
|
68 * Gets the exception code.
|
Chris@0
|
69 *
|
Chris@0
|
70 * @return int The exception code
|
Chris@0
|
71 */
|
Chris@0
|
72 public function getCode()
|
Chris@0
|
73 {
|
Chris@0
|
74 return $this->data['exception']->getCode();
|
Chris@0
|
75 }
|
Chris@0
|
76
|
Chris@0
|
77 /**
|
Chris@0
|
78 * Gets the status code.
|
Chris@0
|
79 *
|
Chris@0
|
80 * @return int The status code
|
Chris@0
|
81 */
|
Chris@0
|
82 public function getStatusCode()
|
Chris@0
|
83 {
|
Chris@0
|
84 return $this->data['exception']->getStatusCode();
|
Chris@0
|
85 }
|
Chris@0
|
86
|
Chris@0
|
87 /**
|
Chris@0
|
88 * Gets the exception trace.
|
Chris@0
|
89 *
|
Chris@0
|
90 * @return array The exception trace
|
Chris@0
|
91 */
|
Chris@0
|
92 public function getTrace()
|
Chris@0
|
93 {
|
Chris@0
|
94 return $this->data['exception']->getTrace();
|
Chris@0
|
95 }
|
Chris@0
|
96
|
Chris@0
|
97 /**
|
Chris@0
|
98 * {@inheritdoc}
|
Chris@0
|
99 */
|
Chris@0
|
100 public function getName()
|
Chris@0
|
101 {
|
Chris@0
|
102 return 'exception';
|
Chris@0
|
103 }
|
Chris@0
|
104 }
|