1 | <?php |
||
9 | class ActiveChecker |
||
10 | { |
||
11 | private $request; |
||
12 | |||
13 | private $url; |
||
14 | |||
15 | 36 | public function __construct(Request $request, UrlGenerator $url) |
|
20 | |||
21 | 34 | public function isActive($item) |
|
22 | { |
||
23 | 34 | if (isset($item['submenu']) && $this->containsActive($item['submenu'])) { |
|
24 | 8 | return true; |
|
25 | } |
||
26 | |||
27 | 31 | if (isset($item['active']) && $this->isExplicitActive($item['active'])) { |
|
28 | 7 | return true; |
|
29 | } |
||
30 | |||
31 | 27 | if (isset($item['href']) && $this->checkPattern($item['href'])) { |
|
32 | 15 | return true; |
|
33 | } |
||
34 | |||
35 | // Support URL for backwards compatibility |
||
36 | 12 | if (isset($item['url']) && $this->checkPattern($item['url'])) { |
|
37 | 11 | return true; |
|
38 | } |
||
39 | |||
40 | 1 | return false; |
|
41 | } |
||
42 | |||
43 | 30 | protected function checkPattern($pattern) |
|
61 | |||
62 | 8 | protected function containsActive($items) |
|
72 | |||
73 | 7 | private function isExplicitActive($active) |
|
87 | } |
||
88 |