From 0127bd24ccd3face99a94de0aa96f96deac7a47e Mon Sep 17 00:00:00 2001 From: bfgasparin Date: Mon, 7 Apr 2014 19:28:54 -0300 Subject: [PATCH 1/4] Updated event_listener.rst Updated event_listener.rst to use the new KernelEvent::isMasterRequest method --- cookbook/service_container/event_listener.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookbook/service_container/event_listener.rst b/cookbook/service_container/event_listener.rst index 0676ca4479a..0aa7da76fd5 100644 --- a/cookbook/service_container/event_listener.rst +++ b/cookbook/service_container/event_listener.rst @@ -115,7 +115,7 @@ done as follow:: { public function onKernelRequest(GetResponseEvent $event) { - if (HttpKernel::MASTER_REQUEST != $event->getRequestType()) { + if (false === $event->isMasterRequest()) { // don't do anything if it's not the master request return; } From 8e8b8a00d04222aafe6e27c394998673ba2194ac Mon Sep 17 00:00:00 2001 From: bfgasparin Date: Tue, 8 Apr 2014 17:15:42 -0300 Subject: [PATCH 2/4] Added Versionadded directive to event_listener.rst Added missing Versionadded directive to event_listener.rst --- cookbook/service_container/event_listener.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cookbook/service_container/event_listener.rst b/cookbook/service_container/event_listener.rst index 0aa7da76fd5..c37edc0a0ce 100644 --- a/cookbook/service_container/event_listener.rst +++ b/cookbook/service_container/event_listener.rst @@ -124,6 +124,10 @@ done as follow:: } } +.. versionadded:: 2.4 + The ``isMasterRequest()`` method was introduced in Symfony 2.4. + Prior, the ``getRequestType()`` method must be used. + .. tip:: Two types of request are available in the :class:`Symfony\\Component\\HttpKernel\\HttpKernelInterface` From a6b17a00297b1315604459883429f9953ce708c4 Mon Sep 17 00:00:00 2001 From: Bruno Ferme Gasparin Date: Thu, 10 Apr 2014 02:25:04 -0300 Subject: [PATCH 3/4] Added KernelEvent::isMasterRequest method reference --- book/internals.rst | 13 ++++++++++--- components/http_kernel/introduction.rst | 10 +++++++--- cookbook/service_container/event_listener.rst | 10 +++++----- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/book/internals.rst b/book/internals.rst index cf204094287..829120a3047 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -208,6 +208,10 @@ processing must only occur on the master request). Events ~~~~~~ +.. versionadded:: 2.4 + The ``isMasterRequest()`` method was introduced in Symfony 2.4. + Prior, the ``getRequestType()`` method must be used. + Each event thrown by the Kernel is a subclass of :class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`. This means that each event has access to the same basic information: @@ -216,22 +220,25 @@ each event has access to the same basic information: - returns the *type* of the request (``HttpKernelInterface::MASTER_REQUEST`` or ``HttpKernelInterface::SUB_REQUEST``); +* :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::isMasterRequest` + - checks if it is a master request; + * :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getKernel` - returns the Kernel handling the request; * :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequest` - returns the current ``Request`` being handled. -``getRequestType()`` +``IsMasterRequest()`` .................... -The ``getRequestType()`` method allows listeners to know the type of the +The ``isMasterRequest()`` method allows listeners to check the type of the request. For instance, if a listener must only be active for master requests, add the following code at the beginning of your listener method:: use Symfony\Component\HttpKernel\HttpKernelInterface; - if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + if (!$event->isMasterRequest()) { // return immediately return; } diff --git a/components/http_kernel/introduction.rst b/components/http_kernel/introduction.rst index 5ab8e5c729b..d486630fc3b 100644 --- a/components/http_kernel/introduction.rst +++ b/components/http_kernel/introduction.rst @@ -665,12 +665,16 @@ argument as follows:: $response = $kernel->handle($request, HttpKernelInterface::SUB_REQUEST); // do something with this response +.. versionadded:: 2.4 + The ``isMasterRequest()`` method was introduced in Symfony 2.4. + Prior, the ``getRequestType()`` method must be used. + This creates another full request-response cycle where this new ``Request`` is transformed into a ``Response``. The only difference internally is that some listeners (e.g. security) may only act upon the master request. Each listener is passed some sub-class of :class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`, -whose :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequestType` -can be used to figure out if the current request is a "master" or "sub" request. +whose :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::isMasterRequest` +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:: @@ -680,7 +684,7 @@ look like this:: public function onKernelRequest(GetResponseEvent $event) { - if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { + if (!$event->isMasterRequest()) { return; } diff --git a/cookbook/service_container/event_listener.rst b/cookbook/service_container/event_listener.rst index c37edc0a0ce..4e61fdbff92 100644 --- a/cookbook/service_container/event_listener.rst +++ b/cookbook/service_container/event_listener.rst @@ -100,6 +100,10 @@ using a special "tag": Request events, checking types ------------------------------ +.. versionadded:: 2.4 + The ``isMasterRequest()`` method was introduced in Symfony 2.4. + Prior, the ``getRequestType()`` method must be used. + A single page can make several requests (one master request, and then multiple sub-requests), which is why when working with the ``KernelEvents::REQUEST`` event, you might need to check the type of the request. This can be easily @@ -115,7 +119,7 @@ done as follow:: { public function onKernelRequest(GetResponseEvent $event) { - if (false === $event->isMasterRequest()) { + if (!$event->isMasterRequest()) { // don't do anything if it's not the master request return; } @@ -124,10 +128,6 @@ done as follow:: } } -.. versionadded:: 2.4 - The ``isMasterRequest()`` method was introduced in Symfony 2.4. - Prior, the ``getRequestType()`` method must be used. - .. tip:: Two types of request are available in the :class:`Symfony\\Component\\HttpKernel\\HttpKernelInterface` From 4fc3b6acd768a9c54249b10fa7746fb80b69b506 Mon Sep 17 00:00:00 2001 From: bfgasparin Date: Thu, 10 Apr 2014 17:22:26 -0300 Subject: [PATCH 4/4] Fixed internals.rst syntax --- book/internals.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/internals.rst b/book/internals.rst index 829120a3047..250242b7277 100644 --- a/book/internals.rst +++ b/book/internals.rst @@ -229,8 +229,8 @@ each event has access to the same basic information: * :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequest` - returns the current ``Request`` being handled. -``IsMasterRequest()`` -.................... +``isMasterRequest()`` +..................... The ``isMasterRequest()`` method allows listeners to check the type of the request. For instance, if a listener must only be active for master requests,