|
1
|
|
|
<?php namespace Anomaly\Streams\Platform\Ui\ControlPanel\Component\Section; |
|
2
|
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Ui\ControlPanel\Component\Section\Contract\SectionInterface; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Section |
|
7
|
|
|
* |
|
8
|
|
|
* @link http://pyrocms.com/ |
|
9
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
|
10
|
|
|
* @author Ryan Thompson <[email protected]> |
|
11
|
|
|
*/ |
|
12
|
|
|
class Section implements SectionInterface |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* The section slug. |
|
17
|
|
|
* |
|
18
|
|
|
* @var null|string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $slug = null; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* The section icon. |
|
24
|
|
|
* |
|
25
|
|
|
* @var null|string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $icon = null; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* The section title. |
|
31
|
|
|
* |
|
32
|
|
|
* @var null|string |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $title = null; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* The section label. |
|
38
|
|
|
* |
|
39
|
|
|
* @var null|string |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $label = null; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* The class. |
|
45
|
|
|
* |
|
46
|
|
|
* @var null|string |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $class = null; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* The active flag. |
|
52
|
|
|
* |
|
53
|
|
|
* @var bool |
|
54
|
|
|
*/ |
|
55
|
|
|
protected $active = false; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* The path matcher. |
|
59
|
|
|
* |
|
60
|
|
|
* @var null|string |
|
61
|
|
|
*/ |
|
62
|
|
|
protected $matcher = null; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* The section permalink. |
|
66
|
|
|
* |
|
67
|
|
|
* @var null|string |
|
68
|
|
|
*/ |
|
69
|
|
|
protected $permalink = null; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* The section description. |
|
73
|
|
|
* |
|
74
|
|
|
* @var null|string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected $description = null; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* The highlighted flag. |
|
80
|
|
|
* |
|
81
|
|
|
* @var bool |
|
82
|
|
|
*/ |
|
83
|
|
|
protected $highlighted = false; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* The section context. |
|
87
|
|
|
* |
|
88
|
|
|
* @var string |
|
89
|
|
|
*/ |
|
90
|
|
|
protected $context = 'danger'; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* The section parent. |
|
94
|
|
|
* |
|
95
|
|
|
* @var null|string |
|
96
|
|
|
*/ |
|
97
|
|
|
protected $parent = null; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* Section buttons. These are only to |
|
101
|
|
|
* transport input to the button builder. |
|
102
|
|
|
* |
|
103
|
|
|
* @var array |
|
104
|
|
|
*/ |
|
105
|
|
|
protected $buttons = []; |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* The section attributes. |
|
109
|
|
|
* |
|
110
|
|
|
* @var array |
|
111
|
|
|
*/ |
|
112
|
|
|
protected $attributes = []; |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* The section permission. |
|
116
|
|
|
* |
|
117
|
|
|
* @var null|string |
|
118
|
|
|
*/ |
|
119
|
|
|
protected $permission = null; |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* The section breadcrumb. |
|
123
|
|
|
* |
|
124
|
|
|
* @var null|string |
|
125
|
|
|
*/ |
|
126
|
|
|
protected $breadcrumb = null; |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* If the section will be hidden from the Control Panel. |
|
130
|
|
|
* |
|
131
|
|
|
* @var bool |
|
132
|
|
|
*/ |
|
133
|
|
|
protected $hidden = false; |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* Get the slug. |
|
137
|
|
|
* |
|
138
|
|
|
* @return null|string |
|
139
|
|
|
*/ |
|
140
|
|
|
public function getSlug() |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->slug; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Set the slug. |
|
147
|
|
|
* |
|
148
|
|
|
* @param $slug |
|
149
|
|
|
* @return $this |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setSlug($slug) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->slug = $slug; |
|
154
|
|
|
|
|
155
|
|
|
return $this; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get the icon. |
|
160
|
|
|
* |
|
161
|
|
|
* @return null|string |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getIcon() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->icon; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Set the icon. |
|
170
|
|
|
* |
|
171
|
|
|
* @param $icon |
|
172
|
|
|
* @return $this |
|
173
|
|
|
*/ |
|
174
|
|
|
public function setIcon($icon) |
|
175
|
|
|
{ |
|
176
|
|
|
$this->icon = $icon; |
|
177
|
|
|
|
|
178
|
|
|
return $this; |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Get the title. |
|
183
|
|
|
* |
|
184
|
|
|
* @return string |
|
185
|
|
|
*/ |
|
186
|
|
|
public function getTitle() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->title; |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
/** |
|
192
|
|
|
* Set the title. |
|
193
|
|
|
* |
|
194
|
|
|
* @param string $title |
|
195
|
|
|
*/ |
|
196
|
|
|
public function setTitle($title) |
|
197
|
|
|
{ |
|
198
|
|
|
$this->title = $title; |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
/** |
|
202
|
|
|
* Get the label. |
|
203
|
|
|
* |
|
204
|
|
|
* @return string |
|
205
|
|
|
*/ |
|
206
|
|
|
public function getLabel() |
|
207
|
|
|
{ |
|
208
|
|
|
return $this->label; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Set the label. |
|
213
|
|
|
* |
|
214
|
|
|
* @param string $label |
|
215
|
|
|
* @return $this |
|
216
|
|
|
*/ |
|
217
|
|
|
public function setLabel($label) |
|
218
|
|
|
{ |
|
219
|
|
|
$this->label = $label; |
|
220
|
|
|
|
|
221
|
|
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Get the class. |
|
226
|
|
|
* |
|
227
|
|
|
* @return string |
|
228
|
|
|
*/ |
|
229
|
|
|
public function getClass() |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->class; |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Set the class. |
|
236
|
|
|
* |
|
237
|
|
|
* @param $class |
|
238
|
|
|
* @return $this |
|
239
|
|
|
*/ |
|
240
|
|
|
public function setClass($class) |
|
241
|
|
|
{ |
|
242
|
|
|
$this->class = $class; |
|
243
|
|
|
|
|
244
|
|
|
return $this; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* Get the active flag. |
|
249
|
|
|
* |
|
250
|
|
|
* @return boolean |
|
251
|
|
|
*/ |
|
252
|
|
|
public function isActive() |
|
253
|
|
|
{ |
|
254
|
|
|
return $this->active; |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Set the active flag. |
|
259
|
|
|
* |
|
260
|
|
|
* @param boolean $active |
|
261
|
|
|
*/ |
|
262
|
|
|
public function setActive($active) |
|
263
|
|
|
{ |
|
264
|
|
|
$this->active = $active; |
|
265
|
|
|
|
|
266
|
|
|
return $this; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Get the matcher. |
|
271
|
|
|
* |
|
272
|
|
|
* @return null|string |
|
273
|
|
|
*/ |
|
274
|
|
|
public function getMatcher() |
|
275
|
|
|
{ |
|
276
|
|
|
return $this->matcher; |
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
/** |
|
280
|
|
|
* Set the matcher. |
|
281
|
|
|
* |
|
282
|
|
|
* @param $matcher |
|
283
|
|
|
* @return $this |
|
284
|
|
|
*/ |
|
285
|
|
|
public function setMatcher($matcher) |
|
286
|
|
|
{ |
|
287
|
|
|
$this->matcher = $matcher; |
|
288
|
|
|
|
|
289
|
|
|
return $this; |
|
290
|
|
|
} |
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* Get the permalink. |
|
294
|
|
|
* |
|
295
|
|
|
* @return null|string |
|
296
|
|
|
*/ |
|
297
|
|
|
public function getPermalink() |
|
298
|
|
|
{ |
|
299
|
|
|
return $this->permalink; |
|
300
|
|
|
} |
|
301
|
|
|
|
|
302
|
|
|
/** |
|
303
|
|
|
* Set the permalink. |
|
304
|
|
|
* |
|
305
|
|
|
* @param $permalink |
|
306
|
|
|
* @return $this |
|
307
|
|
|
*/ |
|
308
|
|
|
public function setPermalink($permalink) |
|
309
|
|
|
{ |
|
310
|
|
|
$this->permalink = $permalink; |
|
311
|
|
|
|
|
312
|
|
|
return $this; |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
/** |
|
316
|
|
|
* Get the description. |
|
317
|
|
|
* |
|
318
|
|
|
* @return null|string |
|
319
|
|
|
*/ |
|
320
|
|
|
public function getDescription() |
|
321
|
|
|
{ |
|
322
|
|
|
return $this->description; |
|
323
|
|
|
} |
|
324
|
|
|
|
|
325
|
|
|
/** |
|
326
|
|
|
* Set the description. |
|
327
|
|
|
* |
|
328
|
|
|
* @param $description |
|
329
|
|
|
* @return $this |
|
330
|
|
|
*/ |
|
331
|
|
|
public function setDescription($description) |
|
332
|
|
|
{ |
|
333
|
|
|
$this->description = $description; |
|
334
|
|
|
|
|
335
|
|
|
return $this; |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* Get the highlighted flag. |
|
340
|
|
|
* |
|
341
|
|
|
* @return boolean |
|
342
|
|
|
*/ |
|
343
|
|
|
public function isHighlighted() |
|
344
|
|
|
{ |
|
345
|
|
|
return $this->highlighted; |
|
346
|
|
|
} |
|
347
|
|
|
|
|
348
|
|
|
/** |
|
349
|
|
|
* Set the highlighted flag. |
|
350
|
|
|
* |
|
351
|
|
|
* @param boolean $active |
|
|
|
|
|
|
352
|
|
|
* @return $this |
|
353
|
|
|
*/ |
|
354
|
|
|
public function setHighlighted($highlighted) |
|
355
|
|
|
{ |
|
356
|
|
|
$this->highlighted = $highlighted; |
|
357
|
|
|
|
|
358
|
|
|
return $this; |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
/** |
|
362
|
|
|
* Get the context. |
|
363
|
|
|
* |
|
364
|
|
|
* @return boolean |
|
365
|
|
|
*/ |
|
366
|
|
|
public function getContext() |
|
367
|
|
|
{ |
|
368
|
|
|
return $this->context; |
|
|
|
|
|
|
369
|
|
|
} |
|
370
|
|
|
|
|
371
|
|
|
/** |
|
372
|
|
|
* Set the context flag. |
|
373
|
|
|
* |
|
374
|
|
|
* @param boolean $active |
|
|
|
|
|
|
375
|
|
|
* @return $this |
|
376
|
|
|
*/ |
|
377
|
|
|
public function setContext($context) |
|
378
|
|
|
{ |
|
379
|
|
|
$this->context = $context; |
|
380
|
|
|
|
|
381
|
|
|
return $this; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* Get the parent. |
|
386
|
|
|
* |
|
387
|
|
|
* @return null|string |
|
388
|
|
|
*/ |
|
389
|
|
|
public function getParent() |
|
390
|
|
|
{ |
|
391
|
|
|
return $this->parent; |
|
392
|
|
|
} |
|
393
|
|
|
|
|
394
|
|
|
/** |
|
395
|
|
|
* Return if the section is |
|
396
|
|
|
* a sub-section or not. |
|
397
|
|
|
* |
|
398
|
|
|
* @return bool |
|
399
|
|
|
*/ |
|
400
|
|
|
public function isSubSection() |
|
401
|
|
|
{ |
|
402
|
|
|
return (bool)$this->getParent(); |
|
403
|
|
|
} |
|
404
|
|
|
|
|
405
|
|
|
/** |
|
406
|
|
|
* Set the parent. |
|
407
|
|
|
* |
|
408
|
|
|
* @param $parent |
|
409
|
|
|
* @return $this |
|
410
|
|
|
*/ |
|
411
|
|
|
public function setParent($parent) |
|
412
|
|
|
{ |
|
413
|
|
|
$this->parent = $parent; |
|
414
|
|
|
|
|
415
|
|
|
return $this; |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* Get the buttons. |
|
420
|
|
|
* |
|
421
|
|
|
* @return array |
|
422
|
|
|
*/ |
|
423
|
|
|
public function getButtons() |
|
424
|
|
|
{ |
|
425
|
|
|
return $this->buttons; |
|
426
|
|
|
} |
|
427
|
|
|
|
|
428
|
|
|
/** |
|
429
|
|
|
* Set the buttons. |
|
430
|
|
|
* |
|
431
|
|
|
* @param array $buttons |
|
432
|
|
|
*/ |
|
433
|
|
|
public function setButtons($buttons) |
|
434
|
|
|
{ |
|
435
|
|
|
$this->buttons = $buttons; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Get the attributes. |
|
440
|
|
|
* |
|
441
|
|
|
* @return array |
|
442
|
|
|
*/ |
|
443
|
|
|
public function getAttributes() |
|
444
|
|
|
{ |
|
445
|
|
|
return $this->attributes; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* Set the attributes. |
|
450
|
|
|
* |
|
451
|
|
|
* @param array $attributes |
|
452
|
|
|
*/ |
|
453
|
|
|
public function setAttributes(array $attributes) |
|
454
|
|
|
{ |
|
455
|
|
|
$this->attributes = $attributes; |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* Get the permission. |
|
460
|
|
|
* |
|
461
|
|
|
* @return null|string |
|
462
|
|
|
*/ |
|
463
|
|
|
public function getPermission() |
|
464
|
|
|
{ |
|
465
|
|
|
return $this->permission; |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* Set the permission. |
|
470
|
|
|
* |
|
471
|
|
|
* @param $permission |
|
472
|
|
|
* @return $this |
|
473
|
|
|
*/ |
|
474
|
|
|
public function setPermission($permission) |
|
475
|
|
|
{ |
|
476
|
|
|
$this->permission = $permission; |
|
477
|
|
|
|
|
478
|
|
|
return $this; |
|
479
|
|
|
} |
|
480
|
|
|
|
|
481
|
|
|
/** |
|
482
|
|
|
* Get the breadcrumb. |
|
483
|
|
|
* |
|
484
|
|
|
* @return null|string |
|
485
|
|
|
*/ |
|
486
|
|
|
public function getBreadcrumb() |
|
487
|
|
|
{ |
|
488
|
|
|
return $this->breadcrumb; |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* Set the breadcrumb. |
|
493
|
|
|
* |
|
494
|
|
|
* @param $breadcrumb |
|
495
|
|
|
* @return $this |
|
496
|
|
|
*/ |
|
497
|
|
|
public function setBreadcrumb($breadcrumb) |
|
498
|
|
|
{ |
|
499
|
|
|
$this->breadcrumb = $breadcrumb; |
|
500
|
|
|
|
|
501
|
|
|
return $this; |
|
502
|
|
|
} |
|
503
|
|
|
|
|
504
|
|
|
/** |
|
505
|
|
|
* Get the hidden flag. |
|
506
|
|
|
* |
|
507
|
|
|
* @return bool |
|
508
|
|
|
*/ |
|
509
|
|
|
public function isHidden() |
|
510
|
|
|
{ |
|
511
|
|
|
return $this->hidden; |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
/** |
|
515
|
|
|
* Set the hidden flag. |
|
516
|
|
|
* |
|
517
|
|
|
* @param $hidden |
|
518
|
|
|
* @return $this |
|
519
|
|
|
*/ |
|
520
|
|
|
public function setHidden($hidden) |
|
521
|
|
|
{ |
|
522
|
|
|
$this->hidden = $hidden; |
|
523
|
|
|
|
|
524
|
|
|
return $this; |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* Get the HREF attribute. |
|
529
|
|
|
* |
|
530
|
|
|
* @param null $path |
|
531
|
|
|
* @return string |
|
532
|
|
|
*/ |
|
533
|
|
|
public function getHref($path = null) |
|
534
|
|
|
{ |
|
535
|
|
|
return ($this->getPermalink() ?: array_get($this->attributes, 'href')) . ($path ? '/' . $path : $path); |
|
536
|
|
|
} |
|
537
|
|
|
|
|
538
|
|
|
/** |
|
539
|
|
|
* Return the child sections. |
|
540
|
|
|
* |
|
541
|
|
|
* @return SectionCollection |
|
542
|
|
|
*/ |
|
543
|
|
|
public function getChildren() |
|
544
|
|
|
{ |
|
545
|
|
|
return app(SectionCollection::class)->children($this->getSlug()); |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
/** |
|
549
|
|
|
* Return whether the section |
|
550
|
|
|
* has children or not. |
|
551
|
|
|
* |
|
552
|
|
|
* @return bool |
|
553
|
|
|
*/ |
|
554
|
|
|
public function hasChildren() |
|
555
|
|
|
{ |
|
556
|
|
|
return !$this->getChildren()->isEmpty(); |
|
557
|
|
|
} |
|
558
|
|
|
} |
|
559
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.