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\Event;
|
Chris@0
|
13
|
Chris@17
|
14 use Symfony\Component\HttpFoundation\Request;
|
Chris@0
|
15 use Symfony\Component\HttpKernel\HttpKernelInterface;
|
Chris@0
|
16
|
Chris@0
|
17 /**
|
Chris@0
|
18 * Allows to create a response for a thrown exception.
|
Chris@0
|
19 *
|
Chris@0
|
20 * Call setResponse() to set the response that will be returned for the
|
Chris@0
|
21 * current request. The propagation of this event is stopped as soon as a
|
Chris@0
|
22 * response is set.
|
Chris@0
|
23 *
|
Chris@0
|
24 * You can also call setException() to replace the thrown exception. This
|
Chris@0
|
25 * exception will be thrown if no response is set during processing of this
|
Chris@0
|
26 * event.
|
Chris@0
|
27 *
|
Chris@0
|
28 * @author Bernhard Schussek <bschussek@gmail.com>
|
Chris@0
|
29 */
|
Chris@0
|
30 class GetResponseForExceptionEvent extends GetResponseEvent
|
Chris@0
|
31 {
|
Chris@0
|
32 /**
|
Chris@0
|
33 * The exception object.
|
Chris@0
|
34 *
|
Chris@0
|
35 * @var \Exception
|
Chris@0
|
36 */
|
Chris@0
|
37 private $exception;
|
Chris@0
|
38
|
Chris@14
|
39 /**
|
Chris@14
|
40 * @var bool
|
Chris@14
|
41 */
|
Chris@14
|
42 private $allowCustomResponseCode = false;
|
Chris@14
|
43
|
Chris@0
|
44 public function __construct(HttpKernelInterface $kernel, Request $request, $requestType, \Exception $e)
|
Chris@0
|
45 {
|
Chris@0
|
46 parent::__construct($kernel, $request, $requestType);
|
Chris@0
|
47
|
Chris@0
|
48 $this->setException($e);
|
Chris@0
|
49 }
|
Chris@0
|
50
|
Chris@0
|
51 /**
|
Chris@0
|
52 * Returns the thrown exception.
|
Chris@0
|
53 *
|
Chris@0
|
54 * @return \Exception The thrown exception
|
Chris@0
|
55 */
|
Chris@0
|
56 public function getException()
|
Chris@0
|
57 {
|
Chris@0
|
58 return $this->exception;
|
Chris@0
|
59 }
|
Chris@0
|
60
|
Chris@0
|
61 /**
|
Chris@0
|
62 * Replaces the thrown exception.
|
Chris@0
|
63 *
|
Chris@0
|
64 * This exception will be thrown if no response is set in the event.
|
Chris@0
|
65 *
|
Chris@0
|
66 * @param \Exception $exception The thrown exception
|
Chris@0
|
67 */
|
Chris@0
|
68 public function setException(\Exception $exception)
|
Chris@0
|
69 {
|
Chris@0
|
70 $this->exception = $exception;
|
Chris@0
|
71 }
|
Chris@14
|
72
|
Chris@14
|
73 /**
|
Chris@14
|
74 * Mark the event as allowing a custom response code.
|
Chris@14
|
75 */
|
Chris@14
|
76 public function allowCustomResponseCode()
|
Chris@14
|
77 {
|
Chris@14
|
78 $this->allowCustomResponseCode = true;
|
Chris@14
|
79 }
|
Chris@14
|
80
|
Chris@14
|
81 /**
|
Chris@14
|
82 * Returns true if the event allows a custom response code.
|
Chris@14
|
83 *
|
Chris@14
|
84 * @return bool
|
Chris@14
|
85 */
|
Chris@14
|
86 public function isAllowingCustomResponseCode()
|
Chris@14
|
87 {
|
Chris@14
|
88 return $this->allowCustomResponseCode;
|
Chris@14
|
89 }
|
Chris@0
|
90 }
|