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
|
|
|
$output=""; |
11
|
|
|
if (is_string($input)) { |
12
|
|
|
$output=$input; |
13
|
|
|
} |
14
|
|
|
if (is_array($input)) { |
15
|
|
|
if (sizeof($input) > 0) { |
16
|
|
|
if (self::containsElement($input) === false) { |
17
|
|
|
$output=self::wrapStrings($input, $js, $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) === true || \is_array($v)) |
29
|
|
|
return true; |
30
|
|
|
} |
31
|
|
|
return false; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function wrapStrings($input, $js, $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, array_values($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_object($v)) |
48
|
|
|
return $v->compile($js); |
49
|
|
|
elseif (\is_array($v)) { |
50
|
|
|
return self::wrap($v, $js, $separator, $valueQuote); |
51
|
|
|
} else |
52
|
|
|
return $v; |
53
|
|
|
}, $input)); |
54
|
|
|
} |
55
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.