@@ -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,7 +63,7 @@ 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
@@ -151,7 +151,7 @@ listen to the same ``kernel.exception`` event::
151
151
namespace App\EventSubscriber;
152
152
153
153
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
154
- use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent ;
154
+ use Symfony\Component\HttpKernel\Event\ExceptionEvent ;
155
155
use Symfony\Component\HttpKernel\KernelEvents;
156
156
157
157
class ExceptionSubscriber implements EventSubscriberInterface
@@ -168,17 +168,17 @@ listen to the same ``kernel.exception`` event::
168
168
];
169
169
}
170
170
171
- public function processException(GetResponseForExceptionEvent $event)
171
+ public function processException(ExceptionEvent $event)
172
172
{
173
173
// ...
174
174
}
175
175
176
- public function logException(GetResponseForExceptionEvent $event)
176
+ public function logException(ExceptionEvent $event)
177
177
{
178
178
// ...
179
179
}
180
180
181
- public function notifyException(GetResponseForExceptionEvent $event)
181
+ public function notifyException(ExceptionEvent $event)
182
182
{
183
183
// ...
184
184
}
@@ -187,6 +187,12 @@ listen to the same ``kernel.exception`` event::
187
187
That's it! Your ``services.yaml `` file should already be setup to load services from
188
188
the ``EventSubscriber `` directory. Symfony takes care of the rest.
189
189
190
+ .. tip ::
191
+
192
+ Since Symfony 4.3 you can subscribe to events using the FQCN of the event.
193
+ For example ``ExceptionEvent::class `` instead of ``KernelEvents::EXCEPTION ``.
194
+ This allows you to develop code based on pure PHP classes instead of inventing arbitrary strings to name events.
195
+
190
196
.. _ref-event-subscriber-configuration :
191
197
192
198
.. tip ::
@@ -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