vendor/friendsofsymfony/http-cache-bundle/src/Command/InvalidateRegexCommand.php line 35

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the FOSHttpCacheBundle package.
  4. *
  5. * (c) FriendsOfSymfony <http://friendsofsymfony.github.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 FOS\HttpCacheBundle\Command;
  11. use FOS\HttpCacheBundle\CacheManager;
  12. use Symfony\Component\Console\Attribute\AsCommand;
  13. use Symfony\Component\Console\Input\InputArgument;
  14. use Symfony\Component\Console\Input\InputInterface;
  15. use Symfony\Component\Console\Output\OutputInterface;
  16. /**
  17. * A command to trigger cache invalidation by regular expression from the command line.
  18. *
  19. * @author Christian Stocker <chregu@liip.ch>
  20. * @author David Buchmann <mail@davidbu.ch>
  21. */
  22. #[AsCommand(name: 'fos:httpcache:invalidate:regex')]
  23. class InvalidateRegexCommand extends BaseInvalidateCommand
  24. {
  25. /**
  26. * If no cache manager is specified explicitly, fos_http_cache.cache_manager
  27. * is automatically loaded.
  28. *
  29. * @param CacheManager|null $cacheManager The cache manager to talk to
  30. */
  31. public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex')
  32. {
  33. parent::__construct($cacheManager);
  34. if (2 <= func_num_args()) {
  35. @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED);
  36. $this->setName(func_get_arg(1));
  37. }
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. protected function configure(): void
  43. {
  44. $this
  45. ->setName('fos:httpcache:invalidate:regex')
  46. ->setDescription('Invalidate everything matching a regular expression on all configured caching proxies')
  47. ->addArgument(
  48. 'regex',
  49. InputArgument::REQUIRED,
  50. 'Regular expression for the paths to match.'
  51. )
  52. ->setHelp(<<<'EOF'
  53. The <info>%command.name%</info> command invalidates all cached content matching a regular expression on the configured caching proxies.
  54. Example:
  55. <info>php %command.full_name% "/some.*/path" </info>
  56. or clear the whole cache
  57. <info>php %command.full_name% .</info>
  58. EOF
  59. )
  60. ;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. protected function execute(InputInterface $input, OutputInterface $output): int
  66. {
  67. $regex = $input->getArgument('regex');
  68. $this->getCacheManager()->invalidateRegex($regex);
  69. return 0;
  70. }
  71. }