Skip to content
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: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions src/SymfonyCache/PurgeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/SymfonyCache/PurgeTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
7 changes: 2 additions & 5 deletions tests/Unit/SymfonyCache/PurgeListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
Expand Down