Skip to content

Commit 0f31d66

Browse files
committed
Replace $GLOBALS['cfg']['Server'] with Config::$selectedServer
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 78a33f1 commit 0f31d66

193 files changed

Lines changed: 1934 additions & 4418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libraries/classes/Config.php

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,96 @@ class Config
102102

103103
private bool $hasSelectedServer = false;
104104

105+
/**
106+
* @psalm-var array{
107+
* host: string,
108+
* port: string,
109+
* socket: string,
110+
* ssl: bool,
111+
* ssl_key: string|null,
112+
* ssl_cert: string|null,
113+
* ssl_ca: string|null,
114+
* ssl_ca_path: string|null,
115+
* ssl_ciphers: string|null,
116+
* ssl_verify: bool,
117+
* compress: bool,
118+
* controlhost: string,
119+
* controlport: string,
120+
* controluser: string,
121+
* controlpass: string,
122+
* control_socket: string|null,
123+
* control_ssl: bool|null,
124+
* control_ssl_key: string|null,
125+
* control_ssl_cert: string|null,
126+
* control_ssl_ca: string|null,
127+
* control_ssl_ca_path: string|null,
128+
* control_ssl_ciphers: string|null,
129+
* control_ssl_verify: bool|null,
130+
* control_compress: bool|null,
131+
* control_hide_connection_errors: bool|null,
132+
* auth_type: non-empty-string,
133+
* auth_http_realm: string,
134+
* user: string,
135+
* password: string,
136+
* SignonSession: string,
137+
* SignonCookieParams: array{
138+
* lifetime: int<0, max>,
139+
* path: string,
140+
* domain: string,
141+
* secure: bool,
142+
* httponly: bool,
143+
* samesite?: 'Lax'|'Strict',
144+
* },
145+
* SignonScript: string,
146+
* SignonURL: string,
147+
* LogoutURL: string,
148+
* only_db: string|string[],
149+
* hide_db: string,
150+
* verbose: string,
151+
* pmadb: string,
152+
* bookmarktable: string|false,
153+
* relation: string|false,
154+
* table_info: string|false,
155+
* table_coords: string|false,
156+
* pdf_pages: string|false,
157+
* column_info: string|false,
158+
* history: string|false,
159+
* recent: string|false,
160+
* favorite: string|false,
161+
* table_uiprefs: string|false,
162+
* tracking: string|false,
163+
* userconfig: string|false,
164+
* users: string|false,
165+
* usergroups: string|false,
166+
* navigationhiding: string|false,
167+
* savedsearches: string|false,
168+
* central_columns: string|false,
169+
* designer_settings: string|false,
170+
* export_templates: string|false,
171+
* MaxTableUiprefs: int<1, max>,
172+
* SessionTimeZone: string,
173+
* AllowRoot: bool,
174+
* AllowNoPassword: bool,
175+
* AllowDeny: array{order: ''|'deny,allow'|'allow,deny'|'explicit', rules: string[]},
176+
* DisableIS: bool,
177+
* tracking_version_auto_create: bool,
178+
* tracking_default_statements: string,
179+
* tracking_add_drop_view: bool,
180+
* tracking_add_drop_table: bool,
181+
* tracking_add_drop_database: bool,
182+
* hide_connection_errors: bool,
183+
* }
184+
*/
185+
public array $selectedServer;
186+
105187
public function __construct()
106188
{
107189
$this->config = new Settings([]);
108190
$config = $this->config->asArray();
109191
$this->default = $config;
110192
$this->settings = $config;
111193
$this->baseSettings = $config;
194+
$this->selectedServer = (new Server())->asArray();
112195
}
113196

114197
public static function getInstance(): self
@@ -430,6 +513,11 @@ public function loadUserPreferences(ThemeManager $themeManager, bool $isMinimumC
430513
$this->set('user_preferences', $_SESSION['cache'][$cacheKey]['userprefs_type']);
431514
$this->set('user_preferences_mtime', $_SESSION['cache'][$cacheKey]['userprefs_mtime']);
432515

516+
if (isset($configData['Server']) && is_array($configData['Server'])) {
517+
$serverConfig = array_replace_recursive($this->selectedServer, $configData['Server']);
518+
$this->selectedServer = (new Server($serverConfig))->asArray();
519+
}
520+
433521
// load config array
434522
$this->settings = array_replace_recursive($this->settings, $configData);
435523
$GLOBALS['cfg'] = array_replace_recursive($GLOBALS['cfg'], $configData);
@@ -1077,14 +1165,17 @@ public function selectServer(mixed $serverParamFromRequest): int
10771165
*/
10781166
if (isset($this->config->Servers[$serverNumber])) {
10791167
$this->hasSelectedServer = true;
1080-
$this->settings['Server'] = $this->config->Servers[$serverNumber]->asArray();
1168+
$this->selectedServer = $this->config->Servers[$serverNumber]->asArray();
1169+
$this->settings['Server'] = $this->selectedServer;
10811170
} elseif (isset($this->config->Servers[$this->config->ServerDefault])) {
10821171
$this->hasSelectedServer = true;
10831172
$serverNumber = $this->config->ServerDefault;
1084-
$this->settings['Server'] = $this->config->Servers[$this->config->ServerDefault]->asArray();
1173+
$this->selectedServer = $this->config->Servers[$this->config->ServerDefault]->asArray();
1174+
$this->settings['Server'] = $this->selectedServer;
10851175
} else {
10861176
$this->hasSelectedServer = false;
10871177
$serverNumber = 0;
1178+
$this->selectedServer = (new Server())->asArray();
10881179
$this->settings['Server'] = [];
10891180
}
10901181

libraries/classes/Config/Settings/Server.php

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,86 @@ public function __construct(array $server = [])
887887
$this->hideConnectionErrors = $this->setHideConnectionErrors($server);
888888
}
889889

890-
/** @return array<string, string|bool|int|array<mixed>|null> */
890+
/**
891+
* @psalm-return array{
892+
* host: string,
893+
* port: string,
894+
* socket: string,
895+
* ssl: bool,
896+
* ssl_key: string|null,
897+
* ssl_cert: string|null,
898+
* ssl_ca: string|null,
899+
* ssl_ca_path: string|null,
900+
* ssl_ciphers: string|null,
901+
* ssl_verify: bool,
902+
* compress: bool,
903+
* controlhost: string,
904+
* controlport: string,
905+
* controluser: string,
906+
* controlpass: string,
907+
* control_socket: string|null,
908+
* control_ssl: bool|null,
909+
* control_ssl_key: string|null,
910+
* control_ssl_cert: string|null,
911+
* control_ssl_ca: string|null,
912+
* control_ssl_ca_path: string|null,
913+
* control_ssl_ciphers: string|null,
914+
* control_ssl_verify: bool|null,
915+
* control_compress: bool|null,
916+
* control_hide_connection_errors: bool|null,
917+
* auth_type: non-empty-string,
918+
* auth_http_realm: string,
919+
* user: string,
920+
* password: string,
921+
* SignonSession: string,
922+
* SignonCookieParams: array{
923+
* lifetime: int<0, max>,
924+
* path: string,
925+
* domain: string,
926+
* secure: bool,
927+
* httponly: bool,
928+
* samesite?: 'Lax'|'Strict',
929+
* },
930+
* SignonScript: string,
931+
* SignonURL: string,
932+
* LogoutURL: string,
933+
* only_db: string|string[],
934+
* hide_db: string,
935+
* verbose: string,
936+
* pmadb: string,
937+
* bookmarktable: string|false,
938+
* relation: string|false,
939+
* table_info: string|false,
940+
* table_coords: string|false,
941+
* pdf_pages: string|false,
942+
* column_info: string|false,
943+
* history: string|false,
944+
* recent: string|false,
945+
* favorite: string|false,
946+
* table_uiprefs: string|false,
947+
* tracking: string|false,
948+
* userconfig: string|false,
949+
* users: string|false,
950+
* usergroups: string|false,
951+
* navigationhiding: string|false,
952+
* savedsearches: string|false,
953+
* central_columns: string|false,
954+
* designer_settings: string|false,
955+
* export_templates: string|false,
956+
* MaxTableUiprefs: int<1, max>,
957+
* SessionTimeZone: string,
958+
* AllowRoot: bool,
959+
* AllowNoPassword: bool,
960+
* AllowDeny: array{order: ''|'deny,allow'|'allow,deny'|'explicit', rules: string[]},
961+
* DisableIS: bool,
962+
* tracking_version_auto_create: bool,
963+
* tracking_default_statements: string,
964+
* tracking_add_drop_view: bool,
965+
* tracking_add_drop_table: bool,
966+
* tracking_add_drop_database: bool,
967+
* hide_connection_errors: bool,
968+
* }
969+
*/
891970
public function asArray(): array
892971
{
893972
return [

0 commit comments

Comments
 (0)