Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,32 @@

namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* listen to HEAD requests, return response after security, but before Controller is invoked
* Listen to HEAD requests, return response after security, but before
* Controller is invoked.
*
* @author Stefan Paschke <stefan.paschke@gmail.com>
*/
class CacheAuthorizationListener
class CacheAuthorizationSubscriber implements EventSubscriberInterface
{
/**
* @param GetResponseEvent $event
*/
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
KernelEvents::REQUEST => 'onKernelRequest',
);
}

/**
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\SecurityContextInterface;

/**
Expand All @@ -15,7 +17,7 @@
*
* @author Lea Haensenberger <lea.haensenberger@gmail.com>
*/
class CacheControlListener
class CacheControlSubscriber implements EventSubscriberInterface
{
/**
* @var SecurityContextInterface
Expand Down Expand Up @@ -61,6 +63,16 @@ public function __construct(SecurityContextInterface $securityContext = null, $d
$this->debugHeader = $debugHeader;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => 'onKernelResponse',
);
}

/**
* @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance
* @param array $options An array of options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace FOS\HttpCacheBundle\EventListener;

use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* This listener reads all flash messages and moves them into a cookie.
* This event handler reads all flash messages and moves them into a cookie.
*
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
*/
class FlashMessageListener
class FlashMessageSubscriber implements EventSubscriberInterface
{
/**
* @var array
Expand All @@ -37,6 +39,16 @@ public function __construct($session, array $options = array())
$this->options = $options;
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => 'onKernelResponse',
);
}

/**
* Moves flash messages from the session to a cookie inside a Response Kernel listener
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
use Symfony\Component\Routing\RouterInterface;

/**
* On kernel.terminate event, this listener invalidates routes for the current
* request and flushes the CacheManager.
* On kernel.terminate event, this event handler invalidates routes for the
* current request and flushes the CacheManager.
*
* @author David de Boer <david@driebit.nl>
*/
class InvalidationListener implements EventSubscriberInterface
class InvalidationSubscriber implements EventSubscriberInterface
{
/**
* Cache manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
namespace FOS\HttpCacheBundle\EventListener;

use FOS\HttpCacheBundle\CacheManager;
use FOS\HttpCacheBundle\Configuration\Tag;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;

class TagListener implements EventSubscriberInterface
/**
* Event handler for the cache tagging tags.
*
* @author David de Boer <david@driebit.nl>
*/
class TagSubscriber implements EventSubscriberInterface
{
/**
* @var CacheManager
Expand Down Expand Up @@ -44,6 +50,7 @@ public function onKernelResponse(FilterResponseEvent $event)

// Check for _tag request attribute that is set when using @Tag
// annotation
/** @var $tagConfigurations Tag[] */
if (!$tagConfigurations = $request->attributes->get('_tag')) {
return;
}
Expand Down Expand Up @@ -87,4 +94,4 @@ public static function getSubscribedEvents()
KernelEvents::RESPONSE => 'onKernelResponse'
);
}
}
}
4 changes: 2 additions & 2 deletions Resources/config/authorization_request_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="fos_http_cache.event_listener.cache_authorization.class">FOS\HttpCacheBundle\EventListener\CacheAuthorizationListener</parameter>
<parameter key="fos_http_cache.event_listener.cache_authorization.class">FOS\HttpCacheBundle\EventListener\CacheAuthorizationSubscriber</parameter>
</parameters>

<services>
<service id="fos_http_cache.event_listener.cache_authorization"
class="%fos_http_cache.event_listener.cache_authorization.class%">
<tag name="kernel.event_listener" event="kernel.request" method="onKernelRequest" priority="-129" />
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions Resources/config/cache_control_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlListener</parameter>
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlSubscriber</parameter>
<parameter key="fos_http_cache.request_matcher.class">Symfony\Component\HttpFoundation\RequestMatcher</parameter>
</parameters>

Expand All @@ -14,7 +14,7 @@
class="%fos_http_cache.event_listener.cache_control.class%">
<argument type="service" id="security.context" on-invalid="ignore"/>
<argument>%fos_http_cache.debug_header%</argument>
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
<tag name="kernel.event_subscriber" />
</service>

<service id="fos_http_cache.request_matcher"
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/cache_manager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parameters>
<parameter key="fos_http_cache.cache_manager.class">FOS\HttpCacheBundle\CacheManager</parameter>
<parameter key="fos_http_cache.event_listener.log.class">FOS\HttpCache\EventListener\LogSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationListener</parameter>
<parameter key="fos_http_cache.event_listener.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationSubscriber</parameter>
</parameters>

<services>
Expand Down
4 changes: 2 additions & 2 deletions Resources/config/flash_message_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="fos_http_cache.event_listener.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageListener</parameter>
<parameter key="fos_http_cache.event_listener.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageSubscriber</parameter>
</parameters>

<services>
<service id="fos_http_cache.event_listener.flash_message"
class="%fos_http_cache.event_listener.flash_message.class%">
<argument type="service" id="session"/>
<argument>%fos_http_cache.event_listener.flash_message.options%</argument>
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
4 changes: 2 additions & 2 deletions Resources/config/tag_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>
<parameter key="fos_http_cache.event_listener.tag.class">FOS\HttpCacheBundle\EventListener\TagListener</parameter>
<parameter key="fos_http_cache.event_listener.tag.class">FOS\HttpCacheBundle\EventListener\TagSubscriber</parameter>
</parameters>

<services>
<service id="fos_http_cache.event_listener.tag"
class="%fos_http_cache.event_listener.tag.class%">
<argument type="service" id="fos_http_cache.cache_manager" />
<tag name="kernel.event_subscriber" event="kernel.response" />
<tag name="kernel.event_subscriber" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TagListenerTest extends WebTestCase
class TagSubscriberTest extends WebTestCase
{
public function testTagsAreSet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace FOS\HttpCacheBundle\Tests\Unit\EventListener;

use FOS\HttpCacheBundle\EventListener\CacheAuthorizationListener;
use FOS\HttpCacheBundle\EventListener\CacheAuthorizationSubscriber;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;

class CacheAuthorizationListenerTest extends \PHPUnit_Framework_TestCase
class CacheAuthorizationSubscriberTest extends \PHPUnit_Framework_TestCase
{
public function testHeadRequest()
{
$request = new Request();
$request->setMethod('HEAD');
$event = $this->getEvent($request);

$listener = new CacheAuthorizationListener();
$listener = new CacheAuthorizationSubscriber();
$listener->onKernelRequest($event);
$this->assertTrue($event->hasResponse());
}
Expand All @@ -26,7 +26,7 @@ public function testNonHeadRequest()
$request->setMethod('GET');
$event = $this->getEvent($request);

$listener = new CacheAuthorizationListener();
$listener = new CacheAuthorizationSubscriber();
$listener->onKernelRequest($event);
$this->assertFalse($event->hasResponse());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
namespace FOS\HttpCacheBundle\Tests\Unit\EventListener;

use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
use FOS\HttpCacheBundle\EventListener\CacheControlListener;
use FOS\HttpCacheBundle\EventListener\CacheControlSubscriber;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcher;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;

class CacheControlListenerTest extends \PHPUnit_Framework_TestCase
class CacheControlSubscriberTest extends \PHPUnit_Framework_TestCase
{
public function testDefaultHeaders()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand Down Expand Up @@ -45,7 +45,7 @@ public function testDefaultHeaders()

public function testExtraHeaders()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand All @@ -72,7 +72,7 @@ public function testExtraHeaders()

public function testCompoundHeaders()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand Down Expand Up @@ -105,7 +105,7 @@ public function testCompoundHeaders()

public function testSetNoCacheHeaders()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand Down Expand Up @@ -139,7 +139,7 @@ public function testSetNoCacheHeaders()

public function testVary()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand All @@ -165,7 +165,7 @@ public function testVary()

public function testReverseProxyTtl()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->getMock();

Expand All @@ -189,7 +189,7 @@ public function testReverseProxyTtl()

public function testDebug()
{
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlListener')
$listener = $this->getMockBuilder('FOS\HttpCacheBundle\EventListener\CacheControlSubscriber')
->setMethods(array('getOptions'))
->setConstructorArgs(array(null, 'X-Cache-Debug'))
->getMock();
Expand Down Expand Up @@ -245,7 +245,7 @@ public function testConfigDefineRequestMatcherWithControllerName() {

public function testMatchRuleWithActionName()
{
$listener = new \FOS\HttpCacheBundle\EventListener\CacheControlListener();
$listener = new \FOS\HttpCacheBundle\EventListener\CacheControlSubscriber();

$headers = array( 'controls' => array(
'etag' => '1337',
Expand Down Expand Up @@ -293,7 +293,7 @@ public function testUnlessRole()
$security = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');


$listener = new CacheControlListener($security);
$listener = new CacheControlSubscriber($security);
$listener->add(
new RequestMatcher(),
array(
Expand Down
Loading