1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCacheBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\HttpCacheBundle\Command; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCacheBundle\CacheManager; |
15
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
16
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* A command to trigger cache invalidation by path from the command line. |
21
|
|
|
* |
22
|
|
|
* @author David Buchmann <[email protected]> |
23
|
|
|
*/ |
24
|
|
View Code Duplication |
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
|
11 |
|
public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:path') |
41
|
|
|
{ |
42
|
11 |
|
$this->commandName = $commandName; |
43
|
11 |
|
parent::__construct($cacheManager); |
44
|
11 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
11 |
|
protected function configure() |
50
|
|
|
{ |
51
|
|
|
$this |
52
|
11 |
|
->setName($this->commandName) |
53
|
11 |
|
->setDescription('Invalidate cached paths on all configured caching proxies') |
54
|
11 |
|
->addArgument( |
55
|
11 |
|
'paths', |
56
|
11 |
|
InputArgument::IS_ARRAY | InputArgument::REQUIRED, |
57
|
11 |
|
'URL paths you want to invalidate, you can specify any number of paths' |
58
|
|
|
) |
59
|
11 |
|
->setHelp(<<<'EOF' |
60
|
11 |
|
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
|
11 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* {@inheritdoc} |
72
|
|
|
*/ |
73
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
74
|
|
|
{ |
75
|
4 |
|
$paths = $input->getArgument('paths'); |
76
|
|
|
|
77
|
4 |
|
foreach ($paths as $path) { |
78
|
4 |
|
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
|
4 |
|
$this->getCacheManager()->invalidatePath($path); |
83
|
|
|
} |
84
|
4 |
|
} |
85
|
|
|
} |
86
|
|
|
|