1
1
Symfony Framework Events
2
2
========================
3
3
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
+
4
9
Kernel Events
5
10
-------------
6
11
@@ -20,22 +25,13 @@ each event has access to the following information:
20
25
21
26
.. _kernel-core-request :
22
27
23
- `` kernel.request ``
24
- ~~~~~~~~~~~~~~~~~~
28
+ kernel.request
29
+ ~~~~~~~~~~~~~~
25
30
26
31
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseEvent `
27
32
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.
39
35
40
36
.. seealso ::
41
37
@@ -54,7 +50,7 @@ Listener Class Name P
54
50
:class: `Symfony\\ Component\\ Security\\ Http\\ Firewall ` 8
55
51
============================================================================= ========
56
52
57
- `` kernel.controller ``
53
+ kernel.controller
58
54
~~~~~~~~~~~~~~~~~~~~~
59
55
60
56
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ FilterControllerEvent `
@@ -84,8 +80,8 @@ Listener Class Name
84
80
:class: `Symfony\\ Bundle\\ FrameworkBundle\\ DataCollector\\ RequestDataCollector ` 0
85
81
============================================================================== ========
86
82
87
- `` kernel.view ``
88
- ~~~~~~~~~~~~~~~
83
+ kernel.view
84
+ ~~~~~~~~~~~
89
85
90
86
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForControllerResultEvent `
91
87
@@ -114,8 +110,8 @@ method::
114
110
115
111
Read more on the :ref: `kernel.view event <component-http-kernel-kernel-view >`.
116
112
117
- `` kernel.response ``
118
- ~~~~~~~~~~~~~~~~~~~
113
+ kernel.response
114
+ ~~~~~~~~~~~~~~~
119
115
120
116
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ FilterResponseEvent `
121
117
@@ -162,8 +158,8 @@ Listener Class Name
162
158
:class: `Symfony\\ Component\\ HttpKernel\\ EventListener\\ StreamedResponseListener ` -1024
163
159
=================================================================================== ========
164
160
165
- `` kernel.terminate ``
166
- ~~~~~~~~~~~~~~~~~~~~
161
+ kernel.terminate
162
+ ~~~~~~~~~~~~~~~~
167
163
168
164
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ PostResponseEvent `
169
165
@@ -185,8 +181,8 @@ Listener Class Name Prior
185
181
186
182
.. _kernel-kernel.exception :
187
183
188
- `` kernel.exception ``
189
- ~~~~~~~~~~~~~~~~~~~~
184
+ kernel.exception
185
+ ~~~~~~~~~~~~~~~~
190
186
191
187
**Event Class **: :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForExceptionEvent `
192
188
@@ -219,7 +215,7 @@ and set a new ``Exception`` object, or do nothing::
219
215
response won't work. If you want to overwrite the status code (which you
220
216
should not without a good reason), set the ``X-Status-Code `` header::
221
217
222
- return new Response(
218
+ $response = Response(
223
219
'Error',
224
220
404 // ignored,
225
221
array('X-Status-Code' => 200)
0 commit comments