Skip to content

cleanup event listener naming #319

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
Nov 24, 2016
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
* [User Context] Added an option always_vary_on_context_hash to make it
possible to disable automatically setting the vary headers for the user
hash.

* [Event Listeners] Renamed the event listener classes to XxxLlistener

1.3.7
-----
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Compiler/LoggerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public function process(ContainerBuilder $container)
return;
}

$subscriber = $container->getDefinition('fos_http_cache.event_listener.log')
$logListener = $container->getDefinition('fos_http_cache.event_listener.log')
->setAbstract(false);

$container->getDefinition('fos_http_cache.cache_manager')
->addMethodCall('addSubscriber', array($subscriber));
->addMethodCall('addSubscriber', array($logListener));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Check for required ControllerListener if TagSubscriber is enabled.
* Check for required ControllerListener if TagListener is enabled.
*/
class TagSubscriberPass implements CompilerPassInterface
class TagListenerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class AbstractRuleSubscriber
abstract class AbstractRuleListener
{
/**
* @var array List of arrays with RuleMatcher, settings array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Lea Haensenberger <[email protected]>
* @author David Buchmann <[email protected]>
*/
class CacheControlSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
class CacheControlListener extends AbstractRuleListener implements EventSubscriberInterface
{
/**
* Whether to skip this response and not set any cache headers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Lukas Kahwe Smith <[email protected]>
*/
class FlashMessageSubscriber implements EventSubscriberInterface
class FlashMessageListener implements EventSubscriberInterface
{
/**
* @var array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* @author David de Boer <[email protected]>
*/
class InvalidationSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface
{
/**
* Cache manager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author David de Boer <[email protected]>
*/
class TagSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
class TagListener extends AbstractRuleListener implements EventSubscriberInterface
{
/**
* @var TagHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Stefan Paschke <[email protected]>
* @author Joel Wurtz <[email protected]>
*/
class UserContextSubscriber implements EventSubscriberInterface
class UserContextListener implements EventSubscriberInterface
{
/**
* @var RequestMatcherInterface
Expand Down
4 changes: 2 additions & 2 deletions FOSHttpCacheBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\SecurityContextPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagSubscriberPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -27,7 +27,7 @@ public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new LoggerPass());
$container->addCompilerPass(new SecurityContextPass());
$container->addCompilerPass(new TagSubscriberPass());
$container->addCompilerPass(new TagListenerPass());
$container->addCompilerPass(new HashGeneratorPass());
}
}
2 changes: 1 addition & 1 deletion 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\CacheControlSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlListener</parameter>
</parameters>

<services>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/cache_tagging.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.tag.class">FOS\HttpCacheBundle\EventListener\TagSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.tag.class">FOS\HttpCacheBundle\EventListener\TagListener</parameter>
<parameter key="fos_http_cache.command.invalidate_tag.class">FOS\HttpCacheBundle\Command\InvalidateTagCommand</parameter>
</parameters>

Expand Down
2 changes: 1 addition & 1 deletion Resources/config/flash_message.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.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageListener</parameter>
</parameters>

<services>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/invalidation_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.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationListener</parameter>
</parameters>

<services>
Expand Down
2 changes: 1 addition & 1 deletion Resources/config/user_context.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.user_context.class">FOS\HttpCacheBundle\EventListener\UserContextSubscriber</parameter>
<parameter key="fos_http_cache.event_listener.user_context.class">FOS\HttpCacheBundle\EventListener\UserContextListener</parameter>
<parameter key="fos_http_cache.user_context.hash_generator.class">FOS\HttpCache\UserContext\HashGenerator</parameter>
<parameter key="fos_http_cache.user_context.role_provider.class">FOS\HttpCacheBundle\UserContext\RoleProvider</parameter>
<parameter key="fos_http_cache.user_context.request_matcher.class">FOS\HttpCacheBundle\UserContext\RequestMatcher</parameter>
Expand Down
8 changes: 4 additions & 4 deletions Resources/doc/features/helpers/flash-message.rst
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
Flash Message Subscriber
========================
Flash Message Listener
======================

**Prerequisites**: *none*

When flash messages are rendered into the content of a page, you can't cache
the page anymore. When enabled, this subscriber reads all flash messages into a
the page anymore. When enabled, this listener reads all flash messages into a
cookie, leading to them not being there anymore when rendering the template.
This will return the page with a set-cookie header which you of course must
make sure to not cache in varnish. By default, varnish will simply not cache
the whole response when there is a set-cookie header. (Maybe you could do
something more clever — if you do, please provide a VCL example.)

The flash message subscriber is automatically enabled if you configure any of
The flash message listener is automatically enabled if you configure any of
the options under ``flash_message``.

.. code-block:: yaml
Expand Down
31 changes: 17 additions & 14 deletions Resources/doc/features/symfony-http-cache.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ running an application on shared hosting for instance
(see the `Symfony HttpCache documentation`_).

You can use features of this library with the Symfony ``HttpCache``. The basic
concept is to use event subscribers on the HttpCache class.
concept is to use event listeners on the HttpCache class.

.. warning::

Expand Down Expand Up @@ -40,10 +40,10 @@ Instead of extending ``Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache``, you
The drawback is that you need to manually check whether you need to adjust your
``AppCache`` each time you update the FOSHttpCache library.

By default, the event dispatching cache kernel registers all subscribers it knows
about. You can disable subscribers, or customize how they are instantiated.
By default, the event dispatching cache kernel registers all event listeners it
knows about. You can disable listeners, or customize how they are instantiated.

If you do not need all subscribers, or need to register some yourself to
If you do not need all listeners, or need to register some yourself to
customize their behavior, overwrite ``getOptions`` and return the right bitmap
in ``fos_default_subscribers``. Use the constants provided by the
``EventDispatchingHttpCache``::
Expand All @@ -55,27 +55,30 @@ in ``fos_default_subscribers``. Use the constants provided by the
);
}

To register subscribers that you need to instantiate yourself, overwrite
``getDefaultSubscribers``::
To register event listeners that you want to instantiate yourself in the cache
kernel, overwrite ``getDefaultSubscribers``::

use FOS\HttpCache\SymfonyCache\UserContextSubscriber;

// ...

public function getDefaultSubscribers()
{
// get enabled subscribers with default settings
// get enabled listeners with default settings
$subscribers = parent::getDefaultSubscribers();

$subscribers[] = new UserContextSubscriber(array(
$subscribers[] = new UserContextListener(array(
'session_name_prefix' => 'eZSESSID',
));

$subscribers[] = new CustomSubscriber();
$subscribers[] = new CustomListener();

return $subscribers;
}

You can also register event listeners from outside the kernel, e.g. in your
``app.php`` with the ``addListener`` and ``addSubscriber`` methods.

.. warning::

Since Symfony 2.8, the class cache (``classes.php``) is compiled even in
Expand All @@ -96,11 +99,11 @@ To register subscribers that you need to instantiate yourself, overwrite
way to achieve this is to call ``class_exists`` resp. ``interface_exists``
with each of them.

Subscribers
~~~~~~~~~~~
Event Listeners
~~~~~~~~~~~~~~~

Each feature has its subscriber. Subscribers are provided by the FOSHttpCache_
library. You can find the documentation for the subscribers in the
:ref:`FOSHttpCache Symfony Cache documentation section <foshttpcache:symfony httpcache configuration>`.
Each cache feature has its own event listener. The listeners are provided by
the FOSHttpCache_ library. You can find the documentation for those listeners
in the :ref:`FOSHttpCache Symfony Cache documentation section <foshttpcache:symfony httpcache configuration>`.

.. _Symfony HttpCache documentation: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy
6 changes: 3 additions & 3 deletions Resources/doc/features/user-context.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ User Context
If your application serves different content depending on the user's group
or context (guest, editor, admin), you can cache that content per user context.
Each user context (group) gets its own unique hash, which is then used to vary
content on. The event subscriber responds to hash requests and sets the Vary
content on. The event listener responds to hash requests and sets the Vary
header. This way, you can differentiate your content between user groups while
not having to store caches for each individual user.

Expand All @@ -27,7 +27,7 @@ These five steps resemble the Overview in the FOSHttpCache documentation.
2. The :term:`foshttpcache:caching proxy` receives the request and holds it.
It first sends a *hash request* to the *context hash route*.
3. The :term:`foshttpcache:application` receives the hash request. An event
subscriber (``UserContextSubscriber``) aborts the request immediately after
listener (``UserContextListener``) aborts the request immediately after
the Symfony2 firewall was applied. The application calculates the hash
(``HashGenerator``) and then sends a response with the hash in a custom
header (``X-User-Context-Hash`` by default).
Expand Down Expand Up @@ -69,7 +69,7 @@ handle the user context URL like the login page:
- { path: ^/_fos_user_context_hash, roles: [IS_AUTHENTICATED_ANONYMOUSLY] }
- { path: ^/, roles: ROLE_USER }

Finally, enable the subscriber with the default settings:
Finally, enable the listener with the default settings:

.. code-block:: yaml

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class CacheControlSubscriberTest extends WebTestCase
class CacheControlListenerTest extends WebTestCase
{
public function testIsCached()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class InvalidationSubscriberTest extends WebTestCase
class InvalidationListenerTest extends WebTestCase
{
public function testInvalidateRoute()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class TagSubscriberTest extends WebTestCase
class TagListenerTest extends WebTestCase
{
public function testAnnotationTagsAreSet()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

namespace FOS\HttpCacheBundle\Tests\Unit\DependencyInjection\Compiler;

use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagSubscriberPass;
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

class TagSubscriberPassTest extends \PHPUnit_Framework_TestCase
class TagListenerPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @expectedException \RuntimeException
Expand All @@ -25,7 +25,7 @@ class TagSubscriberPassTest extends \PHPUnit_Framework_TestCase
public function testNoFrameworkBundle()
{
$extension = new FOSHttpCacheExtension();
$tagListenerPass = new TagSubscriberPass();
$tagListenerPass = new TagListenerPass();
$container = $this->createContainer();
$config = $this->getConfig();
$extension->load(array($config), $container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ public function testConfigWithoutUserContext()
$this->assertFalse($container->has('fos_http_cache.user_context.logout_handler'));
}

public function testConfigLoadFlashMessageSubscriber()
public function testConfigLoadFlashMessageListener()
{
$config = array(
array('flash_message' => true,
Expand Down
Loading