|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PHPPgAdmin v6.0.0-RC9-3-gd93ec300 |
|
5
|
|
|
*/ |
|
6
|
|
|
|
|
7
|
|
|
namespace PHPPgAdmin\Decorators; |
|
8
|
|
|
|
|
9
|
|
|
class Decorator |
|
10
|
|
|
{ |
|
11
|
|
|
use \PHPPgAdmin\Traits\HelperTrait; |
|
12
|
|
|
|
|
13
|
|
|
public $container; |
|
14
|
|
|
|
|
15
|
|
|
public function __construct($value) |
|
16
|
|
|
{ |
|
17
|
|
|
$this->val = $value; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function value($fields) |
|
21
|
|
|
{ |
|
22
|
|
|
return $this->val; |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param null|string $esc |
|
|
|
|
|
|
27
|
|
|
*/ |
|
28
|
|
|
public static function get_sanitized_value(&$var, &array $fields, ?string $esc = null) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
if (\is_a($var, 'PHPPgAdmin\Decorators\Decorator')) { |
|
31
|
|
|
$val = $var->value($fields); |
|
32
|
|
|
} else { |
|
33
|
|
|
$val = &$var; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
if (\is_string($val)) { |
|
37
|
|
|
switch ($esc) { |
|
38
|
|
|
case 'xml': |
|
39
|
|
|
return \strtr($val, [ |
|
40
|
|
|
'&' => '&', |
|
41
|
|
|
"'" => ''', |
|
42
|
|
|
'"' => '"', |
|
43
|
|
|
'<' => '<', |
|
44
|
|
|
'>' => '>', |
|
45
|
|
|
]); |
|
46
|
|
|
case 'html': |
|
47
|
|
|
return \htmlentities($val, \ENT_COMPAT, 'UTF-8'); |
|
48
|
|
|
case 'url': |
|
49
|
|
|
return \urlencode($val); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $val; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param \Closure|\Closure|\Closure $callback |
|
58
|
|
|
* @param (mixed|string)[]|null $params |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function callback($callback, ?array $params = null) |
|
61
|
|
|
{ |
|
62
|
|
|
return new \PHPPgAdmin\Decorators\CallbackDecorator($callback, $params); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param scalar $var |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function value_url(&$var, &$fields) |
|
69
|
|
|
{ |
|
70
|
|
|
return self::get_sanitized_value($var, $fields, 'url'); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public static function concat(/* ... */) |
|
74
|
|
|
{ |
|
75
|
|
|
return new \PHPPgAdmin\Decorators\ConcatDecorator(\func_get_args()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param array $params |
|
|
|
|
|
|
80
|
|
|
*/ |
|
81
|
|
|
public static function replace(string $str, array $params) |
|
82
|
|
|
{ |
|
83
|
|
|
return new \PHPPgAdmin\Decorators\ReplaceDecorator($str, $params); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* @param array|null $default |
|
|
|
|
|
|
88
|
|
|
*/ |
|
89
|
|
|
public static function field(string $fieldName, ?array $default = null) |
|
90
|
|
|
{ |
|
91
|
|
|
return new FieldDecorator($fieldName, $default); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public static function branchurl($base, $vars = null/* ... */) |
|
95
|
|
|
{ |
|
96
|
|
|
// If more than one array of vars is given, |
|
97
|
|
|
// use an ArrayMergeDecorator to have them merged |
|
98
|
|
|
// at value evaluation time. |
|
99
|
|
|
if (2 < \func_num_args()) { |
|
100
|
|
|
$v = \func_get_args(); |
|
101
|
|
|
\array_shift($v); |
|
102
|
|
|
|
|
103
|
|
|
return new BranchUrlDecorator($base, new ArrayMergeDecorator($v)); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return new BranchUrlDecorator($base, $vars); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param array|null $vars |
|
|
|
|
|
|
111
|
|
|
*/ |
|
112
|
|
|
public static function actionurl(string $base, ?array $vars = null/* ... */) |
|
113
|
|
|
{ |
|
114
|
|
|
// If more than one array of vars is given, |
|
115
|
|
|
// use an ArrayMergeDecorator to have them merged |
|
116
|
|
|
// at value evaluation time. |
|
117
|
|
|
if (2 < \func_num_args()) { |
|
118
|
|
|
$v = \func_get_args(); |
|
119
|
|
|
\array_shift($v); |
|
120
|
|
|
|
|
121
|
|
|
return new ActionUrlDecorator($base, new ArrayMergeDecorator($v)); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
return new ActionUrlDecorator($base, $vars); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
public static function redirecturl(string $base, $vars = null/* ... */) |
|
128
|
|
|
{ |
|
129
|
|
|
// If more than one array of vars is given, |
|
130
|
|
|
// use an ArrayMergeDecorator to have them merged |
|
131
|
|
|
// at value evaluation time. |
|
132
|
|
|
if (2 < \func_num_args()) { |
|
133
|
|
|
$v = \func_get_args(); |
|
134
|
|
|
\array_shift($v); |
|
135
|
|
|
|
|
136
|
|
|
return new RedirectUrlDecorator($base, new ArrayMergeDecorator($v)); |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
return new RedirectUrlDecorator($base, $vars); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @param array|null $vars |
|
|
|
|
|
|
144
|
|
|
*/ |
|
145
|
|
|
public static function url(string $base, ?array $vars = null/* ... */) |
|
146
|
|
|
{ |
|
147
|
|
|
// If more than one array of vars is given, |
|
148
|
|
|
// use an ArrayMergeDecorator to have them merged |
|
149
|
|
|
// at value evaluation time. |
|
150
|
|
|
|
|
151
|
|
|
if (2 < \func_num_args()) { |
|
152
|
|
|
$v = \func_get_args(); |
|
153
|
|
|
$base = \array_shift($v); |
|
154
|
|
|
|
|
155
|
|
|
return new UrlDecorator($base, new ArrayMergeDecorator($v)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
return new UrlDecorator($base, $vars); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public static function ifempty($value, string $empty, $full = null) |
|
162
|
|
|
{ |
|
163
|
|
|
return new IfEmptyDecorator($value, $empty, $full); |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|