1 | <?php |
||
2 | |||
3 | /* |
||
4 | * |
||
5 | * (c) Yaroslav Honcharuk <[email protected]> |
||
6 | * |
||
7 | * For the full copyright and license information, please view the LICENSE |
||
8 | * file that was distributed with this source code. |
||
9 | */ |
||
10 | |||
11 | namespace Yarhon\RouteGuardBundle\Security\Http; |
||
12 | |||
13 | use Yarhon\RouteGuardBundle\Security\Test\ProviderAwareTrait; |
||
14 | use Yarhon\RouteGuardBundle\Security\Test\ProviderAwareInterface; |
||
15 | use Yarhon\RouteGuardBundle\Security\Test\TestInterface; |
||
16 | |||
17 | /** |
||
18 | * @author Yaroslav Honcharuk <[email protected]> |
||
19 | */ |
||
20 | class RequestDependentTestBag implements RequestDependentTestBagInterface, ProviderAwareInterface |
||
21 | { |
||
22 | use ProviderAwareTrait; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $map = []; |
||
28 | |||
29 | /** |
||
30 | * @param array $map |
||
31 | */ |
||
32 | 13 | public function __construct(array $map) |
|
33 | { |
||
34 | 13 | foreach ($map as $item) { |
|
35 | 13 | $this->add(...$item); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
36 | } |
||
37 | 13 | } |
|
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 7 | public function getTests(RequestContext $requestContext) |
|
43 | { |
||
44 | 7 | foreach ($this->map as list($tests, $requestConstraint)) { |
|
45 | /** @var RequestConstraintInterface $requestConstraint */ |
||
46 | 7 | if (null === $requestConstraint || $requestConstraint->matches($requestContext)) { |
|
47 | 5 | return $tests; |
|
48 | } |
||
49 | } |
||
50 | |||
51 | 2 | return []; |
|
52 | } |
||
53 | |||
54 | /** |
||
55 | * @param TestInterface[] $tests |
||
56 | * @param RequestConstraintInterface|null $constraint |
||
57 | */ |
||
58 | 13 | private function add(array $tests, RequestConstraintInterface $constraint = null) |
|
59 | { |
||
60 | 13 | $this->map[] = [$tests, $constraint]; |
|
61 | 13 | } |
|
62 | } |
||
63 |