Skip to content

Commit

Permalink
List Cache Strategies command
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 8, 2024
1 parent 4b6294e commit 34a0c42
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
52 changes: 52 additions & 0 deletions src/Command/ListCacheStrategiesCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace SpomkyLabs\PwaBundle\Command;

use SpomkyLabs\PwaBundle\Service\HasCacheStrategies;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Attribute\TaggedIterator;
use Symfony\Component\Yaml\Yaml;
use function assert;

#[AsCommand(name: 'pwa:cache:list-strategies', description: 'List the available cache strategies',)]
final class ListCacheStrategiesCommand extends Command
{
public function __construct(

Check failure on line 20 in src/Command/ListCacheStrategiesCommand.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 Test on ubuntu-latest

Method SpomkyLabs\PwaBundle\Command\ListCacheStrategiesCommand::__construct() has parameter $services with no value type specified in iterable type iterable.
#[TaggedIterator('spomky_labs_pwa.cache_strategy')]
private readonly iterable $services,
) {
parent::__construct();
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$io->title('Cache Strategies');

$table = $io->createTable();
$table->setHeaders(['Name', 'Strategy', 'URL pattern', 'Enabled', 'Workbox?', 'Options']);
foreach ($this->services as $service) {
assert($service instanceof HasCacheStrategies);
$strategies = $service->getCacheStrategies();
foreach ($strategies as $strategy) {
$table->addRow([
$strategy->name,
$strategy->strategy,
$strategy->urlPattern,
$strategy->enabled ? 'Yes' : 'No',
$strategy->requireWorkbox ? 'Yes' : 'No',
Yaml::dump($strategy->options),
]);
}
}
$table->render();

return self::SUCCESS;
}
}
6 changes: 4 additions & 2 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
use Facebook\WebDriver\WebDriverDimension;
use SpomkyLabs\PwaBundle\Command\CreateIconsCommand;
use SpomkyLabs\PwaBundle\Command\CreateScreenshotCommand;
use SpomkyLabs\PwaBundle\Command\ListCacheStrategiesCommand;
use SpomkyLabs\PwaBundle\Dto\Manifest;
use SpomkyLabs\PwaBundle\Dto\ServiceWorker;
use SpomkyLabs\PwaBundle\ImageProcessor\GDImageProcessor;
use SpomkyLabs\PwaBundle\ImageProcessor\ImagickImageProcessor;
use SpomkyLabs\PwaBundle\Service\CacheStrategy;
use SpomkyLabs\PwaBundle\Service\HasCacheStrategies;
use SpomkyLabs\PwaBundle\Service\ManifestBuilder;
use SpomkyLabs\PwaBundle\Service\Rule\ServiceWorkerRule;
use SpomkyLabs\PwaBundle\Service\ServiceWorkerBuilder;
Expand Down Expand Up @@ -63,6 +64,7 @@
if (class_exists(MimeTypes::class)) {
$container->set(CreateIconsCommand::class);
}
$container->set(ListCacheStrategiesCommand::class);

/*** Normalizers ***/
$container->load('SpomkyLabs\\PwaBundle\\Normalizer\\', '../../Normalizer/*')
Expand Down Expand Up @@ -110,7 +112,7 @@
$container->instanceof(ServiceWorkerRule::class)
->tag('spomky_labs_pwa.service_worker_rule')
;
$container->instanceof(CacheStrategy::class)
$container->instanceof(HasCacheStrategies::class)
->tag('spomky_labs_pwa.cache_strategy')
;
$container->load('SpomkyLabs\\PwaBundle\\Service\\Rule\\', '../../Service/Rule/*');
Expand Down

0 comments on commit 34a0c42

Please sign in to comment.