1 | <?php |
||
19 | final class FilterManager implements FilterManagerInterface |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * @var FilterInterface[] |
||
24 | */ |
||
25 | private $filters = []; |
||
26 | |||
27 | /** |
||
28 | * @var EntityManagerInterface |
||
29 | */ |
||
30 | private $entityManager; |
||
31 | |||
32 | /** |
||
33 | * @var bool |
||
34 | */ |
||
35 | private $areFiltersEnabled = FALSE; |
||
36 | |||
37 | |||
38 | 5 | public function __construct(EntityManagerInterface $entityManager) |
|
42 | |||
43 | |||
44 | 5 | public function addFilter(string $name, FilterInterface $filter) |
|
48 | |||
49 | |||
50 | 5 | public function enableFilters() |
|
51 | { |
||
52 | 5 | if ($this->areFiltersEnabled) { |
|
53 | 1 | return; |
|
54 | } |
||
55 | |||
56 | 5 | foreach ($this->filters as $name => $filter) { |
|
57 | 5 | if ($filter instanceof ConditionalFilterInterface && ! $filter->isEnabled()) { |
|
58 | 5 | continue; |
|
59 | } |
||
60 | |||
61 | 5 | $this->addFilterToEnabledInFilterCollection($name, $filter); |
|
62 | } |
||
63 | |||
64 | 5 | $this->areFiltersEnabled = TRUE; |
|
65 | 5 | } |
|
66 | |||
67 | |||
68 | 5 | private function addFilterToEnabledInFilterCollection(string $name, FilterInterface $filter) |
|
80 | |||
81 | } |
||
82 |