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 | namespace Ngtfkx\Laradeck\FormBuilder; |
||
4 | |||
5 | |||
6 | use Ngtfkx\Laradeck\FormBuilder\Elements; |
||
7 | use Ngtfkx\Laradeck\FormBuilder\Exceptions\ProviderNotFound; |
||
8 | use Ngtfkx\Laradeck\FormBuilder\Providers\AbstractProvider; |
||
9 | |||
10 | class FormBuilder |
||
11 | { |
||
12 | /** |
||
13 | * @var bool Признак, что форма должна быть закрыта |
||
14 | */ |
||
15 | protected $isClosed = false; |
||
16 | |||
17 | protected $layout; |
||
18 | |||
19 | /** |
||
20 | * FormBuilder constructor. |
||
21 | */ |
||
22 | public function __construct() |
||
23 | { |
||
24 | |||
25 | } |
||
26 | |||
27 | /** |
||
28 | * Сеттер для шаблона верстки (тип фремворка и тип расположения формы) |
||
29 | * |
||
30 | * @param string $cssFramework |
||
31 | * @param null|string $orientation |
||
32 | * @throws ProviderNotFound |
||
33 | * @return FormBuilder |
||
34 | */ |
||
35 | public function layout(string $cssFramework, ?string $orientation = null): FormBuilder |
||
36 | { |
||
37 | $className = "\\Ngtfkx\\Laradeck\\FormBuilder\\Providers\\" . studly_case($cssFramework); |
||
38 | |||
39 | if(class_exists($className)) { |
||
40 | $this->layout = (new $className)->orientation($orientation); |
||
41 | } else { |
||
42 | throw new ProviderNotFound(); |
||
43 | } |
||
44 | |||
45 | return $this; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * Открыть форму |
||
50 | * |
||
51 | * @param string $action URL для отправки данных формы |
||
52 | * @param string $method Метод отправки данных формы |
||
53 | * @return Elements\Form |
||
54 | */ |
||
55 | public function open(?string $action = '', ?string $method = 'get'): Elements\Form |
||
56 | { |
||
57 | return (new Elements\Form($this->layout))->action($action)->method($method); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Закрыть форму |
||
62 | * |
||
63 | * @return FormBuilder |
||
64 | */ |
||
65 | public function close(): FormBuilder |
||
66 | { |
||
67 | $this->isClosed = true; |
||
68 | |||
69 | return $this; |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Преобразовать в строку для вывода в HTML |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function __toString() |
||
78 | { |
||
79 | return ($this->isClosed) ? '</form>' : '<form>'; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Создать элемент формы типа hidden |
||
84 | * |
||
85 | * @param string|null $name |
||
86 | * @param string|null $value |
||
87 | * @return Elements\Hidden |
||
88 | */ |
||
89 | public function hidden(string $name = null, string $value = null): Elements\Hidden |
||
90 | { |
||
91 | return (new Elements\Hidden($name, $value))->layout($this->layout); |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Создать элемент формы типа text |
||
96 | * |
||
97 | * @param string|null $name |
||
98 | * @param string|null $value |
||
99 | * @return Elements\Text\Text |
||
100 | */ |
||
101 | public function text(string $name = null, string $value = null): Elements\Text\Text |
||
102 | { |
||
103 | return (new Elements\Text\Text($name, $value))->layout($this->layout); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Создать элемент формы типа email |
||
108 | * |
||
109 | * @param string|null $name |
||
110 | * @param string|null $value |
||
111 | * @return Elements\Text\Email |
||
112 | */ |
||
113 | public function email(string $name = null, string $value = null): Elements\Text\Email |
||
114 | { |
||
115 | return (new Elements\Text\Email($name, $value))->layout($this->layout); |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Создать элемент формы типа password |
||
120 | * |
||
121 | * @param string|null $name |
||
122 | * @param string|null $value |
||
123 | * @return Elements\Text\Password |
||
124 | */ |
||
125 | public function password(string $name = null, string $value = null): Elements\Text\Password |
||
126 | { |
||
127 | return (new Elements\Text\Password($name, $value))->layout($this->layout); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Создать элемент формы типа number |
||
132 | * |
||
133 | * @param string|null $name |
||
134 | * @param string|null $value |
||
135 | * @return Elements\Text\Number |
||
136 | */ |
||
137 | public function number(string $name = null, string $value = null): Elements\Text\Number |
||
138 | { |
||
139 | return (new Elements\Text\Number($name, $value))->layout($this->layout); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Создать элемент формы типа tel |
||
144 | * |
||
145 | * @param string|null $name |
||
146 | * @param string|null $value |
||
147 | * @return Elements\Text\Tel |
||
148 | */ |
||
149 | public function tel(string $name = null, string $value = null): Elements\Text\Tel |
||
150 | { |
||
151 | return (new Elements\Text\Tel($name, $value))->layout($this->layout); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Создать элемент формы типа color |
||
156 | * |
||
157 | * @param string|null $name |
||
158 | * @param string|null $value |
||
159 | * @return Elements\Text\Color |
||
160 | */ |
||
161 | public function color(string $name = null, string $value = null): Elements\Text\Color |
||
162 | { |
||
163 | return (new Elements\Text\Color($name, $value))->layout($this->layout); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * Создать элемент формы типа datetime |
||
168 | * |
||
169 | * @param string|null $name |
||
170 | * @param string|null $value |
||
171 | * @return Elements\Text\Datetime |
||
172 | */ |
||
173 | public function datetime(string $name = null, string $value = null): Elements\Text\Datetime |
||
174 | { |
||
175 | return (new Elements\Text\Datetime($name, $value))->layout($this->layout); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * Создать элемент формы типа date |
||
180 | * |
||
181 | * @param string|null $name |
||
182 | * @param string|null $value |
||
183 | * @return Elements\Text\Date |
||
184 | */ |
||
185 | public function date(string $name = null, string $value = null): Elements\Text\Date |
||
186 | { |
||
187 | return (new Elements\Text\Date($name, $value))->layout($this->layout); |
||
188 | } |
||
189 | |||
190 | /** |
||
191 | * Создать элемент формы типа range |
||
192 | * |
||
193 | * @param string|null $name |
||
194 | * @param string|null $value |
||
195 | * @return Elements\Text\Range |
||
196 | */ |
||
197 | public function range(string $name = null, string $value = null): Elements\Text\Range |
||
198 | { |
||
199 | return (new Elements\Text\Range($name, $value))->layout($this->layout); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * Создать элемент формы типа search |
||
204 | * |
||
205 | * @param string|null $name |
||
206 | * @param string|null $value |
||
207 | * @return Elements\Text\Search |
||
208 | */ |
||
209 | public function search(string $name = null, string $value = null): Elements\Text\Search |
||
210 | { |
||
211 | return (new Elements\Text\Search($name, $value))->layout($this->layout); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * Создать элемент формы типа time |
||
216 | * |
||
217 | * @param string|null $name |
||
218 | * @param string|null $value |
||
219 | * @return Elements\Text\Time |
||
220 | */ |
||
221 | public function time(string $name = null, string $value = null): Elements\Text\Time |
||
222 | { |
||
223 | return (new Elements\Text\Time($name, $value))->layout($this->layout); |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Создать элемент формы типа url |
||
228 | * |
||
229 | * @param string|null $name |
||
230 | * @param string|null $value |
||
231 | * @return Elements\Text\Url |
||
232 | */ |
||
233 | public function url(string $name = null, string $value = null): Elements\Text\Url |
||
234 | { |
||
235 | return (new Elements\Text\Url($name, $value))->layout($this->layout); |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Создать элемент формы типа month |
||
240 | * |
||
241 | * @param string|null $name |
||
242 | * @param string|null $value |
||
243 | * @return Elements\Text\Month |
||
244 | */ |
||
245 | public function month(string $name = null, string $value = null): Elements\Text\Month |
||
246 | { |
||
247 | return (new Elements\Text\Month($name, $value))->layout($this->layout); |
||
248 | } |
||
249 | |||
250 | /** |
||
251 | * Создать элемент формы типа week |
||
252 | * |
||
253 | * @param string|null $name |
||
254 | * @param string|null $value |
||
255 | * @return Elements\Text\Week |
||
256 | */ |
||
257 | public function week(string $name = null, string $value = null): Elements\Text\Week |
||
258 | { |
||
259 | return (new Elements\Text\Week($name, $value))->layout($this->layout); |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * Создать элемент формы типа submit |
||
264 | * |
||
265 | * @param string|null $name |
||
266 | * @param string|null $value |
||
267 | * @return Elements\Submit\Submit |
||
268 | */ |
||
269 | public function submit(string $name = null, string $value = null): Elements\Submit\Submit |
||
270 | { |
||
271 | return (new Elements\Submit\Submit($name, $value))->layout($this->layout); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Создать элемент формы типа reset |
||
276 | * |
||
277 | * @param string|null $name |
||
278 | * @param string|null $value |
||
279 | * @return Elements\Submit\Reset |
||
280 | */ |
||
281 | public function reset(string $name = null, string $value = null): Elements\Submit\Reset |
||
282 | { |
||
283 | return (new Elements\Submit\Reset($name, $value))->layout($this->layout); |
||
284 | } |
||
285 | |||
286 | /** |
||
287 | * Создать элемент формы типа button |
||
288 | * |
||
289 | * @param string|null $name |
||
290 | * @param string|null $value |
||
291 | * @return Elements\Area\Button |
||
292 | */ |
||
293 | public function button(string $name = null, string $value = null): Elements\Area\Button |
||
294 | { |
||
295 | return (new Elements\Area\Button($name, $value))->layout($this->layout); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * Создать элемент формы типа textarea |
||
300 | * |
||
301 | * @param string|null $name |
||
302 | * @param string|null $value |
||
303 | * @return Elements\Area\Textarea |
||
304 | */ |
||
305 | public function textarea(string $name = null, string $value = null): Elements\Area\Textarea |
||
306 | { |
||
307 | return (new Elements\Area\Textarea($name, $value))->layout($this->layout); |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Создать элемент формы типа file |
||
312 | * |
||
313 | * @param string|null $name |
||
314 | * @return Elements\File\File |
||
315 | */ |
||
316 | public function file(string $name = null): Elements\File\File |
||
317 | { |
||
318 | return (new Elements\File\File($name))->layout($this->layout); |
||
319 | } |
||
320 | |||
321 | /** |
||
322 | * Создать элемент формы типа image |
||
323 | * |
||
324 | * @param string|null $name |
||
325 | * @return Elements\File\Image |
||
326 | */ |
||
327 | public function image(string $name = null): Elements\File\Image |
||
328 | { |
||
329 | return (new Elements\File\Image($name))->layout($this->layout); |
||
330 | } |
||
331 | |||
332 | /** |
||
333 | * Создать элемент формы типа checkbox |
||
334 | * |
||
335 | * @param string|null $name |
||
336 | * @param string|null $value |
||
337 | * @param bool|null $state |
||
338 | * @return Elements\Checked\Checkbox |
||
339 | */ |
||
340 | public function checkbox(string $name = null, ?string $value = '1', ?bool $state = false): Elements\Checked\Checkbox |
||
341 | { |
||
342 | return (new Elements\Checked\Checkbox($name, $value, $state))->layout($this->layout); |
||
0 ignored issues
–
show
|
|||
343 | } |
||
344 | |||
345 | /** |
||
346 | * Создать элемент формы типа radio |
||
347 | * |
||
348 | * @param string|null $name |
||
349 | * @param string|null $value |
||
350 | * @param bool|null $state |
||
351 | * @return Elements\Checked\Radio |
||
352 | */ |
||
353 | public function radio(string $name = null, ?string $value = '1', ?bool $state = false): Elements\Checked\Radio |
||
354 | { |
||
355 | return (new Elements\Checked\Radio($name, $value, $state))->layout($this->layout); |
||
0 ignored issues
–
show
It seems like
$state defined by parameter $state on line 353 can also be of type null ; however, Ngtfkx\Laradeck\FormBuil...dElement::__construct() does only seem to accept boolean , maybe add an additional type check?
This check looks at variables that have been passed in as parameters and are passed out again to other methods. If the outgoing method call has stricter type requirements than the method itself, an issue is raised. An additional type check may prevent trouble.
Loading history...
|
|||
356 | } |
||
357 | |||
358 | /** |
||
359 | * Создать элемент формы типа select |
||
360 | * |
||
361 | * @param string|null $name |
||
362 | * @param string|null $value |
||
363 | * @param iterable|null $options |
||
364 | * @return Elements\Select |
||
365 | */ |
||
366 | public function select(string $name = null, string $value = null, ?iterable $options = null): Elements\Select |
||
367 | { |
||
368 | return (new Elements\Select($name, $value, $options))->layout($this->layout); |
||
369 | } |
||
370 | } |
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.