@@ -27,12 +27,12 @@ The most common way to listen to an event is to register an **event listener**::
27
27
namespace App\EventListener;
28
28
29
29
use Symfony\Component\HttpFoundation\Response;
30
- use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent ;
30
+ use Symfony\Component\HttpKernel\Event\ExceptionEvent ;
31
31
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
32
32
33
33
class ExceptionListener
34
34
{
35
- public function onKernelException(GetResponseForExceptionEvent $event)
35
+ public function onKernelException(ExceptionEvent $event)
36
36
{
37
37
// You get the exception object from the received event
38
38
$exception = $event->getException();
@@ -63,10 +63,16 @@ The most common way to listen to an event is to register an **event listener**::
63
63
.. tip ::
64
64
65
65
Each event receives a slightly different type of ``$event `` object. For
66
- the ``kernel.exception `` event, it is :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForExceptionEvent `.
66
+ the ``kernel.exception `` event, it is :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent `.
67
67
Check out the :doc: `Symfony events reference </reference/events >` to see
68
68
what type of object each event provides.
69
69
70
+ .. versionadded ::
71
+
72
+ The :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ ExceptionEvent ` class was
73
+ introduced in Symfony 4.3. In previous versions it was called
74
+ ``Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent ``.
75
+
70
76
Now that the class is created, you need to register it as a service and
71
77
notify Symfony that it is a "listener" on the ``kernel.exception `` event by
72
78
using a special "tag":
@@ -151,7 +157,7 @@ listen to the same ``kernel.exception`` event::
151
157
namespace App\EventSubscriber;
152
158
153
159
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
154
- use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent ;
160
+ use Symfony\Component\HttpKernel\Event\ExceptionEvent ;
155
161
use Symfony\Component\HttpKernel\KernelEvents;
156
162
157
163
class ExceptionSubscriber implements EventSubscriberInterface
@@ -168,17 +174,17 @@ listen to the same ``kernel.exception`` event::
168
174
];
169
175
}
170
176
171
- public function processException(GetResponseForExceptionEvent $event)
177
+ public function processException(ExceptionEvent $event)
172
178
{
173
179
// ...
174
180
}
175
181
176
- public function logException(GetResponseForExceptionEvent $event)
182
+ public function logException(ExceptionEvent $event)
177
183
{
178
184
// ...
179
185
}
180
186
181
- public function notifyException(GetResponseForExceptionEvent $event)
187
+ public function notifyException(ExceptionEvent $event)
182
188
{
183
189
// ...
184
190
}
@@ -207,11 +213,11 @@ or a "sub request"::
207
213
// src/EventListener/RequestListener.php
208
214
namespace App\EventListener;
209
215
210
- use Symfony\Component\HttpKernel\Event\GetResponseEvent ;
216
+ use Symfony\Component\HttpKernel\Event\RequestEvent ;
211
217
212
218
class RequestListener
213
219
{
214
- public function onKernelRequest(GetResponseEvent $event)
220
+ public function onKernelRequest(RequestEvent $event)
215
221
{
216
222
if (!$event->isMasterRequest()) {
217
223
// don't do anything if it's not the master request
0 commit comments