Passed
Push — master ( 8bd912...d93388 )
by Alan
06:58 queued 02:20
created

src/Api/FilterCollectionFactory.php (1 issue)

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
The class ApiPlatform\Core\Api\FilterCollection has been deprecated: since version 2.1, to be removed in 3.0. Use a service locator {@see \Psr\Container\ContainerInterface}. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
        return /** @scrutinizer ignore-deprecated */ new FilterCollection($filters);
Loading history...
51
    }
52
}
53