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