1 | <?php namespace NukaCode\Menu; |
||
10 | class Container extends Collection |
||
11 | { |
||
12 | |||
13 | /** |
||
14 | * The slug to set to active during render |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | private $active; |
||
19 | |||
20 | /** |
||
21 | * Get a menu you have created. |
||
22 | * |
||
23 | * @param $menuName |
||
24 | * |
||
25 | * @return mixed |
||
26 | */ |
||
27 | 12 | public function getMenu($menuName) |
|
36 | |||
37 | /** |
||
38 | * Add a new menu. |
||
39 | * |
||
40 | * @param $menuName |
||
41 | * |
||
42 | * @return Menu |
||
43 | */ |
||
44 | 12 | private function add($menuName) |
|
48 | |||
49 | /** |
||
50 | * Check if a menu exists. |
||
51 | * |
||
52 | * @param $menuName |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 2 | public function exists($menuName) |
|
60 | |||
61 | /** |
||
62 | * Check if a menu is empty |
||
63 | * |
||
64 | * @param $menuName |
||
65 | * |
||
66 | * @return bool |
||
67 | */ |
||
68 | 2 | public function hasLinks($menuName) |
|
72 | |||
73 | /** |
||
74 | * Update the active and order values and then return the object. |
||
75 | * |
||
76 | * @param $menuName |
||
77 | * |
||
78 | * @return Menu |
||
79 | * @throws \Exception |
||
80 | */ |
||
81 | 4 | public function render($menuName) |
|
94 | |||
95 | /** |
||
96 | * Sanitize the menus names for safe use in array keys. |
||
97 | * |
||
98 | * @param $name |
||
99 | * |
||
100 | * @return string |
||
101 | */ |
||
102 | 14 | public function snakeName($name) |
|
106 | |||
107 | /** |
||
108 | * Get the menu object |
||
109 | * |
||
110 | * @param $menuName |
||
111 | * |
||
112 | * @return mixed|null |
||
113 | */ |
||
114 | 14 | private function getMenuObject($menuName) |
|
118 | |||
119 | /** |
||
120 | * Get the active link by slug. |
||
121 | * |
||
122 | * @return string |
||
123 | */ |
||
124 | 1 | public function getActive() |
|
128 | |||
129 | /** |
||
130 | * Set the active link by slug. |
||
131 | * |
||
132 | * @param $slug |
||
133 | */ |
||
134 | 3 | public function setActive($slug) |
|
138 | |||
139 | /** |
||
140 | * Use the active param and set the link to active |
||
141 | */ |
||
142 | private function updateActive() |
||
150 | 1 | ||
151 | 1 | /** |
|
152 | * Loop through the links and check for active. |
||
153 | 3 | * Sets the item and it's parents as active when told to. |
|
154 | 1 | */ |
|
155 | 1 | private function makeActive($item, $parent = null) |
|
170 | |||
171 | /** |
||
172 | * Set the parent item as active if able to do so. |
||
173 | */ |
||
174 | private function makeParentActive($parent) |
||
183 | } |
||
184 |