Total Complexity | 6 |
Total Lines | 37 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
5 | final class ActiveMenuItemProcessor implements LaravelMenuItemProcessor |
||
6 | { |
||
7 | /** |
||
8 | * @var array |
||
9 | */ |
||
10 | private $lastActiveItem = []; |
||
11 | |||
12 | public function process($item) |
||
13 | { |
||
14 | if(array_key_exists('active', $item)) |
||
15 | { |
||
16 | $item['active'] = $item['active'](); |
||
17 | |||
18 | if($item['active']) |
||
19 | { |
||
20 | $this->lastActiveItem = $item; |
||
21 | } |
||
22 | } |
||
23 | else |
||
24 | { |
||
25 | $item['active'] = false; |
||
26 | |||
27 | if(array_key_exists('items', $item) && $this->lastActiveItem !== null) |
||
28 | { |
||
29 | $item['activeParent'] = array_search($this->lastActiveItem, $item['items']) !== false; |
||
30 | } |
||
31 | } |
||
32 | |||
33 | return $item; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * @return array |
||
38 | */ |
||
39 | public function getLastActiveItem(): array |
||
42 | } |
||
43 | } |