@@ -107,6 +107,9 @@ listeners to the events discussed below::
107
107
// echo the content and send the headers
108
108
$response->send();
109
109
110
+ // triggers the kernel.terminate event
111
+ $kernel->terminate($request, $response);
112
+
110
113
See ":ref: `http-kernel-working-example `" for a more concrete implementation.
111
114
112
115
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.
148
151
:align: center
149
152
150
153
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 ``
152
155
object.
153
156
154
157
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.
441
444
serializes the current user's information into the
442
445
session so that it can be reloaded on the next request.
443
446
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
+
444
486
.. _component-http-kernel-kernel-exception :
445
487
446
488
Handling Exceptions:: the ``kernel.exception `` event
@@ -537,6 +579,8 @@ each event has their own event object:
537
579
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
538
580
| kernel.response | ``KernelEvents::RESPONSE `` | :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ FilterResponseEvent ` |
539
581
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
582
+ | kernel.terminate | ``KernelEvents::TERMINATE `` | :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ PostResponseEvent ` |
583
+ +-------------------+-------------------------------+-------------------------------------------------------------------------------------+
540
584
| kernel.exception | ``KernelEvents::EXCEPTION `` | :class: `Symfony\\ Component\\ HttpKernel\\ Event\\ GetResponseForExceptionEvent ` |
541
585
+-------------------+-------------------------------+-------------------------------------------------------------------------------------+
542
586
@@ -581,6 +625,8 @@ a built-in ControllerResolver that can be used to create a working example::
581
625
$response = $kernel->handle($request);
582
626
$response->send();
583
627
628
+ $kernel->terminate($request, $response);
629
+
584
630
Sub Requests
585
631
------------
586
632
0 commit comments