|
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 regular expression from the command line. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Christian Stocker <[email protected]> |
|
23
|
|
|
* @author David Buchmann <[email protected]> |
|
24
|
|
|
*/ |
|
25
|
|
View Code Duplication |
class InvalidateRegexCommand extends BaseInvalidateCommand |
|
26
|
|
|
{ |
|
27
|
|
|
protected static $defaultName = 'fos:httpcache:invalidate:regex'; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* If no cache manager is specified explicitly, fos_http_cache.cache_manager |
|
31
|
|
|
* is automatically loaded. |
|
32
|
|
|
* |
|
33
|
|
|
* @param CacheManager|null $cacheManager The cache manager to talk to |
|
34
|
|
|
*/ |
|
35
|
4 |
|
public function __construct(CacheManager $cacheManager = null, $commandName = 'fos:httpcache:invalidate:regex') |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
4 |
|
if (2 <= func_num_args()) { |
|
38
|
|
|
@trigger_error('Passing a command name in the constructor is deprecated and will be removed in version 3', E_USER_DEPRECATED); |
|
|
|
|
|
|
39
|
|
|
static::$defaultName = func_get_arg(1); |
|
40
|
|
|
} |
|
41
|
4 |
|
parent::__construct($cacheManager); |
|
42
|
4 |
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* {@inheritdoc} |
|
46
|
|
|
*/ |
|
47
|
4 |
|
protected function configure() |
|
48
|
|
|
{ |
|
49
|
|
|
$this |
|
50
|
4 |
|
->setDescription('Invalidate everything matching a regular expression on all configured caching proxies') |
|
51
|
4 |
|
->addArgument( |
|
52
|
4 |
|
'regex', |
|
53
|
4 |
|
InputArgument::REQUIRED, |
|
54
|
4 |
|
'Regular expression for the paths to match.' |
|
55
|
|
|
) |
|
56
|
4 |
|
->setHelp(<<<'EOF' |
|
57
|
4 |
|
The <info>%command.name%</info> command invalidates all cached content matching a regular expression on the configured caching proxies. |
|
58
|
|
|
|
|
59
|
|
|
Example: |
|
60
|
|
|
|
|
61
|
|
|
<info>php %command.full_name% "/some.*/path" </info> |
|
62
|
|
|
|
|
63
|
|
|
or clear the whole cache |
|
64
|
|
|
|
|
65
|
|
|
<info>php %command.full_name% .</info> |
|
66
|
|
|
EOF |
|
67
|
|
|
) |
|
68
|
|
|
; |
|
69
|
4 |
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* {@inheritdoc} |
|
73
|
|
|
*/ |
|
74
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
75
|
|
|
{ |
|
76
|
2 |
|
$regex = $input->getArgument('regex'); |
|
77
|
|
|
|
|
78
|
2 |
|
$this->getCacheManager()->invalidateRegex($regex); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
2 |
|
return 0; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.