diff --git a/.travis.yml b/.travis.yml index e3dd7657..6b29579e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ cache: env: global: - VARNISH_VERSION=5.1 - - DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^1.1.2" + - DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^2.2.0" matrix: fast_finish: true @@ -18,7 +18,6 @@ matrix: env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES="" - php: 5.6 - - php: 7.0 - php: 7.1 - php: 7.2 - php: 7.3 @@ -30,7 +29,7 @@ matrix: # Test Symfony LTS versions - php: 7.3 - env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^1.0" + env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^2.2.0" - php: 7.3 env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4" diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ee502e..a4c6c66c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,18 @@ Changelog See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpCache/releases). +2.8.1 +----- + +### General + +* Removed PHP 7.0 compatibility + +### Symfony HttpCache + +* Fixed issue with `PurgeTagsListener` and Symfony 5 +* Fixed clearing the cache completely together with toflar psr6 store did not work + 2.8.0 ----- diff --git a/composer.json b/composer.json index 786aafb5..390fcafe 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ } ], "require": { - "php": "^5.6 || ^7.0.0", + "php": "^5.6 || ^7.1.0", "symfony/event-dispatcher": "^3.4 || ^4.3 || ^5.0", "symfony/options-resolver": "^3.4 || ^4.3 || ^5.0", "php-http/client-implementation": "^1.0 || ^2.0", @@ -39,7 +39,7 @@ "symfony/http-kernel": "^3.4 || ^4.3 || ^5.0" }, "conflict": { - "toflar/psr6-symfony-http-cache-store": "<1.1.2" + "toflar/psr6-symfony-http-cache-store": "<2.2.1" }, "suggest": { "friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework", diff --git a/src/SymfonyCache/PurgeListener.php b/src/SymfonyCache/PurgeListener.php index f05b32b4..91f7cfb4 100644 --- a/src/SymfonyCache/PurgeListener.php +++ b/src/SymfonyCache/PurgeListener.php @@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\OptionsResolver\OptionsResolver; -use Toflar\Psr6HttpCacheStore\Psr6StoreInterface; +use Toflar\Psr6HttpCacheStore\ClearableInterface; /** * Purge handler for the symfony built-in HttpCache. @@ -98,17 +98,17 @@ public function handlePurge(CacheEvent $event) // Purge whole cache if ($request->headers->has($this->clearCacheHeader)) { - if (!$store instanceof Psr6StoreInterface) { + if (!$store instanceof ClearableInterface) { $response->setStatusCode(400); - $response->setContent('Store must be an instance of '.Psr6StoreInterface::class.'. Please check your proxy configuration.'); + $response->setContent('Store must be an instance of '.ClearableInterface::class.'. Please check your proxy configuration.'); $event->setResponse($response); return; } - $store->prune(); + $store->clear(); - $response->setStatusCode(200, 'Pruned'); + $response->setStatusCode(200, 'Purged'); $event->setResponse($response); return; diff --git a/src/SymfonyCache/PurgeTagsListener.php b/src/SymfonyCache/PurgeTagsListener.php index b8f746dc..821213fe 100644 --- a/src/SymfonyCache/PurgeTagsListener.php +++ b/src/SymfonyCache/PurgeTagsListener.php @@ -119,8 +119,16 @@ public function handlePurgeTags(CacheEvent $event) $tags = []; - foreach ($request->headers->get($this->tagsHeader, '', false) as $v) { - foreach (explode(',', $v) as $tag) { + // Compatibility with Symfony < 4.4 + $reflection = new \ReflectionClass($request->headers); + if (1 === $reflection->getMethod('all')->getNumberOfParameters()) { + $headers = $request->headers->all($this->tagsHeader); + } else { + $headers = $request->headers->get($this->tagsHeader, '', false); + } + + foreach ($headers as $header) { + foreach (explode(',', $header) as $tag) { $tags[] = $tag; } } diff --git a/tests/Unit/SymfonyCache/PurgeListenerTest.php b/tests/Unit/SymfonyCache/PurgeListenerTest.php index 748f3bdc..27795103 100644 --- a/tests/Unit/SymfonyCache/PurgeListenerTest.php +++ b/tests/Unit/SymfonyCache/PurgeListenerTest.php @@ -71,7 +71,7 @@ public function testClearCache() /** @var Psr6Store $store */ $store = \Mockery::mock(Psr6Store::class) - ->shouldReceive('prune') + ->shouldReceive('clear') ->once() ->getMock(); $kernel = $this->getKernelMock($store); @@ -93,18 +93,15 @@ public function testClearCacheWithoutPsr6Store() /** @var StoreInterface $store */ $store = \Mockery::mock(StoreInterface::class); $kernel = $this->getKernelMock($store); - $purgeListener = new PurgeListener(); $request = Request::create('http://example.com/', 'PURGE'); $request->headers->set('Clear-Cache', 'true'); $event = new CacheEvent($kernel, $request); - $purgeListener->handlePurge($event); $response = $event->getResponse(); - $this->assertInstanceOf(Response::class, $response); $this->assertSame(400, $response->getStatusCode()); - $this->assertSame('Store must be an instance of Toflar\Psr6HttpCacheStore\Psr6StoreInterface. Please check your proxy configuration.', $response->getContent()); + $this->assertSame('Store must be an instance of Toflar\Psr6HttpCacheStore\ClearableInterface. Please check your proxy configuration.', $response->getContent()); } public function testPurgeAllowedMiss()