1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\common\html; |
4
|
|
|
|
5
|
|
|
use Ajax\service\JArray; |
6
|
|
|
|
7
|
|
|
class PropertyWrapper { |
8
|
|
|
|
9
|
|
|
public static function wrap($input, $js=NULL, $separator=' ', $valueQuote='"') { |
10
|
|
|
if (is_string($input)) { |
11
|
|
|
return $input; |
12
|
|
|
} |
13
|
|
|
$output=""; |
14
|
|
|
if (\is_array($input)) { |
15
|
|
|
if (sizeof($input) > 0) { |
16
|
|
|
if (self::containsElement($input) === false) { |
17
|
|
|
$output=self::wrapStrings($input, $separator=' ', $valueQuote='"'); |
18
|
|
|
} else { |
19
|
|
|
$output=self::wrapObjects($input, $js, $separator, $valueQuote); |
20
|
|
|
} |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
return $output; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
private static function containsElement($input) { |
27
|
|
|
foreach ( $input as $v ) { |
28
|
|
|
if (\is_object($v) || \is_array($v)) |
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function wrapStrings($input, $separator=' ', $valueQuote='"') { |
35
|
|
|
if (JArray::isAssociative($input) === true) { |
36
|
|
|
$result=implode($separator, array_map(function ($v, $k) use($valueQuote) { |
37
|
|
|
return $k . '=' . $valueQuote . $v . $valueQuote; |
38
|
|
|
}, $input, array_keys($input))); |
39
|
|
|
} else { |
40
|
|
|
$result=implode($separator, $input); |
41
|
|
|
} |
42
|
|
|
return $result; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function wrapObjects($input, $js=NULL, $separator=' ', $valueQuote='"') { |
46
|
|
|
return implode($separator, array_map(function ($v) use($js, $separator, $valueQuote) { |
47
|
|
|
if(\is_string($v)){ |
48
|
|
|
return $v; |
49
|
|
|
} |
50
|
|
|
if ($v instanceof BaseHtml){ |
51
|
|
|
return $v->compile($js); |
52
|
|
|
} |
53
|
|
|
if (\is_array($v)) { |
54
|
|
|
return self::wrap($v, $js, $separator, $valueQuote); |
55
|
|
|
} |
56
|
|
|
if(!\is_callable($v)){ |
57
|
|
|
return $v; |
58
|
|
|
} |
59
|
|
|
}, $input)); |
60
|
|
|
/*$result=''; |
|
|
|
|
61
|
|
|
foreach ($input as $value) { |
62
|
|
|
if($result!==''){ |
63
|
|
|
$result.=$separator; |
64
|
|
|
} |
65
|
|
|
if(\is_string($value)){ |
66
|
|
|
$result.=$value; |
67
|
|
|
}else{ |
68
|
|
|
$result.=self::wrapValue($value,$js,$separator,$valueQuote); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
return $result;*/ |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
protected static function wrapValue($value,$js=NULL, $separator=' ', $valueQuote='"'){ |
75
|
|
|
if (\is_array($value)) { |
76
|
|
|
return self::wrap($value, $js, $separator, $valueQuote); |
77
|
|
|
} |
78
|
|
|
if ($value instanceof BaseHtml){ |
79
|
|
|
return $value->compile($js); |
80
|
|
|
} |
81
|
|
|
if(!\is_callable($value)){ |
82
|
|
|
return $value; |
83
|
|
|
} |
84
|
|
|
return ''; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.