Completed
Push — master ( a40985...862247 )
by Kévin
14s
created

FilterCollectionFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
     * @param ContainerInterface $filterLocator
41
     *
42
     * @return FilterCollection
43
     */
44
    public function createFilterCollectionFromLocator(ContainerInterface $filterLocator): FilterCollection
45
    {
46
        $filters = [];
47
48
        foreach ($this->filtersIds as $filterId) {
49
            if ($filterLocator->has($filterId)) {
50
                $filters[$filterId] = $filterLocator->get($filterId);
51
            }
52
        }
53
54
        return new FilterCollection($filters);
1 ignored issue
show
Deprecated Code introduced by
The class ApiPlatform\Core\Api\FilterCollection has been deprecated with message: since version 2.1, to be removed in 3.0. Use a service locator {@see \Psr\Container\ContainerInterface}.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
55
    }
56
}
57