Skip to content

Commit

Permalink
features: CachePlugin and CacheStrategy are now interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Spomky committed Mar 21, 2024
1 parent 4d6c08a commit 811c4e3
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions src/Command/ListCacheStrategiesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

namespace SpomkyLabs\PwaBundle\Command;

use SpomkyLabs\PwaBundle\CachingStrategy\CacheStrategy;
use SpomkyLabs\PwaBundle\CachingStrategy\HasCacheStrategies;
use SpomkyLabs\PwaBundle\CachingStrategy\WorkboxCacheStrategy;
use SpomkyLabs\PwaBundle\WorkboxPlugin\CachePlugin;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
Expand Down Expand Up @@ -39,35 +41,39 @@ protected function execute(InputInterface $input, OutputInterface $output): int
['Name', 'Strategy', 'URL pattern', 'Enabled', 'Workbox?', 'Plugins', 'Preload URLs', 'Options']
);
foreach ($this->services as $service) {
$strategies = $service->getCacheStrategies();
foreach ($strategies as $strategy) {
if ($strategy instanceof WorkboxCacheStrategy) {
$table->addRow([
$strategy->getName(),
$strategy->strategy,
$strategy->matchCallback,
$strategy->isEnabled() ? 'Yes' : 'No',
$strategy->needsWorkbox() ? 'Yes' : 'No',
Yaml::dump(array_map(fn (CachePlugin $v): string => $v->getName(), $strategy->getPlugins())),
count($strategy->getPreloadUrls()),
Yaml::dump($strategy->getOptions()),
]);
} else {
$table->addRow([
$strategy->getName(),
'---',
'---',
$strategy->isEnabled() ? 'Yes' : 'No',
$strategy->needsWorkbox() ? 'Yes' : 'No',
'',
'',
'',
]);
}
foreach ($service->getCacheStrategies() as $strategy) {
$this->processStrategy($strategy, $table);
}
}
$table->render();

return self::SUCCESS;
}

private function processStrategy(CacheStrategy $strategy, Table $table): void
{
if ($strategy instanceof WorkboxCacheStrategy) {
$table->addRow([
$strategy->getName(),
$strategy->strategy,
$strategy->matchCallback,
$strategy->isEnabled() ? 'Yes' : 'No',
$strategy->needsWorkbox() ? 'Yes' : 'No',
Yaml::dump(array_map(fn (CachePlugin $v): string => $v->getName(), $strategy->getPlugins())),
count($strategy->getPreloadUrls()),
Yaml::dump($strategy->getOptions()),
]);
} else {
$table->addRow([
$strategy->getName(),
'---',
'---',
$strategy->isEnabled() ? 'Yes' : 'No',
$strategy->needsWorkbox() ? 'Yes' : 'No',
'',
'',
'',
]);
}
}
}

0 comments on commit 811c4e3

Please sign in to comment.