From 00f3807495f10e5ec72142ff0d0ed591b485a7f0 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 22 Jul 2019 13:33:00 +0200 Subject: [PATCH] Use new Event names --- components/event_dispatcher.rst | 8 ++-- components/http_kernel.rst | 43 ++++++++++++------- components/security/authentication.rst | 4 +- controller/error_pages.rst | 2 +- .../http_kernel_httpkernel_class.rst | 4 +- event_dispatcher/before_after_filters.rst | 10 ++--- profiler.rst | 4 +- reference/events.rst | 32 +++++++------- security/custom_authentication_provider.rst | 6 +-- service_container/3.3-di-changes.rst | 4 +- translation/locale.rst | 2 +- 11 files changed, 66 insertions(+), 53 deletions(-) diff --git a/components/event_dispatcher.rst b/components/event_dispatcher.rst index dced7cf051d..d44ccb57dd8 100644 --- a/components/event_dispatcher.rst +++ b/components/event_dispatcher.rst @@ -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 @@ -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 @@ -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) { // ... } diff --git a/components/http_kernel.rst b/components/http_kernel.rst index 469690c0a26..4b2f4a9c668 100644 --- a/components/http_kernel.rst +++ b/components/http_kernel.rst @@ -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 ` +by calling :method:`ControllerEvent::setController ` on the event object that's passed to listeners on this event. .. sidebar:: ``kernel.controller`` in the Symfony Framework @@ -524,9 +524,9 @@ to the exception. -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``. @@ -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: @@ -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; diff --git a/components/security/authentication.rst b/components/security/authentication.rst index da2b55fa6c8..d606bd1a627 100644 --- a/components/security/authentication.rst +++ b/components/security/authentication.rst @@ -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 `:: - 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; @@ -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(); diff --git a/controller/error_pages.rst b/controller/error_pages.rst index a17d2b2529f..7bfd8fd0932 100644 --- a/controller/error_pages.rst +++ b/controller/error_pages.rst @@ -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. diff --git a/create_framework/http_kernel_httpkernel_class.rst b/create_framework/http_kernel_httpkernel_class.rst index 43dd45b7182..f9f8f16932f 100644 --- a/create_framework/http_kernel_httpkernel_class.rst +++ b/create_framework/http_kernel_httpkernel_class.rst @@ -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(); diff --git a/event_dispatcher/before_after_filters.rst b/event_dispatcher/before_after_filters.rst index 99ca428f5ee..4202918ba92 100644 --- a/event_dispatcher/before_after_filters.rst +++ b/event_dispatcher/before_after_filters.rst @@ -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; @@ -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(); @@ -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) { // ... @@ -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')) { diff --git a/profiler.rst b/profiler.rst index e9b146831c6..cfc0bf61dd6 100644 --- a/profiler.rst +++ b/profiler.rst @@ -197,11 +197,11 @@ production. To do that, create an :doc:`event subscriber ` and listen to the :ref:`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; diff --git a/reference/events.rst b/reference/events.rst index dfb67ba4131..6e4aab42441 100644 --- a/reference/events.rst +++ b/reference/events.rst @@ -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 @@ -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) { // ... @@ -79,7 +79,7 @@ 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. @@ -87,7 +87,7 @@ 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) { // ... @@ -109,7 +109,7 @@ 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` @@ -117,9 +117,9 @@ 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(); @@ -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(); @@ -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). @@ -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(); @@ -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(); diff --git a/security/custom_authentication_provider.rst b/security/custom_authentication_provider.rst index 783b7e45e61..d81c9fa01ac 100644 --- a/security/custom_authentication_provider.rst +++ b/security/custom_authentication_provider.rst @@ -100,7 +100,7 @@ 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 @@ -108,7 +108,7 @@ set an authenticated token in the token storage if successful:: 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; @@ -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(); diff --git a/service_container/3.3-di-changes.rst b/service_container/3.3-di-changes.rst index 2932436a18a..7aed2e63980 100644 --- a/service_container/3.3-di-changes.rst +++ b/service_container/3.3-di-changes.rst @@ -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'); } diff --git a/translation/locale.rst b/translation/locale.rst index 4e3a46f9874..da2fc84cfd9 100644 --- a/translation/locale.rst +++ b/translation/locale.rst @@ -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();