1 | <?php |
||
7 | class Item |
||
8 | { |
||
9 | /** |
||
10 | * The unique name used to identify an `Item` instance. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $title; |
||
15 | |||
16 | /** |
||
17 | * The URL for the item. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $url; |
||
22 | |||
23 | /** |
||
24 | * The active state of the item. |
||
25 | * |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $isActive; |
||
29 | |||
30 | /** |
||
31 | * The CSS class used to highlight an active item. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $activeClass; |
||
36 | |||
37 | /** |
||
38 | * A `Collection` of `Item` instances for any child items. |
||
39 | * |
||
40 | * @var Collection|null |
||
41 | */ |
||
42 | protected $children; |
||
43 | |||
44 | /** |
||
45 | * The CSS class used to highlight an item with children. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $childrenClass; |
||
50 | |||
51 | /** |
||
52 | * Create a new `Item` instance. |
||
53 | * |
||
54 | * @param string $title |
||
55 | * @param string $url |
||
56 | * @param boolean $isActive |
||
57 | * @param Collection|null $children |
||
58 | * @param string $activeClass |
||
59 | * @param string $childrenClass |
||
60 | */ |
||
61 | 48 | public function __construct( |
|
76 | |||
77 | /** |
||
78 | * Return title of the `Item` instance. |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | 6 | public function getTitle() |
|
86 | |||
87 | /** |
||
88 | * Return the URL of the `Item` instance. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 6 | public function getUrl() |
|
96 | |||
97 | /** |
||
98 | * Returns the active status of the item. |
||
99 | * |
||
100 | * @return boolean |
||
101 | */ |
||
102 | 12 | public function isActive() |
|
106 | |||
107 | /** |
||
108 | * Check if this item has any children. |
||
109 | * |
||
110 | * @return boolean |
||
111 | */ |
||
112 | 8 | public function hasChildren() |
|
116 | |||
117 | /** |
||
118 | * Returns any child items as a `Collection`. |
||
119 | * |
||
120 | * @return Collection |
||
121 | */ |
||
122 | 8 | public function getChildren() |
|
126 | |||
127 | /** |
||
128 | * Returns any CSS classes that should be applied to this item when, for |
||
129 | * example highlighting an active link, or displaying a menu item with children. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 16 | public function getClasses() |
|
148 | } |
||
149 |
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.