1 | <?php |
||
22 | class Menu |
||
23 | { |
||
24 | |||
25 | use MethodPropertyAccess, ObjectOptions, FetchesWeight; |
||
26 | |||
27 | /** |
||
28 | * Store the menu items. |
||
29 | * |
||
30 | * @var \Illuminate\Support\Collection |
||
31 | */ |
||
32 | protected $items; |
||
33 | |||
34 | /** |
||
35 | * Store the menu label. |
||
36 | * |
||
37 | * @var null|string |
||
38 | */ |
||
39 | protected $label; |
||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private $options; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * Menu constructor. |
||
49 | * |
||
50 | * @param string|null $label |
||
51 | * @param array $options |
||
52 | */ |
||
53 | public function __construct($label = null, array $options = [ ]) |
||
59 | |||
60 | |||
61 | /** |
||
62 | * Return this menu's label. |
||
63 | * |
||
64 | * @return null|string |
||
65 | */ |
||
66 | public function label() |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Add a new link to the menu. |
||
74 | * |
||
75 | * @param string $item |
||
76 | * @param string $link |
||
77 | * @param array $options |
||
78 | * |
||
79 | * @return \Iatstuti\SimpleMenu\MenuItem |
||
80 | */ |
||
81 | public function link($item, $link, array $options = [ ]) |
||
89 | |||
90 | |||
91 | /** |
||
92 | * Return this menu's items. |
||
93 | * |
||
94 | * @return \Illuminate\Support\Collection |
||
95 | */ |
||
96 | public function items() |
||
102 | |||
103 | |||
104 | /** |
||
105 | * Sort the menu items by their weight. |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | private function sortItems() |
||
115 | |||
116 | |||
117 | /** |
||
118 | * Add a new sub menu item to the menu. |
||
119 | * |
||
120 | * @param \Iatstuti\SimpleMenu\Menu $menu |
||
121 | * |
||
122 | * @return \Iatstuti\SimpleMenu\Menu |
||
123 | */ |
||
124 | public function subMenu(Menu $menu) |
||
130 | |||
131 | |||
132 | /** |
||
133 | * Render the menu using the given presenter, |
||
134 | * or the default UnorderedListPresenter. |
||
135 | * |
||
136 | * @param \Iatstuti\SimpleMenu\Presenters\MenuPresenter|null $presenter |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | public function render(MenuPresenter $presenter = null) |
||
148 | |||
149 | |||
150 | /** |
||
151 | * Overload the __toString method to be able to |
||
152 | * print this object using the render method. |
||
153 | * |
||
154 | * @return string |
||
155 | */ |
||
156 | public function __toString() |
||
160 | } |
||
161 |