Skip to content

Commit e446b18

Browse files
ro0NLdbu
andauthored
Allow empty tag list (#553)
--------- Co-authored-by: David Buchmann <[email protected]>
1 parent 979224d commit e446b18

File tree

8 files changed

+27
-2
lines changed

8 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ See also the [GitHub releases page](https://github.com/FriendsOfSymfony/FOSHttpC
1414
* Test with PHP 8.2 and 8.3
1515
* Drop support for PHP < 8.1
1616
* Parameter and return type declarations where possible.
17+
* Ignore empty tag lists passed to `TagCapable::invalidateTags` so you don't need to check if there are tags or not.
1718

1819
2.x
1920
===

src/CacheInvalidator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public function invalidate(array $headers)
221221
*
222222
* @see TagCapable::tags()
223223
*
224-
* @param array $tags Tags that should be removed/expired from the cache
224+
* @param array $tags Tags that should be removed/expired from the cache. An empty tag list is ignored.
225225
*
226226
* @return $this
227227
*
@@ -232,6 +232,10 @@ public function invalidateTags(array $tags)
232232
if (!$this->cache instanceof TagCapable) {
233233
throw UnsupportedProxyOperationException::cacheDoesNotImplement('Tags');
234234
}
235+
if (!$tags) {
236+
return $this;
237+
}
238+
235239
$this->cache->invalidateTags($tags);
236240

237241
return $this;

src/ProxyClient/Cloudflare.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function __construct(
7070
*/
7171
public function invalidateTags(array $tags)
7272
{
73+
if (!$tags) {
74+
return $this;
75+
}
76+
7377
$this->queueRequest(
7478
'POST',
7579
sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']),

src/ProxyClient/Fastly.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function __construct(
6262
*/
6363
public function invalidateTags(array $tags)
6464
{
65+
if (!$tags) {
66+
return $this;
67+
}
68+
6569
$url = sprintf(self::API_ENDPOINT.'/service/%s/purge', $this->options['service_identifier']);
6670
$headers = ['Accept' => 'application/json'];
6771
if (true === $this->options['soft_purge']) {

src/ProxyClient/Invalidation/TagCapable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface TagCapable extends ProxyClient
2525
/**
2626
* Remove/Expire cache objects based on cache tags.
2727
*
28-
* @param array $tags Tags that should be removed/expired from the cache
28+
* @param array $tags Tags that should be removed/expired from the cache. An empty tag list should be ignored.
2929
*
3030
* @return $this
3131
*/

src/ProxyClient/MultiplexerClient.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ public function flush()
107107
*/
108108
public function invalidateTags(array $tags)
109109
{
110+
if (!$tags) {
111+
return $this;
112+
}
113+
110114
$this->invoke(TagCapable::class, 'invalidateTags', [$tags]);
111115

112116
return $this;

src/ProxyClient/Symfony.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ protected function configureOptions()
6969

7070
public function invalidateTags(array $tags)
7171
{
72+
if (!$tags) {
73+
return $this;
74+
}
75+
7276
$escapedTags = $this->escapeTags($tags);
7377

7478
$chunkSize = $this->determineTagsPerHeader($escapedTags, ',');

src/ProxyClient/Varnish.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ class Varnish extends HttpProxyClient implements BanCapable, PurgeCapable, Refre
6969

7070
public function invalidateTags(array $tags)
7171
{
72+
if (!$tags) {
73+
return $this;
74+
}
75+
7276
$banMode = self::TAG_BAN === $this->options['tag_mode'];
7377

7478
// If using BAN's, escape each tag

0 commit comments

Comments
 (0)