@@ 24-85 (lines=62) @@ | ||
21 | * |
|
22 | * @author David Buchmann <[email protected]> |
|
23 | */ |
|
24 | class InvalidatePathCommand extends BaseInvalidateCommand |
|
25 | { |
|
26 | use PathSanityCheck; |
|
27 | ||
28 | protected static $defaultName = 'fos:httpcache:invalidate:path'; |
|
29 | ||
30 | /** |
|
31 | * If no cache manager is specified explicitly, fos_http_cache.cache_manager |
|
32 | * is automatically loaded. |
|
33 | * |
|
34 | * @param CacheManager|null $cacheManager The cache manager to talk to |
|
35 | */ |
|
36 | public function __construct(CacheManager $cacheManager = null) |
|
37 | { |
|
38 | if (2 <= func_num_args()) { |
|
39 | @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); |
|
40 | static::$defaultName = func_get_arg(1); |
|
41 | } |
|
42 | parent::__construct($cacheManager); |
|
43 | } |
|
44 | ||
45 | /** |
|
46 | * {@inheritdoc} |
|
47 | */ |
|
48 | protected function configure() |
|
49 | { |
|
50 | $this |
|
51 | ->setDescription('Invalidate cached paths on all configured caching proxies') |
|
52 | ->addArgument( |
|
53 | 'paths', |
|
54 | InputArgument::IS_ARRAY | InputArgument::REQUIRED, |
|
55 | 'URL paths you want to invalidate, you can specify any number of paths' |
|
56 | ) |
|
57 | ->setHelp(<<<'EOF' |
|
58 | The <info>%command.name%</info> command invalidates a list of paths on the configured caching proxies. |
|
59 | ||
60 | Example: |
|
61 | ||
62 | <info>php %command.full_name% /some/path /other/path</info> |
|
63 | EOF |
|
64 | ) |
|
65 | ; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * {@inheritdoc} |
|
70 | */ |
|
71 | protected function execute(InputInterface $input, OutputInterface $output): int |
|
72 | { |
|
73 | $paths = $input->getArgument('paths'); |
|
74 | ||
75 | foreach ($paths as $path) { |
|
76 | if ($this->looksLikeRegularExpression($path)) { |
|
77 | $output->writeln(sprintf('Path %s looks like a regular expression. Invalidation requests operate on exact paths. Use regex invalidation for regular expressions.', $path)); |
|
78 | } |
|
79 | ||
80 | $this->getCacheManager()->invalidatePath($path); |
|
81 | } |
|
82 | ||
83 | return 0; |
|
84 | } |
|
85 | } |
|
86 |
@@ 24-85 (lines=62) @@ | ||
21 | * |
|
22 | * @author David Buchmann <[email protected]> |
|
23 | */ |
|
24 | class RefreshPathCommand extends BaseInvalidateCommand |
|
25 | { |
|
26 | use PathSanityCheck; |
|
27 | ||
28 | protected static $defaultName = 'fos:httpcache:refresh:path'; |
|
29 | ||
30 | /** |
|
31 | * If no cache manager is specified explicitly, fos_http_cache.cache_manager |
|
32 | * is automatically loaded. |
|
33 | * |
|
34 | * @param CacheManager|null $cacheManager The cache manager to talk to |
|
35 | */ |
|
36 | public function __construct(CacheManager $cacheManager = null) |
|
37 | { |
|
38 | if (2 <= func_num_args()) { |
|
39 | @trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); |
|
40 | static::$defaultName = func_get_arg(1); |
|
41 | } |
|
42 | parent::__construct($cacheManager); |
|
43 | } |
|
44 | ||
45 | /** |
|
46 | * {@inheritdoc} |
|
47 | */ |
|
48 | protected function configure() |
|
49 | { |
|
50 | $this |
|
51 | ->setDescription('Refresh paths on all configured caching proxies') |
|
52 | ->addArgument( |
|
53 | 'paths', |
|
54 | InputArgument::IS_ARRAY | InputArgument::REQUIRED, |
|
55 | 'URL paths you want to refresh, you can specify any number of paths' |
|
56 | ) |
|
57 | ->setHelp(<<<'EOF' |
|
58 | The <info>%command.name%</info> command refreshes a list of paths on the configured caching proxies. |
|
59 | ||
60 | Example: |
|
61 | ||
62 | <info>php %command.full_name% /some/path /other/path</info> |
|
63 | EOF |
|
64 | ) |
|
65 | ; |
|
66 | } |
|
67 | ||
68 | /** |
|
69 | * {@inheritdoc} |
|
70 | */ |
|
71 | protected function execute(InputInterface $input, OutputInterface $output): int |
|
72 | { |
|
73 | $paths = $input->getArgument('paths'); |
|
74 | ||
75 | foreach ($paths as $path) { |
|
76 | if ($this->looksLikeRegularExpression($path)) { |
|
77 | $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)); |
|
78 | } |
|
79 | ||
80 | $this->getCacheManager()->refreshPath($path); |
|
81 | } |
|
82 | ||
83 | return 0; |
|
84 | } |
|
85 | } |
|
86 |