Completed
Push — config-reader ( 6b41c3 )
by
unknown
03:29
created

FilterSetCollection::getFilterSets()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
/**
3
 * This file is part of the `liip/LiipImagineBundle` project.
4
 *
5
 * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
6
 *
7
 * For the full copyright and license information, please view the LICENSE.md
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Liip\ImagineBundle\Config;
12
13
use Liip\ImagineBundle\Imagine\Filter\FilterConfiguration;
14
15
final class FilterSetCollection
16
{
17
    /**
18
     * @var array
19
     */
20
    private $filterSets = [];
21
22
    /**
23
     * @var FilterConfiguration
24
     */
25
    private $filterConfiguration;
26
27
    /**
28
     * @var FilterSetBuilderInterface
29
     */
30
    private $filterSetBuilder;
31
32
    /**
33
     * @param FilterConfiguration $filterConfiguration
34
     * @param FilterSetBuilderInterface $filterSetBuilder
35
     */
36
    public function __construct(FilterConfiguration $filterConfiguration, FilterSetBuilderInterface $filterSetBuilder)
37
    {
38
        $this->filterConfiguration = $filterConfiguration;
39
        $this->filterSetBuilder = $filterSetBuilder;
40
    }
41
42
    /**
43
     * @return FilterSetInterface[]
44
     */
45
    public function getFilterSets()
46
    {
47
        if (!empty($this->filterSets)) {
48
            return $this->filterSets;
49
        }
50
51
        foreach ($this->filterConfiguration->all() as $filterSetName => $filterSetData) {
52
            $this->filterSets[] = $this->filterSetBuilder->build($filterSetName, $filterSetData);
53
        }
54
55
        return $this->filterSets;
56
    }
57
}
58