11Symfony Framework Events
22========================
33
4+ When the Symfony Framework (or anything using the :class: `Symfony\\ Component\\ HttpKernel\\ HttpKernel `)
5+ handles a request, a few core events are dispatched so that you can add listeners
6+ throughout the process. These are called the "kernel events". For a larger
7+ explanation, see :doc: `/reference/http_kernel/introduction `.
8+
49Kernel Events
510-------------
611
@@ -20,22 +25,13 @@ each event has access to the following information:
2025
2126.. _kernel-core-request :
2227
23- `` kernel.request ``
24- ~~~~~~~~~~~~~~~~~~
28+ kernel.request
29+ ~~~~~~~~~~~~~~
2530
2631**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseEvent `
2732
28- The goal of this event is to either return a ``Response `` object immediately
29- or setup variables so that a Controller can be called after the event. Any
30- listener can return a ``Response `` object via the ``setResponse() `` method on
31- the event. In this case, all other listeners won't be called.
32-
33- This event is used by the FrameworkBundle to populate the ``_controller ``
34- ``Request `` attribute, via the
35- :class: `Symfony\\ Bundle\\ FrameworkBundle\\ EventListener\\ RouterListener `.
36- RequestListener uses a :class: `Symfony\\ Component\\ Routing\\ RouterInterface `
37- object to match the ``Request `` and determine the Controller name (stored in the
38- ``_controller `` ``Request `` attribute).
33+ This event is dispatched very early in Symfony, before the controller is
34+ determined.
3935
4036.. seealso ::
4137
@@ -54,7 +50,7 @@ Listener Class Name P
5450:class: `Symfony\\ Component\\ Security\\ Http\\ Firewall ` 8
5551============================================================================= ========
5652
57- `` kernel.controller ``
53+ kernel.controller
5854~~~~~~~~~~~~~~~~~~~~~
5955
6056**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ FilterControllerEvent `
@@ -84,8 +80,8 @@ Listener Class Name
8480:class: `Symfony\\ Bundle\\ FrameworkBundle\\ DataCollector\\ RequestDataCollector ` 0
8581============================================================================== ========
8682
87- `` kernel.view ``
88- ~~~~~~~~~~~~~~~
83+ kernel.view
84+ ~~~~~~~~~~~
8985
9086**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForControllerResultEvent `
9187
@@ -114,8 +110,8 @@ method::
114110
115111 Read more on the :ref: `kernel.view event <component-http-kernel-kernel-view >`.
116112
117- `` kernel.response ``
118- ~~~~~~~~~~~~~~~~~~~
113+ kernel.response
114+ ~~~~~~~~~~~~~~~
119115
120116**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ FilterResponseEvent `
121117
@@ -162,8 +158,8 @@ Listener Class Name
162158:class: `Symfony\\ Component\\ HttpKernel\\ EventListener\\ StreamedResponseListener ` -1024
163159=================================================================================== ========
164160
165- `` kernel.terminate ``
166- ~~~~~~~~~~~~~~~~~~~~
161+ kernel.terminate
162+ ~~~~~~~~~~~~~~~~
167163
168164**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ PostResponseEvent `
169165
@@ -185,8 +181,8 @@ Listener Class Name Prior
185181
186182.. _kernel-kernel.exception :
187183
188- `` kernel.exception ``
189- ~~~~~~~~~~~~~~~~~~~~
184+ kernel.exception
185+ ~~~~~~~~~~~~~~~~
190186
191187**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForExceptionEvent `
192188
@@ -219,7 +215,7 @@ and set a new ``Exception`` object, or do nothing::
219215 response won't work. If you want to overwrite the status code (which you
220216 should not without a good reason), set the ``X-Status-Code `` header::
221217
222- return new Response(
218+ $response = Response(
223219 'Error',
224220 404 // ignored,
225221 array('X-Status-Code' => 200)
0 commit comments