1 | <?php |
||
2 | |||
3 | /** |
||
4 | * This class contains a standard way of displaying side/drop down menus. |
||
5 | * |
||
6 | * @package ElkArte Forum |
||
7 | * @copyright ElkArte Forum contributors |
||
8 | * @license BSD http://opensource.org/licenses/BSD-3-Clause (see accompanying LICENSE.txt file) |
||
9 | * |
||
10 | * @version 2.0 dev |
||
11 | * |
||
12 | */ |
||
13 | |||
14 | namespace ElkArte\Menu; |
||
15 | |||
16 | /** |
||
17 | * Class MenuItem |
||
18 | * |
||
19 | * This class implements a standard way of setting/getting menu params |
||
20 | * |
||
21 | * @package ElkArte\Menu |
||
22 | */ |
||
23 | abstract class MenuItem |
||
24 | { |
||
25 | /** @var string $label Text label for this subsection. */ |
||
26 | protected $label = ''; |
||
27 | |||
28 | /** @var string $counter Index of counter specified in the menu options. */ |
||
29 | protected $counter = ''; |
||
30 | |||
31 | /** @var string $url URL to use for this menu item. */ |
||
32 | protected $url = ''; |
||
33 | |||
34 | /** @var string[] $permission Array of permissions to check for this subsection. */ |
||
35 | protected $permission = []; |
||
36 | |||
37 | /** @var bool $enabled Bool to say whether this should be enabled. */ |
||
38 | protected $enabled = true; |
||
39 | |||
40 | /** |
||
41 | * @param array $arr |
||
42 | * @param string $sa |
||
43 | * |
||
44 | * @return MenuItem |
||
45 | */ |
||
46 | 62 | public static function buildFromArray($arr, $sa = '') |
|
47 | { |
||
48 | 62 | $obj = new static(); |
|
49 | |||
50 | // Prepare |
||
51 | 62 | $arr = $obj->camelCaseKeys($arr); |
|
52 | 62 | $arr['permission'] = isset($arr['permission']) ? (array) $arr['permission'] : []; |
|
53 | |||
54 | // Fetch the protected and public vars of this abstract + extended |
||
55 | 62 | $vars = get_object_vars($obj); |
|
56 | |||
57 | // Call the setters, using the defined class vars, with the supplied menu values |
||
58 | 62 | foreach (array_replace($vars, array_intersect_key($arr, $vars)) as $var => $val) |
|
59 | { |
||
60 | 62 | $obj->{'set' . ucfirst($var)}($val); |
|
61 | } |
||
62 | |||
63 | // Account for any special setters |
||
64 | 62 | $obj->buildMoreFromArray($arr, $sa); |
|
0 ignored issues
–
show
|
|||
65 | |||
66 | 62 | return $obj; |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Renames array keys from under_score to underScore camelCase |
||
71 | * |
||
72 | * @param array $arr |
||
73 | * |
||
74 | * @return array |
||
75 | */ |
||
76 | 62 | private function camelCaseKeys($arr) |
|
77 | { |
||
78 | 62 | $keys = array_keys($arr); |
|
79 | 62 | foreach ($keys as $key) |
|
80 | { |
||
81 | 62 | $keynew = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))); |
|
82 | 62 | if (!isset($arr[$keynew])) |
|
83 | { |
||
84 | 20 | $arr[$keynew] = $arr[$key]; |
|
85 | 41 | unset($arr[$key]); |
|
86 | } |
||
87 | } |
||
88 | |||
89 | 62 | return $arr; |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Get the label |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | 56 | public function getLabel() |
|
98 | { |
||
99 | 56 | return $this->label; |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Set the label |
||
104 | * |
||
105 | * @param string $label |
||
106 | * |
||
107 | * @return MenuItem |
||
108 | */ |
||
109 | 62 | public function setLabel($label) |
|
110 | { |
||
111 | 62 | $this->label = $label; |
|
112 | |||
113 | 62 | return $this; |
|
114 | } |
||
115 | |||
116 | /** |
||
117 | * Get the current counter |
||
118 | * |
||
119 | * @return string |
||
120 | */ |
||
121 | 56 | public function getCounter() |
|
122 | { |
||
123 | 56 | return $this->counter; |
|
124 | } |
||
125 | |||
126 | /** |
||
127 | * Set the counter |
||
128 | * |
||
129 | * @param string $counter |
||
130 | * |
||
131 | * @return MenuItem |
||
132 | */ |
||
133 | 62 | public function setCounter($counter) |
|
134 | { |
||
135 | 62 | $this->counter = $counter; |
|
136 | |||
137 | 62 | return $this; |
|
138 | } |
||
139 | |||
140 | /** |
||
141 | * Get the url value |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | 56 | public function getUrl() |
|
146 | { |
||
147 | 56 | return $this->url; |
|
148 | } |
||
149 | |||
150 | /** |
||
151 | * Set the url value |
||
152 | * |
||
153 | * @param string $url |
||
154 | * |
||
155 | * @return MenuItem |
||
156 | */ |
||
157 | 62 | public function setUrl($url) |
|
158 | { |
||
159 | 62 | $this->url = $url; |
|
160 | |||
161 | 62 | return $this; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * Get the permissions |
||
166 | * |
||
167 | * @return string[] |
||
168 | */ |
||
169 | 58 | public function getPermission() |
|
170 | { |
||
171 | 58 | return $this->permission; |
|
172 | } |
||
173 | |||
174 | /** |
||
175 | * Set the permissions |
||
176 | * |
||
177 | * @param string[] $permission |
||
178 | * |
||
179 | * @return MenuItem |
||
180 | */ |
||
181 | 62 | public function setPermission($permission) |
|
182 | { |
||
183 | 62 | $this->permission = $permission; |
|
184 | |||
185 | 62 | return $this; |
|
186 | } |
||
187 | |||
188 | /** |
||
189 | * Get if the item is enabled |
||
190 | * |
||
191 | * @return bool |
||
192 | */ |
||
193 | 58 | public function isEnabled() |
|
194 | { |
||
195 | 58 | return $this->enabled; |
|
196 | } |
||
197 | |||
198 | /** |
||
199 | * Set if the item is enabled |
||
200 | * |
||
201 | * @param bool $enabled |
||
202 | * |
||
203 | * @return MenuItem |
||
204 | */ |
||
205 | 62 | public function setEnabled($enabled) |
|
206 | { |
||
207 | 62 | $this->enabled = $enabled; |
|
208 | |||
209 | 62 | return $this; |
|
210 | } |
||
211 | } |
||
212 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.