1 | <?php |
||
12 | class MenuItem |
||
13 | { |
||
14 | /** |
||
15 | * The properties array. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | public $properties = []; |
||
20 | |||
21 | /** |
||
22 | * The childs collection. |
||
23 | * |
||
24 | * @var \Illuminate\Support\Collection |
||
25 | */ |
||
26 | protected $childs; |
||
|
|||
27 | |||
28 | /** |
||
29 | * The hide callbacks collection. |
||
30 | * |
||
31 | * @var \Illuminate\Support\Collection |
||
32 | */ |
||
33 | protected $hideCallbacks; |
||
34 | |||
35 | /** |
||
36 | * The active callback. |
||
37 | * |
||
38 | * @var callable |
||
39 | */ |
||
40 | protected $activeWhen; |
||
41 | |||
42 | /** |
||
43 | * Constructor. |
||
44 | * |
||
45 | * @param array $properties |
||
46 | */ |
||
47 | public function __construct($properties = []) |
||
54 | |||
55 | /** |
||
56 | * Get property. |
||
57 | * |
||
58 | * @param string $key |
||
59 | * |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public function __get($key) |
||
66 | |||
67 | /** |
||
68 | * Fill the properties. |
||
69 | * |
||
70 | * @param array $properties |
||
71 | * |
||
72 | * @return static |
||
73 | */ |
||
74 | public function fill($properties) |
||
80 | |||
81 | /** |
||
82 | * Create new menu with dropdown. |
||
83 | * |
||
84 | * @param callable $callback |
||
85 | * @param string $title |
||
86 | * @param int $order |
||
87 | * @param string $icon |
||
88 | * @param array $attributes |
||
89 | * |
||
90 | * @return static |
||
91 | */ |
||
92 | public function dropdown(callable $callback, string $title, int $order = null, string $icon = null, array $attributes = []) |
||
98 | |||
99 | /** |
||
100 | * Register new menu item using registered route. |
||
101 | * |
||
102 | * @param string $route |
||
103 | * @param string $title |
||
104 | * @param int $order |
||
105 | * @param string $icon |
||
106 | * @param array $attributes |
||
107 | * |
||
108 | * @return static |
||
109 | */ |
||
110 | public function route(array $route, string $title, int $order = null, string $icon = null, array $attributes = []) |
||
114 | |||
115 | /** |
||
116 | * Register new menu item using url. |
||
117 | * |
||
118 | * @param string $url |
||
119 | * @param string $title |
||
120 | * @param int $order |
||
121 | * @param string $icon |
||
122 | * @param array $attributes |
||
123 | * |
||
124 | * @return static |
||
125 | */ |
||
126 | public function url(string $url, string $title, int $order = null, string $icon = null, array $attributes = []) |
||
130 | |||
131 | /** |
||
132 | * Add new header item. |
||
133 | * |
||
134 | * @param string $title |
||
135 | * @param int $order |
||
136 | * @param string $icon |
||
137 | * @param array $attributes |
||
138 | * |
||
139 | * @return static |
||
140 | */ |
||
141 | public function header(string $title, int $order = null, string $icon = null, array $attributes = []) |
||
147 | |||
148 | /** |
||
149 | * Add new divider item. |
||
150 | * |
||
151 | * @param int $order |
||
152 | * @param array $attributes |
||
153 | * |
||
154 | * @return static |
||
155 | */ |
||
156 | public function divider(int $order = null, array $attributes = []) |
||
160 | |||
161 | /** |
||
162 | * Get childs. |
||
163 | * |
||
164 | * @return \Illuminate\Support\Collection |
||
165 | */ |
||
166 | public function getChilds(): Collection |
||
170 | |||
171 | /** |
||
172 | * Get url. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getUrl(): string |
||
180 | |||
181 | /** |
||
182 | * Get HTML attribute data. |
||
183 | * |
||
184 | * @return mixed |
||
185 | */ |
||
186 | public function getAttributes() |
||
190 | |||
191 | /** |
||
192 | * Check if the current item is divider. |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public function isDivider(): bool |
||
200 | |||
201 | /** |
||
202 | * Check if the current item is header. |
||
203 | * |
||
204 | * @return bool |
||
205 | */ |
||
206 | public function isHeader(): bool |
||
210 | |||
211 | /** |
||
212 | * Check is the current item has sub menu . |
||
213 | * |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function hasChilds(): bool |
||
220 | |||
221 | /** |
||
222 | * Check the active state for current menu. |
||
223 | * |
||
224 | * @return bool |
||
225 | */ |
||
226 | public function hasActiveOnChild(): bool |
||
230 | |||
231 | /** |
||
232 | * Set hide callback for current menu item. |
||
233 | * |
||
234 | * @param callable $callback |
||
235 | * |
||
236 | * @return $this |
||
237 | */ |
||
238 | public function hideWhen(callable $callback) |
||
244 | |||
245 | /** |
||
246 | * Set authorization callback for current menu item. |
||
247 | * |
||
248 | * @param string $ability |
||
249 | * @param mixed $params |
||
250 | * @param string $guard |
||
251 | * |
||
252 | * @return $this |
||
253 | */ |
||
254 | public function ifCan(string $ability, $params = null, $guard = null) |
||
262 | |||
263 | /** |
||
264 | * Set condition callback for current menu item. |
||
265 | * |
||
266 | * @param mixed $condition |
||
267 | * |
||
268 | * @return $this |
||
269 | */ |
||
270 | public function if($condition) |
||
278 | |||
279 | /** |
||
280 | * Set authentication callback for current menu item. |
||
281 | * |
||
282 | * @param string $guard |
||
283 | * |
||
284 | * @return $this |
||
285 | */ |
||
286 | public function ifUser($guard = null) |
||
294 | |||
295 | /** |
||
296 | * Set authentication callback for current menu item. |
||
297 | * |
||
298 | * @param string $guard |
||
299 | * |
||
300 | * @return $this |
||
301 | */ |
||
302 | public function ifGuest($guard = null) |
||
310 | |||
311 | /** |
||
312 | * Check if the menu item is hidden. |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | public function isHidden(): bool |
||
322 | |||
323 | /** |
||
324 | * Get active state for current item. |
||
325 | * |
||
326 | * @return bool |
||
327 | */ |
||
328 | public function isActive(): bool |
||
340 | |||
341 | /** |
||
342 | * Set active callback. |
||
343 | * |
||
344 | * @param callable $route |
||
345 | * |
||
346 | * @return $this |
||
347 | */ |
||
348 | public function activateWhen(callable $callback) |
||
354 | |||
355 | /** |
||
356 | * Set active callback on the given route. |
||
357 | * |
||
358 | * @param string $route |
||
359 | * |
||
360 | * @return $this |
||
361 | */ |
||
362 | public function activateOnRoute(string $route) |
||
370 | |||
371 | /** |
||
372 | * Add new child item. |
||
373 | * |
||
374 | * @param array $properties |
||
375 | * |
||
376 | * @return static |
||
377 | */ |
||
378 | protected function add(array $properties = []) |
||
385 | |||
386 | /** |
||
387 | * Get active status using route. |
||
388 | * |
||
389 | * @return bool |
||
390 | */ |
||
391 | protected function hasActiveStateFromRoute(): bool |
||
395 | |||
396 | /** |
||
397 | * Get active status using request url. |
||
398 | * |
||
399 | * @return bool |
||
400 | */ |
||
401 | protected function hasActiveStateFromUrl(): bool |
||
405 | |||
406 | /** |
||
407 | * Check if the item has active state from childs. |
||
408 | * |
||
409 | * @return bool |
||
410 | */ |
||
411 | protected function hasActiveStateFromChilds(): bool |
||
419 | } |
||
420 |
If you place a parameter with a default value before a parameter with a default value, the default value of the first parameter will never be used as it will always need to be passed anyway: