This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Menus for Yii2. |
||
4 | * |
||
5 | * @link https://github.com/hiqdev/yii2-menus |
||
6 | * @package yii2-menus |
||
7 | * @license BSD-3-Clause |
||
8 | * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/) |
||
9 | */ |
||
10 | |||
11 | namespace hiqdev\yii2\menus; |
||
12 | |||
13 | use hiqdev\yii2\menus\widgets\Menu as MenuWidget; |
||
14 | use ReflectionClass; |
||
15 | use Yii; |
||
16 | use yii\base\View; |
||
17 | |||
18 | /** |
||
19 | * Menu is a manageable collection of child [[Menu]]s. |
||
20 | * |
||
21 | * @property array $add array of menus that will be added to the [[Menu]] |
||
22 | * @property array $merge array of menus that will be merged into the [[Menu]] |
||
23 | */ |
||
24 | class Menu extends \hiqdev\yii2\collection\BaseObject implements \yii\base\ViewContextInterface |
||
25 | { |
||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | protected $_itemClass = self::class; |
||
30 | |||
31 | public $label; |
||
32 | public $url; |
||
33 | public $icon; |
||
34 | public $active; |
||
35 | public $visible; |
||
36 | public $options = []; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $_add; |
||
42 | |||
43 | /** |
||
44 | * @var array |
||
45 | */ |
||
46 | protected $_merge; |
||
47 | |||
48 | /** |
||
49 | * @var string parent menu |
||
50 | */ |
||
51 | public $_parent; |
||
52 | |||
53 | /** |
||
54 | * Getter for addTo. |
||
55 | * @return string add to |
||
56 | */ |
||
57 | public function getParent() |
||
58 | { |
||
59 | return $this->_parent; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Adds $items to the Menu. |
||
64 | * |
||
65 | * @param array $items |
||
66 | * @see addItems() |
||
67 | */ |
||
68 | public function addMenus(array $items) |
||
69 | { |
||
70 | foreach ($items as $item) { |
||
71 | /// XXX ugly crutch, but no better ideas for the moment |
||
72 | $config = $item['menu']; |
||
73 | if (is_array($config) && empty($config['class'])) { |
||
74 | continue; |
||
75 | } |
||
76 | |||
77 | $menu = Yii::createObject($item['menu']); |
||
78 | $this->addItems($menu->getItems(), isset($item['where']) ? $item['where'] : null); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Merges $items to the Menu. |
||
84 | * |
||
85 | * @param array $items |
||
86 | * @see mergeItems() |
||
87 | */ |
||
88 | public function mergeMenus(array $items) |
||
89 | { |
||
90 | foreach ($items as $item) { |
||
91 | $menu = Yii::createObject($item['menu']); |
||
92 | $this->mergeItems($menu->getItems()); |
||
93 | } |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns default items defined in class. |
||
98 | * @return array |
||
99 | */ |
||
100 | public function items() |
||
101 | { |
||
102 | return []; |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | * Implements adding and merging. |
||
108 | */ |
||
109 | public function init() |
||
110 | { |
||
111 | parent::init(); |
||
112 | |||
113 | $this->addItems($this->items()); |
||
114 | |||
115 | if (($add = $this->getAdd()) !== null) { |
||
116 | $this->addMenus($add); |
||
117 | } |
||
118 | |||
119 | if (($merge = $this->getMerge()) !== null) { |
||
120 | $this->mergeMenus($merge); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | public $widgetConfig = [ |
||
125 | 'class' => MenuWidget::class, |
||
126 | ]; |
||
127 | |||
128 | public static function widget($menuConfig = [], $widgetConfig = []) |
||
129 | { |
||
130 | $menu = static::create($menuConfig); |
||
131 | |||
132 | return $menu->run($widgetConfig); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Renders menu widget with given config. |
||
137 | * @param mixed $config |
||
138 | * @return string rendered menu |
||
139 | */ |
||
140 | public function run($config = []) |
||
141 | { |
||
142 | if (!is_array($config)) { |
||
143 | $config = ['class' => $config]; |
||
144 | } |
||
145 | $config = array_merge($this->widgetConfig, $config); |
||
146 | if (!empty($config['options']) || !empty($this->options)) { |
||
147 | $config['options'] = array_merge( |
||
148 | isset($this->options) ? $this->options : [], |
||
149 | isset($config['options']) ? $config['options'] : [] |
||
150 | ); |
||
151 | } |
||
152 | $config['items'] = $this->getItems(); |
||
153 | |||
154 | return call_user_func([$config['class'], 'widget'], $config); |
||
155 | } |
||
156 | |||
157 | /** |
||
158 | * Creates menu and sets $config. |
||
159 | * @param array $config |
||
160 | * @return static |
||
161 | */ |
||
162 | public static function create(array $config = []) |
||
163 | { |
||
164 | $config['class'] = get_called_class(); |
||
165 | |||
166 | return Yii::createObject($config); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * Renders a view. |
||
171 | * @param string $view the view name |
||
172 | * @param array $params the parameters (name-value pairs) to be available in the view |
||
173 | * @return string the rendering result |
||
174 | */ |
||
175 | public function render($view, $params = []) |
||
176 | { |
||
177 | return $this->getView()->render($view, $params, $this); |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * @var View the view object to be used to render views |
||
182 | */ |
||
183 | private $_view; |
||
184 | |||
185 | /** |
||
186 | * Returns the view object to be used to render views or view files. |
||
187 | * If not set, it will default to the "view" application component. |
||
188 | * @return View|\yii\web\View the view object to be used to render views |
||
189 | */ |
||
190 | public function getView() |
||
191 | { |
||
192 | if ($this->_view === null) { |
||
193 | $this->_view = Yii::$app->getView(); |
||
194 | } |
||
195 | return $this->_view; |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Sets the view object to be used by this menu. |
||
200 | * @param View $view the view object to be used to render views |
||
201 | */ |
||
202 | public function setView($view) |
||
203 | { |
||
204 | $this->_view = $view; |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @var string the root directory that contains view files for this menu |
||
209 | */ |
||
210 | protected $_viewPath; |
||
211 | |||
212 | /** |
||
213 | * Sets the directory that contains the view files. |
||
214 | * @param string $path the root directory of view files |
||
215 | */ |
||
216 | public function setViewPath($path) |
||
217 | { |
||
218 | $this->_viewPath = Yii::getAlias($path); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Returns the directory containing view files for this menu. |
||
223 | * The default implementation returns `views/menus` in the current module. |
||
224 | * @return string the directory containing the view files for this controller |
||
225 | */ |
||
226 | public function getViewPath() |
||
227 | { |
||
228 | if ($this->_viewPath === null) { |
||
229 | $ref = new ReflectionClass($this); |
||
230 | $this->_viewPath = dirname(dirname($ref->getFileName())) . '/views/menus'; |
||
231 | } |
||
232 | return $this->_viewPath; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @return mixed |
||
237 | */ |
||
238 | public function getAdd() |
||
239 | { |
||
240 | return $this->_add; |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @param mixed $add |
||
245 | */ |
||
246 | public function setAdd($add) |
||
247 | { |
||
248 | $this->_add = $add; |
||
0 ignored issues
–
show
|
|||
249 | } |
||
250 | |||
251 | /** |
||
252 | * @return mixed |
||
253 | */ |
||
254 | public function getMerge() |
||
255 | { |
||
256 | return $this->_merge; |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @param mixed $merge |
||
261 | */ |
||
262 | public function setMerge($merge) |
||
263 | { |
||
264 | $this->_merge = $merge; |
||
0 ignored issues
–
show
It seems like
$merge of type * is incompatible with the declared type array of property $_merge .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
265 | } |
||
266 | } |
||
267 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..