|
1 <?php |
|
2 |
|
3 /* |
|
4 * This file is part of the Symfony package. |
|
5 * |
|
6 * (c) Fabien Potencier <fabien@symfony.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 Symfony\Component\HttpKernel\Event; |
|
13 |
|
14 use Symfony\Component\HttpKernel\HttpKernelInterface; |
|
15 use Symfony\Component\HttpFoundation\Request; |
|
16 |
|
17 /** |
|
18 * Allows to create a response for a thrown exception |
|
19 * |
|
20 * Call setResponse() to set the response that will be returned for the |
|
21 * current request. The propagation of this event is stopped as soon as a |
|
22 * response is set. |
|
23 * |
|
24 * You can also call setException() to replace the thrown exception. This |
|
25 * exception will be thrown if no response is set during processing of this |
|
26 * event. |
|
27 * |
|
28 * @author Bernhard Schussek <bernhard.schussek@symfony.com> |
|
29 * |
|
30 * @api |
|
31 */ |
|
32 class GetResponseForExceptionEvent extends GetResponseEvent |
|
33 { |
|
34 /** |
|
35 * The exception object |
|
36 * @var \Exception |
|
37 */ |
|
38 private $exception; |
|
39 |
|
40 public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e) |
|
41 { |
|
42 parent::__construct($kernel, $request, $requestType); |
|
43 |
|
44 $this->setException($e); |
|
45 } |
|
46 |
|
47 /** |
|
48 * Returns the thrown exception |
|
49 * |
|
50 * @return \Exception The thrown exception |
|
51 * |
|
52 * @api |
|
53 */ |
|
54 public function getException() |
|
55 { |
|
56 return $this->exception; |
|
57 } |
|
58 |
|
59 /** |
|
60 * Replaces the thrown exception |
|
61 * |
|
62 * This exception will be thrown if no response is set in the event. |
|
63 * |
|
64 * @param \Exception $exception The thrown exception |
|
65 * |
|
66 * @api |
|
67 */ |
|
68 public function setException(\Exception $exception) |
|
69 { |
|
70 $this->exception = $exception; |
|
71 } |
|
72 } |