1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Everlution\Navigation\Match; |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
6 | |||
7 | use Everlution\Navigation\Item\MatchableInterface; |
||
8 | |||
9 | /** |
||
10 | * Class VoterContainer. |
||
11 | * |
||
12 | * @author Ivan Barlog <[email protected]> |
||
13 | */ |
||
14 | class VoterContainer implements UrlMatchVoterInterface |
||
15 | { |
||
16 | /** @var VoterInterface[] */ |
||
17 | private $voters = []; |
||
18 | |||
19 | public function __construct(array $voters = []) |
||
20 | { |
||
21 | array_map([$this, 'addVoter'], $voters); |
||
22 | } |
||
23 | |||
24 | public function addVoter(VoterInterface $voter): void |
||
25 | { |
||
26 | $this->voters[] = $voter; |
||
27 | } |
||
28 | |||
29 | public function matches(string $url, MatchableInterface $item): bool |
||
30 | { |
||
31 | foreach ($item->getMatches() as $match) { |
||
32 | if ($this->isMatch($url, $match)) { |
||
33 | return true; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | return false; |
||
38 | } |
||
39 | |||
40 | private function isMatch(string $url, MatchInterface $match): bool |
||
41 | { |
||
42 | foreach ($this->voters as $voter) { |
||
43 | if ($voter->matches($url, $match)) { |
||
44 | return true; |
||
45 | } |
||
46 | } |
||
47 | |||
48 | return false; |
||
49 | } |
||
50 | } |
||
51 |