Skip to content

Commit 5abb500

Browse files
authored
Merge pull request #475 from FriendsOfSymfony/hotfix/fix-symfony-not-clearing
Fixed Symfony PurgeListener was pruning instead of purging
2 parents 80a947b + b7cf2c1 commit 5abb500

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

.travis.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ cache:
88
env:
99
global:
1010
- VARNISH_VERSION=5.1
11-
- DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^1.1.2"
11+
- DEPENDENCIES="toflar/psr6-symfony-http-cache-store:^2.2.0"
1212

1313
matrix:
1414
fast_finish: true
@@ -18,7 +18,6 @@ matrix:
1818
env: VARNISH_VERSION=3.0 COMPOSER_FLAGS="--prefer-lowest" DEPENDENCIES=""
1919

2020
- php: 5.6
21-
- php: 7.0
2221
- php: 7.1
2322
- php: 7.2
2423
- php: 7.3
@@ -30,7 +29,7 @@ matrix:
3029

3130
# Test Symfony LTS versions
3231
- php: 7.3
33-
env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^1.0"
32+
env: DEPENDENCIES="symfony/lts:^3 toflar/psr6-symfony-http-cache-store:^2.2.0"
3433
- php: 7.3
3534
env: DEPENDENCIES="symfony/flex" SYMFONY_VERSION="^4"
3635

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ Changelog
33

44
See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpCache/releases).
55

6+
2.8.1
7+
-----
8+
9+
### General
10+
11+
* Removed PHP 7.0 compatibility
12+
13+
### Symfony HttpCache
14+
15+
* Fixed issue with `PurgeTagsListener` and Symfony 5
16+
* Fixed clearing the cache completely together with toflar psr6 store did not work
17+
618
2.8.0
719
-----
820

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
}
2222
],
2323
"require": {
24-
"php": "^5.6 || ^7.0.0",
24+
"php": "^5.6 || ^7.1.0",
2525
"symfony/event-dispatcher": "^3.4 || ^4.3 || ^5.0",
2626
"symfony/options-resolver": "^3.4 || ^4.3 || ^5.0",
2727
"php-http/client-implementation": "^1.0 || ^2.0",
@@ -39,7 +39,7 @@
3939
"symfony/http-kernel": "^3.4 || ^4.3 || ^5.0"
4040
},
4141
"conflict": {
42-
"toflar/psr6-symfony-http-cache-store": "<1.1.2"
42+
"toflar/psr6-symfony-http-cache-store": "<2.2.1"
4343
},
4444
"suggest": {
4545
"friendsofsymfony/http-cache-bundle": "For integration with the Symfony framework",

src/SymfonyCache/PurgeListener.php

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

1414
use Symfony\Component\HttpFoundation\Response;
1515
use Symfony\Component\OptionsResolver\OptionsResolver;
16-
use Toflar\Psr6HttpCacheStore\Psr6StoreInterface;
16+
use Toflar\Psr6HttpCacheStore\ClearableInterface;
1717

1818
/**
1919
* Purge handler for the symfony built-in HttpCache.
@@ -98,17 +98,17 @@ public function handlePurge(CacheEvent $event)
9898

9999
// Purge whole cache
100100
if ($request->headers->has($this->clearCacheHeader)) {
101-
if (!$store instanceof Psr6StoreInterface) {
101+
if (!$store instanceof ClearableInterface) {
102102
$response->setStatusCode(400);
103-
$response->setContent('Store must be an instance of '.Psr6StoreInterface::class.'. Please check your proxy configuration.');
103+
$response->setContent('Store must be an instance of '.ClearableInterface::class.'. Please check your proxy configuration.');
104104
$event->setResponse($response);
105105

106106
return;
107107
}
108108

109-
$store->prune();
109+
$store->clear();
110110

111-
$response->setStatusCode(200, 'Pruned');
111+
$response->setStatusCode(200, 'Purged');
112112
$event->setResponse($response);
113113

114114
return;

src/SymfonyCache/PurgeTagsListener.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,16 @@ public function handlePurgeTags(CacheEvent $event)
119119

120120
$tags = [];
121121

122-
foreach ($request->headers->get($this->tagsHeader, '', false) as $v) {
123-
foreach (explode(',', $v) as $tag) {
122+
// Compatibility with Symfony < 4.4
123+
$reflection = new \ReflectionClass($request->headers);
124+
if (1 === $reflection->getMethod('all')->getNumberOfParameters()) {
125+
$headers = $request->headers->all($this->tagsHeader);
126+
} else {
127+
$headers = $request->headers->get($this->tagsHeader, '', false);
128+
}
129+
130+
foreach ($headers as $header) {
131+
foreach (explode(',', $header) as $tag) {
124132
$tags[] = $tag;
125133
}
126134
}

tests/Unit/SymfonyCache/PurgeListenerTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function testClearCache()
7171

7272
/** @var Psr6Store $store */
7373
$store = \Mockery::mock(Psr6Store::class)
74-
->shouldReceive('prune')
74+
->shouldReceive('clear')
7575
->once()
7676
->getMock();
7777
$kernel = $this->getKernelMock($store);
@@ -93,18 +93,15 @@ public function testClearCacheWithoutPsr6Store()
9393
/** @var StoreInterface $store */
9494
$store = \Mockery::mock(StoreInterface::class);
9595
$kernel = $this->getKernelMock($store);
96-
9796
$purgeListener = new PurgeListener();
9897
$request = Request::create('http://example.com/', 'PURGE');
9998
$request->headers->set('Clear-Cache', 'true');
10099
$event = new CacheEvent($kernel, $request);
101-
102100
$purgeListener->handlePurge($event);
103101
$response = $event->getResponse();
104-
105102
$this->assertInstanceOf(Response::class, $response);
106103
$this->assertSame(400, $response->getStatusCode());
107-
$this->assertSame('Store must be an instance of Toflar\Psr6HttpCacheStore\Psr6StoreInterface. Please check your proxy configuration.', $response->getContent());
104+
$this->assertSame('Store must be an instance of Toflar\Psr6HttpCacheStore\ClearableInterface. Please check your proxy configuration.', $response->getContent());
108105
}
109106

110107
public function testPurgeAllowedMiss()

0 commit comments

Comments
 (0)