/
RemoveCacheCommand.php
60 lines (49 loc) · 1.99 KB
/
RemoveCacheCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Liip\ImagineBundle\Command;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class RemoveCacheCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('liip:imagine:cache:remove')
->setDescription('Remove cache for given paths and set of filters.')
->addArgument('paths', InputArgument::OPTIONAL|InputArgument::IS_ARRAY, 'Image paths')
->addOption(
'filters',
'f',
InputOption::VALUE_OPTIONAL|InputOption::VALUE_IS_ARRAY,
'Filters list'
)
->setHelp(<<<EOF
The <info>%command.name%</info> command removes cache by specified parameters.
Paths should be separated by spaces:
<info>php app/console %command.name% path1 path2</info>
All cache for a given `paths` will be lost.
If you use --filters parameter:
<info>php app/console %command.name% --filters=thumb1 --filters=thumb2</info>
All cache for a given filters will be lost.
You can combine these parameters:
<info>php app/console %command.name% path1 path2 --filters=thumb1 --filters=thumb2</info>
<info>php app/console %command.name%</info>
Cache for all paths and filters will be lost when executing this command without parameters.
EOF
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$paths = $input->getArgument('paths');
$filters = $input->getOption('filters');
if (empty($filters)) {
$filters = null;
}
/* @var CacheManager cacheManager */
$cacheManager = $this->getContainer()->get('liip_imagine.cache.manager');
$cacheManager->remove($paths, $filters);
}
}