/
ResolveCacheCommand.php
88 lines (74 loc) · 2.97 KB
/
ResolveCacheCommand.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/*
* This file is part of the `liip/LiipImagineBundle` project.
*
* (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace Liip\ImagineBundle\Command;
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
use Liip\ImagineBundle\Service\FilterService;
use Symfony\Component\Console\Command\Command;
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 ResolveCacheCommand extends Command
{
/* @var FilterManager $filterManager */
private $filterManager;
/* @var FilterService $filterService */
private $filterService;
public function __construct(FilterManager $filterManager, FilterService $filterService)
{
$this->filterManager = $filterManager;
$this->filterService = $filterService;
parent::__construct('liip:imagine:cache:resolve');
}
protected function configure()
{
$this
->setDescription('Resolve cache for given path and set of filters.')
->addArgument('paths', InputArgument::REQUIRED | 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 resolves cache by specified parameters.
It returns list of urls.
<info>php app/console %command.name% path1 path2 --filters=thumb1</info>
Cache for this two paths will be resolved with passed filter.
As a result you will get<info>
http://localhost/media/cache/thumb1/path1
http://localhost/media/cache/thumb1/path2</info>
You can pass few filters:
<info>php app/console %command.name% path1 --filters=thumb1 --filters=thumb2</info>
As a result you will get<info>
http://localhost/media/cache/thumb1/path1
http://localhost/media/cache/thumb2/path1</info>
If you omit --filters parameter then to resolve given paths will be used all configured and available filters in application:
<info>php app/console %command.name% path1</info>
As a result you will get<info>
http://localhost/media/cache/thumb1/path1
http://localhost/media/cache/thumb2/path1</info>
EOF
);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$paths = $input->getArgument('paths');
$filters = $input->getOption('filters');
if (empty($filters)) {
$filters = array_keys($this->filterManager->getFilterConfiguration()->all());
}
foreach ($paths as $path) {
foreach ($filters as $filter) {
$output->writeln($this->filterService->getUrlOfFilteredImage($path, $filter));
}
}
}
}