Skip to content

Commit a0eb371

Browse files
committed
Merge branch '2.8' into 3.3
* 2.8: Some fixes for testing/* articles in 2.7 docs Fixed some issues in PHPUnit XML config examples Removed a wrong note about controllers as services Removed lots of redundant contents [#8650] Minor rewording [#8649] Small reword Improved the link to the Symfony events reference Minor fixes for upload_file.rst Fixed a typo Added getSubscribedEvents() to UserLocaleSubscriber Reworded the explanation about service tags Reworded the intro of reference/dic_tags.rst Fixed RST syntax issue Revamped the reference/events.rst article Change some docs to be gender-neutral
2 parents f944a49 + ee5c919 commit a0eb371

File tree

9 files changed

+114
-142
lines changed

9 files changed

+114
-142
lines changed

controller/upload_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ to :doc:`customize form rendering </form/form_customization>`):
108108
Finally, you need to update the code of the controller that handles the form::
109109

110110
// src/AppBundle/Controller/ProductController.php
111-
namespace AppBundle\ProductController;
111+
namespace AppBundle\Controller;
112112

113113
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
114114
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

event_dispatcher.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ The most common way to listen to an event is to register an **event listener**::
6464

6565
Each event receives a slightly different type of ``$event`` object. For
6666
the ``kernel.exception`` event, it is :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`.
67-
To see what type of object each event listener receives, see :class:`Symfony\\Component\\HttpKernel\\KernelEvents`
68-
or the documentation about the specific event you're listening to.
67+
Check out the :doc:`Symfony events reference </reference/events>` to see
68+
what type of object each event provides.
6969

7070
Now that the class is created, you just need to register it as a service and
7171
notify Symfony that it is a "listener" on the ``kernel.exception`` event by

form/events.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Creating and binding an event listener to the form is very easy::
282282
return;
283283
}
284284

285-
// Check whether the user has chosen to display his email or not.
285+
// Check whether the user has chosen to display their email or not.
286286
// If the data was submitted previously, the additional value that is
287287
// included in the request variables needs to be removed.
288288
if (true === $user['show_email']) {
@@ -363,7 +363,7 @@ Event subscribers have different uses:
363363
$form = $event->getForm();
364364
365365
// Check whether the user from the initial data has chosen to
366-
// display his email or not.
366+
// display their email or not.
367367
if (true === $user->isShowEmail()) {
368368
$form->add('email', EmailType::class);
369369
}
@@ -378,7 +378,7 @@ Event subscribers have different uses:
378378
return;
379379
}
380380
381-
// Check whether the user has chosen to display his email or not.
381+
// Check whether the user has chosen to display their email or not.
382382
// If the data was submitted previously, the additional value that
383383
// is included in the request variables needs to be removed.
384384
if (true === $user['show_email']) {

reference/dic_tags.rst

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
The Dependency Injection Tags
1+
Built-in Symfony Service Tags
22
=============================
33

4-
Dependency Injection Tags are little strings that can be applied to a service
5-
to "flag" it to be used in some special way. For example, if you have a
6-
service that you would like to register as a listener to one of Symfony's
7-
core events, you can flag it with the ``kernel.event_listener`` tag.
4+
:doc:`Service tags </service_container/tags>` are the mechanism used by the
5+
:doc:`DependencyInjection component </components/dependency_injection>` to flag
6+
services that require special processing, like console commands or Twig extensions.
87

9-
You can learn a little bit more about "tags" by reading the ":doc:`/service_container/tags`"
10-
article.
11-
12-
Below is information about all of the tags available inside Symfony. There
13-
may also be tags in other bundles you use that aren't listed here.
8+
These are the most common tags provided by Symfony components, but in your
9+
application there could be more tags available provided by third-party bundles:
1410

1511
======================================== ========================================================================
1612
Tag Name Usage

reference/events.rst

Lines changed: 79 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Symfony Framework Events
2-
========================
1+
Built-in Symfony Events
2+
=======================
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
6-
listeners throughout the process. These are called the "kernel events".
7-
For a larger explanation, see :doc:`/components/http_kernel`.
4+
During the handling of an HTTP request, the Symfony framework (or any
5+
application using the :doc:`HttpKernel component </components/http_kernel>`)
6+
dispatches some :doc:`events </event_dispatcher>` which you can use to modify
7+
how the request is handled.
88

99
Kernel Events
1010
-------------
1111

12-
Each event dispatched by the kernel is a subclass of
13-
:class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`. This means
14-
that each event has access to the following information:
12+
Each event dispatched by the HttpKernel component is a subclass of
13+
:class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`, which provides the
14+
following information:
1515

1616
:method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequestType`
1717
Returns the *type* of the request (``HttpKernelInterface::MASTER_REQUEST``
@@ -31,67 +31,60 @@ that each event has access to the following information:
3131
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent`
3232

3333
This event is dispatched very early in Symfony, before the controller is
34-
determined.
34+
determined. It's useful to add information to the Request or return a Response
35+
early to stop the handling of the request.
3536

3637
.. seealso::
3738

3839
Read more on the :ref:`kernel.request event <component-http-kernel-kernel-request>`.
3940

40-
These are the built-in Symfony listeners registered to this event:
41+
Execute this command to find out which listeners are registered for this event and
42+
their priorities:
4143

42-
============================================================================= ========
43-
Listener Class Name Priority
44-
============================================================================= ========
45-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener` 1024
46-
:class:`Symfony\\Bundle\\FrameworkBundle\\EventListener\\TestSessionListener` 192
47-
:class:`Symfony\\Bundle\\FrameworkBundle\\EventListener\\SessionListener` 128
48-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\RouterListener` 32
49-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\LocaleListener` 16
50-
:class:`Symfony\\Component\\Security\\Http\\Firewall` 8
51-
============================================================================= ========
44+
.. code-block:: terminal
45+
46+
$ php bin/console debug:event-dispatcher kernel.request
5247
5348
``kernel.controller``
5449
~~~~~~~~~~~~~~~~~~~~~
5550

5651
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent`
5752

58-
This event can be an entry point used to modify the controller that should be executed::
53+
This event is dispatched after the controller to be executed has been resolved
54+
but before executing it. It's useful to initialize things later needed by the
55+
controller, such as `param converters`_, and even to change the controller
56+
entirely::
5957

6058
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
6159

6260
public function onKernelController(FilterControllerEvent $event)
6361
{
64-
$controller = $event->getController();
6562
// ...
6663

6764
// the controller can be changed to any PHP callable
68-
$event->setController($controller);
65+
$event->setController($myCustomController);
6966
}
7067

7168
.. seealso::
7269

7370
Read more on the :ref:`kernel.controller event <component-http-kernel-kernel-controller>`.
7471

75-
This is the built-in Symfony listener related to this event:
72+
Execute this command to find out which listeners are registered for this event and
73+
their priorities:
74+
75+
.. code-block:: terminal
7676
77-
============================================================================== ========
78-
Listener Class Name Priority
79-
============================================================================== ========
80-
:class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\RequestDataCollector` 0
81-
============================================================================== ========
77+
$ php bin/console debug:event-dispatcher kernel.controller
8278
8379
``kernel.view``
8480
~~~~~~~~~~~~~~~
8581

8682
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent`
8783

88-
This event is not used by the FrameworkBundle, but it can be used to implement
89-
a view sub-system. This event is called *only* if the Controller does *not*
90-
return a ``Response`` object. The purpose of the event is to allow some
91-
other return value to be converted into a ``Response``.
92-
93-
The value returned by the Controller is accessible via the ``getControllerResult()``
94-
method::
84+
This event is dispatched after the controller has been executed but *only* if
85+
the controller does *not* return a :class:`Symfony\\Component\\HttpFoundation\\Response`
86+
object. It's useful to transform the returned value (e.g. a string with some
87+
HTML contents) into the ``Response`` object needed by Symfony::
9588

9689
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
9790
use Symfony\Component\HttpFoundation\Response;
@@ -110,13 +103,21 @@ method::
110103

111104
Read more on the :ref:`kernel.view event <component-http-kernel-kernel-view>`.
112105

106+
Execute this command to find out which listeners are registered for this event and
107+
their priorities:
108+
109+
.. code-block:: terminal
110+
111+
$ php bin/console debug:event-dispatcher kernel.view
112+
113113
``kernel.response``
114114
~~~~~~~~~~~~~~~~~~~
115115

116116
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent`
117117

118-
The purpose of this event is to allow other systems to modify or replace
119-
the ``Response`` object after its creation::
118+
This event is dispatched after the controller or any ``kernel.view`` listener
119+
returns a ``Response`` object. It's useful to modify or replace the response
120+
before sending it back (e.g. add/modify HTTP headers, add cookies, etc.)::
120121

121122
public function onKernelResponse(FilterResponseEvent $event)
122123
{
@@ -125,91 +126,64 @@ the ``Response`` object after its creation::
125126
// ... modify the response object
126127
}
127128

128-
The FrameworkBundle registers several listeners:
129-
130-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener`
131-
Collects data for the current request.
132-
133-
:class:`Symfony\\Bundle\\WebProfilerBundle\\EventListener\\WebDebugToolbarListener`
134-
Injects the Web Debug Toolbar.
135-
136-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener`
137-
Fixes the Response ``Content-Type`` based on the request format.
138-
139-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\EsiListener`
140-
Adds a ``Surrogate-Control`` HTTP header when the Response needs to
141-
be parsed for ESI tags.
142-
143129
.. seealso::
144130

145131
Read more on the :ref:`kernel.response event <component-http-kernel-kernel-response>`.
146132

147-
These are the built-in Symfony listeners registered to this event:
148-
149-
=================================================================================== ========
150-
Listener Class Name Priority
151-
=================================================================================== ========
152-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\EsiListener` 0
153-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ResponseListener` 0
154-
:class:`Symfony\\Component\\Security\\Http\\RememberMe\\ResponseListener` 0
155-
:class:`Symfony\\Bundle\\FrameworkBundle\\DataCollector\\RequestDataCollector` 0
156-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener` -100
157-
:class:`Symfony\\Bundle\\FrameworkBundle\\EventListener\\TestSessionListener` -128
158-
:class:`Symfony\\Bundle\\WebProfilerBundle\\EventListener\\WebDebugToolbarListener` -128
159-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\StreamedResponseListener` -1024
160-
=================================================================================== ========
133+
Execute this command to find out which listeners are registered for this event and
134+
their priorities:
135+
136+
.. code-block:: terminal
137+
138+
$ php bin/console debug:event-dispatcher kernel.response
161139
162140
``kernel.finish_request``
163141
~~~~~~~~~~~~~~~~~~~~~~~~~
164142

165143
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FinishRequestEvent`
166144

167-
The purpose of this event is to allow you to reset the global and environmental
168-
state of the application after a sub-request has finished (for example, the
169-
translator listener resets the translator's locale to the one of the parent
170-
request)::
145+
This event is dispatched after a :ref:`sub request <http-kernel-sub-requests>`
146+
has finished. It's useful to reset the global state of the application (for
147+
example, the translator listener resets the translator's locale to the one of
148+
the parent request)::
171149

172150
public function onKernelFinishRequest(FinishRequestEvent $event)
173151
{
174152
if (null === $parentRequest = $this->requestStack->getParentRequest()) {
175153
return;
176154
}
177155

178-
//Reset the locale of the subrequest to the locale of the parent request
156+
// Reset the locale of the subrequest to the locale of the parent request
179157
$this->setLocale($parentRequest);
180158
}
181159

182-
These are the built-in Symfony listeners related to this event:
160+
Execute this command to find out which listeners are registered for this event and
161+
their priorities:
183162

184-
========================================================================== ========
185-
Listener Class Name Priority
186-
========================================================================== ========
187-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\LocaleListener` 0
188-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\TranslatorListener` 0
189-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\RouterListener` 0
190-
:class:`Symfony\\Component\\Security\\Http\\Firewall` 0
191-
========================================================================== ========
163+
.. code-block:: terminal
164+
165+
$ php bin/console debug:event-dispatcher kernel.finish_request
192166
193167
``kernel.terminate``
194168
~~~~~~~~~~~~~~~~~~~~
195169

196170
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\PostResponseEvent`
197171

198-
The purpose of this event is to perform tasks after the response was already
199-
served to the client.
172+
This event is dispatched after the response has been sent (after the execution
173+
of the :method:`Symfony\\Component\\HttpKernel\\HttpKernel::handle` method).
174+
It's useful to perform slow or complex tasks that don't need to be completed to
175+
send the response (e.g. sending emails).
200176

201177
.. seealso::
202178

203179
Read more on the :ref:`kernel.terminate event <component-http-kernel-kernel-terminate>`.
204180

205-
This is the built-in Symfony listener related to this event:
181+
Execute this command to find out which listeners are registered for this event and
182+
their priorities:
206183

207-
========================================================================= ========
208-
Listener Class Name Priority
209-
========================================================================= ========
210-
`EmailSenderListener`_ 0
211-
========================================================================= ========
184+
.. code-block:: terminal
212185
186+
$ php bin/console debug:event-dispatcher kernel.terminate
213187
214188
.. _kernel-kernel.exception:
215189

@@ -218,12 +192,9 @@ Listener Class Name Prior
218192

219193
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`
220194

221-
The TwigBundle registers an :class:`Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener`
222-
that forwards the ``Request`` to a given controller defined by the
223-
``exception_listener.controller`` parameter.
224-
225-
A listener on this event can create and set a ``Response`` object, create
226-
and set a new ``Exception`` object, or do nothing::
195+
This event is dispatched as soon as an error occurs during the handling of the
196+
HTTP request. It's useful to recover from errors or modify the exception details
197+
sent as response::
227198

228199
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
229200
use Symfony\Component\HttpFoundation\Response;
@@ -240,6 +211,12 @@ and set a new ``Exception`` object, or do nothing::
240211
// $event->setException($exception);
241212
}
242213

214+
.. note::
215+
216+
The TwigBundle registers an :class:`Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener`
217+
that forwards the ``Request`` to a given controller defined by the
218+
``exception_listener.controller`` parameter.
219+
243220
.. note::
244221

245222
Symfony uses the following logic to determine the HTTP status code of the
@@ -261,13 +238,11 @@ and set a new ``Exception`` object, or do nothing::
261238

262239
Read more on the :ref:`kernel.exception event <component-http-kernel-kernel-exception>`.
263240

264-
These are the built-in Symfony listeners registered to this event:
241+
Execute this command to find out which listeners are registered for this event and
242+
their priorities:
243+
244+
.. code-block:: terminal
265245
266-
========================================================================= ========
267-
Listener Class Name Priority
268-
========================================================================= ========
269-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ProfilerListener` 0
270-
:class:`Symfony\\Component\\HttpKernel\\EventListener\\ExceptionListener` -128
271-
========================================================================= ========
246+
$ php bin/console debug:event-dispatcher kernel.exception
272247
273-
.. _`EmailSenderListener`: https://github.com/symfony/swiftmailer-bundle/blob/master/EventListener/EmailSenderListener.php
248+
.. _`param converters`: https://symfony.com/doc/master/bundles/SensioFrameworkExtraBundle/annotations/converters.html

0 commit comments

Comments
 (0)