Total Complexity | 6 |
Total Lines | 27 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | class Matcher implements MatcherInterface |
||
19 | { |
||
20 | /** @var UrlMatchVoterInterface */ |
||
21 | private $voter; |
||
22 | /** @var Request */ |
||
23 | private $request; |
||
24 | |||
25 | public function __construct(RequestStack $requestStack, UrlMatchVoterInterface $voter) |
||
26 | { |
||
27 | $this->request = $requestStack->getMasterRequest(); |
||
28 | $this->voter = $voter; |
||
29 | } |
||
30 | |||
31 | public function isCurrent($item): bool |
||
32 | { |
||
33 | if (!$this->request || !$item instanceof MatchableInterface) { |
||
34 | return false; |
||
35 | } |
||
36 | |||
37 | // we search matches within URL and route |
||
38 | foreach ([$this->request->getPathInfo(), $this->request->get('_route', '')] as $url) { |
||
39 | if ($this->voter->matches($url, $item)) { |
||
40 | return true; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | return false; |
||
45 | } |
||
47 |