Skip to content

Commit 2c6f31b

Browse files
dbuddeboer
authored andcommitted
clean up event listener class naming (#324)
1 parent e9c6726 commit 2c6f31b

19 files changed

+146
-138
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
1616
* Added support and documentation for setting a custom TTL specifically for the
1717
caching proxy.
1818

19+
### Logging
20+
21+
* BC BREAK: Renamed the log event listener from Logsubscriber to LogListener.
22+
1923
### Tagging
2024

2125
* Abstracting tags by adding new `TagsInterface` for ProxyClients, as part of
@@ -29,7 +33,7 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
2933

3034
* Varnish configuration are now files that you can directly include from your
3135
.vcl and call custom functions to avoid copy-pasting VCL code.
32-
* Moved Varnish 4 and 5 configuration files from `resources/config/varnish-4/`
36+
* Moved Varnish 4 and 5 configuration files from `resources/config/varnish-4/`
3337
to `resources/config/varnish/`.
3438
* Changed default Varnish version to 5.
3539

@@ -40,7 +44,8 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
4044

4145
### Symfony HttpCache
4246

43-
* BC BREAK: Constructors for PurgeSubscriber and RefreshSubscriber now use an
47+
* BC BREAK: Renamed all event listeners to XxListener instead of XxSubscriber.
48+
* BC BREAK: Constructors for PurgeListener and RefreshListener now use an
4449
options array for customization.
4550

4651
### Testing

doc/cache-invalidator.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ So, to catch exceptions::
224224
Logging errors
225225
~~~~~~~~~~~~~~
226226

227-
You can log any exceptions with the help of the ``LogSubscriber`` provided in
227+
You can log any exceptions with the help of the ``LogListener`` provided in
228228
this library. First construct a logger that implements
229229
``\Psr\Log\LoggerInterface``. For instance, when using Monolog_::
230230

@@ -233,12 +233,12 @@ this library. First construct a logger that implements
233233
$monolog = new Logger(...);
234234
$monolog->pushHandler(...);
235235

236-
Then add the logger as a subscriber to the cache invalidator::
236+
Then add the logger as a listener to the cache invalidator::
237237

238-
use FOS\HttpCache\EventListener\LogSubscriber;
238+
use FOS\HttpCache\EventListener\LogListener;
239239

240-
$subscriber = new LogSubscriber($monolog);
241-
$cacheInvalidator->getEventDispatcher()->addSubscriber($subscriber);
240+
$logListener = new LogListener($monolog);
241+
$cacheInvalidator->getEventDispatcher()->addSubscriber($logListener);
242242

243243
Now, if you flush the invalidator, errors will be logged::
244244

doc/symfony-cache-configuration.rst

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait ``FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache``::
4040
use EventDispatchingHttpCache;
4141

4242
/**
43-
* Made public to allow event subscribers to do refresh operations.
43+
* Made public to allow event listeners to do refresh operations.
4444
*
4545
* {@inheritDoc}
4646
*/
@@ -86,14 +86,14 @@ the listeners you need there::
8686

8787
use FOS\HttpCache\SymfonyCache\DebugListener();
8888
use FOS\HttpCache\SymfonyCache\CustomTtlListener();
89-
use FOS\HttpCache\SymfonyCache\PurgeSubscriber;
90-
use FOS\HttpCache\SymfonyCache\RefreshSubscriber;
91-
use FOS\HttpCache\SymfonyCache\UserContextSubscriber;
89+
use FOS\HttpCache\SymfonyCache\PurgeListener;
90+
use FOS\HttpCache\SymfonyCache\RefreshListener;
91+
use FOS\HttpCache\SymfonyCache\UserContextListener;
9292

9393
// ...
9494

9595
/**
96-
* Overwrite constructor to register event subscribers for FOSHttpCache.
96+
* Overwrite constructor to register event listeners for FOSHttpCache.
9797
*/
9898
public function __construct(
9999
HttpKernelInterface $kernel,
@@ -104,9 +104,9 @@ the listeners you need there::
104104
parent::__construct($kernel, $store, $surrogate, $options);
105105

106106
$this->addSubscriber(new CustomTtlListener());
107-
$this->addSubscriber(new PurgeSubscriber());
108-
$this->addSubscriber(new RefreshSubscriber());
109-
$this->addSubscriber(new UserContextSubscriber());
107+
$this->addSubscriber(new PurgeListener());
108+
$this->addSubscriber(new RefreshListener());
109+
$this->addSubscriber(new UserContextListener());
110110
if (isset($options['debug']) && $options['debug']) {
111111
$this->addSubscriber(new DebugListener());
112112
}
@@ -120,7 +120,7 @@ Purge
120120
~~~~~
121121

122122
To support :ref:`cache invalidation <cache invalidate>`, register the
123-
``PurgeSubscriber``. If the default settings are right for you, you don't
123+
``PurgeListener``. If the default settings are right for you, you don't
124124
need to do anything more.
125125

126126
Purging is only allowed from the same machine by default. To purge data from
@@ -146,14 +146,14 @@ Refresh
146146
~~~~~~~
147147

148148
To support :ref:`cache refresh <cache refresh>`, register the
149-
``RefreshSubscriber``. You can pass the constructor an option to specify
149+
``RefreshListener``. You can pass the constructor an option to specify
150150
what clients are allowed to refresh cache entries. Refreshing is only allowed
151151
from the same machine by default. To refresh from other hosts, provide the
152152
IPs of the machines allowed to refresh, or provide a RequestMatcher that
153153
checks for an Authorization header or similar. *Only set one of
154154
``client_ips`` or ``client_matcher``*.
155155

156-
The refresh subscriber needs to access the ``HttpCache::fetch`` method which
156+
The refresh listener needs to access the ``HttpCache::fetch`` method which
157157
is protected on the base HttpCache class. The ``EventDispatchingHttpCache``
158158
exposes the method as public, but if you implement your own kernel, you need
159159
to overwrite the method to make it public.
@@ -174,7 +174,7 @@ User Context
174174
~~~~~~~~~~~~
175175

176176
To support :doc:`user context hashing <user-context>` you need to register the
177-
``UserContextSubscriber``. The user context is then automatically recognized
177+
``UserContextListener``. The user context is then automatically recognized
178178
based on session cookies or authorization headers. If the default settings are
179179
right for you, you don't need to do anything more. You can customize a number of
180180
options through the constructor:
@@ -230,9 +230,9 @@ options through the constructor:
230230
Cleaning the Cookie Header
231231
^^^^^^^^^^^^^^^^^^^^^^^^^^
232232

233-
By default, the UserContextSubscriber only sets the session cookie (according to
233+
By default, the UserContextListener only sets the session cookie (according to
234234
the ``session_name_prefix`` option) in the requests to the backend. If you need
235-
a different behavior, overwrite ``UserContextSubscriber::cleanupHashLookupRequest``
235+
a different behavior, overwrite ``UserContextListener::cleanupHashLookupRequest``
236236
with your own logic.
237237

238238
.. _symfonycache_customttl:
@@ -242,11 +242,11 @@ Custom TTL
242242

243243
.. include:: includes/custom-ttl.rst
244244

245-
The ``CustomTtlSubscriber`` looks at a specific header to determine the TTL,
245+
The ``CustomTtlListener`` looks at a specific header to determine the TTL,
246246
preferring that over ``s-maxage``. The default header is ``X-Reverse-Proxy-TTL``
247-
but you can customize that in the subscriber constructor::
247+
but you can customize that in the listener constructor::
248248

249-
new CustomTtlSubscriber('My-TTL-Header');
249+
new CustomTtlListener('My-TTL-Header');
250250

251251
The custom header is removed before sending the response to the client.
252252

src/EventListener/LogSubscriber.php renamed to src/EventListener/LogListener.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
use Psr\Log\LogLevel;
1818
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1919

20-
class LogSubscriber implements EventSubscriberInterface
20+
/**
21+
* Log when the caching proxy client can't send requests to the caching server.
22+
*/
23+
class LogListener implements EventSubscriberInterface
2124
{
2225
/**
2326
* @var LoggerInterface

src/ProxyClient/Symfony.php

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

1414
use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
1515
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
16-
use FOS\HttpCache\SymfonyCache\PurgeSubscriber;
16+
use FOS\HttpCache\SymfonyCache\PurgeListener;
1717

1818
/**
1919
* Symfony HttpCache invalidator.
@@ -53,7 +53,7 @@ protected function configureOptions()
5353
{
5454
$resolver = parent::configureOptions();
5555
$resolver->setDefaults([
56-
'purge_method' => PurgeSubscriber::DEFAULT_PURGE_METHOD,
56+
'purge_method' => PurgeListener::DEFAULT_PURGE_METHOD,
5757
]);
5858

5959
return $resolver;

src/SymfonyCache/AccessControlledSubscriber.php renamed to src/SymfonyCache/AccessControlledListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@
2525
*
2626
* {@inheritdoc}
2727
*/
28-
abstract class AccessControlledSubscriber implements EventSubscriberInterface
28+
abstract class AccessControlledListener implements EventSubscriberInterface
2929
{
3030
/**
3131
* @var RequestMatcher
3232
*/
3333
private $clientMatcher;
3434

3535
/**
36-
* When creating this subscriber, you can configure a number of options.
36+
* When creating this event listener, you can configure a number of options.
3737
*
3838
* - client_matcher: RequestMatcherInterface to identify clients that are allowed to send request.
3939
* - client_ips: IP or array of IPs of clients that are allowed to send requests.

src/SymfonyCache/CacheInvalidationInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface CacheInvalidationInterface extends HttpKernelInterface
2626
*
2727
* This methods is triggered when the cache missed or a reload is required.
2828
*
29-
* This method is present on HttpCache but must be public to allow event subscribers to do
29+
* This method is present on HttpCache but must be public to allow event listeners to do
3030
* refresh operations.
3131
*
3232
* @param Request $request A Request instance

src/SymfonyCache/EventDispatchingHttpCache.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* public does not satisfy the interface for whatever reason. See also
2727
* http://stackoverflow.com/questions/31877844/php-trait-exposing-a-method-and-interfaces )
2828
*
29-
* CacheInvalidator kernels support event subscribers that can act on the
29+
* CacheInvalidator kernels support event listeners that can act on the
3030
* events defined in FOS\HttpCache\SymfonyCache\Events and may alter the
3131
* request flow.
3232
*
@@ -62,7 +62,7 @@ public function getEventDispatcher()
6262
}
6363

6464
/**
65-
* Add subscriber.
65+
* Add an event subscriber.
6666
*
6767
* @param EventSubscriberInterface $subscriber
6868
*/

src/SymfonyCache/PurgeSubscriber.php renamed to src/SymfonyCache/PurgeListener.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* {@inheritdoc}
2323
*/
24-
class PurgeSubscriber extends AccessControlledSubscriber
24+
class PurgeListener extends AccessControlledListener
2525
{
2626
const DEFAULT_PURGE_METHOD = 'PURGE';
2727

@@ -33,15 +33,15 @@ class PurgeSubscriber extends AccessControlledSubscriber
3333
private $purgeMethod;
3434

3535
/**
36-
* When creating the purge subscriber, you can configure an additional option.
36+
* When creating the purge listener, you can configure an additional option.
3737
*
38-
* - purge_method: HTTP method that identifies purge requests.
38+
* - purge_method: HTTP method that identifies purge requests.
3939
*
4040
* @param array $options Options to overwrite the default options
4141
*
4242
* @throws \InvalidArgumentException if unknown keys are found in $options
4343
*
44-
* @see AccessControlledSubscriber::__construct
44+
* @see AccessControlledListener::__construct
4545
*/
4646
public function __construct(array $options = [])
4747
{

src/SymfonyCache/RefreshSubscriber.php renamed to src/SymfonyCache/RefreshListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* {@inheritdoc}
2323
*/
24-
class RefreshSubscriber extends AccessControlledSubscriber
24+
class RefreshListener extends AccessControlledListener
2525
{
2626
/**
2727
* {@inheritdoc}

src/SymfonyCache/UserContextSubscriber.php renamed to src/SymfonyCache/UserContextListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
* {@inheritdoc}
2626
*/
27-
class UserContextSubscriber implements EventSubscriberInterface
27+
class UserContextListener implements EventSubscriberInterface
2828
{
2929
/**
3030
* The options configured in the constructor argument or default values.
@@ -41,7 +41,7 @@ class UserContextSubscriber implements EventSubscriberInterface
4141
private $userHash;
4242

4343
/**
44-
* When creating this subscriber, you can configure a number of options.
44+
* When creating this listener, you can configure a number of options.
4545
*
4646
* - anonymous_hash: Hash used for anonymous user.
4747
* - user_hash_accept_header: Accept header value to be used to request the user hash to the

0 commit comments

Comments
 (0)