Skip to content

Commit e4325ba

Browse files
committed
refactor: refactor files for v13
1 parent fc3c40d commit e4325ba

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

Classes/Cache/FastlyBackend.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Psr\Log\LoggerAwareInterface;
1111
use Psr\Log\LoggerAwareTrait;
1212
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
13+
use TYPO3\CMS\Core\Cache\CacheTag;
1314
use TYPO3\CMS\Core\Utility\GeneralUtility;
15+
use function array_map;
1416

1517
class FastlyBackend extends NullBackend implements LoggerAwareInterface
1618
{
@@ -63,6 +65,16 @@ public function flushByTags(array $tags): void
6365
if ($fastlyService === null) {
6466
return;
6567
}
66-
$fastlyService->purgeKeys($tags);
68+
69+
$tagStrings = [];
70+
foreach ($tags as $tag) {
71+
if ($tag instanceof CacheTag) {
72+
$tagStrings[] = $tag->name;
73+
} else {
74+
$tagStrings[] = (string)$tag;
75+
}
76+
}
77+
78+
$fastlyService->purgeKeys($tagStrings);
6779
}
6880
}

Classes/Middleware/FastlyMiddleware.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
use Psr\Http\Message\ServerRequestInterface;
99
use Psr\Http\Server\MiddlewareInterface;
1010
use Psr\Http\Server\RequestHandlerInterface;
11+
use TYPO3\CMS\Core\Cache\CacheTag;
1112
use TYPO3\CMS\Core\Http\ApplicationType;
13+
use function array_map;
1214
use function array_unique;
1315
use function implode;
1416
use function is_array;
@@ -63,11 +65,22 @@ protected function isFastlyDisabledOrNotConfigured(): bool
6365

6466
protected function appendSurrogateKeys(ResponseInterface $response): ResponseInterface
6567
{
66-
if (is_array($GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector')->getCacheTags()) && $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector')->getCacheTags() !== []) {
67-
$cacheTags = implode(' ', array_unique($GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector')->getCacheTags()));
68-
$response = $response->withHeader('Surrogate-Key', $cacheTags);
68+
$cacheTagObjects = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.cache.collector')->getCacheTags();
69+
if (!is_array($cacheTagObjects) || $cacheTagObjects === []) {
70+
return $response;
6971
}
70-
return $response;
72+
73+
$cacheTagStrings = [];
74+
foreach ($cacheTagObjects as $tag) {
75+
if ($tag instanceof CacheTag) {
76+
$cacheTagStrings[] = $tag->name;
77+
} else {
78+
$cacheTagStrings[] = (string)$tag;
79+
}
80+
}
81+
82+
$cacheTags = implode(' ', array_unique($cacheTagStrings));
83+
return $response->withHeader('Surrogate-Key', $cacheTags);
7184
}
7285

7386
protected function appendSurrogateControl(ResponseInterface $response): ResponseInterface

0 commit comments

Comments
 (0)