@@ -289,26 +289,31 @@ After the controller callable has been determined, ``HttpKernel::handle()``
289
289
dispatches the ``kernel.controller `` event. Listeners to this event might initialize
290
290
some part of the system that needs to be initialized after certain things
291
291
have been determined (e.g. the controller, routing information) but before
292
- the controller is executed. For some examples, see the Symfony section below.
292
+ the controller is executed.
293
+
294
+ Another typical use-case for this event is to retrieve the attributes from
295
+ the controller using the :method: `Symfony\\ Component\\ HttpKernel\\ Event\\ ControllerEvent::getAttributes `
296
+ method. See the Symfony section below for some examples.
297
+
298
+ .. versionadded :: 6.2
299
+
300
+ The ``ControllerEvent::getAttributes() `` method was introduced in Symfony 6.2.
293
301
294
302
Listeners to this event can also change the controller callable completely
295
303
by calling :method: `ControllerEvent::setController <Symfony\\ Component\\ HttpKernel\\ Event\\ ControllerEvent::setController> `
296
304
on the event object that's passed to listeners on this event.
297
305
298
306
.. sidebar :: ``kernel.controller`` in the Symfony Framework
299
307
300
- There are a few minor listeners to the ``kernel.controller `` event in
301
- the Symfony Framework, and many deal with collecting profiler data when
302
- the profiler is enabled.
308
+ An interesting listener to ``kernel.controller `` in the Symfony
309
+ Framework is :class: `Symfony\\ Component\\ HttpKernel\\ EventListener\\ CacheAttributeListener `.
310
+ This class fetches ``#[Cache] `` attribute configuration from the
311
+ controller and uses it to configure :doc: `HTTP caching </http_cache >`
312
+ on the response.
303
313
304
- One interesting listener comes from the `SensioFrameworkExtraBundle `_. This
305
- listener's `#[ParamConverter] `_ functionality allows you to pass a full object
306
- (e.g. a ``Post `` object) to your controller instead of a scalar value (e.g.
307
- an ``id `` parameter that was on your route). The listener -
308
- ``ParamConverterListener `` - uses reflection to look at each of the
309
- arguments of the controller and tries to use different methods to convert
310
- those to objects, which are then stored in the ``attributes `` property of
311
- the ``Request `` object. Read the next section to see why this is important.
314
+ There are a few other minor listeners to the ``kernel.controller `` event in
315
+ the Symfony Framework that deal with collecting profiler data when the
316
+ profiler is enabled.
312
317
313
318
4) Getting the Controller Arguments
314
319
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -749,6 +754,4 @@ Learn more
749
754
.. _reflection : https://www.php.net/manual/en/book.reflection.php
750
755
.. _FOSRestBundle : https://github.com/friendsofsymfony/FOSRestBundle
751
756
.. _`PHP FPM` : https://www.php.net/manual/en/install.fpm.php
752
- .. _`SensioFrameworkExtraBundle` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html
753
- .. _`#[ParamConverter]` : https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html
754
757
.. _variadic : https://www.php.net/manual/en/functions.arguments.php#functions.variable-arg-list
0 commit comments