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

Skip to content

Use new Event names #12007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/event_dispatcher.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Often times, data about a specific event needs to be passed along with the
case, a special subclass that has additional methods for retrieving and
overriding information can be passed when dispatching an event. For example,
the ``kernel.response`` event uses a
:class:`Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent`, which
:class:`Symfony\\Component\\HttpKernel\\Event\\ResponseEvent`, which
contains methods to get and even replace the ``Response`` object.

The Dispatcher
Expand Down Expand Up @@ -334,7 +334,7 @@ Take the following example of a subscriber that subscribes to the

use Acme\Store\Event\OrderPlacedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class StoreSubscriber implements EventSubscriberInterface
Expand All @@ -350,12 +350,12 @@ Take the following example of a subscriber that subscribes to the
];
}

public function onKernelResponsePre(FilterResponseEvent $event)
public function onKernelResponsePre(ResponseEvent $event)
{
// ...
}

public function onKernelResponsePost(FilterResponseEvent $event)
public function onKernelResponsePost(ResponseEvent $event)
{
// ...
}
Expand Down
43 changes: 28 additions & 15 deletions components/http_kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ have been determined (e.g. the controller, routing information) but before
the controller is executed. For some examples, see the Symfony section below.

Listeners to this event can also change the controller callable completely
by calling :method:`FilterControllerEvent::setController <Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent::setController>`
by calling :method:`ControllerEvent::setController <Symfony\\Component\\HttpKernel\\Event\\ControllerEvent::setController>`
on the event object that's passed to listeners on this event.

.. sidebar:: ``kernel.controller`` in the Symfony Framework
Expand Down Expand Up @@ -524,9 +524,9 @@ to the exception.

<object data="../_images/components/http_kernel/http-workflow-exception.svg" type="image/svg+xml"></object>

Each listener to this event is passed a :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`
Each listener to this event is passed a :class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent`
object, which you can use to access the original exception via the
:method:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent::getException`
:method:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent::getException`
method. A typical listener on this event will check for a certain type of
exception and create an appropriate error ``Response``.

Expand Down Expand Up @@ -602,18 +602,31 @@ each event has their own event object:

.. _component-http-kernel-event-table:

=========================== ====================================== ===================================================================================
=========================== ====================================== ========================================================================
Name ``KernelEvents`` Constant Argument passed to the listener
=========================== ====================================== ===================================================================================
kernel.request ``KernelEvents::REQUEST`` :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent`
kernel.controller ``KernelEvents::CONTROLLER`` :class:`Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent`
kernel.controller_arguments ``KernelEvents::CONTROLLER_ARGUMENTS`` :class:`Symfony\\Component\\HttpKernel\\Event\\FilterControllerArgumentsEvent`
kernel.view ``KernelEvents::VIEW`` :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent`
kernel.response ``KernelEvents::RESPONSE`` :class:`Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent`
=========================== ====================================== ========================================================================
kernel.request ``KernelEvents::REQUEST`` :class:`Symfony\\Component\\HttpKernel\\Event\\RequestEvent`
kernel.controller ``KernelEvents::CONTROLLER`` :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerEvent`
kernel.controller_arguments ``KernelEvents::CONTROLLER_ARGUMENTS`` :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerArgumentsEvent`
kernel.view ``KernelEvents::VIEW`` :class:`Symfony\\Component\\HttpKernel\\Event\\ViewEvent`
kernel.response ``KernelEvents::RESPONSE`` :class:`Symfony\\Component\\HttpKernel\\Event\\ResponseEvent`
kernel.finish_request ``KernelEvents::FINISH_REQUEST`` :class:`Symfony\\Component\\HttpKernel\\Event\\FinishRequestEvent`
kernel.terminate ``KernelEvents::TERMINATE`` :class:`Symfony\\Component\\HttpKernel\\Event\\PostResponseEvent`
kernel.exception ``KernelEvents::EXCEPTION`` :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`
=========================== ====================================== ===================================================================================
kernel.terminate ``KernelEvents::TERMINATE`` :class:`Symfony\\Component\\HttpKernel\\Event\\TerminateEvent`
kernel.exception ``KernelEvents::EXCEPTION`` :class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent`
=========================== ====================================== ========================================================================

.. deprecated:: 4.3

Since Symfony 4.3, most of the event classes were renamed.
The following old classes were deprecated:

* `GetResponseEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\RequestEvent`
* `FilterControllerEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerEvent`
* `FilterControllerArgumentsEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerArgumentsEvent`
* `GetResponseForControllerResultEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\ViewEvent`
* `FilterResponseEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\ResponseEvent`
* `PostResponseEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\TerminateEvent`
* `GetResponseForExceptionEvent` renamed to :class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent`

.. _http-kernel-working-example:

Expand Down Expand Up @@ -709,10 +722,10 @@ can be used to check if the current request is a "master" or "sub" request.
For example, a listener that only needs to act on the master request may
look like this::

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
// ...

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
if (!$event->isMasterRequest()) {
return;
Expand Down
4 changes: 2 additions & 2 deletions components/security/authentication.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ an *authenticated* token if the supplied credentials were found to be valid.
The listener should then store the authenticated token using
:class:`the token storage <Symfony\\Component\\Security\\Core\\Authentication\\Token\\Storage\\TokenStorageInterface>`::

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
Expand All @@ -38,7 +38,7 @@ The listener should then store the authenticated token using

// ...

public function handle(GetResponseEvent $event)
public function handle(RequestEvent $event)
{
$request = $event->getRequest();

Expand Down
2 changes: 1 addition & 1 deletion controller/error_pages.rst
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ error pages.
.. note::

If your listener calls ``setResponse()`` on the
:class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`,
:class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent`,
event, propagation will be stopped and the response will be sent to
the client.

Expand Down
4 changes: 2 additions & 2 deletions create_framework/http_kernel_httpkernel_class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,11 @@ only if needed::

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;

class StringResponseListener implements EventSubscriberInterface
{
public function onView(GetResponseForControllerResultEvent $event)
public function onView(ViewEvent $event)
{
$response = $event->getControllerResult();

Expand Down
10 changes: 5 additions & 5 deletions event_dispatcher/before_after_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`::

use App\Controller\TokenAuthenticatedController;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Symfony\Component\HttpKernel\KernelEvents;

Expand All @@ -128,7 +128,7 @@ event subscribers, you can learn more about them at :doc:`/event_dispatcher`::
$this->tokens = $tokens;
}

public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
$controller = $event->getController();

Expand Down Expand Up @@ -188,7 +188,7 @@ For example, take the ``TokenSubscriber`` from the previous example and first
record the authentication token inside the request attributes. This will
serve as a basic flag that this request underwent token authentication::

public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
// ...

Expand All @@ -208,9 +208,9 @@ This will look for the ``auth_token`` flag on the request object and set a custo
header on the response if it's found::

// add the new use statement at the top of your file
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
// check to see if onKernelController marked this as a token "auth'ed" request
if (!$token = $event->getRequest()->attributes->get('auth_token')) {
Expand Down
4 changes: 2 additions & 2 deletions profiler.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ production. To do that, create an :doc:`event subscriber </event_dispatcher>`
and listen to the :ref:`kernel.response<component-http-kernel-kernel-response>`
event::

use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

// ...

public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
if (!$this->getKernel()->isDebug()) {
return;
Expand Down
32 changes: 16 additions & 16 deletions reference/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ following information:
``kernel.request``
~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\RequestEvent`

This event is dispatched very early in Symfony, before the controller is
determined. It's useful to add information to the Request or return a Response
Expand All @@ -48,16 +48,16 @@ their priorities:
``kernel.controller``
~~~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FilterControllerEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerEvent`

This event is dispatched after the controller to be executed has been resolved
but before executing it. It's useful to initialize things later needed by the
controller, such as `param converters`_, and even to change the controller
entirely::

use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;

public function onKernelController(FilterControllerEvent $event)
public function onKernelController(ControllerEvent $event)
{
// ...

Expand All @@ -79,15 +79,15 @@ their priorities:
``kernel.controller_arguments``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FilterControllerArgumentsEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\ControllerArgumentsEvent`

This event is dispatched just before a controller is called. It's useful to
configure the arguments that are going to be passed to the controller.
Typically, this is used to map URL routing parameters to their corresponding
named arguments; or pass the current request when the ``Request`` type-hint is
found::

public function onKernelControllerArguments(FilterControllerArgumentsEvent $event)
public function onKernelControllerArguments(ControllerArgumentsEvent $event)
{
// ...

Expand All @@ -109,17 +109,17 @@ their priorities:
``kernel.view``
~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForControllerResultEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\ViewEvent`

This event is dispatched after the controller has been executed but *only* if
the controller does *not* return a :class:`Symfony\\Component\\HttpFoundation\\Response`
object. It's useful to transform the returned value (e.g. a string with some
HTML contents) into the ``Response`` object needed by Symfony::

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;

public function onKernelView(GetResponseForControllerResultEvent $event)
public function onKernelView(ViewEvent $event)
{
$value = $event->getControllerResult();
$response = new Response();
Expand All @@ -143,13 +143,13 @@ their priorities:
``kernel.response``
~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\FilterResponseEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\ResponseEvent`

This event is dispatched after the controller or any ``kernel.view`` listener
returns a ``Response`` object. It's useful to modify or replace the response
before sending it back (e.g. add/modify HTTP headers, add cookies, etc.)::

public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
$response = $event->getResponse();

Expand Down Expand Up @@ -196,7 +196,7 @@ their priorities:
``kernel.terminate``
~~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\PostResponseEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\TerminateEvent`

This event is dispatched after the response has been sent (after the execution
of the :method:`Symfony\\Component\\HttpKernel\\HttpKernel::handle` method).
Expand All @@ -219,16 +219,16 @@ their priorities:
``kernel.exception``
~~~~~~~~~~~~~~~~~~~~

**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`
**Event Class**: :class:`Symfony\\Component\\HttpKernel\\Event\\ExceptionEvent`

This event is dispatched as soon as an error occurs during the handling of the
HTTP request. It's useful to recover from errors or modify the exception details
sent as response::

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;

public function onKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(ExceptionEvent $event)
{
$exception = $event->getException();
$response = new Response();
Expand Down Expand Up @@ -265,7 +265,7 @@ response:

If you want to overwrite the status code of the exception response, which
you should not without a good reason, call
``GetResponseForExceptionEvent::allowCustomResponseCode()`` first and then
``ExceptionEvent::allowCustomResponseCode()`` first and then
set the status code on the response::

$event->allowCustomResponseCode();
Expand Down
6 changes: 3 additions & 3 deletions security/custom_authentication_provider.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ is responsible for fielding requests to the firewall and calling the authenticat
provider. A listener must be an instance of
:class:`Symfony\\Component\\Security\\Http\\Firewall\\ListenerInterface`.
A security listener should handle the
:class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent` event, and
:class:`Symfony\\Component\\HttpKernel\\Event\\RequestEvent` event, and
set an authenticated token in the token storage if successful::

// src/Security/Firewall/WsseListener.php
namespace App\Security\Firewall;

use App\Security\Authentication\Token\WsseUserToken;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
Expand All @@ -125,7 +125,7 @@ set an authenticated token in the token storage if successful::
$this->authenticationManager = $authenticationManager;
}

public function handle(GetResponseEvent $event)
public function handle(RequestEvent $event)
{
$request = $event->getRequest();

Expand Down
4 changes: 2 additions & 2 deletions service_container/3.3-di-changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,12 +373,12 @@ create the class::
// ...

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

class SetHeaderSusbcriber implements EventSubscriberInterface
{
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
$event->getResponse()->headers->set('X-SYMFONY-3.3', 'Less config');
}
Expand Down
2 changes: 1 addition & 1 deletion translation/locale.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To set the user's locale, you may want to create a custom event listener so
that it's set before any other parts of the system (i.e. the translator) need
it::

public function onKernelRequest(GetResponseEvent $event)
public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();

Expand Down