CachePoolPruneCommand.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Command;
  11. use Symfony\Component\Cache\PruneableInterface;
  12. use Symfony\Component\Console\Command\Command;
  13. use Symfony\Component\Console\Input\InputInterface;
  14. use Symfony\Component\Console\Output\OutputInterface;
  15. use Symfony\Component\Console\Style\SymfonyStyle;
  16. /**
  17. * Cache pool pruner command.
  18. *
  19. * @author Rob Frawley 2nd <rmf@src.run>
  20. */
  21. final class CachePoolPruneCommand extends Command
  22. {
  23. protected static $defaultName = 'cache:pool:prune';
  24. private $pools;
  25. /**
  26. * @param iterable|PruneableInterface[] $pools
  27. */
  28. public function __construct(iterable $pools)
  29. {
  30. parent::__construct();
  31. $this->pools = $pools;
  32. }
  33. /**
  34. * {@inheritdoc}
  35. */
  36. protected function configure()
  37. {
  38. $this
  39. ->setDescription('Prune cache pools')
  40. ->setHelp(<<<'EOF'
  41. The <info>%command.name%</info> command deletes all expired items from all pruneable pools.
  42. %command.full_name%
  43. EOF
  44. )
  45. ;
  46. }
  47. /**
  48. * {@inheritdoc}
  49. */
  50. protected function execute(InputInterface $input, OutputInterface $output): int
  51. {
  52. $io = new SymfonyStyle($input, $output);
  53. foreach ($this->pools as $name => $pool) {
  54. $io->comment(sprintf('Pruning cache pool: <info>%s</info>', $name));
  55. $pool->prune();
  56. }
  57. $io->success('Successfully pruned cache pool(s).');
  58. return 0;
  59. }
  60. }