3 declare(strict_types
=1);
5 namespace PhpMyAdmin\Config\Settings
;
10 // phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
15 final class Transformations
18 * Default transformations for Substring
20 * @var array<int, int|string>
21 * @psalm-var array{0: int, 1: 'all'|int, 2: string}
23 public $Substring = [0, 'all', '…'];
26 * Default transformations for Bool2Text
29 * @psalm-var array{0: string, 1: string}
31 public $Bool2Text = ['T', 'F'];
34 * Default transformations for External
36 * @var array<int, int|string>
37 * @psalm-var array{0: int, 1: string, 2: int, 3: int}
39 public $External = [0, '-f /dev/null -i -wrap -q', 1, 1];
42 * Default transformations for PreApPend
45 * @psalm-var array{0: string, 1: string}
47 public $PreApPend = ['', ''];
50 * Default transformations for Hex
53 * @psalm-var array{0: string}
58 * Default transformations for DateFormat
60 * @var array<int, int|string>
61 * @psalm-var array{0: int, 1: string, 2: 'local'|'utc'}
63 public $DateFormat = [0, '', 'local'];
66 * Default transformations for Inline
68 * @var array<(int|string), (int|string|array<string, string>|null)>
69 * @psalm-var array{0: string|int, 1: string|int, wrapper_link: string|null, wrapper_params: array<string, string>}
71 public $Inline = ['100', 100, 'wrapper_link' => null, 'wrapper_params' => []];
74 * Default transformations for TextImageLink
76 * @var array<int, int|string|null>
77 * @psalm-var array{0: string|null, 1: int, 2: int}
79 public $TextImageLink = [null, 100, 50];
82 * Default transformations for TextLink
84 * @var array<int, string|null>
85 * @psalm-var array{0: string|null, 1: string|null, 2: string|null}
87 public $TextLink = [null, null, null];
90 * @param array<int|string, mixed> $transformations
92 public function __construct(array $transformations = [])
94 if (isset($transformations['Substring']) && is_array($transformations['Substring'])) {
95 if (isset($transformations['Substring'][0])) {
96 $this->Substring
[0] = (int) $transformations['Substring'][0];
99 if (isset($transformations['Substring'][1]) && $transformations['Substring'][1] !== 'all') {
100 $this->Substring
[1] = (int) $transformations['Substring'][1];
103 if (isset($transformations['Substring'][2])) {
104 $this->Substring
[2] = (string) $transformations['Substring'][2];
108 if (isset($transformations['Bool2Text']) && is_array($transformations['Bool2Text'])) {
109 if (isset($transformations['Bool2Text'][0])) {
110 $this->Bool2Text
[0] = (string) $transformations['Bool2Text'][0];
113 if (isset($transformations['Bool2Text'][1])) {
114 $this->Bool2Text
[1] = (string) $transformations['Bool2Text'][1];
118 if (isset($transformations['External']) && is_array($transformations['External'])) {
119 if (isset($transformations['External'][0])) {
120 $this->External
[0] = (int) $transformations['External'][0];
123 if (isset($transformations['External'][1])) {
124 $this->External
[1] = (string) $transformations['External'][1];
127 if (isset($transformations['External'][2])) {
128 $this->External
[2] = (int) $transformations['External'][2];
131 if (isset($transformations['External'][3])) {
132 $this->External
[3] = (int) $transformations['External'][3];
136 if (isset($transformations['PreApPend']) && is_array($transformations['PreApPend'])) {
137 if (isset($transformations['PreApPend'][0])) {
138 $this->PreApPend
[0] = (string) $transformations['PreApPend'][0];
141 if (isset($transformations['PreApPend'][1])) {
142 $this->PreApPend
[1] = (string) $transformations['PreApPend'][1];
146 if (isset($transformations['Hex']) && is_array($transformations['Hex'])) {
147 if (isset($transformations['Hex'][0])) {
148 $this->Hex
[0] = (string) $transformations['Hex'][0];
152 if (isset($transformations['DateFormat']) && is_array($transformations['DateFormat'])) {
153 if (isset($transformations['DateFormat'][0])) {
154 $this->DateFormat
[0] = (int) $transformations['DateFormat'][0];
157 if (isset($transformations['DateFormat'][1])) {
158 $this->DateFormat
[1] = (string) $transformations['DateFormat'][1];
162 isset($transformations['DateFormat'][2])
163 && in_array($transformations['DateFormat'][2], ['local', 'utc'], true)
165 $this->DateFormat
[2] = $transformations['DateFormat'][2];
169 if (isset($transformations['Inline']) && is_array($transformations['Inline'])) {
170 if (isset($transformations['Inline'][0])) {
171 $this->Inline
[0] = (int) $transformations['Inline'][0];
174 if (isset($transformations['Inline'][1])) {
175 $this->Inline
[1] = (int) $transformations['Inline'][1];
178 if (isset($transformations['Inline']['wrapper_link'])) {
179 $this->Inline
['wrapper_link'] = (string) $transformations['Inline']['wrapper_link'];
183 isset($transformations['Inline']['wrapper_params'])
184 && is_array($transformations['Inline']['wrapper_params'])
187 * @var int|string $key
190 foreach ($transformations['Inline']['wrapper_params'] as $key => $value) {
191 $this->Inline
['wrapper_params'][(string) $key] = (string) $value;
196 if (isset($transformations['TextImageLink']) && is_array($transformations['TextImageLink'])) {
197 if (isset($transformations['TextImageLink'][0])) {
198 $this->TextImageLink
[0] = (string) $transformations['TextImageLink'][0];
201 if (isset($transformations['TextImageLink'][1])) {
202 $this->TextImageLink
[1] = (int) $transformations['TextImageLink'][1];
205 if (isset($transformations['TextImageLink'][2])) {
206 $this->TextImageLink
[2] = (int) $transformations['TextImageLink'][2];
210 if (! isset($transformations['TextLink']) ||
! is_array($transformations['TextLink'])) {
214 if (isset($transformations['TextLink'][0])) {
215 $this->TextLink
[0] = (string) $transformations['TextLink'][0];
218 if (isset($transformations['TextLink'][1])) {
219 $this->TextLink
[1] = (string) $transformations['TextLink'][1];
222 if (! isset($transformations['TextLink'][2])) {
226 $this->TextLink
[2] = (string) $transformations['TextLink'][2];