1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the API Platform project. |
||
5 | * |
||
6 | * (c) Kévin Dunglas <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | declare(strict_types=1); |
||
13 | |||
14 | namespace ApiPlatform\Core\Api; |
||
15 | |||
16 | use Psr\Container\ContainerInterface; |
||
17 | |||
18 | /** |
||
19 | * Filter collection factory. |
||
20 | * |
||
21 | * @author Baptiste Meyer <[email protected]> |
||
22 | * |
||
23 | * @internal |
||
24 | */ |
||
25 | class FilterCollectionFactory |
||
26 | { |
||
27 | private $filtersIds; |
||
28 | |||
29 | /** |
||
30 | * @param string[] $filtersIds |
||
31 | */ |
||
32 | public function __construct(array $filtersIds) |
||
33 | { |
||
34 | $this->filtersIds = $filtersIds; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Creates a filter collection from a filter locator. |
||
39 | */ |
||
40 | public function createFilterCollectionFromLocator(ContainerInterface $filterLocator): FilterCollection |
||
41 | { |
||
42 | $filters = []; |
||
43 | |||
44 | foreach ($this->filtersIds as $filterId) { |
||
45 | if ($filterLocator->has($filterId)) { |
||
46 | $filters[$filterId] = $filterLocator->get($filterId); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return new FilterCollection($filters); |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
Loading history...
|
|||
51 | } |
||
52 | } |
||
53 |