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