From 5e2e5a64bf98196b6ad256c06e149cda18c90624 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Sun, 17 Mar 2024 17:01:53 +0100 Subject: [PATCH] Better Cache Strategy Support --- phpstan-baseline.neon | 82 ++++++++++++++++--- src/Command/ListCacheStrategiesCommand.php | 4 +- src/Dto/Cache.php | 7 +- src/Service/Plugin/BackgroundSyncPlugin.php | 17 ++++ src/Service/Plugin/BroadcastUpdatePlugin.php | 12 +++ src/Service/Plugin/CachePlugin.php | 58 ------------- .../Plugin/CacheableResponsePlugin.php | 17 ++++ src/Service/Plugin/ExpirationPlugin.php | 8 ++ src/Service/Plugin/RangeRequestsPlugin.php | 5 ++ src/Service/Rule/AssetCache.php | 4 +- src/Service/Rule/BackgroundSync.php | 11 +-- src/Service/Rule/FontCache.php | 10 ++- src/Service/Rule/GoogleFontCache.php | 7 +- src/Service/Rule/ImageCache.php | 7 +- src/Service/Rule/PageCaches.php | 13 +-- 15 files changed, 169 insertions(+), 93 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b0262d2..5fd7404 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -91,22 +91,22 @@ parameters: path: src/Dto/BackgroundSync.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$maxRetentionTime\\. Give it default value or assign it in the constructor\\.$#" + message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$matchCallback\\. Give it default value or assign it in the constructor\\.$#" count: 1 path: src/Dto/BackgroundSync.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$method\\. Give it default value or assign it in the constructor\\.$#" + message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$maxRetentionTime\\. Give it default value or assign it in the constructor\\.$#" count: 1 path: src/Dto/BackgroundSync.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$queueName\\. Give it default value or assign it in the constructor\\.$#" + message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$method\\. Give it default value or assign it in the constructor\\.$#" count: 1 path: src/Dto/BackgroundSync.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$regex\\. Give it default value or assign it in the constructor\\.$#" + message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\BackgroundSync has an uninitialized property \\$queueName\\. Give it default value or assign it in the constructor\\.$#" count: 1 path: src/Dto/BackgroundSync.php @@ -176,12 +176,12 @@ parameters: path: src/Dto/Manifest.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\PageCache has an uninitialized property \\$cacheName\\. Give it default value or assign it in the constructor\\.$#" + message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\PageCache has an uninitialized property \\$matchCallback\\. Give it default value or assign it in the constructor\\.$#" count: 1 path: src/Dto/PageCache.php - - message: "#^Class SpomkyLabs\\\\PwaBundle\\\\Dto\\\\PageCache has an uninitialized property \\$regex\\. Give it default value or assign it in the constructor\\.$#" + message: "#^PHPDoc tag @var for property SpomkyLabs\\\\PwaBundle\\\\Dto\\\\PageCache\\:\\:\\$cacheableResponseHeaders with type array\\\\|null is not subtype of native type array\\.$#" count: 1 path: src/Dto/PageCache.php @@ -492,7 +492,7 @@ parameters: - message: "#^Anonymous function should return array but returns mixed\\.$#" - count: 6 + count: 8 path: src/Resources/config/definition/service_worker.php - @@ -500,6 +500,11 @@ parameters: count: 1 path: src/Resources/config/definition/service_worker.php + - + message: "#^Cannot access an offset on mixed\\.$#" + count: 1 + path: src/Resources/config/definition/service_worker.php + - message: "#^Cannot access offset 'asset_cache' on mixed\\.$#" count: 2 @@ -560,11 +565,31 @@ parameters: count: 1 path: src/Resources/config/definition/service_worker.php + - + message: "#^Cannot access offset 'network_timeout…' on mixed\\.$#" + count: 1 + path: src/Resources/config/definition/service_worker.php + + - + message: "#^Cannot access offset 'page_cache_name' on mixed\\.$#" + count: 1 + path: src/Resources/config/definition/service_worker.php + + - + message: "#^Cannot access offset 'page_caches' on mixed\\.$#" + count: 2 + path: src/Resources/config/definition/service_worker.php + - message: "#^Cannot access offset 'static_regex' on mixed\\.$#" count: 1 path: src/Resources/config/definition/service_worker.php + - + message: "#^Cannot access offset 'warm_cache_urls' on mixed\\.$#" + count: 1 + path: src/Resources/config/definition/service_worker.php + - message: "#^Strict comparison using \\!\\=\\= between mixed and null will always evaluate to true\\.$#" count: 3 @@ -626,14 +651,44 @@ parameters: path: src/Resources/config/definition/web_client.php - - message: "#^Parameter \\#6 \\$options of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\CacheStrategy\\:\\:create\\(\\) expects array\\{maxTimeout\\?\\: int, maxAge\\?\\: int, maxEntries\\?\\: int, warmUrls\\?\\: array\\, plugins\\?\\: array\\\\}, array\\{maxEntries\\: int\\<0, max\\>, maxAge\\: int, warmUrls\\: mixed\\} given\\.$#" + message: "#^Part \\$broadcastChannel \\(mixed\\) of encapsed string cannot be cast to string\\.$#" + count: 1 + path: src/Service/Plugin/BackgroundSyncPlugin.php + + - + message: "#^Part \\$maxRetentionTime \\(mixed\\) of encapsed string cannot be cast to string\\.$#" + count: 1 + path: src/Service/Plugin/BackgroundSyncPlugin.php + + - + message: "#^Part \\$queueName \\(mixed\\) of encapsed string cannot be cast to string\\.$#" + count: 2 + path: src/Service/Plugin/BackgroundSyncPlugin.php + + - + message: "#^Parameter \\#2 \\.\\.\\.\\$values of function sprintf expects bool\\|float\\|int\\|string\\|null, mixed given\\.$#" + count: 1 + path: src/Service/Rule/AppendCacheStrategies.php + + - + message: "#^Parameter \\#1 \\$name of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\WorkboxCacheStrategy\\:\\:create\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/Service/Rule/AssetCache.php + + - + message: "#^Parameter \\#8 \\$preloadUrls of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\WorkboxCacheStrategy\\:\\:create\\(\\) expects array\\, mixed given\\.$#" count: 1 path: src/Service/Rule/AssetCache.php - - message: "#^Parameter \\#6 \\$options of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\CacheStrategy\\:\\:create\\(\\) expects array\\{maxTimeout\\?\\: int, maxAge\\?\\: int, maxEntries\\?\\: int, warmUrls\\?\\: array\\, plugins\\?\\: array\\\\}, array\\{maxAge\\: int\\|null, maxEntries\\: int\\|null\\} given\\.$#" + message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, mixed given\\.$#" count: 1 - path: src/Service/Rule/GoogleFontCache.php + path: src/Service/Rule/FontCache.php + + - + message: "#^Parameter \\#8 \\$preloadUrls of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\WorkboxCacheStrategy\\:\\:create\\(\\) expects array\\, mixed given\\.$#" + count: 1 + path: src/Service/Rule/FontCache.php - message: "#^Strict comparison using \\=\\=\\= between int\\<1, max\\> and 0 will always evaluate to false\\.$#" @@ -641,10 +696,15 @@ parameters: path: src/Service/Rule/OfflineFallback.php - - message: "#^Parameter \\#6 \\$options of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\CacheStrategy\\:\\:create\\(\\) expects array\\{maxTimeout\\?\\: int, maxAge\\?\\: int, maxEntries\\?\\: int, warmUrls\\?\\: array\\, plugins\\?\\: array\\\\}, array\\{maxTimeout\\: int, plugins\\: array\\{0\\: 'CacheableResponsePl…', 1\\?\\: 'BroadcastUpdatePlug…'\\}, warmUrls\\: mixed\\} given\\.$#" + message: "#^Parameter \\#8 \\$preloadUrls of static method SpomkyLabs\\\\PwaBundle\\\\Service\\\\WorkboxCacheStrategy\\:\\:create\\(\\) expects array\\, mixed given\\.$#" count: 1 path: src/Service/Rule/PageCaches.php + - + message: "#^Part \\$this\\-\\>options\\['networkTimeoutSeconds'\\] \\(mixed\\) of encapsed string cannot be cast to string\\.$#" + count: 1 + path: src/Service/WorkboxCacheStrategy.php + - message: "#^Method SpomkyLabs\\\\PwaBundle\\\\SpomkyLabsPwaBundle\\:\\:loadExtension\\(\\) has parameter \\$config with no value type specified in iterable type array\\.$#" count: 1 diff --git a/src/Command/ListCacheStrategiesCommand.php b/src/Command/ListCacheStrategiesCommand.php index 3001210..d563859 100644 --- a/src/Command/ListCacheStrategiesCommand.php +++ b/src/Command/ListCacheStrategiesCommand.php @@ -55,8 +55,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int } else { $table->addRow([ $strategy->name, - $strategy->strategy, - $strategy->matchCallback, + '---', + '---', $strategy->enabled ? 'Yes' : 'No', $strategy->requireWorkbox ? 'Yes' : 'No', '', diff --git a/src/Dto/Cache.php b/src/Dto/Cache.php index fe0f509..f11b118 100644 --- a/src/Dto/Cache.php +++ b/src/Dto/Cache.php @@ -6,6 +6,7 @@ use DateInterval; use DateTimeImmutable; +use InvalidArgumentException; use Symfony\Component\Serializer\Attribute\SerializedName; use function is_string; @@ -27,7 +28,11 @@ public function maxAgeInSeconds(): null|int } if (is_string($this->maxAge)) { $now = new DateTimeImmutable(); - $future = $now->add(DateInterval::createFromDateString($this->maxAge)); + $interval = DateInterval::createFromDateString($this->maxAge); + if ($interval === false) { + throw new InvalidArgumentException('Invalid max age'); + } + $future = $now->add($interval); return abs($future->getTimestamp() - $now->getTimestamp()); } return $this->maxAge; diff --git a/src/Service/Plugin/BackgroundSyncPlugin.php b/src/Service/Plugin/BackgroundSyncPlugin.php index f1690c2..13b6aea 100644 --- a/src/Service/Plugin/BackgroundSyncPlugin.php +++ b/src/Service/Plugin/BackgroundSyncPlugin.php @@ -39,4 +39,21 @@ public function render(int $jsonOptions = 0): string return trim($declaration); } + + public static function create( + string $queueName, + int $maxRetentionTime, + bool $forceSyncFallback, + ?string $broadcastChannel + ): static { + return new self( + 'BackgroundSyncPlugin', + [ + 'queueName' => $queueName, + 'maxRetentionTime' => $maxRetentionTime, + 'forceSyncFallback' => $forceSyncFallback, + 'broadcastChannel' => $broadcastChannel, + ] + ); + } } diff --git a/src/Service/Plugin/BroadcastUpdatePlugin.php b/src/Service/Plugin/BroadcastUpdatePlugin.php index ff7c400..67d0d8f 100644 --- a/src/Service/Plugin/BroadcastUpdatePlugin.php +++ b/src/Service/Plugin/BroadcastUpdatePlugin.php @@ -13,4 +13,16 @@ public function render(int $jsonOptions = 0): string json_encode($this->options, $jsonOptions) ); } + + /** + * @param array $headersToCheck + */ + public static function create(array $headersToCheck = []): static + { + $headersToCheck = $headersToCheck === [] ? ['Content-Type', 'ETag', 'Last-Modified'] : $headersToCheck; + + return new self('BroadcastUpdatePlugin', [ + 'headersToCheck' => $headersToCheck, + ]); + } } diff --git a/src/Service/Plugin/CachePlugin.php b/src/Service/Plugin/CachePlugin.php index 07cec7d..f1c82a0 100644 --- a/src/Service/Plugin/CachePlugin.php +++ b/src/Service/Plugin/CachePlugin.php @@ -16,62 +16,4 @@ public function __construct( } abstract public function render(int $jsonOptions = 0): string; - - public static function createExpirationPlugin(null|int $maxEntries, null|string|int $maxAgeSeconds): static - { - return new ExpirationPlugin( - 'ExpirationPlugin', - [ - 'maxEntries' => $maxEntries, - 'maxAgeSeconds' => $maxAgeSeconds, - ] - ); - } - - public static function createBroadcastUpdatePlugin(array $headersToCheck = []): static - { - $headersToCheck = $headersToCheck === [] ? ['Content-Type', 'ETag', 'Last-Modified'] : $headersToCheck; - - return new BroadcastUpdatePlugin( - 'BroadcastUpdatePlugin', - [ - 'headersToCheck' => $headersToCheck, - ] - ); - } - - public static function createCacheableResponsePlugin(array $statuses = [0, 200], array $headers = []): static - { - $options = array_filter([ - 'statuses' => $statuses, - 'headers' => $headers, - ], fn ($value) => $value !== []); - $options = $options === [] ? [ - 'statuses' => [0, 200], - ] : $options; - - return new CacheableResponsePlugin('CacheableResponsePlugin', $options); - } - - public static function createRangeRequestsPlugin(): static - { - return new RangeRequestsPlugin('RangeRequestsPlugin'); - } - - public static function createBackgroundSyncPlugin( - string $queueName, - int $maxRetentionTime, - bool $forceSyncFallback, - ?string $broadcastChannel - ): static { - return new BackgroundSyncPlugin( - 'BackgroundSyncPlugin', - [ - 'queueName' => $queueName, - 'maxRetentionTime' => $maxRetentionTime, - 'forceSyncFallback' => $forceSyncFallback, - 'broadcastChannel' => $broadcastChannel, - ] - ); - } } diff --git a/src/Service/Plugin/CacheableResponsePlugin.php b/src/Service/Plugin/CacheableResponsePlugin.php index 933fb74..978e102 100644 --- a/src/Service/Plugin/CacheableResponsePlugin.php +++ b/src/Service/Plugin/CacheableResponsePlugin.php @@ -13,4 +13,21 @@ public function render(int $jsonOptions = 0): string json_encode($this->options, $jsonOptions) ); } + + /** + * @param array $statuses + * @param array $headers + */ + public static function create(array $statuses = [0, 200], array $headers = []): static + { + $options = array_filter([ + 'statuses' => $statuses, + 'headers' => $headers, + ], fn ($value) => $value !== []); + $options = $options === [] ? [ + 'statuses' => [0, 200], + ] : $options; + + return new self('CacheableResponsePlugin', $options); + } } diff --git a/src/Service/Plugin/ExpirationPlugin.php b/src/Service/Plugin/ExpirationPlugin.php index 40fd1bb..c87b3a6 100644 --- a/src/Service/Plugin/ExpirationPlugin.php +++ b/src/Service/Plugin/ExpirationPlugin.php @@ -10,4 +10,12 @@ public function render(int $jsonOptions = 0): string { return sprintf('new workbox.expiration.ExpirationPlugin(%s)', json_encode($this->options, $jsonOptions)); } + + public static function create(null|int $maxEntries, null|string|int $maxAgeSeconds): static + { + return new self('ExpirationPlugin', [ + 'maxEntries' => $maxEntries, + 'maxAgeSeconds' => $maxAgeSeconds, + ]); + } } diff --git a/src/Service/Plugin/RangeRequestsPlugin.php b/src/Service/Plugin/RangeRequestsPlugin.php index 9789f0a..6ad1242 100644 --- a/src/Service/Plugin/RangeRequestsPlugin.php +++ b/src/Service/Plugin/RangeRequestsPlugin.php @@ -10,4 +10,9 @@ public function render(int $jsonOptions = 0): string { return 'new workbox.rangeRequests.RangeRequestsPlugin()'; } + + public static function create(): static + { + return new self('RangeRequestsPlugin'); + } } diff --git a/src/Service/Rule/AssetCache.php b/src/Service/Rule/AssetCache.php index 6d515ed..5d7c110 100644 --- a/src/Service/Rule/AssetCache.php +++ b/src/Service/Rule/AssetCache.php @@ -8,7 +8,7 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\ExpirationPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface; @@ -61,7 +61,7 @@ public function getCacheStrategies(): array true, null, [ - CachePlugin::createExpirationPlugin( + ExpirationPlugin::create( count($this->getAssets()) * 2, $this->workbox->assetCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 365, ), diff --git a/src/Service/Rule/BackgroundSync.php b/src/Service/Rule/BackgroundSync.php index aea2fe7..f93ae10 100644 --- a/src/Service/Rule/BackgroundSync.php +++ b/src/Service/Rule/BackgroundSync.php @@ -8,21 +8,22 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\MatchCallbackHandler\MatchCallbackHandler; +use SpomkyLabs\PwaBundle\Service\Plugin\BackgroundSyncPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; -use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; final readonly class BackgroundSync implements HasCacheStrategies { private Workbox $workbox; + /** + * @param iterable $matchCallbackHandlers + */ public function __construct( ServiceWorker $serviceWorker, #[TaggedIterator('spomky_labs_pwa.match_callback_handler')] private iterable $matchCallbackHandlers, - #[Autowire('%kernel.debug%')] - bool $debug, ) { $this->workbox = $serviceWorker->workbox; } @@ -42,7 +43,7 @@ public function getCacheStrategies(): array true, null, [ - CachePlugin::createBackgroundSyncPlugin( + BackgroundSyncPlugin::create( $sync->queueName, $sync->maxRetentionTime, $sync->forceSyncFallback, diff --git a/src/Service/Rule/FontCache.php b/src/Service/Rule/FontCache.php index cf8f5da..4c0682b 100644 --- a/src/Service/Rule/FontCache.php +++ b/src/Service/Rule/FontCache.php @@ -8,7 +8,8 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\CacheableResponsePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\ExpirationPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; @@ -57,17 +58,20 @@ public function getCacheStrategies(): array true, null, [ - CachePlugin::createExpirationPlugin( + ExpirationPlugin::create( $maxEntries, $this->workbox->fontCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 365, ), - CachePlugin::createCacheableResponsePlugin(), + CacheableResponsePlugin::create(), ], $urls ), ]; } + /** + * @return array + */ private function getFonts(): array { $fonts = []; diff --git a/src/Service/Rule/GoogleFontCache.php b/src/Service/Rule/GoogleFontCache.php index 8a57b95..fe4031b 100644 --- a/src/Service/Rule/GoogleFontCache.php +++ b/src/Service/Rule/GoogleFontCache.php @@ -8,7 +8,8 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\CacheableResponsePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\ExpirationPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; final readonly class GoogleFontCache implements HasCacheStrategies @@ -44,8 +45,8 @@ public function getCacheStrategies(): array true, null, [ - CachePlugin::createCacheableResponsePlugin(), - CachePlugin::createExpirationPlugin( + CacheableResponsePlugin::create(), + ExpirationPlugin::create( $this->workbox->googleFontCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 365, $this->workbox->googleFontCache->maxEntries ?? 30 ), diff --git a/src/Service/Rule/ImageCache.php b/src/Service/Rule/ImageCache.php index 39c83ef..5426917 100644 --- a/src/Service/Rule/ImageCache.php +++ b/src/Service/Rule/ImageCache.php @@ -8,7 +8,8 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\CacheableResponsePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\ExpirationPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; @@ -42,8 +43,8 @@ public function getCacheStrategies(): array true, null, [ - CachePlugin::createCacheableResponsePlugin(), - CachePlugin::createExpirationPlugin( + CacheableResponsePlugin::create(), + ExpirationPlugin::create( $this->workbox->imageCache->maxEntries ?? 60, $this->workbox->imageCache->maxAgeInSeconds() ?? 60 * 60 * 24 * 7 ), diff --git a/src/Service/Rule/PageCaches.php b/src/Service/Rule/PageCaches.php index 44b190a..f461786 100644 --- a/src/Service/Rule/PageCaches.php +++ b/src/Service/Rule/PageCaches.php @@ -9,7 +9,10 @@ use SpomkyLabs\PwaBundle\Service\CacheStrategy; use SpomkyLabs\PwaBundle\Service\HasCacheStrategies; use SpomkyLabs\PwaBundle\Service\MatchCallbackHandler\MatchCallbackHandler; -use SpomkyLabs\PwaBundle\Service\Plugin\CachePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\BroadcastUpdatePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\CacheableResponsePlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\ExpirationPlugin; +use SpomkyLabs\PwaBundle\Service\Plugin\RangeRequestsPlugin; use SpomkyLabs\PwaBundle\Service\WorkboxCacheStrategy; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; @@ -56,19 +59,19 @@ public function getCacheStrategies(): array $cacheName = $pageCache->cacheName ?? sprintf('page-cache-%d', $id); $plugins = [ - CachePlugin::createCacheableResponsePlugin( + CacheableResponsePlugin::create( $pageCache->cacheableResponseStatuses, $pageCache->cacheableResponseHeaders ), ]; if ($pageCache->broadcast === true && $pageCache->strategy === CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE) { - $plugins[] = CachePlugin::createBroadcastUpdatePlugin($pageCache->broadcastHeaders); + $plugins[] = BroadcastUpdatePlugin::create($pageCache->broadcastHeaders); } if ($pageCache->rangeRequests === true && $pageCache->strategy !== CacheStrategy::STRATEGY_NETWORK_ONLY) { - $plugins[] = CachePlugin::createRangeRequestsPlugin(); + $plugins[] = RangeRequestsPlugin::create(); } if ($pageCache->maxEntries !== null || $pageCache->maxAgeInSeconds() !== null) { - $plugins[] = CachePlugin::createExpirationPlugin($pageCache->maxEntries, $pageCache->maxAgeInSeconds()); + $plugins[] = ExpirationPlugin::create($pageCache->maxEntries, $pageCache->maxAgeInSeconds()); } $strategies[] =