1 | <?php |
||
17 | class Builder implements BuilderContract |
||
18 | { |
||
19 | use HasAttributes; |
||
20 | |||
21 | /** |
||
22 | * @var Container |
||
23 | */ |
||
24 | protected $container; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $items; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $name; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | protected $type; |
||
40 | |||
41 | /** |
||
42 | * @var AttributesContract |
||
43 | */ |
||
44 | protected $activeAttributes; |
||
45 | |||
46 | /** |
||
47 | * @var ViewFactory |
||
48 | */ |
||
49 | protected $viewFactory; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $config; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $view = null; |
||
60 | |||
61 | /** |
||
62 | * Builder constructor. |
||
63 | * |
||
64 | * @param Container $container |
||
65 | * @param string $name |
||
66 | * @param AttributesContract $attributes |
||
67 | * @param AttributesContract $activeAttributes |
||
68 | * @param string $type |
||
69 | * @param string $view |
||
70 | */ |
||
71 | 19 | public function __construct(Container $container, $name, AttributesContract $attributes, |
|
86 | |||
87 | /** |
||
88 | * Make sub menu |
||
89 | * |
||
90 | * @param string $name |
||
91 | * @param \Closure $itemCallable |
||
92 | * @param \Closure $menuCallable |
||
93 | * @return mixed |
||
94 | */ |
||
95 | 3 | public function group($name, \Closure $itemCallable, \Closure $menuCallable) |
|
125 | |||
126 | /** |
||
127 | * Add new element |
||
128 | * |
||
129 | * @param string $name |
||
130 | * @param string $title |
||
131 | * @param string $url |
||
132 | * @param array $attributes |
||
133 | * @param array $linkAttributes |
||
134 | * @param \Closure|null $callback |
||
135 | * @return ItemContract |
||
136 | */ |
||
137 | 11 | public function add($name, $title, $url, $attributes = [], $linkAttributes = [], $callback = null) |
|
160 | |||
161 | /** |
||
162 | * Check exits by name |
||
163 | * |
||
164 | * @param string $name |
||
165 | * @return bool |
||
166 | */ |
||
167 | 6 | public function has($name) |
|
171 | |||
172 | /** |
||
173 | * Get element or sub menu by name |
||
174 | * |
||
175 | * @param string $name |
||
176 | * @param mixed|null $default |
||
177 | * @return ItemContract|GroupContract|null |
||
178 | */ |
||
179 | 3 | public function get($name, $default = null) |
|
186 | |||
187 | /** |
||
188 | * Get all elements and sub menus |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | 5 | public function all() |
|
196 | |||
197 | /** |
||
198 | * Delete element |
||
199 | * |
||
200 | * @param string $name |
||
201 | */ |
||
202 | 1 | public function forget($name) |
|
208 | |||
209 | /** |
||
210 | * Get menu type: UL or OL |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | 5 | public function getType() |
|
218 | |||
219 | /** |
||
220 | * Set menu type. You can use constants at this interface |
||
221 | * |
||
222 | * @param string $type |
||
223 | */ |
||
224 | 1 | public function setType($type) |
|
228 | |||
229 | /** |
||
230 | * Render menu to html |
||
231 | * |
||
232 | * @param string|null $renderView |
||
233 | * @return string |
||
234 | */ |
||
235 | 4 | public function render($renderView = null) |
|
252 | |||
253 | /** |
||
254 | * Get active attributes object. |
||
255 | * If send \Closure option as parameter then returned callback result. |
||
256 | * |
||
257 | * @param \Closure|null $callback |
||
258 | * @return AttributesContract|mixed |
||
259 | */ |
||
260 | 7 | public function activeAttributes($callback = null) |
|
268 | |||
269 | /** |
||
270 | * Get render view |
||
271 | * |
||
272 | * @return string |
||
273 | */ |
||
274 | 3 | public function getView() |
|
278 | |||
279 | /** |
||
280 | * Set render view |
||
281 | * |
||
282 | * @param string $view |
||
283 | * @throws \Exception |
||
284 | */ |
||
285 | 19 | public function setView($view) |
|
293 | |||
294 | /** |
||
295 | * Minify html |
||
296 | * |
||
297 | * @param string $html |
||
298 | * @return string |
||
299 | */ |
||
300 | 4 | protected function minifyHtmlOutput($html) |
|
316 | |||
317 | /** |
||
318 | * Get view for render |
||
319 | * |
||
320 | * @param string $view |
||
321 | * @return string |
||
322 | */ |
||
323 | 4 | protected function getRenderView($view = null) |
|
337 | } |