Skip to content

clean up event listener class naming #324

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 1, 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
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
* Added support and documentation for setting a custom TTL specifically for the
caching proxy.

### Logging

* BC BREAK: Renamed the log event listener from Logsubscriber to LogListener.

### Tagging

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

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

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

### Symfony HttpCache

* BC BREAK: Constructors for PurgeSubscriber and RefreshSubscriber now use an
* BC BREAK: Renamed all event listeners to XxListener instead of XxSubscriber.
* BC BREAK: Constructors for PurgeListener and RefreshListener now use an
options array for customization.

### Testing
Expand Down
10 changes: 5 additions & 5 deletions doc/cache-invalidator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ So, to catch exceptions::
Logging errors
~~~~~~~~~~~~~~

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

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

Then add the logger as a subscriber to the cache invalidator::
Then add the logger as a listener to the cache invalidator::

use FOS\HttpCache\EventListener\LogSubscriber;
use FOS\HttpCache\EventListener\LogListener;

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

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

Expand Down
34 changes: 17 additions & 17 deletions doc/symfony-cache-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ trait ``FOS\HttpCache\SymfonyCache\EventDispatchingHttpCache``::
use EventDispatchingHttpCache;

/**
* Made public to allow event subscribers to do refresh operations.
* Made public to allow event listeners to do refresh operations.
*
* {@inheritDoc}
*/
Expand Down Expand Up @@ -86,14 +86,14 @@ the listeners you need there::

use FOS\HttpCache\SymfonyCache\DebugListener();
use FOS\HttpCache\SymfonyCache\CustomTtlListener();
use FOS\HttpCache\SymfonyCache\PurgeSubscriber;
use FOS\HttpCache\SymfonyCache\RefreshSubscriber;
use FOS\HttpCache\SymfonyCache\UserContextSubscriber;
use FOS\HttpCache\SymfonyCache\PurgeListener;
use FOS\HttpCache\SymfonyCache\RefreshListener;
use FOS\HttpCache\SymfonyCache\UserContextListener;

// ...

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

$this->addSubscriber(new CustomTtlListener());
$this->addSubscriber(new PurgeSubscriber());
$this->addSubscriber(new RefreshSubscriber());
$this->addSubscriber(new UserContextSubscriber());
$this->addSubscriber(new PurgeListener());
$this->addSubscriber(new RefreshListener());
$this->addSubscriber(new UserContextListener());
if (isset($options['debug']) && $options['debug']) {
$this->addSubscriber(new DebugListener());
}
Expand All @@ -120,7 +120,7 @@ Purge
~~~~~

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

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

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

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

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

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

.. _symfonycache_customttl:
Expand All @@ -242,11 +242,11 @@ Custom TTL

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

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

new CustomTtlSubscriber('My-TTL-Header');
new CustomTtlListener('My-TTL-Header');

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
use Psr\Log\LogLevel;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LogSubscriber implements EventSubscriberInterface
/**
* Log when the caching proxy client can't send requests to the caching server.
*/
class LogListener implements EventSubscriberInterface
{
/**
* @var LoggerInterface
Expand Down
4 changes: 2 additions & 2 deletions src/ProxyClient/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
use FOS\HttpCache\SymfonyCache\PurgeSubscriber;
use FOS\HttpCache\SymfonyCache\PurgeListener;

/**
* Symfony HttpCache invalidator.
Expand Down Expand Up @@ -53,7 +53,7 @@ protected function configureOptions()
{
$resolver = parent::configureOptions();
$resolver->setDefaults([
'purge_method' => PurgeSubscriber::DEFAULT_PURGE_METHOD,
'purge_method' => PurgeListener::DEFAULT_PURGE_METHOD,
]);

return $resolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
*
* {@inheritdoc}
*/
abstract class AccessControlledSubscriber implements EventSubscriberInterface
abstract class AccessControlledListener implements EventSubscriberInterface
{
/**
* @var RequestMatcher
*/
private $clientMatcher;

/**
* When creating this subscriber, you can configure a number of options.
* When creating this event listener, you can configure a number of options.
*
* - client_matcher: RequestMatcherInterface to identify clients that are allowed to send request.
* - client_ips: IP or array of IPs of clients that are allowed to send requests.
Expand Down
2 changes: 1 addition & 1 deletion src/SymfonyCache/CacheInvalidationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface CacheInvalidationInterface extends HttpKernelInterface
*
* This methods is triggered when the cache missed or a reload is required.
*
* This method is present on HttpCache but must be public to allow event subscribers to do
* This method is present on HttpCache but must be public to allow event listeners to do
* refresh operations.
*
* @param Request $request A Request instance
Expand Down
4 changes: 2 additions & 2 deletions src/SymfonyCache/EventDispatchingHttpCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* public does not satisfy the interface for whatever reason. See also
* http://stackoverflow.com/questions/31877844/php-trait-exposing-a-method-and-interfaces )
*
* CacheInvalidator kernels support event subscribers that can act on the
* CacheInvalidator kernels support event listeners that can act on the
* events defined in FOS\HttpCache\SymfonyCache\Events and may alter the
* request flow.
*
Expand Down Expand Up @@ -62,7 +62,7 @@ public function getEventDispatcher()
}

/**
* Add subscriber.
* Add an event subscriber.
*
* @param EventSubscriberInterface $subscriber
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* {@inheritdoc}
*/
class PurgeSubscriber extends AccessControlledSubscriber
class PurgeListener extends AccessControlledListener
{
const DEFAULT_PURGE_METHOD = 'PURGE';

Expand All @@ -33,15 +33,15 @@ class PurgeSubscriber extends AccessControlledSubscriber
private $purgeMethod;

/**
* When creating the purge subscriber, you can configure an additional option.
* When creating the purge listener, you can configure an additional option.
*
* - purge_method: HTTP method that identifies purge requests.
* - purge_method: HTTP method that identifies purge requests.
*
* @param array $options Options to overwrite the default options
*
* @throws \InvalidArgumentException if unknown keys are found in $options
*
* @see AccessControlledSubscriber::__construct
* @see AccessControlledListener::__construct
*/
public function __construct(array $options = [])
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* {@inheritdoc}
*/
class RefreshSubscriber extends AccessControlledSubscriber
class RefreshListener extends AccessControlledListener
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* {@inheritdoc}
*/
class UserContextSubscriber implements EventSubscriberInterface
class UserContextListener implements EventSubscriberInterface
{
/**
* The options configured in the constructor argument or default values.
Expand All @@ -41,7 +41,7 @@ class UserContextSubscriber implements EventSubscriberInterface
private $userHash;

/**
* When creating this subscriber, you can configure a number of options.
* When creating this listener, you can configure a number of options.
*
* - anonymous_hash: Hash used for anonymous user.
* - user_hash_accept_header: Accept header value to be used to request the user hash to the
Expand Down
Loading