Skip to content

Remove deprecations #217

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
Jun 19, 2015
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
5 changes: 0 additions & 5 deletions doc/invalidation-handlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ to simplify common operations.
Tag Handler
-----------

.. versionadded:: 1.3
The tag handler was added in FOSHttpCache 1.3. If you are using an older
version of the library and can not update, you need to use
``CacheInvalidator::invalidateTags``.

The tag handler helps you to mark responses with tags that you can later use to
invalidate all cache entries with that tag. Tag invalidation works only with a
``CacheInvalidator`` that supports ``CacheInvalidator::INVALIDATE``.
Expand Down
93 changes: 4 additions & 89 deletions src/CacheInvalidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use FOS\HttpCache\ProxyClient\Invalidation\BanInterface;
use FOS\HttpCache\ProxyClient\Invalidation\PurgeInterface;
use FOS\HttpCache\ProxyClient\Invalidation\RefreshInterface;
use FOS\HttpCache\Handler\TagHandler;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -58,18 +57,6 @@ class CacheInvalidator
*/
private $eventDispatcher;

/**
* @deprecated This reference is only for BC and will be removed in version 2.0.
*
* @var TagHandler
*/
private $tagHandler;

/**
* @var string
*/
private $tagsHeader = 'X-Cache-Tags';

/**
* Constructor
*
Expand All @@ -78,9 +65,6 @@ class CacheInvalidator
public function __construct(ProxyClientInterface $cache)
{
$this->cache = $cache;
if ($cache instanceof BanInterface) {
$this->tagHandler = new TagHandler($this, $this->tagsHeader);
}
}

/**
Expand Down Expand Up @@ -144,52 +128,6 @@ public function getEventDispatcher()
return $this->eventDispatcher;
}

/**
* Add subscriber
*
* @param EventSubscriberInterface $subscriber
*
* @return $this
*
* @deprecated Use getEventDispatcher()->addSubscriber($subscriber) instead.
*/
public function addSubscriber(EventSubscriberInterface $subscriber)
{
$this->getEventDispatcher()->addSubscriber($subscriber);

return $this;
}

/**
* Set the HTTP header name that will hold cache tags
*
* @param string $tagsHeader
*
* @return $this
*
* @deprecated Use constructor argument to TagHandler instead.
*/
public function setTagsHeader($tagsHeader)
{
if ($this->tagHandler && $this->tagHandler->getTagsHeaderName() !== $tagsHeader) {
$this->tagHandler = new TagHandler($this, $tagsHeader);
}

return $this;
}

/**
* Get the HTTP header name that will hold cache tags
*
* @return string
*
* @deprecated Use TagHandler::getTagsHeaderName instead.
*/
public function getTagsHeader()
{
return $this->tagHandler ? $this->tagHandler->getTagsHeaderName() : $this->tagsHeader;
}

/**
* Invalidate a path or URL
*
Expand All @@ -200,7 +138,7 @@ public function getTagsHeader()
*
* @return $this
*/
public function invalidatePath($path, array $headers = array())
public function invalidatePath($path, array $headers = [])
{
if (!$this->cache instanceof PurgeInterface) {
throw UnsupportedProxyOperationException::cacheDoesNotImplement('PURGE');
Expand All @@ -223,7 +161,7 @@ public function invalidatePath($path, array $headers = array())
*
* @return $this
*/
public function refreshPath($path, array $headers = array())
public function refreshPath($path, array $headers = [])
{
if (!$this->cache instanceof RefreshInterface) {
throw UnsupportedProxyOperationException::cacheDoesNotImplement('REFRESH');
Expand All @@ -238,7 +176,7 @@ public function refreshPath($path, array $headers = array())
* Invalidate all cached objects matching the provided HTTP headers.
*
* Each header is a a POSIX regular expression, for example
* array('X-Host' => '^(www\.)?(this|that)\.com$')
* ['X-Host' => '^(www\.)?(this|that)\.com$']
*
* @see BanInterface::ban()
*
Expand All @@ -265,7 +203,7 @@ public function invalidate(array $headers)
*
* The hosts parameter can either be a regular expression, e.g.
* '^(www\.)?(this|that)\.com$' or an array of exact host names, e.g.
* array('example.com', 'other.net'). If the parameter is empty, all hosts
* ['example.com', 'other.net']. If the parameter is empty, all hosts
* are matched.
*
* @see BanInterface::banPath()
Expand All @@ -292,29 +230,6 @@ public function invalidateRegex($path, $contentType = null, $hosts = null)
return $this;
}

/**
* Invalidate cache entries that contain any of the specified tags in their
* tag header.
*
* @param array $tags Cache tags
*
* @throws UnsupportedProxyOperationException If HTTP cache does not support BAN requests
*
* @return $this
*
* @deprecated Use TagHandler::invalidateTags instead.
*/
public function invalidateTags(array $tags)
{
if (!$this->tagHandler) {
throw UnsupportedProxyOperationException::cacheDoesNotImplement('BAN');
}

$this->tagHandler->invalidateTags($tags);

return $this;
}

/**
* Send all pending invalidation requests.
*
Expand Down
6 changes: 3 additions & 3 deletions src/Exception/ExceptionCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
class ExceptionCollection extends \Exception implements \IteratorAggregate, \Countable, HttpCacheExceptionInterface
{
private $exceptions = array();
public function __construct(array $exceptions = array())
private $exceptions = [];

public function __construct(array $exceptions = [])
{
foreach ($exceptions as $exception) {
$this->add($exception);
Expand Down
6 changes: 3 additions & 3 deletions src/Handler/TagHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class TagHandler
/**
* @var array
*/
private $tags = array();
private $tags = [];

/**
* Constructor
Expand Down Expand Up @@ -113,7 +113,7 @@ public function addTags(array $tags)
public function invalidateTags(array $tags)
{
$tagExpression = sprintf('(%s)(,.+)?$', implode('|', array_map('preg_quote', $this->escapeTags($tags))));
$headers = array($this->tagsHeader => $tagExpression);
$headers = [$this->tagsHeader => $tagExpression];
$this->invalidator->invalidate($headers);

return $this;
Expand All @@ -129,7 +129,7 @@ public function invalidateTags(array $tags)
protected function escapeTags(array $tags)
{
array_walk($tags, function (&$tag) {
$tag = str_replace(array(',', "\n"), array('_', '_'), $tag);
$tag = str_replace([',', "\n"], ['_', '_'], $tag);
});

return $tags;
Expand Down
2 changes: 1 addition & 1 deletion src/ProxyClient/Invalidation/BanInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function ban(array $headers);
*
* The hosts parameter can either be a regular expression, e.g.
* '^(www\.)?(this|that)\.com$' or an array of exact host names, e.g.
* array('example.com', 'other.net'). If the parameter is empty, all hosts
* ['example.com', 'other.net']. If the parameter is empty, all hosts
* are matched.

* @param string $path Regular expression pattern for URI to
Expand Down
2 changes: 1 addition & 1 deletion src/ProxyClient/Invalidation/PurgeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ interface PurgeInterface extends ProxyClientInterface
*
* @return $this
*/
public function purge($url, array $headers = array());
public function purge($url, array $headers = []);
}
2 changes: 1 addition & 1 deletion src/ProxyClient/Invalidation/RefreshInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ interface RefreshInterface extends ProxyClientInterface
*
* @return $this
*/
public function refresh($url, array $headers = array());
public function refresh($url, array $headers = []);
}
6 changes: 3 additions & 3 deletions src/ProxyClient/Symfony.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function purge($url, array $headers = array())
public function purge($url, array $headers = [])
{
$this->queueRequest($this->options['purge_method'], $url, $headers);

Expand All @@ -72,9 +72,9 @@ public function purge($url, array $headers = array())
/**
* {@inheritdoc}
*/
public function refresh($url, array $headers = array())
public function refresh($url, array $headers = [])
{
$headers = array_merge($headers, array('Cache-Control' => 'no-cache'));
$headers = array_merge($headers, ['Cache-Control' => 'no-cache']);
$this->queueRequest(self::HTTP_METHOD_REFRESH, $url, $headers);

return $this;
Expand Down
10 changes: 3 additions & 7 deletions src/SymfonyCache/CacheEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,13 @@ class CacheEvent extends Event
private $response;

/**
* Make sure your $kernel implements CacheInvalidationInterface. Creating the event with other
* HttpCache classes is deprecated and will no longer be supported in version 2 of this library.
* Make sure your $kernel implements CacheInvalidationInterface
*
* @param CacheInvalidationInterface|HttpCache $kernel The kernel raising with this event.
* @param CacheInvalidationInterface$kernel The kernel raising with this event.
* @param Request $request The request being processed.
*/
public function __construct($kernel, Request $request)
public function __construct(CacheInvalidationInterface $kernel, Request $request)
{
if (!($kernel instanceof CacheInvalidationInterface || $kernel instanceof HttpCache)) {
throw new \InvalidArgumentException('Expected a CacheInvalidationInterface or HttpCache');
}
$this->kernel = $kernel;
$this->request = $request;
}
Expand Down
8 changes: 4 additions & 4 deletions src/SymfonyCache/PurgeSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PurgeSubscriber extends AccessControlledSubscriber
*
* @var array
*/
private $options = array();
private $options = [];

/**
* When creating this subscriber, you can configure a number of options.
Expand All @@ -49,14 +49,14 @@ class PurgeSubscriber extends AccessControlledSubscriber
*
* @throws \InvalidArgumentException if unknown keys are found in $options
*/
public function __construct(array $options = array())
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
if (method_exists($resolver, 'setDefined')) {
// this was only added in symfony 2.6
$resolver->setDefined(array('purge_client_matcher', 'purge_client_ips', 'purge_method'));
$resolver->setDefined(['purge_client_matcher', 'purge_client_ips', 'purge_method']);
} else {
$resolver->setOptional(array('purge_client_matcher', 'purge_client_ips', 'purge_method'));
$resolver->setOptional(['purge_client_matcher', 'purge_client_ips', 'purge_method']);
}
$resolver->setDefaults(array(
'purge_client_matcher' => null,
Expand Down
2 changes: 1 addition & 1 deletion src/SymfonyCache/RefreshSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RefreshSubscriber extends AccessControlledSubscriber
*
* @throws \InvalidArgumentException if unknown keys are found in $options
*/
public function __construct(array $options = array())
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
Expand Down
6 changes: 3 additions & 3 deletions src/SymfonyCache/UserContextSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class UserContextSubscriber implements EventSubscriberInterface
*
* @throws \InvalidArgumentException if unknown keys are found in $options
*/
public function __construct(array $options = array())
public function __construct(array $options = [])
{
$resolver = new OptionsResolver();
$resolver->setDefaults(array(
Expand Down Expand Up @@ -123,7 +123,7 @@ public function preHandle(CacheEvent $event)
*/
protected function cleanupHashLookupRequest(Request $hashLookupRequest, Request $originalRequest)
{
$sessionIds = array();
$sessionIds = [];
foreach ($originalRequest->cookies as $name => $value) {
if ($this->isSessionName($name)) {
$sessionIds[$name] = $value;
Expand Down Expand Up @@ -223,7 +223,7 @@ private function isSessionName($name)
*/
private function generateHashLookupRequest(Request $request)
{
$hashLookupRequest = Request::create($this->options['user_hash_uri'], $this->options['user_hash_method'], array(), array(), array(), $request->server->all());
$hashLookupRequest = Request::create($this->options['user_hash_uri'], $this->options['user_hash_method'], [], [], [], $request->server->all());
$hashLookupRequest->attributes->set('internalRequest', true);
$hashLookupRequest->headers->set('Accept', $this->options['user_hash_accept_header']);
$this->cleanupHashLookupRequest($hashLookupRequest, $request);
Expand Down
2 changes: 1 addition & 1 deletion src/Test/NginxTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function getProxyClient($purgeLocation = '')
{
if (null === $this->proxyClient) {
$this->proxyClient = new Nginx(
array('http://127.0.0.1:' . $this->getCachingProxyPort()),
['http://127.0.0.1:' . $this->getCachingProxyPort()],
$this->getHostName()
);

Expand Down
4 changes: 2 additions & 2 deletions src/Test/Proxy/NginxProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function start()
public function stop()
{
if (file_exists($this->pid)) {
$this->runCommand('kill', array(file_get_contents($this->pid)));
$this->runCommand('kill', [file_get_contents($this->pid)]);
}
}

Expand All @@ -61,7 +61,7 @@ public function stop()
*/
public function clear()
{
$this->runCommand('rm', array('-rf', $this->getCacheDir()));
$this->runCommand('rm', ['-rf', $this->getCacheDir()]);
$this->start();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Test/Proxy/VarnishProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function stop()
{
if (file_exists($this->pid)) {
try {
$this->runCommand('kill', array('-9', file_get_contents($this->pid)));
$this->runCommand('kill', ['-9', file_get_contents($this->pid)]);
} catch (\RuntimeException $e) {
// Ignore if command fails when Varnish wasn't running
}
Expand Down
4 changes: 2 additions & 2 deletions src/Test/SymfonyTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ protected function getProxyClient()
{
if (null === $this->proxyClient) {
$this->proxyClient = new Symfony(
array('http://127.0.0.1:' . $this->getCachingProxyPort()),
['http://127.0.0.1:' . $this->getCachingProxyPort()],
$this->getHostName() . ':' . $this->getCachingProxyPort(),
null,
array('purge_method' => 'NOTIFY')
['purge_method' => 'NOTIFY']
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Test/VarnishTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ protected function getProxyClient()
{
if (null === $this->proxyClient) {
$this->proxyClient = new Varnish(
array('http://127.0.0.1:' . $this->getProxy()->getPort()),
['http://127.0.0.1:' . $this->getProxy()->getPort()],
$this->getHostName() . ':' . $this->getProxy()->getPort()
);
}
Expand Down
Loading