vendor/friendsofsymfony/http-cache-bundle/src/Command/RefreshPathCommand.php line 36

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 refresh by path from the command line.
  18. *
  19. * @author David Buchmann <mail@davidbu.ch>
  20. */
  21. #[AsCommand(name: 'fos:httpcache:refresh:path')]
  22. class RefreshPathCommand extends BaseInvalidateCommand
  23. {
  24. use PathSanityCheck;
  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)
  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:refresh:path')
  46. ->setDescription('Refresh paths on all configured caching proxies')
  47. ->addArgument(
  48. 'paths',
  49. InputArgument::IS_ARRAY | InputArgument::REQUIRED,
  50. 'URL paths you want to refresh, you can specify any number of paths'
  51. )
  52. ->setHelp(<<<'EOF'
  53. The <info>%command.name%</info> command refreshes a list of paths on the configured caching proxies.
  54. Example:
  55. <info>php %command.full_name% /some/path /other/path</info>
  56. EOF
  57. )
  58. ;
  59. }
  60. /**
  61. * {@inheritdoc}
  62. */
  63. protected function execute(InputInterface $input, OutputInterface $output): int
  64. {
  65. $paths = $input->getArgument('paths');
  66. foreach ($paths as $path) {
  67. if ($this->looksLikeRegularExpression($path)) {
  68. $output->writeln(sprintf('Path %s looks like a regular expression. Refresh requests operate with actual requests and thus use exact paths. Use regex invalidation for regular expressions.', $path));
  69. }
  70. $this->getCacheManager()->refreshPath($path);
  71. }
  72. return 0;
  73. }
  74. }