Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2d23d72

Browse files
committed
[#2064] Updating the HttpKernel component documentation for Symfony 2.1
1 parent 0c8840b commit 2d23d72

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

components/http_kernel/introduction.rst

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ listeners to the events discussed below::
107107
// echo the content and send the headers
108108
$response->send();
109109

110+
// triggers the kernel.terminate event
111+
$kernel->terminate($request, $response);
112+
110113
See ":ref:`http-kernel-working-example`" for a more concrete implementation.
111114

112115
For general information on adding listeners to the events below, see
@@ -148,7 +151,7 @@ the :ref:`kernel.response<component-http-kernel-kernel-response>` event.
148151
:align: center
149152

150153
Other listeners simply initialize things or add more information to the request.
151-
For example, a listener might determine and set the locale on the Session
154+
For example, a listener might determine and set the locale on the ``Request``
152155
object.
153156

154157
Another common listener is routing. A router listener may process the ``Request``
@@ -441,6 +444,45 @@ method, which sends the headers and prints the ``Response`` content.
441444
serializes the current user's information into the
442445
session so that it can be reloaded on the next request.
443446

447+
8) The ``kernel.terminate`` event
448+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
449+
450+
.. versionadded:: 2.1
451+
The ``kernel.terminate`` event is new to Symfony 2.1.
452+
453+
**Typical Purposes**: To perform some "heavy" action after the response has
454+
been streamed to the user
455+
456+
:ref:`Kernel Events Information Table<component-http-kernel-event-table>`
457+
458+
The final event of the HttpKernel process is ``kernel.terminate`` and is unique
459+
because it occurs *after* the ``HttpKernel::handle`` method, and after the
460+
response is send to the user. Recall from above, then the code that uses
461+
the kernel, ends like this::
462+
463+
// echo the content and send the headers
464+
$response->send();
465+
466+
// triggers the kernel.terminate event
467+
$kernel->terminate($request, $response);
468+
469+
As you can see, by calling ``$kernel->terminate`` after sending the response,
470+
you will trigger the ``kernel.terminate`` event where you can perform certain
471+
actions that you may have delayed in order to return the response as quickly
472+
as possible to the client (e.g. sending emails).
473+
474+
.. note::
475+
476+
Using the ``kernel.terminate`` event is optional, and should only be
477+
called if your kernel implements :class:`Symfony\\Component\\HttpKernel\\TerminableInterface`.
478+
479+
.. sidebar:: ``kernel.terminate`` in the Symfony Framework
480+
481+
If you use the ``SwiftmailerBundle`` with Symfony2 and use ``memory``
482+
spooling, then the :class:`Symfony\\Bundle\\SwiftmailerBundle\\EventListener\\EmailSenderListener`
483+
is activated, which actually delivers any emails that you scheduled to
484+
send during the request.
485+
444486
.. _component-http-kernel-kernel-exception:
445487

446488
Handling Exceptions:: the ``kernel.exception`` event
@@ -537,6 +579,8 @@ each event has their own event object:
537579
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
538580
| kernel.response | ``KernelEvents::RESPONSE`` | :class:`Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent` |
539581
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
582+
| kernel.terminate | ``KernelEvents::TERMINATE`` | :class:`Symfony\\Component\\HttpKernel\\Event\\PostResponseEvent` |
583+
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
540584
| kernel.exception | ``KernelEvents::EXCEPTION`` | :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent` |
541585
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
542586

@@ -581,6 +625,8 @@ a built-in ControllerResolver that can be used to create a working example::
581625
$response = $kernel->handle($request);
582626
$response->send();
583627

628+
$kernel->terminate($request, $response);
629+
584630
Sub Requests
585631
------------
586632

0 commit comments

Comments
 (0)