[HttpKernel] added $event->isMasterRequest()

This commit is contained in:
Kris Wallsmith 2013-08-08 14:41:21 -07:00
parent 5cbfe302c2
commit 554f95fd9f
16 changed files with 32 additions and 35 deletions

View File

@ -14,7 +14,6 @@ namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\ChromePHPHandler as BaseChromePhpHandler; use Monolog\Handler\ChromePHPHandler as BaseChromePhpHandler;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/** /**
* ChromePhpHandler. * ChromePhpHandler.
@ -38,7 +37,7 @@ class ChromePhpHandler extends BaseChromePhpHandler
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -14,7 +14,6 @@ namespace Symfony\Bridge\Monolog\Handler;
use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler; use Monolog\Handler\FirePHPHandler as BaseFirePHPHandler;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/** /**
* FirePHPHandler. * FirePHPHandler.
@ -38,7 +37,7 @@ class FirePHPHandler extends BaseFirePHPHandler
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -13,7 +13,6 @@ namespace Symfony\Bridge\Monolog\Processor;
use Monolog\Processor\WebProcessor as BaseWebProcessor; use Monolog\Processor\WebProcessor as BaseWebProcessor;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
/** /**
* WebProcessor override to read from the HttpFoundation's Request * WebProcessor override to read from the HttpFoundation's Request
@ -30,7 +29,7 @@ class WebProcessor extends BaseWebProcessor
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { if ($event->isMasterRequest()) {
$this->serverData = $event->getRequest()->server->all(); $this->serverData = $event->getRequest()->server->all();
} }
} }

View File

@ -14,7 +14,6 @@ namespace Symfony\Bridge\Monolog\Tests\Processor;
use Monolog\Logger; use Monolog\Logger;
use Symfony\Bridge\Monolog\Processor\WebProcessor; use Symfony\Bridge\Monolog\Processor\WebProcessor;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class WebProcessorTest extends \PHPUnit_Framework_TestCase class WebProcessorTest extends \PHPUnit_Framework_TestCase
{ {
@ -42,8 +41,8 @@ class WebProcessorTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
$event->expects($this->any()) $event->expects($this->any())
->method('getRequestType') ->method('isMasterRequest')
->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST)); ->will($this->returnValue(true));
$event->expects($this->any()) $event->expects($this->any())
->method('getRequest') ->method('getRequest')
->will($this->returnValue($request)); ->will($this->returnValue($request));

View File

@ -12,8 +12,6 @@
namespace Symfony\Bundle\FrameworkBundle\EventListener; namespace Symfony\Bundle\FrameworkBundle\EventListener;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -37,7 +35,7 @@ class SessionListener implements EventSubscriberInterface
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -12,7 +12,6 @@
namespace Symfony\Bundle\FrameworkBundle\EventListener; namespace Symfony\Bundle\FrameworkBundle\EventListener;
use Symfony\Component\HttpFoundation\Cookie; use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
@ -38,7 +37,7 @@ class TestSessionListener implements EventSubscriberInterface
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }
@ -63,7 +62,7 @@ class TestSessionListener implements EventSubscriberInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -13,7 +13,6 @@ namespace Symfony\Bundle\WebProfilerBundle\EventListener;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag; use Symfony\Component\HttpFoundation\Session\Flash\AutoExpireFlashBag;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -53,7 +52,7 @@ class WebDebugToolbarListener implements EventSubscriberInterface
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -16,7 +16,6 @@ use Symfony\Component\HttpKernel\KernelEvents;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Profiler\Profile; use Symfony\Component\HttpKernel\Profiler\Profile;
use Symfony\Component\HttpKernel\Profiler\Profiler; use Symfony\Component\HttpKernel\Profiler\Profiler;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -412,7 +411,7 @@ class TraceableEventDispatcher implements EventDispatcherInterface, TraceableEve
case KernelEvents::RESPONSE: case KernelEvents::RESPONSE:
$token = $event->getResponse()->headers->get('X-Debug-Token'); $token = $event->getResponse()->headers->get('X-Debug-Token');
$this->stopwatch->stopSection($token); $this->stopwatch->stopSection($token);
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { if ($event->isMasterRequest()) {
// The profiles can only be updated once they have been created // The profiles can only be updated once they have been created
// that is after the 'kernel.response' event of the main request // that is after the 'kernel.response' event of the main request
$this->updateProfiles($token, true); $this->updateProfiles($token, true);

View File

@ -86,4 +86,16 @@ class KernelEvent extends Event
{ {
return $this->requestType; return $this->requestType;
} }
/**
* Checks if this is a master request.
*
* @return Boolean True if the request is a master request
*
* @api
*/
public function isMasterRequest()
{
return HttpKernelInterface::MASTER_REQUEST === $this->requestType;
}
} }

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\HttpKernel\EventListener; namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\HttpCache\Esi; use Symfony\Component\HttpKernel\HttpCache\Esi;
@ -43,7 +42,7 @@ class EsiListener implements EventSubscriberInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType() || null === $this->esi) { if (!$event->isMasterRequest() || null === $this->esi) {
return; return;
} }

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\HttpKernel\EventListener; namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@ -62,7 +61,7 @@ class ProfilerListener implements EventSubscriberInterface
*/ */
public function onKernelException(GetResponseForExceptionEvent $event) public function onKernelException(GetResponseForExceptionEvent $event)
{ {
if ($this->onlyMasterRequests && HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if ($this->onlyMasterRequests && !$event->isMasterRequest()) {
return; return;
} }
@ -81,7 +80,7 @@ class ProfilerListener implements EventSubscriberInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
$master = HttpKernelInterface::MASTER_REQUEST === $event->getRequestType(); $master = $event->isMasterRequest();
if ($this->onlyMasterRequests && !$master) { if ($this->onlyMasterRequests && !$master) {
return; return;
} }

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\HttpKernel\EventListener; namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -37,7 +36,7 @@ class ResponseListener implements EventSubscriberInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -13,7 +13,6 @@ namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -32,7 +31,7 @@ class StreamedResponseListener implements EventSubscriberInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Security\Http; namespace Symfony\Component\Security\Http;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@ -51,7 +50,7 @@ class Firewall implements EventSubscriberInterface
*/ */
public function onKernelRequest(GetResponseEvent $event) public function onKernelRequest(GetResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\Security\Http\Firewall; namespace Symfony\Component\Security\Http\Firewall;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
@ -65,7 +64,7 @@ class ContextListener implements ListenerInterface
*/ */
public function handle(GetResponseEvent $event) public function handle(GetResponseEvent $event)
{ {
if (null !== $this->dispatcher && HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { if (null !== $this->dispatcher && $event->isMasterRequest()) {
$this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse')); $this->dispatcher->addListener(KernelEvents::RESPONSE, array($this, 'onKernelResponse'));
} }
@ -104,7 +103,7 @@ class ContextListener implements ListenerInterface
*/ */
public function onKernelResponse(FilterResponseEvent $event) public function onKernelResponse(FilterResponseEvent $event)
{ {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) { if (!$event->isMasterRequest()) {
return; return;
} }

View File

@ -201,8 +201,8 @@ class ContextListenerTest extends \PHPUnit_Framework_TestCase
$listener = new ContextListener($context, array(), 'key123', null, $dispatcher); $listener = new ContextListener($context, array(), 'key123', null, $dispatcher);
$event->expects($this->any()) $event->expects($this->any())
->method('getRequestType') ->method('isMasterRequest')
->will($this->returnValue(HttpKernelInterface::MASTER_REQUEST)); ->will($this->returnValue(true));
$event->expects($this->any()) $event->expects($this->any())
->method('getRequest') ->method('getRequest')
->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Request'))); ->will($this->returnValue($this->getMock('Symfony\Component\HttpFoundation\Request')));