Skip to content

Commit 536c735

Browse files
authored
Merge pull request #319 from FriendsOfSymfony/event-listener-naming
cleanup event listener naming
2 parents 9bb55b1 + e98d245 commit 536c735

28 files changed

+133
-127
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ Changelog
77
* [User Context] Added an option always_vary_on_context_hash to make it
88
possible to disable automatically setting the vary headers for the user
99
hash.
10+
11+
* [Event Listeners] Renamed the event listener classes to XxxLlistener
1012

1113
1.3.7
1214
-----

DependencyInjection/Compiler/LoggerPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public function process(ContainerBuilder $container)
2828
return;
2929
}
3030

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

3434
$container->getDefinition('fos_http_cache.cache_manager')
35-
->addMethodCall('addSubscriber', array($subscriber));
35+
->addMethodCall('addSubscriber', array($logListener));
3636
}
3737
}

DependencyInjection/Compiler/TagSubscriberPass.php renamed to DependencyInjection/Compiler/TagListenerPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616

1717
/**
18-
* Check for required ControllerListener if TagSubscriber is enabled.
18+
* Check for required ControllerListener if TagListener is enabled.
1919
*/
20-
class TagSubscriberPass implements CompilerPassInterface
20+
class TagListenerPass implements CompilerPassInterface
2121
{
2222
/**
2323
* {@inheritdoc}

EventListener/AbstractRuleSubscriber.php renamed to EventListener/AbstractRuleListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717

18-
class AbstractRuleSubscriber
18+
abstract class AbstractRuleListener
1919
{
2020
/**
2121
* @var array List of arrays with RuleMatcher, settings array

EventListener/CacheControlSubscriber.php renamed to EventListener/CacheControlListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @author Lea Haensenberger <[email protected]>
2626
* @author David Buchmann <[email protected]>
2727
*/
28-
class CacheControlSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
28+
class CacheControlListener extends AbstractRuleListener implements EventSubscriberInterface
2929
{
3030
/**
3131
* Whether to skip this response and not set any cache headers.

EventListener/FlashMessageSubscriber.php renamed to EventListener/FlashMessageListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* @author Lukas Kahwe Smith <[email protected]>
2626
*/
27-
class FlashMessageSubscriber implements EventSubscriberInterface
27+
class FlashMessageListener implements EventSubscriberInterface
2828
{
2929
/**
3030
* @var array

EventListener/InvalidationSubscriber.php renamed to EventListener/InvalidationListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @author David de Boer <[email protected]>
3434
*/
35-
class InvalidationSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
35+
class InvalidationListener extends AbstractRuleListener implements EventSubscriberInterface
3636
{
3737
/**
3838
* Cache manager.

EventListener/TagSubscriber.php renamed to EventListener/TagListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @author David de Boer <[email protected]>
2727
*/
28-
class TagSubscriber extends AbstractRuleSubscriber implements EventSubscriberInterface
28+
class TagListener extends AbstractRuleListener implements EventSubscriberInterface
2929
{
3030
/**
3131
* @var TagHandler

EventListener/UserContextSubscriber.php renamed to EventListener/UserContextListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @author Stefan Paschke <[email protected]>
3131
* @author Joel Wurtz <[email protected]>
3232
*/
33-
class UserContextSubscriber implements EventSubscriberInterface
33+
class UserContextListener implements EventSubscriberInterface
3434
{
3535
/**
3636
* @var RequestMatcherInterface

FOSHttpCacheBundle.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use FOS\HttpCacheBundle\DependencyInjection\Compiler\LoggerPass;
1515
use FOS\HttpCacheBundle\DependencyInjection\Compiler\SecurityContextPass;
16-
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagSubscriberPass;
16+
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
1717
use FOS\HttpCacheBundle\DependencyInjection\Compiler\HashGeneratorPass;
1818
use Symfony\Component\DependencyInjection\ContainerBuilder;
1919
use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -27,7 +27,7 @@ public function build(ContainerBuilder $container)
2727
{
2828
$container->addCompilerPass(new LoggerPass());
2929
$container->addCompilerPass(new SecurityContextPass());
30-
$container->addCompilerPass(new TagSubscriberPass());
30+
$container->addCompilerPass(new TagListenerPass());
3131
$container->addCompilerPass(new HashGeneratorPass());
3232
}
3333
}

Resources/config/cache_control_listener.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlSubscriber</parameter>
8+
<parameter key="fos_http_cache.event_listener.cache_control.class">FOS\HttpCacheBundle\EventListener\CacheControlListener</parameter>
99
</parameters>
1010

1111
<services>

Resources/config/cache_tagging.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="fos_http_cache.event_listener.tag.class">FOS\HttpCacheBundle\EventListener\TagSubscriber</parameter>
8+
<parameter key="fos_http_cache.event_listener.tag.class">FOS\HttpCacheBundle\EventListener\TagListener</parameter>
99
<parameter key="fos_http_cache.command.invalidate_tag.class">FOS\HttpCacheBundle\Command\InvalidateTagCommand</parameter>
1010
</parameters>
1111

Resources/config/flash_message.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="fos_http_cache.event_listener.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageSubscriber</parameter>
8+
<parameter key="fos_http_cache.event_listener.flash_message.class">FOS\HttpCacheBundle\EventListener\FlashMessageListener</parameter>
99
</parameters>
1010

1111
<services>

Resources/config/invalidation_listener.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="fos_http_cache.event_listener.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationSubscriber</parameter>
8+
<parameter key="fos_http_cache.event_listener.invalidation.class">FOS\HttpCacheBundle\EventListener\InvalidationListener</parameter>
99
</parameters>
1010

1111
<services>

Resources/config/user_context.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="fos_http_cache.event_listener.user_context.class">FOS\HttpCacheBundle\EventListener\UserContextSubscriber</parameter>
8+
<parameter key="fos_http_cache.event_listener.user_context.class">FOS\HttpCacheBundle\EventListener\UserContextListener</parameter>
99
<parameter key="fos_http_cache.user_context.hash_generator.class">FOS\HttpCache\UserContext\HashGenerator</parameter>
1010
<parameter key="fos_http_cache.user_context.role_provider.class">FOS\HttpCacheBundle\UserContext\RoleProvider</parameter>
1111
<parameter key="fos_http_cache.user_context.request_matcher.class">FOS\HttpCacheBundle\UserContext\RequestMatcher</parameter>

Resources/doc/features/helpers/flash-message.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
Flash Message Subscriber
2-
========================
1+
Flash Message Listener
2+
======================
33

44
**Prerequisites**: *none*
55

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

14-
The flash message subscriber is automatically enabled if you configure any of
14+
The flash message listener is automatically enabled if you configure any of
1515
the options under ``flash_message``.
1616

1717
.. code-block:: yaml

Resources/doc/features/symfony-http-cache.rst

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ running an application on shared hosting for instance
99
(see the `Symfony HttpCache documentation`_).
1010

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

1414
.. warning::
1515

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

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

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

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

6161
use FOS\HttpCache\SymfonyCache\UserContextSubscriber;
6262

6363
// ...
6464

6565
public function getDefaultSubscribers()
6666
{
67-
// get enabled subscribers with default settings
67+
// get enabled listeners with default settings
6868
$subscribers = parent::getDefaultSubscribers();
6969

70-
$subscribers[] = new UserContextSubscriber(array(
70+
$subscribers[] = new UserContextListener(array(
7171
'session_name_prefix' => 'eZSESSID',
7272
));
7373

74-
$subscribers[] = new CustomSubscriber();
74+
$subscribers[] = new CustomListener();
7575

7676
return $subscribers;
7777
}
7878

79+
You can also register event listeners from outside the kernel, e.g. in your
80+
``app.php`` with the ``addListener`` and ``addSubscriber`` methods.
81+
7982
.. warning::
8083

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

99-
Subscribers
100-
~~~~~~~~~~~
102+
Event Listeners
103+
~~~~~~~~~~~~~~~
101104

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

106109
.. _Symfony HttpCache documentation: http://symfony.com/doc/current/book/http_cache.html#symfony-reverse-proxy

Resources/doc/features/user-context.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ User Context
99
If your application serves different content depending on the user's group
1010
or context (guest, editor, admin), you can cache that content per user context.
1111
Each user context (group) gets its own unique hash, which is then used to vary
12-
content on. The event subscriber responds to hash requests and sets the Vary
12+
content on. The event listener responds to hash requests and sets the Vary
1313
header. This way, you can differentiate your content between user groups while
1414
not having to store caches for each individual user.
1515

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

7474
.. code-block:: yaml
7575

Tests/Functional/EventListener/CacheControlSubscriberTest.php renamed to Tests/Functional/EventListener/CacheControlListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1515

16-
class CacheControlSubscriberTest extends WebTestCase
16+
class CacheControlListenerTest extends WebTestCase
1717
{
1818
public function testIsCached()
1919
{

Tests/Functional/EventListener/InvalidationSubscriberTest.php renamed to Tests/Functional/EventListener/InvalidationListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1515

16-
class InvalidationSubscriberTest extends WebTestCase
16+
class InvalidationListenerTest extends WebTestCase
1717
{
1818
public function testInvalidateRoute()
1919
{

Tests/Functional/EventListener/TagSubscriberTest.php renamed to Tests/Functional/EventListener/TagListenerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1515

16-
class TagSubscriberTest extends WebTestCase
16+
class TagListenerTest extends WebTestCase
1717
{
1818
public function testAnnotationTagsAreSet()
1919
{

Tests/Unit/DependencyInjection/Compiler/TagSubscriberPassTest.php renamed to Tests/Unit/DependencyInjection/Compiler/TagListenerPassTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111

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

14-
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagSubscriberPass;
14+
use FOS\HttpCacheBundle\DependencyInjection\Compiler\TagListenerPass;
1515
use FOS\HttpCacheBundle\DependencyInjection\FOSHttpCacheExtension;
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1818

19-
class TagSubscriberPassTest extends \PHPUnit_Framework_TestCase
19+
class TagListenerPassTest extends \PHPUnit_Framework_TestCase
2020
{
2121
/**
2222
* @expectedException \RuntimeException
@@ -25,7 +25,7 @@ class TagSubscriberPassTest extends \PHPUnit_Framework_TestCase
2525
public function testNoFrameworkBundle()
2626
{
2727
$extension = new FOSHttpCacheExtension();
28-
$tagListenerPass = new TagSubscriberPass();
28+
$tagListenerPass = new TagListenerPass();
2929
$container = $this->createContainer();
3030
$config = $this->getConfig();
3131
$extension->load(array($config), $container);

Tests/Unit/DependencyInjection/FOSHttpCacheExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ public function testConfigWithoutUserContext()
350350
$this->assertFalse($container->has('fos_http_cache.user_context.logout_handler'));
351351
}
352352

353-
public function testConfigLoadFlashMessageSubscriber()
353+
public function testConfigLoadFlashMessageListener()
354354
{
355355
$config = array(
356356
array('flash_message' => true,

0 commit comments

Comments
 (0)