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.
1 | <?php |
||||
2 | |||||
3 | namespace XoopsModules\Modulebuilder\Files; |
||||
4 | |||||
5 | use XoopsModules\Modulebuilder; |
||||
6 | |||||
7 | /* |
||||
8 | You may not change or alter any portion of this comment or credits |
||||
9 | of supporting developers from this source code or any supporting source code |
||||
10 | which is considered copyrighted (c) material of the original comment or credit authors. |
||||
11 | |||||
12 | This program is distributed in the hope that it will be useful, |
||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||||
15 | */ |
||||
16 | /** |
||||
17 | * modulebuilder module. |
||||
18 | * |
||||
19 | * @copyright XOOPS Project (https://xoops.org) |
||||
20 | * @license GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
||||
21 | * |
||||
22 | * @since 2.5.0 |
||||
23 | * |
||||
24 | * @author Txmod Xoops https://xoops.org |
||||
25 | * Goffy https://myxoops.org |
||||
26 | * |
||||
27 | */ |
||||
28 | |||||
29 | /** |
||||
30 | * Class CreatePhpCode. |
||||
31 | */ |
||||
32 | class CreatePhpCode |
||||
33 | { |
||||
34 | /** |
||||
35 | * @static function getInstance |
||||
36 | * @param null |
||||
37 | * @return CreatePhpCode |
||||
38 | */ |
||||
39 | public static function getInstance() |
||||
40 | { |
||||
41 | static $instance = false; |
||||
42 | if (!$instance) { |
||||
43 | $instance = new self(); |
||||
44 | } |
||||
45 | |||||
46 | return $instance; |
||||
47 | } |
||||
48 | |||||
49 | /** |
||||
50 | * @public function getPhpCodeCommentLine |
||||
51 | * @param $comment |
||||
52 | * @param $var |
||||
53 | * @param string $t |
||||
54 | * @param string $n |
||||
55 | * @return string |
||||
56 | */ |
||||
57 | public function getPhpCodeCommentLine($comment = null, $var = null, $t = '', $n = "\n") |
||||
58 | { |
||||
59 | $value = !empty($var) ? ' ' . $var : ''; |
||||
60 | $ret = "{$t}// {$comment}{$value}{$n}"; |
||||
61 | |||||
62 | return $ret; |
||||
63 | } |
||||
64 | |||||
65 | /** |
||||
66 | * @public function getPhpCodeCommentMultiLine |
||||
67 | * @param array $multiLine |
||||
68 | * @param string $t |
||||
69 | * @param bool $blankLineBefore |
||||
70 | * @return string |
||||
71 | */ |
||||
72 | public function getPhpCodeCommentMultiLine($multiLine = [], $t = '', $blankLineBefore = true) |
||||
73 | { |
||||
74 | $values = !empty($multiLine) ? $multiLine : []; |
||||
75 | $ret = ''; |
||||
76 | if ($blankLineBefore) { |
||||
77 | $ret .= "\n"; |
||||
78 | } |
||||
79 | $ret .= "{$t}/**\n"; |
||||
80 | foreach ($values as $string => $value) { |
||||
81 | if ('' === $string && '' === $value) { |
||||
82 | $ret .= "{$t} *\n"; |
||||
83 | } else { |
||||
84 | if ('' === $value) { |
||||
85 | $ret .= "{$t} * {$string}\n"; |
||||
86 | } else { |
||||
87 | $ret .= "{$t} * {$string} {$value}\n"; |
||||
88 | } |
||||
89 | } |
||||
90 | } |
||||
91 | $ret .= "{$t} */\n"; |
||||
92 | |||||
93 | return $ret; |
||||
94 | } |
||||
95 | |||||
96 | /** |
||||
97 | * @public function getPhpCodeDefine |
||||
98 | * @param $left |
||||
99 | * @param $right |
||||
100 | * |
||||
101 | * @param string $t |
||||
102 | * @param bool $leftstr |
||||
103 | * @return string |
||||
104 | */ |
||||
105 | public function getPhpCodeDefine($left, $right, $t = '', $leftstr = true) |
||||
106 | { |
||||
107 | $ret = "{$t}\define("; |
||||
108 | if ($leftstr) { |
||||
109 | $ret .= "'{$left}'"; |
||||
110 | } else { |
||||
111 | $ret .= "{$left}"; |
||||
112 | } |
||||
113 | $ret .= ", {$right});\n"; |
||||
114 | return $ret; |
||||
115 | } |
||||
116 | |||||
117 | /** |
||||
118 | * @public function getPhpCodeDefine |
||||
119 | * @param $left |
||||
120 | * @param $right |
||||
121 | * |
||||
122 | * @return string |
||||
123 | */ |
||||
124 | public function getPhpCodeDefined($left = 'XOOPS_ROOT_PATH', $right = 'Restricted access') |
||||
125 | { |
||||
126 | return "\defined('{$left}') || die('{$right}');\n"; |
||||
127 | } |
||||
128 | |||||
129 | /** |
||||
130 | * @public function getPhpCodeGlobals |
||||
131 | * @param $var |
||||
132 | * @param $value |
||||
133 | * |
||||
134 | * @return string |
||||
135 | */ |
||||
136 | public function getPhpCodeGlobals($var, $value = '') |
||||
137 | { |
||||
138 | if ('' != $value) { |
||||
139 | $ret = "\$GLOBALS['{$var}'] = \${$value};\n"; |
||||
140 | } else { |
||||
141 | $ret = "\$GLOBALS['{$var}']"; |
||||
142 | } |
||||
143 | |||||
144 | return $ret; |
||||
145 | } |
||||
146 | |||||
147 | /** |
||||
148 | * @public function getPhpCodeGlobalsVariables |
||||
149 | * @param $var |
||||
150 | * @param $type |
||||
151 | * |
||||
152 | * @return string |
||||
153 | */ |
||||
154 | public function getPhpCodeGlobalsVariables($var = null, $type = 'REQUEST') |
||||
155 | { |
||||
156 | $type = \mb_strtoupper($type); |
||||
157 | switch ($type) { |
||||
158 | case 'GET': |
||||
159 | $ret = "\$_GET['{$var}']"; |
||||
160 | break; |
||||
161 | case 'POST': |
||||
162 | $ret = "\$_POST['{$var}']"; |
||||
163 | break; |
||||
164 | case 'FILES': |
||||
165 | $ret = "\$_FILES['{$var}']"; |
||||
166 | break; |
||||
167 | case 'COOKIE': |
||||
168 | $ret = "\$_COOKIE['{$var}']"; |
||||
169 | break; |
||||
170 | case 'ENV': |
||||
171 | $ret = "\$_ENV['{$var}']"; |
||||
172 | break; |
||||
173 | case 'SERVER': |
||||
174 | $ret = "\$_SERVER['{$var}']"; |
||||
175 | break; |
||||
176 | default: |
||||
177 | $ret = "\$_REQUEST['{$var}']"; |
||||
178 | break; |
||||
179 | } |
||||
180 | |||||
181 | return $ret; |
||||
182 | } |
||||
183 | |||||
184 | /** |
||||
185 | * @public function getPhpCodeRemoveCarriageReturn |
||||
186 | * @param $string |
||||
187 | * |
||||
188 | * @param string $n |
||||
189 | * @param string $t |
||||
190 | * @return string |
||||
191 | */ |
||||
192 | public function getPhpCodeRemoveCarriageReturn($string, $n = "\n", $t = "\r") |
||||
193 | { |
||||
194 | return \str_replace([(string)$n, (string)$t], '', $string); |
||||
195 | } |
||||
196 | |||||
197 | /** |
||||
198 | * @public function getPhpCodeFileExists |
||||
199 | * @param $filename |
||||
200 | * |
||||
201 | * @return string |
||||
202 | */ |
||||
203 | public function getPhpCodeFileExists($filename) |
||||
204 | { |
||||
205 | return "\\file_exists({$filename})"; |
||||
206 | } |
||||
207 | |||||
208 | /** |
||||
209 | * @public function getPhpCodeIncludeDir |
||||
210 | * @param $directory |
||||
211 | * @param $filename |
||||
212 | * @param bool $once |
||||
213 | * @param bool $isPath |
||||
214 | * |
||||
215 | * @param string $type |
||||
216 | * @param string $t |
||||
217 | * @return string |
||||
218 | */ |
||||
219 | public function getPhpCodeIncludeDir($directory = null, $filename = null, $once = false, $isPath = false, $type = 'require', $t = '') |
||||
220 | { |
||||
221 | if ('' === $type) { |
||||
222 | $type = 'require'; |
||||
223 | } |
||||
224 | if (false === $once) { |
||||
225 | if (!$isPath) { |
||||
226 | $ret = "{$t}{$type} {$directory} . '/{$filename}.php';\n"; |
||||
227 | } else { |
||||
228 | $ret = "{$t}{$type} {$directory};\n"; |
||||
229 | } |
||||
230 | } else { |
||||
231 | if (!$isPath) { |
||||
232 | $ret = "{$t}{$type}_once {$directory} . '/{$filename}.php';\n"; |
||||
233 | } else { |
||||
234 | $ret = "{$t}{$type}_once {$directory};\n"; |
||||
235 | } |
||||
236 | } |
||||
237 | |||||
238 | return $ret; |
||||
239 | } |
||||
240 | |||||
241 | /** |
||||
242 | * @public function getPhpCodeTernaryOperator |
||||
243 | * @param $return |
||||
244 | * @param $condition |
||||
245 | * @param $one |
||||
246 | * @param $two |
||||
247 | * @param $t - Indentation |
||||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||||
248 | * |
||||
249 | * @return string |
||||
250 | */ |
||||
251 | public function getPhpCodeTernaryOperator($return, $condition, $one, $two, $t = '') |
||||
252 | { |
||||
253 | $ret = "{$t}\${$return} = {$condition} ?"; |
||||
254 | if ('' != $one) { |
||||
255 | //not shorthand/elvis |
||||
256 | $ret .= " {$one} "; |
||||
257 | } |
||||
258 | $ret .= ": {$two};\n"; |
||||
259 | return $ret; |
||||
260 | } |
||||
261 | |||||
262 | /** |
||||
263 | * @public function getPhpCodeClass |
||||
264 | * @param $name |
||||
265 | * @param $content |
||||
266 | * @param $extends |
||||
267 | * @param $type |
||||
268 | * |
||||
269 | * @param null $implements |
||||
0 ignored issues
–
show
|
|||||
270 | * @return string |
||||
271 | */ |
||||
272 | public function getPhpCodeClass($name = null, $content = null, $extends = null, $type = null, $implements = null) |
||||
273 | { |
||||
274 | $typ = (null != $type) ? "{$type} " : ''; |
||||
275 | $ext = (null != $extends) ? " extends {$extends}" : ''; |
||||
276 | $imp = (null != $implements) ? " implements {$implements}" : ''; |
||||
0 ignored issues
–
show
|
|||||
277 | $ret = "{$typ}class {$name}{$ext}{$imp}\n"; |
||||
278 | $ret .= '{'; |
||||
279 | $ret .= $content; |
||||
280 | $ret .= "}\n"; |
||||
281 | |||||
282 | return $ret; |
||||
283 | } |
||||
284 | |||||
285 | /** |
||||
286 | * @public function getPhpCodeClass |
||||
287 | * @param $type |
||||
288 | * @param $name |
||||
289 | * @param $assign |
||||
290 | * @param $t - Indentation |
||||
0 ignored issues
–
show
|
|||||
291 | * |
||||
292 | * @return string |
||||
293 | */ |
||||
294 | public function getPhpCodeVariableClass($type = 'private', $name = null, $assign = 'null', $t = '') |
||||
295 | { |
||||
296 | return "{$t}{$type} \${$name} = {$assign};\n"; |
||||
297 | } |
||||
298 | |||||
299 | /** |
||||
300 | * @public function getPhpCodeInstance |
||||
301 | * @param $name |
||||
302 | * @param $content |
||||
303 | * @param $extends |
||||
304 | * @param $type |
||||
305 | * |
||||
306 | * @return string |
||||
307 | */ |
||||
308 | public function getPhpCodeInterface($name = null, $content = null, $extends = null, $type = null) |
||||
309 | { |
||||
310 | $typ = (null != $type) ? "{$type} " : ''; |
||||
311 | $ext = (null != $extends) ? " extends {$extends}" : ''; |
||||
312 | $ret = "{$typ}interface {$name}{$ext}\n"; |
||||
313 | $ret .= '{'; |
||||
314 | $ret .= $content; |
||||
315 | $ret .= "}\n"; |
||||
316 | |||||
317 | return $ret; |
||||
318 | } |
||||
319 | |||||
320 | /** |
||||
321 | * @public function getPhpCodeFunction |
||||
322 | * @param $name |
||||
323 | * @param $params |
||||
324 | * @param $content |
||||
325 | * @param $method |
||||
326 | * @param bool $isRef |
||||
327 | * @param string $t - Indentation |
||||
328 | * @return string |
||||
329 | */ |
||||
330 | public function getPhpCodeFunction($name = null, $params = null, $content = null, $method = null, $isRef = false, $t = '') |
||||
331 | { |
||||
332 | $inClass = (null != $method) ? $method : ''; |
||||
333 | $ref = (false !== $isRef) ? '&' : ''; |
||||
334 | $ret = "{$t}{$inClass}function {$ref}{$name}({$params})\n"; |
||||
335 | $ret .= "{$t}{\n"; |
||||
336 | $ret .= $content; |
||||
337 | $ret .= "{$t}}\n"; |
||||
338 | |||||
339 | return $ret; |
||||
340 | } |
||||
341 | |||||
342 | /** |
||||
343 | * @public function getPhpCodeConditions |
||||
344 | * @param string $condition |
||||
345 | * @param string $operator |
||||
346 | * @param string $type |
||||
347 | * @param string $contentIf |
||||
348 | * @param mixed $contentElse |
||||
349 | * @param string $t - Indentation |
||||
350 | * |
||||
351 | * @param string $conditionElse |
||||
352 | * @return string |
||||
353 | */ |
||||
354 | public function getPhpCodeConditions($condition = null, $operator = null, $type = null, $contentIf = null, $contentElse = false, $t = '', $conditionElse = '') |
||||
355 | { |
||||
356 | if ('==' === \trim($operator) || '===' === \trim($operator) || '!=' === \trim($operator) || '!==' === \trim($operator)) { |
||||
0 ignored issues
–
show
It seems like
$operator can also be of type null ; however, parameter $string of trim() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
357 | //yoda conditions |
||||
358 | $left = $type; |
||||
359 | $right = $condition; |
||||
360 | } else { |
||||
361 | $left = $condition; |
||||
362 | $right = $type; |
||||
363 | } |
||||
364 | if (false === $contentElse) { |
||||
365 | $ret = "{$t}if ({$left}{$operator}{$right}) {\n"; |
||||
366 | $ret .= $contentIf; |
||||
367 | $ret .= "{$t}}\n"; |
||||
368 | } else { |
||||
369 | $ret = "{$t}if ({$left}{$operator}{$right}) {\n"; |
||||
370 | $ret .= $contentIf; |
||||
371 | if ('' !== $conditionElse) { |
||||
372 | $ret .= "{$t}} elseif ({$conditionElse}) {\n"; |
||||
373 | } else { |
||||
374 | $ret .= "{$t}} else {\n"; |
||||
375 | } |
||||
376 | |||||
377 | $ret .= $contentElse; |
||||
378 | $ret .= "{$t}}\n"; |
||||
379 | } |
||||
380 | |||||
381 | return $ret; |
||||
382 | } |
||||
383 | |||||
384 | /** |
||||
385 | * @public function getPhpCodeForeach |
||||
386 | * @param string $array |
||||
387 | * @param bool|string $arrayKey |
||||
388 | * @param bool|string $key |
||||
389 | * @param bool|string $value |
||||
390 | * @param string $content |
||||
391 | * |
||||
392 | * @param string $t |
||||
393 | * @return string |
||||
394 | */ |
||||
395 | public function getPhpCodeForeach($array, $arrayKey = false, $key = false, $value = false, $content = null, $t = '') |
||||
396 | { |
||||
397 | $vars = ''; |
||||
398 | $value = '' !== $value ? $value : 'i'; |
||||
399 | if ((false === $arrayKey) && (false === $key)) { |
||||
400 | $vars = "\${$array} as \${$value}"; |
||||
401 | } elseif ((false === $arrayKey) && (false !== $key)) { |
||||
402 | $vars = "\${$array} as \${$key} => \${$value}"; |
||||
403 | } elseif ((false !== $arrayKey) && (false === $key)) { |
||||
404 | $vars = "\array_keys(\${$array}) as \${$value}"; |
||||
405 | } |
||||
406 | |||||
407 | $ret = "{$t}foreach ({$vars}) {\n"; |
||||
408 | $ret .= "{$content}"; |
||||
409 | $ret .= "{$t}}\n"; |
||||
410 | |||||
411 | return $ret; |
||||
412 | } |
||||
413 | |||||
414 | /** |
||||
415 | * @public function getPhpCodeFor |
||||
416 | * @param $var |
||||
417 | * @param $content |
||||
418 | * @param $value |
||||
419 | * @param $initVal |
||||
420 | * @param $operator |
||||
421 | * |
||||
422 | * @param string $t |
||||
423 | * @return string |
||||
424 | */ |
||||
425 | public function getPhpCodeFor($var = null, $content = null, $value = null, $initVal = null, $operator = null, $t = '') |
||||
426 | { |
||||
427 | $ret = "{$t}for (\${$var} = {$initVal}; \${$var} {$operator} \${$value}; \${$var}++) {\n"; |
||||
428 | $ret .= "{$content}"; |
||||
429 | $ret .= "{$t}}\n"; |
||||
430 | |||||
431 | return $ret; |
||||
432 | } |
||||
433 | |||||
434 | /** |
||||
435 | * @public function getPhpCodeWhile |
||||
436 | * @param $var |
||||
437 | * @param $content |
||||
438 | * @param $value |
||||
439 | * @param $operator |
||||
440 | * @param $t |
||||
441 | * |
||||
442 | * @return string |
||||
443 | */ |
||||
444 | public function getPhpCodeWhile($var = null, $content = null, $value = null, $operator = null, $t = '') |
||||
445 | { |
||||
446 | $ret = "{$t}while (\${$var} {$operator} {$value}) {\n"; |
||||
447 | $ret .= "{$t}{$content}"; |
||||
448 | $ret .= "{$t}}\n"; |
||||
449 | |||||
450 | return $ret; |
||||
451 | } |
||||
452 | |||||
453 | /** |
||||
454 | * @public function getPhpCodeSwitch |
||||
455 | * |
||||
456 | * @param $op |
||||
457 | * @param $content |
||||
458 | * @param string $t |
||||
459 | * |
||||
460 | * @param bool $isParam |
||||
461 | * @return string |
||||
462 | */ |
||||
463 | public function getPhpCodeSwitch($op = null, $content = null, $t = '', $isParam = true) |
||||
464 | { |
||||
465 | $value = $isParam ? "\${$op}" : $op; |
||||
466 | $ret = "{$t}switch ({$value}) {\n"; |
||||
467 | $ret .= $content; |
||||
468 | $ret .= "{$t}}\n"; |
||||
469 | |||||
470 | return $ret; |
||||
471 | } |
||||
472 | |||||
473 | /** |
||||
474 | * @public function getPhpCodeCaseSwitch |
||||
475 | * |
||||
476 | * @param array $cases |
||||
477 | * @param bool $defaultAfterCase |
||||
478 | * @param bool $default |
||||
479 | * @param string $t |
||||
480 | * |
||||
481 | * @param bool $isConst |
||||
482 | * @return string |
||||
483 | */ |
||||
484 | public function getPhpCodeCaseSwitch($cases = [], $defaultAfterCase = false, $default = false, $t = '', $isConst = false) |
||||
485 | { |
||||
486 | $ret = ''; |
||||
487 | $def = "{$t}default:\n"; |
||||
488 | foreach ($cases as $case => $value) { |
||||
489 | $case = $isConst || !\is_string($case) ? $case : "'{$case}'"; |
||||
490 | if (empty($value)) { |
||||
491 | $ret .= "{$t}case {$case}:\n"; |
||||
492 | } elseif (!empty($case)) { |
||||
493 | $ret .= "{$t}case {$case}:\n"; |
||||
494 | if (false !== $defaultAfterCase) { |
||||
495 | $ret .= $def; |
||||
496 | } |
||||
497 | if (\is_array($value)) { |
||||
498 | foreach ($value as $content) { |
||||
499 | $ret .= "{$content}"; |
||||
500 | } |
||||
501 | } |
||||
502 | $ret .= "{$t}\tbreak;\n"; |
||||
503 | $defaultAfterCase = false; |
||||
504 | } |
||||
505 | } |
||||
506 | if (false !== $default) { |
||||
507 | $ret .= $def; |
||||
508 | $ret .= "{$t}{$default}\n"; |
||||
509 | $ret .= "{$t}\tbreak;\n"; |
||||
510 | } |
||||
511 | |||||
512 | return $ret; |
||||
513 | } |
||||
514 | |||||
515 | /** |
||||
516 | * @public function getPhpCodeIsset |
||||
517 | * @param $var |
||||
518 | * @return string |
||||
519 | */ |
||||
520 | public function getPhpCodeIsset($var) |
||||
521 | { |
||||
522 | return "isset(\${$var})"; |
||||
523 | } |
||||
524 | |||||
525 | /** |
||||
526 | * @public function getPhpCodeUnset |
||||
527 | * @param string $var |
||||
528 | * @param string $t |
||||
529 | * @return string |
||||
530 | */ |
||||
531 | public function getPhpCodeUnset($var = '', $t = '') |
||||
532 | { |
||||
533 | return "{$t}unset(\${$var});\n"; |
||||
534 | } |
||||
535 | |||||
536 | /** |
||||
537 | * @public function getPhpCodeIsDir |
||||
538 | * @param $var |
||||
539 | * @return string |
||||
540 | */ |
||||
541 | public function getPhpCodeIsDir($var) |
||||
542 | { |
||||
543 | return "\is_dir({$var})"; |
||||
544 | } |
||||
545 | |||||
546 | /** |
||||
547 | * @public function getPhpCodeImplode |
||||
548 | * @param $left |
||||
549 | * @param $right |
||||
550 | * @return string |
||||
551 | */ |
||||
552 | public function getPhpCodeImplode($left, $right) |
||||
553 | { |
||||
554 | return "\implode('{$left}', {$right})"; |
||||
555 | } |
||||
556 | |||||
557 | /** |
||||
558 | * @public function getPhpCodeExplode |
||||
559 | * @param $left |
||||
560 | * @param $right |
||||
561 | * @return string |
||||
562 | */ |
||||
563 | public function getPhpCodeExplode($left, $right) |
||||
564 | { |
||||
565 | return "\\explode('{$left}', {$right})"; |
||||
566 | } |
||||
567 | |||||
568 | /** |
||||
569 | * @public function getPhpCodeChmod |
||||
570 | * @param $var |
||||
571 | * @param string $perm |
||||
572 | * @param string $t |
||||
573 | * @return string |
||||
574 | */ |
||||
575 | public function getPhpCodeChmod($var, $perm = '0777', $t = '') |
||||
576 | { |
||||
577 | return "{$t}chmod(\${$var}, {$perm});\n"; |
||||
578 | } |
||||
579 | |||||
580 | /** |
||||
581 | * @public function getPhpCodeMkdir |
||||
582 | * @param $var |
||||
583 | * @param string $perm |
||||
584 | * @param string $t |
||||
585 | * @return string |
||||
586 | */ |
||||
587 | public function getPhpCodeMkdir($var, $perm = '0777', $t = '') |
||||
588 | { |
||||
589 | return "{$t}\mkdir(\${$var}, {$perm});\n"; |
||||
590 | } |
||||
591 | |||||
592 | /** |
||||
593 | * @public function getPhpCodeCopy |
||||
594 | * @param $file |
||||
595 | * @param string $newfile |
||||
596 | * @param string $t |
||||
597 | * @return string |
||||
598 | */ |
||||
599 | public function getPhpCodeCopy($file, $newfile = '', $t = '') |
||||
600 | { |
||||
601 | return "{$t}\copy({$file}, {$newfile});\n"; |
||||
602 | } |
||||
603 | |||||
604 | /** |
||||
605 | * @public function getPhpCodeArray |
||||
606 | * @param $var |
||||
607 | * @param $array |
||||
608 | * @param bool $isParam |
||||
609 | * |
||||
610 | * @param string $t |
||||
611 | * @return string |
||||
612 | */ |
||||
613 | public function getPhpCodeArray($var, $array = null, $isParam = false, $t = "\t\t") |
||||
614 | { |
||||
615 | $retArray = []; |
||||
616 | if (\is_array($array) && !empty($array)) { |
||||
617 | foreach ($array as $k => $v) { |
||||
618 | if (is_numeric($k)) { |
||||
619 | $retArray[] = $v; |
||||
620 | } else { |
||||
621 | $retArray[] = "{$k} => {$v}"; |
||||
622 | } |
||||
623 | } |
||||
624 | $arrayContent = \implode(', ', $retArray); |
||||
625 | } else { |
||||
626 | $arrayContent = ''; |
||||
627 | } |
||||
628 | unset($retArray); |
||||
629 | |||||
630 | if (!$isParam) { |
||||
631 | $ret = "{$t}\${$var} = [{$arrayContent}];\n"; |
||||
632 | } else { |
||||
633 | $ret = "[{$array}]"; |
||||
634 | } |
||||
635 | |||||
636 | return $ret; |
||||
637 | } |
||||
638 | |||||
639 | /** |
||||
640 | * @public function getPhpCodeArrayType |
||||
641 | * @param $var |
||||
642 | * @param $type |
||||
643 | * @param $left |
||||
644 | * @param $right |
||||
645 | * @param bool $isParam |
||||
646 | * |
||||
647 | * @param string $t |
||||
648 | * @return string |
||||
649 | */ |
||||
650 | public function getPhpCodeArrayType($var, $type, $left, $right = null, $isParam = false, $t = "\t\t") |
||||
651 | { |
||||
652 | $vars = (null != $right) ? "\${$left}, {$right}" : "\${$left}"; |
||||
653 | if (!$isParam) { |
||||
654 | $ret = "{$t}\${$var}[] = \array_{$type}({$vars});\n"; |
||||
655 | } else { |
||||
656 | $ret = "\array_{$type}({$vars})"; |
||||
657 | } |
||||
658 | |||||
659 | return $ret; |
||||
660 | } |
||||
661 | |||||
662 | /** |
||||
663 | * @public function getPhpCodeArrayType |
||||
664 | * @param $var |
||||
665 | * @param string $t |
||||
666 | * @return string |
||||
667 | */ |
||||
668 | public function getPhpCodeArrayShift($var, $t = '') |
||||
669 | { |
||||
670 | return "{$t}\array_shift({$var});\n"; |
||||
671 | } |
||||
672 | |||||
673 | /** |
||||
674 | * @public function getPhpCodeSprintf |
||||
675 | * @param $left |
||||
676 | * @param $right |
||||
677 | * @return string |
||||
678 | */ |
||||
679 | public function getPhpCodeSprintf($left, $right) |
||||
680 | { |
||||
681 | return "\sprintf({$left}, {$right})"; |
||||
682 | } |
||||
683 | |||||
684 | /** |
||||
685 | * @public function getPhpCodeEmpty |
||||
686 | * @param $var |
||||
687 | * @return string |
||||
688 | */ |
||||
689 | public function getPhpCodeEmpty($var) |
||||
690 | { |
||||
691 | return "empty({$var})"; |
||||
692 | } |
||||
693 | |||||
694 | /** |
||||
695 | * @public function getPhpCodeHeader |
||||
696 | * @param $var |
||||
697 | * @return string |
||||
698 | */ |
||||
699 | public function getPhpCodeHeader($var) |
||||
700 | { |
||||
701 | return "header({$var})"; |
||||
702 | } |
||||
703 | |||||
704 | /** |
||||
705 | * @public function getPhpCodeRawurlencode |
||||
706 | * @param $var |
||||
707 | * @return string |
||||
708 | */ |
||||
709 | public function getPhpCodeRawurlencode($var) |
||||
710 | { |
||||
711 | return "rawurlencode({$var})"; |
||||
712 | } |
||||
713 | |||||
714 | /** |
||||
715 | * @public function getPhpCodePregFunzions |
||||
716 | * @param $var |
||||
717 | * @param $exp |
||||
718 | * @param $str |
||||
719 | * @param $val |
||||
720 | * @param string $type |
||||
721 | * @param bool $isParam |
||||
722 | * |
||||
723 | * @param string $t |
||||
724 | * @return string |
||||
725 | */ |
||||
726 | public function getPhpCodePregFunzions($var, $exp, $str, $val, $type = 'match', $isParam = false, $t = "\t") |
||||
727 | { |
||||
728 | $pregFunz = "\preg_{$type}('"; |
||||
729 | if (!$isParam) { |
||||
730 | $ret = "{$t}\${$var} = {$pregFunz}{$exp}', '{$str}', {$val});\n"; |
||||
731 | } else { |
||||
732 | $ret = "{$pregFunz}{$exp}', '{$str}', {$val})"; |
||||
733 | } |
||||
734 | |||||
735 | return $ret; |
||||
736 | } |
||||
737 | |||||
738 | /** |
||||
739 | * @public function getPhpCodeStrType |
||||
740 | * @param $left |
||||
741 | * @param $var |
||||
742 | * @param $str |
||||
743 | * @param $value |
||||
744 | * @param string $type |
||||
745 | * @param bool $isParam |
||||
746 | * |
||||
747 | * @param string $t |
||||
748 | * @return string |
||||
749 | */ |
||||
750 | public function getPhpCodeStrType($left, $var, $str, $value, $type = 'replace', $isParam = false, $t = "\t") |
||||
751 | { |
||||
752 | $strType = "\str_{$type}('"; |
||||
753 | if (!$isParam) { |
||||
754 | $ret = "{$t}\${$left} = {$strType}{$var}', '{$str}', {$value});\n"; |
||||
755 | } else { |
||||
756 | $ret = "{$strType}{$var}', '{$str}', {$value})"; |
||||
757 | } |
||||
758 | |||||
759 | return $ret; |
||||
760 | } |
||||
761 | |||||
762 | /** |
||||
763 | * @public function getPhpCodeStripTags |
||||
764 | * @param $left |
||||
765 | * @param $value |
||||
766 | * @param bool $isParam |
||||
767 | * |
||||
768 | * @param string $t |
||||
769 | * @return string |
||||
770 | */ |
||||
771 | public function getPhpCodeStripTags($left, $value, $isParam = false, $t = '') |
||||
772 | { |
||||
773 | if (!$isParam) { |
||||
774 | $ret = "{$t}\${$left} = \strip_tags({$value});\n"; |
||||
775 | } else { |
||||
776 | $ret = "\strip_tags({$value})"; |
||||
777 | } |
||||
778 | |||||
779 | return $ret; |
||||
780 | } |
||||
781 | |||||
782 | /** |
||||
783 | * @public function getPhpCodeHtmlentities |
||||
784 | * @param $entitiesVar |
||||
785 | * @param $entitiesQuote |
||||
786 | * @return string |
||||
787 | */ |
||||
788 | public function getPhpCodeHtmlentities($entitiesVar, $entitiesQuote = false) |
||||
789 | { |
||||
790 | $entitiesVar = (false !== $entitiesQuote) ? $entitiesVar . ', ' . $entitiesQuote : $entitiesVar; |
||||
791 | $entities = "htmlentities({$entitiesVar})"; |
||||
792 | |||||
793 | return $entities; |
||||
794 | } |
||||
795 | |||||
796 | /** |
||||
797 | * @public function getPhpCodeHtmlspecialchars |
||||
798 | * @param $specialVar |
||||
799 | * @param $specialQuote |
||||
800 | * @return string |
||||
801 | */ |
||||
802 | public function getPhpCodeHtmlspecialchars($specialVar, $specialQuote = false) |
||||
803 | { |
||||
804 | $specialVar = (false !== $specialQuote) ? $specialVar . ', ' . $specialQuote : $specialVar; |
||||
805 | $specialchars = "htmlspecialchars({$specialVar})"; |
||||
806 | |||||
807 | return $specialchars; |
||||
808 | } |
||||
809 | |||||
810 | /** |
||||
811 | * @public function getPhpCodeNamespace |
||||
812 | * @param $dimensions |
||||
813 | * @param string $t |
||||
814 | * @param string $n |
||||
815 | * @return string |
||||
816 | */ |
||||
817 | public function getPhpCodeNamespace($dimensions, $t = '', $n = "\n\n") |
||||
818 | { |
||||
819 | $ret = "\n{$t}namespace "; |
||||
820 | foreach ($dimensions as $key => $dim) { |
||||
821 | if ($key > 0) { |
||||
822 | $ucfDim = \ucfirst($dim); |
||||
823 | $ret .= "\\{$ucfDim}"; |
||||
824 | } else { |
||||
825 | $ret .= "{$dim}"; |
||||
826 | } |
||||
827 | } |
||||
828 | $ret .= ";" . $n; |
||||
829 | |||||
830 | return $ret; |
||||
831 | } |
||||
832 | |||||
833 | /** |
||||
834 | * @public function getPhpCodeUseNamespace |
||||
835 | * @param $dimensions |
||||
836 | * @param string $t |
||||
837 | * @param string $n |
||||
838 | * @return string |
||||
839 | */ |
||||
840 | public function getPhpCodeUseNamespace($dimensions, $t = '', $n = "\n\n") |
||||
841 | { |
||||
842 | $ret = "\n{$t}use "; |
||||
843 | foreach ($dimensions as $key => $dim) { |
||||
844 | if ($key > 0) { |
||||
845 | $ucfDim = \ucfirst($dim); |
||||
846 | $ret .= "\\{$ucfDim}"; |
||||
847 | } else { |
||||
848 | $ret .= "{$dim}"; |
||||
849 | } |
||||
850 | } |
||||
851 | $ret .= ";" . $n; |
||||
852 | |||||
853 | return $ret; |
||||
854 | } |
||||
855 | |||||
856 | /** |
||||
857 | * @public function getPhpCodeBlankLine |
||||
858 | * |
||||
859 | * @return string |
||||
860 | */ |
||||
861 | public function getPhpCodeBlankLine() |
||||
862 | { |
||||
863 | return "\n"; |
||||
864 | } |
||||
865 | |||||
866 | /** |
||||
867 | * @public function getPhpCodeConstant |
||||
868 | * |
||||
869 | * @param $const |
||||
870 | * @param $value |
||||
871 | * @param string $t |
||||
872 | * @param string $type |
||||
873 | * @return string |
||||
874 | */ |
||||
875 | public function getPhpCodeConstant($const, $value, $t = '', $type = 'const') |
||||
876 | { |
||||
877 | return "{$t}{$type} {$const} = {$value};\n"; |
||||
878 | } |
||||
879 | |||||
880 | /** |
||||
881 | * @public function getPhpCodeTriggerError |
||||
882 | * |
||||
883 | * @param $msg |
||||
884 | * @param $type |
||||
885 | * @param string $t |
||||
886 | * @return string |
||||
887 | */ |
||||
888 | public function getPhpCodeTriggerError($msg, $type, $t = '') |
||||
889 | { |
||||
890 | $ret = "{$t}\\trigger_error($msg, {$type});\n"; |
||||
891 | return $ret; |
||||
892 | } |
||||
893 | } |
||||
894 |