|
11 | 11 | use Throwable; |
12 | 12 |
|
13 | 13 | use function __; |
14 | | -use function array_filter; |
15 | 14 | use function array_key_last; |
16 | | -use function array_merge; |
17 | 15 | use function array_replace_recursive; |
18 | 16 | use function array_slice; |
19 | 17 | use function count; |
|
34 | 32 | use function is_array; |
35 | 33 | use function is_bool; |
36 | 34 | use function is_dir; |
37 | | -use function is_int; |
38 | 35 | use function is_numeric; |
39 | 36 | use function is_readable; |
40 | 37 | use function is_string; |
|
53 | 50 | use function rtrim; |
54 | 51 | use function setcookie; |
55 | 52 | use function sprintf; |
56 | | -use function str_contains; |
57 | 53 | use function stripos; |
58 | 54 | use function strtolower; |
59 | 55 | use function substr; |
60 | 56 | use function sys_get_temp_dir; |
61 | 57 | use function time; |
62 | 58 | use function trim; |
63 | 59 |
|
64 | | -use const ARRAY_FILTER_USE_KEY; |
65 | 60 | use const DIRECTORY_SEPARATOR; |
66 | 61 | use const PHP_OS; |
67 | 62 | use const PHP_URL_PATH; |
@@ -103,7 +98,6 @@ public function __construct() |
103 | 98 | $this->config = new Settings([]); |
104 | 99 | $this->defaultServer = $this->config->Servers[1]->asArray(); |
105 | 100 | $config = $this->config->asArray(); |
106 | | - unset($config['Servers']); |
107 | 101 | $this->default = $config; |
108 | 102 | $this->settings = $config; |
109 | 103 | $this->baseSettings = $config; |
@@ -346,6 +340,7 @@ public function load(string|null $source = null): bool |
346 | 340 | return false; |
347 | 341 | } |
348 | 342 |
|
| 343 | + /** @var mixed $cfg */ |
349 | 344 | $cfg = []; |
350 | 345 |
|
351 | 346 | /** |
@@ -379,25 +374,11 @@ public function load(string|null $source = null): bool |
379 | 374 | $this->sourceMtime = (int) filemtime($this->getSource()); |
380 | 375 | } |
381 | 376 |
|
382 | | - /** |
383 | | - * Ignore keys with / as we do not use these |
384 | | - * |
385 | | - * These can be confusing for user configuration layer as it |
386 | | - * flatten array using / and thus don't see difference between |
387 | | - * $cfg['Export/method'] and $cfg['Export']['method'], while rest |
388 | | - * of the code uses the setting only in latter form. |
389 | | - * |
390 | | - * This could be removed once we consistently handle both values |
391 | | - * in the functional code as well. |
392 | | - */ |
393 | | - $cfg = array_filter( |
394 | | - $cfg, |
395 | | - static fn (string $key): bool => ! str_contains($key, '/'), |
396 | | - ARRAY_FILTER_USE_KEY, |
397 | | - ); |
| 377 | + if (is_array($cfg)) { |
| 378 | + $this->config = new Settings($cfg); |
| 379 | + } |
398 | 380 |
|
399 | | - $this->settings = array_replace_recursive($this->settings, $cfg); |
400 | | - $this->config = new Settings($cfg); |
| 381 | + $this->settings = array_replace_recursive($this->settings, $this->config->asArray()); |
401 | 382 |
|
402 | 383 | return true; |
403 | 384 | } |
@@ -1138,52 +1119,6 @@ public function selectServer(): int |
1138 | 1119 | return (int) $server; |
1139 | 1120 | } |
1140 | 1121 |
|
1141 | | - /** |
1142 | | - * Checks whether Servers configuration is valid and possibly apply fixups. |
1143 | | - */ |
1144 | | - public function checkServers(): void |
1145 | | - { |
1146 | | - // Do we have some server? |
1147 | | - if (! isset($this->settings['Servers']) || count($this->settings['Servers']) === 0) { |
1148 | | - // No server => create one with defaults |
1149 | | - $this->settings['Servers'] = [1 => $this->defaultServer]; |
1150 | | - $this->config = new Settings($this->settings); |
1151 | | - |
1152 | | - return; |
1153 | | - } |
1154 | | - |
1155 | | - // We have server(s) => apply default configuration |
1156 | | - $newServers = []; |
1157 | | - |
1158 | | - foreach ($this->settings['Servers'] as $serverIndex => $server) { |
1159 | | - // Detect wrong configuration |
1160 | | - if (! is_int($serverIndex) || $serverIndex < 1 || ! is_array($server)) { |
1161 | | - continue; |
1162 | | - } |
1163 | | - |
1164 | | - $server = array_merge($this->defaultServer, $server); |
1165 | | - |
1166 | | - // Final solution to bug #582890 |
1167 | | - // If we are using a socket connection |
1168 | | - // and there is nothing in the verbose server name |
1169 | | - // or the host field, then generate a name for the server |
1170 | | - // in the form of "Server 2", localized of course! |
1171 | | - if (empty($server['host']) && empty($server['verbose'])) { |
1172 | | - $server['verbose'] = sprintf(__('Server %d'), $serverIndex); |
1173 | | - } |
1174 | | - |
1175 | | - $newServers[$serverIndex] = $server; |
1176 | | - } |
1177 | | - |
1178 | | - if ($newServers === []) { |
1179 | | - // Ensures it has at least one valid server config. |
1180 | | - $newServers = [1 => $this->defaultServer]; |
1181 | | - } |
1182 | | - |
1183 | | - $this->settings['Servers'] = $newServers; |
1184 | | - $this->config = new Settings($this->settings); |
1185 | | - } |
1186 | | - |
1187 | 1122 | /** |
1188 | 1123 | * Return connection parameters for the database server |
1189 | 1124 | * |
|
0 commit comments