1 | <?php |
||
9 | class ActiveChecker |
||
10 | { |
||
11 | private $request; |
||
12 | |||
13 | private $url; |
||
14 | |||
15 | 32 | public function __construct(Request $request, UrlGenerator $url) |
|
20 | |||
21 | 13 | public function isActive($item) |
|
22 | { |
||
23 | 13 | if (isset($item['submenu'])) { |
|
24 | 2 | return $this->containsActive($item['submenu']); |
|
25 | } |
||
26 | |||
27 | 13 | if (isset($item['active'])) { |
|
28 | 3 | return $this->isExplicitActive($item['active']); |
|
29 | } |
||
30 | |||
31 | 10 | if (isset($item['href'])) { |
|
32 | return $this->checkExactOrSub($item['href']); |
||
33 | } |
||
34 | |||
35 | // Support URL for backwards compatibility |
||
36 | 10 | if (isset($item['url'])) { |
|
37 | 9 | return $this->checkExactOrSub($item['url']); |
|
38 | } |
||
39 | |||
40 | 1 | return false; |
|
41 | } |
||
42 | |||
43 | 9 | protected function checkExactOrSub($url) |
|
47 | |||
48 | 12 | protected function checkExact($url) |
|
52 | |||
53 | 3 | protected function checkSub($url) |
|
57 | |||
58 | 12 | protected function checkPattern($pattern) |
|
66 | |||
67 | 2 | protected function containsActive($items) |
|
77 | |||
78 | 3 | private function isExplicitActive($active) |
|
92 | } |
||
93 |