From 01cfbfb4851ffe8d8f56be33c97e1947ee7bad38 Mon Sep 17 00:00:00 2001 From: Florent Morselli Date: Thu, 4 Apr 2024 14:01:23 +0200 Subject: [PATCH] Naming convention for interfaces Interfaces now have an `Interface` suffix as per https://www.php-fig.org/bylaws/psr-naming-conventions/ --- phpstan-baseline.neon | 12 +++---- src/CachingStrategy/AssetCache.php | 4 +-- src/CachingStrategy/BackgroundSync.php | 10 +++--- src/CachingStrategy/CacheStrategy.php | 30 +++------------- .../CacheStrategyInterface.php | 34 +++++++++++++++++++ src/CachingStrategy/FontCache.php | 4 +-- src/CachingStrategy/GoogleFontCache.php | 6 ++-- src/CachingStrategy/HasCacheStrategies.php | 9 +++-- .../HasCacheStrategiesInterface.php | 13 +++++++ src/CachingStrategy/ImageCache.php | 4 +-- src/CachingStrategy/ManifestCache.php | 4 +-- src/CachingStrategy/ResourceCaches.php | 10 +++--- src/CachingStrategy/WorkboxCacheStrategy.php | 12 +++---- src/Command/CreateIconsCommand.php | 4 +-- src/Command/CreateScreenshotCommand.php | 4 +-- src/Command/ListCacheStrategiesCommand.php | 12 +++---- src/ImageProcessor/GDImageProcessor.php | 2 +- src/ImageProcessor/ImageProcessor.php | 11 +++--- .../ImageProcessorInterface.php | 15 ++++++++ src/ImageProcessor/ImagickImageProcessor.php | 2 +- .../DestinationMatchCallbackHandler.php | 2 +- .../ExactPathnameMatchCallbackHandler.php | 2 +- .../MatchCallbackHandler.php | 8 ++--- .../MatchCallbackHandlerInterface.php | 12 +++++++ .../NavigationMatchCallbackHandler.php | 2 +- .../OriginMatchCallbackHandler.php | 2 +- .../PathnameEndsWithMatchCallbackHandler.php | 2 +- ...PathnameStartsWithMatchCallbackHandler.php | 2 +- .../RouteMatchCallbackHandler.php | 2 +- src/Normalizer/ScreenshotNormalizer.php | 4 +-- .../config/definition/service_worker.php | 6 ++-- src/Resources/config/services.php | 12 +++---- src/Service/ServiceWorkerCompiler.php | 4 +-- .../AppendCacheStrategies.php | 6 ++-- src/ServiceWorkerRule/ClearCache.php | 2 +- src/ServiceWorkerRule/OfflineFallback.php | 2 +- src/ServiceWorkerRule/ServiceWorkerRule.php | 6 ++-- .../ServiceWorkerRuleInterface.php | 10 ++++++ src/ServiceWorkerRule/SkipWaiting.php | 2 +- src/ServiceWorkerRule/WindowsWidgets.php | 2 +- src/ServiceWorkerRule/WorkboxImport.php | 2 +- src/SpomkyLabsPwaBundle.php | 4 +-- src/WorkboxPlugin/BackgroundSyncPlugin.php | 2 +- src/WorkboxPlugin/BroadcastUpdatePlugin.php | 2 +- src/WorkboxPlugin/CachePlugin.php | 8 ++--- src/WorkboxPlugin/CachePluginInterface.php | 12 +++++++ src/WorkboxPlugin/CacheableResponsePlugin.php | 2 +- src/WorkboxPlugin/ExpirationPlugin.php | 2 +- src/WorkboxPlugin/RangeRequestsPlugin.php | 2 +- 49 files changed, 200 insertions(+), 128 deletions(-) create mode 100644 src/CachingStrategy/CacheStrategyInterface.php create mode 100644 src/CachingStrategy/HasCacheStrategiesInterface.php create mode 100644 src/ImageProcessor/ImageProcessorInterface.php create mode 100644 src/MatchCallbackHandler/MatchCallbackHandlerInterface.php create mode 100644 src/ServiceWorkerRule/ServiceWorkerRuleInterface.php create mode 100644 src/WorkboxPlugin/CachePluginInterface.php diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3bf735d..e53359a 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -71,7 +71,7 @@ parameters: path: src/Command/CreateIconsCommand.php - - message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string, string\\|false given\\.$#" + message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string, string\\|false given\\.$#" count: 1 path: src/Command/CreateIconsCommand.php @@ -91,7 +91,7 @@ parameters: path: src/Command/CreateIconsCommand.php - - message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#" + message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#" count: 1 path: src/Command/CreateIconsCommand.php @@ -111,12 +111,12 @@ parameters: path: src/Command/CreateScreenshotCommand.php - - message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#" + message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#" count: 1 path: src/Command/CreateScreenshotCommand.php - - message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string, string\\|false given\\.$#" + message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string, string\\|false given\\.$#" count: 1 path: src/Command/CreateScreenshotCommand.php @@ -136,7 +136,7 @@ parameters: path: src/Command/CreateScreenshotCommand.php - - message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#" + message: "#^Parameter \\#4 \\$format of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:process\\(\\) expects string\\|null, mixed given\\.$#" count: 1 path: src/Command/CreateScreenshotCommand.php @@ -501,7 +501,7 @@ parameters: path: src/Normalizer/ScreenshotNormalizer.php - - message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessor\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#" + message: "#^Parameter \\#1 \\$image of method SpomkyLabs\\\\PwaBundle\\\\ImageProcessor\\\\ImageProcessorInterface\\:\\:getSizes\\(\\) expects string, string\\|false given\\.$#" count: 1 path: src/Normalizer/ScreenshotNormalizer.php diff --git a/src/CachingStrategy/AssetCache.php b/src/CachingStrategy/AssetCache.php index 927ccf4..24e8e98 100644 --- a/src/CachingStrategy/AssetCache.php +++ b/src/CachingStrategy/AssetCache.php @@ -18,7 +18,7 @@ use const JSON_UNESCAPED_SLASHES; use const JSON_UNESCAPED_UNICODE; -final readonly class AssetCache implements HasCacheStrategies +final readonly class AssetCache implements HasCacheStrategiesInterface { private int $jsonOptions; @@ -53,7 +53,7 @@ public function getCacheStrategies(): array $strategy = WorkboxCacheStrategy::create( $this->workbox->enabled && $this->workbox->assetCache->enabled, true, - CacheStrategy::STRATEGY_CACHE_FIRST, + CacheStrategyInterface::STRATEGY_CACHE_FIRST, sprintf("({url}) => url.pathname.startsWith('%s')", $this->assetPublicPrefix), ) ->withName($this->workbox->assetCache->cacheName) diff --git a/src/CachingStrategy/BackgroundSync.php b/src/CachingStrategy/BackgroundSync.php index 29c9d89..1386e63 100644 --- a/src/CachingStrategy/BackgroundSync.php +++ b/src/CachingStrategy/BackgroundSync.php @@ -6,16 +6,16 @@ use SpomkyLabs\PwaBundle\Dto\ServiceWorker; use SpomkyLabs\PwaBundle\Dto\Workbox; -use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandler; +use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface; use SpomkyLabs\PwaBundle\WorkboxPlugin\BackgroundSyncPlugin; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; -final readonly class BackgroundSync implements HasCacheStrategies +final readonly class BackgroundSync implements HasCacheStrategiesInterface { private Workbox $workbox; /** - * @param iterable $matchCallbackHandlers + * @param iterable $matchCallbackHandlers */ public function __construct( ServiceWorker $serviceWorker, @@ -26,7 +26,7 @@ public function __construct( } /** - * @return array + * @return array */ public function getCacheStrategies(): array { @@ -35,7 +35,7 @@ public function getCacheStrategies(): array $strategies[] = WorkboxCacheStrategy::create( $this->workbox->enabled, true, - CacheStrategy::STRATEGY_NETWORK_ONLY, + CacheStrategyInterface::STRATEGY_NETWORK_ONLY, $this->prepareMatchCallback($sync->matchCallback) ) ->withName('Background Sync') diff --git a/src/CachingStrategy/CacheStrategy.php b/src/CachingStrategy/CacheStrategy.php index ccfb686..da98301 100644 --- a/src/CachingStrategy/CacheStrategy.php +++ b/src/CachingStrategy/CacheStrategy.php @@ -4,31 +4,9 @@ namespace SpomkyLabs\PwaBundle\CachingStrategy; -interface CacheStrategy +/** + * @deprecated since 1.2.0, will be removed in 2.0.0. Use CacheStrategyInterface instead. + */ +interface CacheStrategy extends CacheStrategyInterface { - public const STRATEGY_CACHE_FIRST = 'CacheFirst'; - - public const STRATEGY_CACHE_ONLY = 'CacheOnly'; - - public const STRATEGY_NETWORK_FIRST = 'NetworkFirst'; - - public const STRATEGY_NETWORK_ONLY = 'NetworkOnly'; - - public const STRATEGY_STALE_WHILE_REVALIDATE = 'StaleWhileRevalidate'; - - public const STRATEGIES = [ - self::STRATEGY_CACHE_FIRST, - self::STRATEGY_CACHE_ONLY, - self::STRATEGY_NETWORK_FIRST, - self::STRATEGY_NETWORK_ONLY, - self::STRATEGY_STALE_WHILE_REVALIDATE, - ]; - - public function getName(): ?string; - - public function isEnabled(): bool; - - public function needsWorkbox(): bool; - - public function render(string $cacheObjectName, bool $debug = false): string; } diff --git a/src/CachingStrategy/CacheStrategyInterface.php b/src/CachingStrategy/CacheStrategyInterface.php new file mode 100644 index 0000000..d8610f4 --- /dev/null +++ b/src/CachingStrategy/CacheStrategyInterface.php @@ -0,0 +1,34 @@ +workbox->enabled && $this->workbox->fontCache->enabled, true, - CacheStrategy::STRATEGY_CACHE_FIRST, + CacheStrategyInterface::STRATEGY_CACHE_FIRST, "({request}) => request.destination === 'font'" ) ->withName($this->workbox->fontCache->cacheName ?? 'fonts') diff --git a/src/CachingStrategy/GoogleFontCache.php b/src/CachingStrategy/GoogleFontCache.php index 94cf243..c521095 100644 --- a/src/CachingStrategy/GoogleFontCache.php +++ b/src/CachingStrategy/GoogleFontCache.php @@ -9,7 +9,7 @@ use SpomkyLabs\PwaBundle\WorkboxPlugin\CacheableResponsePlugin; use SpomkyLabs\PwaBundle\WorkboxPlugin\ExpirationPlugin; -final readonly class GoogleFontCache implements HasCacheStrategies +final readonly class GoogleFontCache implements HasCacheStrategiesInterface { private Workbox $workbox; @@ -30,14 +30,14 @@ public function getCacheStrategies(): array WorkboxCacheStrategy::create( $this->workbox->enabled && $this->workbox->googleFontCache->enabled, true, - CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE, + CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE, "({url}) => url.origin === 'https://fonts.googleapis.com'", ) ->withName($prefix . 'google-fonts-stylesheets'), WorkboxCacheStrategy::create( $this->workbox->enabled && $this->workbox->googleFontCache->enabled, true, - CacheStrategy::STRATEGY_CACHE_FIRST, + CacheStrategyInterface::STRATEGY_CACHE_FIRST, "({url}) => url.origin === 'https://fonts.gstatic.com'" ) ->withName($prefix . 'google-fonts-webfonts') diff --git a/src/CachingStrategy/HasCacheStrategies.php b/src/CachingStrategy/HasCacheStrategies.php index 0444ec5..96b5df0 100644 --- a/src/CachingStrategy/HasCacheStrategies.php +++ b/src/CachingStrategy/HasCacheStrategies.php @@ -4,10 +4,9 @@ namespace SpomkyLabs\PwaBundle\CachingStrategy; -interface HasCacheStrategies +/** + * @deprecated since 1.2.0, will be removed in 2.0.0. Use HasCacheStrategiesInterface instead. + */ +interface HasCacheStrategies extends HasCacheStrategiesInterface { - /** - * @return array - */ - public function getCacheStrategies(): array; } diff --git a/src/CachingStrategy/HasCacheStrategiesInterface.php b/src/CachingStrategy/HasCacheStrategiesInterface.php new file mode 100644 index 0000000..1d0fb9c --- /dev/null +++ b/src/CachingStrategy/HasCacheStrategiesInterface.php @@ -0,0 +1,13 @@ + + */ + public function getCacheStrategies(): array; +} diff --git a/src/CachingStrategy/ImageCache.php b/src/CachingStrategy/ImageCache.php index db46eee..c667661 100644 --- a/src/CachingStrategy/ImageCache.php +++ b/src/CachingStrategy/ImageCache.php @@ -9,7 +9,7 @@ use Symfony\Component\AssetMapper\Path\PublicAssetsPathResolverInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; -final readonly class ImageCache implements HasCacheStrategies +final readonly class ImageCache implements HasCacheStrategiesInterface { private string $assetPublicPrefix; @@ -30,7 +30,7 @@ public function getCacheStrategies(): array WorkboxCacheStrategy::create( $this->workbox->enabled && $this->workbox->imageCache->enabled, true, - CacheStrategy::STRATEGY_CACHE_FIRST, + CacheStrategyInterface::STRATEGY_CACHE_FIRST, sprintf( "({request, url}) => (request.destination === 'image' && !url.pathname.startsWith('%s'))", $this->assetPublicPrefix diff --git a/src/CachingStrategy/ManifestCache.php b/src/CachingStrategy/ManifestCache.php index 4840298..805616d 100644 --- a/src/CachingStrategy/ManifestCache.php +++ b/src/CachingStrategy/ManifestCache.php @@ -8,7 +8,7 @@ use SpomkyLabs\PwaBundle\Dto\Workbox; use Symfony\Component\DependencyInjection\Attribute\Autowire; -final readonly class ManifestCache implements HasCacheStrategies +final readonly class ManifestCache implements HasCacheStrategiesInterface { private string $manifestPublicUrl; @@ -29,7 +29,7 @@ public function getCacheStrategies(): array WorkboxCacheStrategy::create( $this->workbox->enabled && $this->workbox->cacheManifest, true, - CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE, + CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE, sprintf("({url}) => '%s' === url.pathname", $this->manifestPublicUrl), ) ->withName('manifest'), diff --git a/src/CachingStrategy/ResourceCaches.php b/src/CachingStrategy/ResourceCaches.php index 62ed80f..52831ff 100644 --- a/src/CachingStrategy/ResourceCaches.php +++ b/src/CachingStrategy/ResourceCaches.php @@ -6,7 +6,7 @@ use SpomkyLabs\PwaBundle\Dto\ServiceWorker; use SpomkyLabs\PwaBundle\Dto\Workbox; -use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandler; +use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface; use SpomkyLabs\PwaBundle\WorkboxPlugin\BroadcastUpdatePlugin; use SpomkyLabs\PwaBundle\WorkboxPlugin\CacheableResponsePlugin; use SpomkyLabs\PwaBundle\WorkboxPlugin\ExpirationPlugin; @@ -21,14 +21,14 @@ use const JSON_UNESCAPED_SLASHES; use const JSON_UNESCAPED_UNICODE; -final readonly class ResourceCaches implements HasCacheStrategies +final readonly class ResourceCaches implements HasCacheStrategiesInterface { private int $jsonOptions; private Workbox $workbox; /** - * @param iterable $matchCallbackHandlers + * @param iterable $matchCallbackHandlers */ public function __construct( ServiceWorker $serviceWorker, @@ -63,10 +63,10 @@ public function getCacheStrategies(): array $resourceCache->cacheableResponseHeaders ), ]; - if ($resourceCache->broadcast === true && $resourceCache->strategy === CacheStrategy::STRATEGY_STALE_WHILE_REVALIDATE) { + if ($resourceCache->broadcast === true && $resourceCache->strategy === CacheStrategyInterface::STRATEGY_STALE_WHILE_REVALIDATE) { $plugins[] = BroadcastUpdatePlugin::create($resourceCache->broadcastHeaders); } - if ($resourceCache->rangeRequests === true && $resourceCache->strategy !== CacheStrategy::STRATEGY_NETWORK_ONLY) { + if ($resourceCache->rangeRequests === true && $resourceCache->strategy !== CacheStrategyInterface::STRATEGY_NETWORK_ONLY) { $plugins[] = RangeRequestsPlugin::create(); } if ($resourceCache->maxEntries !== null || $resourceCache->maxAgeInSeconds() !== null) { diff --git a/src/CachingStrategy/WorkboxCacheStrategy.php b/src/CachingStrategy/WorkboxCacheStrategy.php index b916b81..73076ec 100644 --- a/src/CachingStrategy/WorkboxCacheStrategy.php +++ b/src/CachingStrategy/WorkboxCacheStrategy.php @@ -4,21 +4,21 @@ namespace SpomkyLabs\PwaBundle\CachingStrategy; -use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePlugin; +use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePluginInterface; use function in_array; use const JSON_PRETTY_PRINT; use const JSON_THROW_ON_ERROR; use const JSON_UNESCAPED_SLASHES; use const JSON_UNESCAPED_UNICODE; -final class WorkboxCacheStrategy implements CacheStrategy +final class WorkboxCacheStrategy implements CacheStrategyInterface { private null|string $name = null; private null|string $method = null; /** - * @var array + * @var array */ private array $plugins = []; @@ -63,7 +63,7 @@ public function withMethod(string $method): static return $this; } - public function withPlugin(CachePlugin $plugin, CachePlugin ...$plugins): static + public function withPlugin(CachePluginInterface $plugin, CachePluginInterface ...$plugins): static { $this->plugins = array_merge([$plugin], $plugins); return $this; @@ -122,7 +122,7 @@ public function render(string $cacheObjectName, bool $debug = false): string $cacheName = sprintf("cacheName: '%s',", $this->getName() ?? $cacheObjectName); } $plugins = sprintf('[%s]', implode(', ', array_map( - fn (CachePlugin $plugin) => $plugin->render($jsonOptions), + fn (CachePluginInterface $plugin) => $plugin->render($jsonOptions), $this->plugins ))); $method = $this->method !== null ? ",'{$this->method}'" : ''; @@ -191,7 +191,7 @@ public function getMethod(): ?string } /** - * @return array + * @return array */ public function getPlugins(): array { diff --git a/src/Command/CreateIconsCommand.php b/src/Command/CreateIconsCommand.php index 0b2b691..1ff0aac 100644 --- a/src/Command/CreateIconsCommand.php +++ b/src/Command/CreateIconsCommand.php @@ -4,7 +4,7 @@ namespace SpomkyLabs\PwaBundle\Command; -use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessor; +use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessorInterface; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -28,7 +28,7 @@ public function __construct( private readonly Filesystem $filesystem, #[Autowire('%kernel.project_dir%')] private readonly string $projectDir, - private readonly null|ImageProcessor $imageProcessor, + private readonly null|ImageProcessorInterface $imageProcessor, ) { parent::__construct(); } diff --git a/src/Command/CreateScreenshotCommand.php b/src/Command/CreateScreenshotCommand.php index 42363a5..6a14df5 100644 --- a/src/Command/CreateScreenshotCommand.php +++ b/src/Command/CreateScreenshotCommand.php @@ -5,7 +5,7 @@ namespace SpomkyLabs\PwaBundle\Command; use Facebook\WebDriver\WebDriverDimension; -use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessor; +use SpomkyLabs\PwaBundle\ImageProcessor\ImageProcessorInterface; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; @@ -35,7 +35,7 @@ public function __construct( private readonly Filesystem $filesystem, #[Autowire('%kernel.project_dir%')] private readonly string $projectDir, - private readonly null|ImageProcessor $imageProcessor, + private readonly null|ImageProcessorInterface $imageProcessor, #[Autowire('@pwa.web_client')] null|Client $webClient = null, ) { diff --git a/src/Command/ListCacheStrategiesCommand.php b/src/Command/ListCacheStrategiesCommand.php index e795c5d..ba0d1b1 100644 --- a/src/Command/ListCacheStrategiesCommand.php +++ b/src/Command/ListCacheStrategiesCommand.php @@ -4,10 +4,10 @@ namespace SpomkyLabs\PwaBundle\Command; -use SpomkyLabs\PwaBundle\CachingStrategy\CacheStrategy; -use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategies; +use SpomkyLabs\PwaBundle\CachingStrategy\CacheStrategyInterface; +use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface; use SpomkyLabs\PwaBundle\CachingStrategy\WorkboxCacheStrategy; -use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePlugin; +use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePluginInterface; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\Table; @@ -22,7 +22,7 @@ final class ListCacheStrategiesCommand extends Command { /** - * @param iterable $services + * @param iterable $services */ public function __construct( #[TaggedIterator('spomky_labs_pwa.cache_strategy')] @@ -50,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int return self::SUCCESS; } - private function processStrategy(CacheStrategy $strategy, Table $table): void + private function processStrategy(CacheStrategyInterface $strategy, Table $table): void { if ($strategy instanceof WorkboxCacheStrategy) { $table->addRow([ @@ -59,7 +59,7 @@ private function processStrategy(CacheStrategy $strategy, Table $table): void $strategy->matchCallback, $strategy->isEnabled() ? 'Yes' : 'No', $strategy->needsWorkbox() ? 'Yes' : 'No', - Yaml::dump(array_map(fn (CachePlugin $v): string => $v->getName(), $strategy->getPlugins())), + Yaml::dump(array_map(fn (CachePluginInterface $v): string => $v->getName(), $strategy->getPlugins())), count($strategy->getPreloadUrls()), Yaml::dump($strategy->getOptions()), ]); diff --git a/src/ImageProcessor/GDImageProcessor.php b/src/ImageProcessor/GDImageProcessor.php index 137d97c..4e4fd2a 100644 --- a/src/ImageProcessor/GDImageProcessor.php +++ b/src/ImageProcessor/GDImageProcessor.php @@ -6,7 +6,7 @@ use function assert; -final readonly class GDImageProcessor implements ImageProcessor +final readonly class GDImageProcessor implements ImageProcessorInterface { public function process(string $image, ?int $width, ?int $height, ?string $format): string { diff --git a/src/ImageProcessor/ImageProcessor.php b/src/ImageProcessor/ImageProcessor.php index d692a33..8023729 100644 --- a/src/ImageProcessor/ImageProcessor.php +++ b/src/ImageProcessor/ImageProcessor.php @@ -4,12 +4,9 @@ namespace SpomkyLabs\PwaBundle\ImageProcessor; -interface ImageProcessor +/** + * @deprecated since 1.2.0, will be removed in 2.0.0. Use ImageProcessorInterface instead. + */ +interface ImageProcessor extends ImageProcessorInterface { - public function process(string $image, ?int $width, ?int $height, ?string $format): string; - - /** - * @return array{width: int, height: int} - */ - public function getSizes(string $image): array; } diff --git a/src/ImageProcessor/ImageProcessorInterface.php b/src/ImageProcessor/ImageProcessorInterface.php new file mode 100644 index 0000000..ca74886 --- /dev/null +++ b/src/ImageProcessor/ImageProcessorInterface.php @@ -0,0 +1,15 @@ +example(['NetworkFirst', 'StaleWhileRevalidate', 'CacheFirst']) ->validate() - ->ifNotInArray(CacheStrategy::STRATEGIES) + ->ifNotInArray(CacheStrategyInterface::STRATEGIES) ->thenInvalid( 'Invalid caching strategy "%s". Should be one of: ' . implode( ', ', - CacheStrategy::STRATEGIES + CacheStrategyInterface::STRATEGIES ) ) ->end() diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 1374b9f..a368deb 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -3,7 +3,7 @@ declare(strict_types=1); use Facebook\WebDriver\WebDriverDimension; -use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategies; +use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface; use SpomkyLabs\PwaBundle\Command\CreateIconsCommand; use SpomkyLabs\PwaBundle\Command\CreateScreenshotCommand; use SpomkyLabs\PwaBundle\Command\ListCacheStrategiesCommand; @@ -11,11 +11,11 @@ use SpomkyLabs\PwaBundle\Dto\ServiceWorker; use SpomkyLabs\PwaBundle\ImageProcessor\GDImageProcessor; use SpomkyLabs\PwaBundle\ImageProcessor\ImagickImageProcessor; -use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandler; +use SpomkyLabs\PwaBundle\MatchCallbackHandler\MatchCallbackHandlerInterface; use SpomkyLabs\PwaBundle\Service\ManifestBuilder; use SpomkyLabs\PwaBundle\Service\ServiceWorkerBuilder; use SpomkyLabs\PwaBundle\Service\ServiceWorkerCompiler; -use SpomkyLabs\PwaBundle\ServiceWorkerRule\ServiceWorkerRule; +use SpomkyLabs\PwaBundle\ServiceWorkerRule\ServiceWorkerRuleInterface; use SpomkyLabs\PwaBundle\Subscriber\ManifestCompileEventListener; use SpomkyLabs\PwaBundle\Subscriber\PwaDevServerSubscriber; use SpomkyLabs\PwaBundle\Subscriber\ServiceWorkerCompileEventListener; @@ -110,17 +110,17 @@ ; /*** Service Worker Compiler Rules ***/ - $container->instanceof(ServiceWorkerRule::class) + $container->instanceof(ServiceWorkerRuleInterface::class) ->tag('spomky_labs_pwa.service_worker_rule') ; $container->load('SpomkyLabs\\PwaBundle\\ServiceWorkerRule\\', '../../ServiceWorkerRule/*'); - $container->instanceof(HasCacheStrategies::class) + $container->instanceof(HasCacheStrategiesInterface::class) ->tag('spomky_labs_pwa.cache_strategy') ; $container->load('SpomkyLabs\\PwaBundle\\CachingStrategy\\', '../../CachingStrategy/*'); - $container->instanceof(MatchCallbackHandler::class) + $container->instanceof(MatchCallbackHandlerInterface::class) ->tag('spomky_labs_pwa.match_callback_handler') ; $container->load('SpomkyLabs\\PwaBundle\\MatchCallbackHandler\\', '../../MatchCallbackHandler/*'); diff --git a/src/Service/ServiceWorkerCompiler.php b/src/Service/ServiceWorkerCompiler.php index dda6476..aa62f89 100644 --- a/src/Service/ServiceWorkerCompiler.php +++ b/src/Service/ServiceWorkerCompiler.php @@ -5,7 +5,7 @@ namespace SpomkyLabs\PwaBundle\Service; use SpomkyLabs\PwaBundle\Dto\ServiceWorker; -use SpomkyLabs\PwaBundle\ServiceWorkerRule\ServiceWorkerRule; +use SpomkyLabs\PwaBundle\ServiceWorkerRule\ServiceWorkerRuleInterface; use Symfony\Component\AssetMapper\AssetMapperInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; @@ -15,7 +15,7 @@ final readonly class ServiceWorkerCompiler { /** - * @param iterable $serviceworkerRules + * @param iterable $serviceworkerRules */ public function __construct( #[Autowire('%spomky_labs_pwa.sw.enabled%')] diff --git a/src/ServiceWorkerRule/AppendCacheStrategies.php b/src/ServiceWorkerRule/AppendCacheStrategies.php index d4c06f4..083495e 100644 --- a/src/ServiceWorkerRule/AppendCacheStrategies.php +++ b/src/ServiceWorkerRule/AppendCacheStrategies.php @@ -4,15 +4,15 @@ namespace SpomkyLabs\PwaBundle\ServiceWorkerRule; -use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategies; +use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategiesInterface; use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\DependencyInjection\Attribute\TaggedIterator; use const PHP_EOL; -final readonly class AppendCacheStrategies implements ServiceWorkerRule +final readonly class AppendCacheStrategies implements ServiceWorkerRuleInterface { /** - * @param iterable $cacheStrategies + * @param iterable $cacheStrategies */ public function __construct( #[TaggedIterator('spomky_labs_pwa.cache_strategy')] diff --git a/src/ServiceWorkerRule/ClearCache.php b/src/ServiceWorkerRule/ClearCache.php index f9495d4..6d959ac 100644 --- a/src/ServiceWorkerRule/ClearCache.php +++ b/src/ServiceWorkerRule/ClearCache.php @@ -7,7 +7,7 @@ use SpomkyLabs\PwaBundle\Dto\ServiceWorker; use SpomkyLabs\PwaBundle\Dto\Workbox; -final readonly class ClearCache implements ServiceWorkerRule +final readonly class ClearCache implements ServiceWorkerRuleInterface { private Workbox $workbox; diff --git a/src/ServiceWorkerRule/OfflineFallback.php b/src/ServiceWorkerRule/OfflineFallback.php index 03fa036..49d45a3 100644 --- a/src/ServiceWorkerRule/OfflineFallback.php +++ b/src/ServiceWorkerRule/OfflineFallback.php @@ -15,7 +15,7 @@ use const JSON_UNESCAPED_SLASHES; use const JSON_UNESCAPED_UNICODE; -final readonly class OfflineFallback implements ServiceWorkerRule +final readonly class OfflineFallback implements ServiceWorkerRuleInterface { private Workbox $workbox; diff --git a/src/ServiceWorkerRule/ServiceWorkerRule.php b/src/ServiceWorkerRule/ServiceWorkerRule.php index 88c0078..d7720a8 100644 --- a/src/ServiceWorkerRule/ServiceWorkerRule.php +++ b/src/ServiceWorkerRule/ServiceWorkerRule.php @@ -4,7 +4,9 @@ namespace SpomkyLabs\PwaBundle\ServiceWorkerRule; -interface ServiceWorkerRule +/** + * @deprecated since 1.2.0, to be removed in 2.0.0. Use ServiceWorkerRuleInterface instead. + */ +interface ServiceWorkerRule extends ServiceWorkerRuleInterface { - public function process(bool $debug = false): string; } diff --git a/src/ServiceWorkerRule/ServiceWorkerRuleInterface.php b/src/ServiceWorkerRule/ServiceWorkerRuleInterface.php new file mode 100644 index 0000000..41b9a1c --- /dev/null +++ b/src/ServiceWorkerRule/ServiceWorkerRuleInterface.php @@ -0,0 +1,10 @@ +import('Resources/config/services.php'); if ($config['image_processor'] !== null) { - $builder->setAlias(ImageProcessor::class, $config['image_processor']); + $builder->setAlias(ImageProcessorInterface::class, $config['image_processor']); } if ($config['web_client'] !== null) { $builder->setAlias('pwa.web_client', $config['web_client']); diff --git a/src/WorkboxPlugin/BackgroundSyncPlugin.php b/src/WorkboxPlugin/BackgroundSyncPlugin.php index 21c8008..825a528 100644 --- a/src/WorkboxPlugin/BackgroundSyncPlugin.php +++ b/src/WorkboxPlugin/BackgroundSyncPlugin.php @@ -4,7 +4,7 @@ namespace SpomkyLabs\PwaBundle\WorkboxPlugin; -final readonly class BackgroundSyncPlugin implements CachePlugin +final readonly class BackgroundSyncPlugin implements CachePluginInterface { private const NAME = 'BackgroundSyncPlugin'; diff --git a/src/WorkboxPlugin/BroadcastUpdatePlugin.php b/src/WorkboxPlugin/BroadcastUpdatePlugin.php index a50ee43..6a97005 100644 --- a/src/WorkboxPlugin/BroadcastUpdatePlugin.php +++ b/src/WorkboxPlugin/BroadcastUpdatePlugin.php @@ -4,7 +4,7 @@ namespace SpomkyLabs\PwaBundle\WorkboxPlugin; -final readonly class BroadcastUpdatePlugin implements CachePlugin +final readonly class BroadcastUpdatePlugin implements CachePluginInterface { private const NAME = 'BroadcastUpdatePlugin'; diff --git a/src/WorkboxPlugin/CachePlugin.php b/src/WorkboxPlugin/CachePlugin.php index c778a8b..998efcd 100644 --- a/src/WorkboxPlugin/CachePlugin.php +++ b/src/WorkboxPlugin/CachePlugin.php @@ -4,9 +4,9 @@ namespace SpomkyLabs\PwaBundle\WorkboxPlugin; -interface CachePlugin +/** + * @deprecated since 1.2.0, to be removed in 2.0.0. Use CachePluginInterface instead. + */ +interface CachePlugin extends CachePluginInterface { - public function getName(): string; - - public function render(int $jsonOptions = 0): string; } diff --git a/src/WorkboxPlugin/CachePluginInterface.php b/src/WorkboxPlugin/CachePluginInterface.php new file mode 100644 index 0000000..ef79062 --- /dev/null +++ b/src/WorkboxPlugin/CachePluginInterface.php @@ -0,0 +1,12 @@ +