Completed
Pull Request — 2.0 (#1023)
by Lukas Kahwe
15:12 queued 13:25
created

ResolveCacheCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the `liip/LiipImagineBundle` project.
5
 *
6
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
7
 *
8
 * For the full copyright and license information, please view the LICENSE.md
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Liip\ImagineBundle\Command;
13
14
use Liip\ImagineBundle\Imagine\Filter\FilterManager;
15
use Liip\ImagineBundle\Service\FilterService;
16
use Symfony\Component\Console\Command\Command;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
class ResolveCacheCommand extends Command
23
{
24
    /* @var FilterManager $filterManager */
25
    private $filterManager;
26
27
    /* @var FilterService $filterService */
28
    private $filterService;
29
30
    public function __construct(FilterManager $filterManager, FilterService $filterService)
31
    {
32
        $this->filterManager = $filterManager;
33
        $this->filterService = $filterService;
34
35
        parent::__construct('liip:imagine:cache:resolve');
36
    }
37
38 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
39
    {
40
        $this
41
            ->setDescription('Resolve cache for given path and set of filters.')
42
            ->addArgument('paths', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'Image paths')
43
            ->addOption(
44
                'filters',
45
                'f',
46
                InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
47
                'Filters list'
48
            )->setHelp(<<<'EOF'
49
The <info>%command.name%</info> command resolves cache by specified parameters.
50
It returns list of urls.
51
52
<info>php app/console %command.name% path1 path2 --filters=thumb1</info>
53
Cache for this two paths will be resolved with passed filter.
54
As a result you will get<info>
55
    http://localhost/media/cache/thumb1/path1
56
    http://localhost/media/cache/thumb1/path2</info>
57
58
You can pass few filters:
59
<info>php app/console %command.name% path1 --filters=thumb1 --filters=thumb2</info>
60
As a result you will get<info>
61
    http://localhost/media/cache/thumb1/path1
62
    http://localhost/media/cache/thumb2/path1</info>
63
64
If you omit --filters parameter then to resolve given paths will be used all configured and available filters in application:
65
<info>php app/console %command.name% path1</info>
66
As a result you will get<info>
67
    http://localhost/media/cache/thumb1/path1
68
    http://localhost/media/cache/thumb2/path1</info>
69
EOF
70
            );
71
    }
72
73
    protected function execute(InputInterface $input, OutputInterface $output)
74
    {
75
        $paths = $input->getArgument('paths');
76
        $filters = $input->getOption('filters');
77
78
        if (empty($filters)) {
79
            $filters = array_keys($this->filterManager->getFilterConfiguration()->all());
80
        }
81
82
        foreach ($paths as $path) {
83
            foreach ($filters as $filter) {
84
                $output->writeln($this->filterService->getUrlOfFilteredImage($path, $filter));
85
            }
86
        }
87
    }
88
}
89