Skip to content

Commit 605e56b

Browse files
Merge pull request #19503 from MauricioFauth/globals-removal
Remove global variables
2 parents 17c477b + ed9dc6c commit 605e56b

108 files changed

Lines changed: 919 additions & 1927 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.

phpstan-baseline.neon

Lines changed: 93 additions & 597 deletions
Large diffs are not rendered by default.

psalm-baseline.xml

Lines changed: 88 additions & 407 deletions
Large diffs are not rendered by default.

psalm.xml

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,4 @@
3636
<plugins>
3737
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
3838
</plugins>
39-
40-
<globals>
41-
<var name="GLOBALS" type="array{
42-
asfile: bool,
43-
buffer_needed: bool,
44-
cached_affected_rows: int|numeric-string,
45-
charset: string,
46-
complete_query: string,
47-
compression: 'none'|'zip'|'gzip',
48-
conn_error: string,
49-
display_query: string,
50-
errno: int,
51-
error: bool,
52-
file_handle: resource|null,
53-
from_cookie: bool,
54-
hostname: string,
55-
import_text: string,
56-
knjenc: string,
57-
maxsize: string,
58-
memory_limit: int,
59-
old_tz: string,
60-
onfly_compression: bool,
61-
output_charset_conversion: bool,
62-
output_kanji_conversion: bool,
63-
plugin_scripts: string[],
64-
pma_auth_server: string,
65-
querytime: float|int,
66-
save_on_server: bool,
67-
SESSION_KEY: string,
68-
username: string
69-
}"/>
70-
</globals>
7139
</psalm>

resources/templates/server/privileges/login_information_fields.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
<label for="select_pred_username">{{ t('User name:') }}</label>
66
<span class="options">
77
<select name="pred_username" id="select_pred_username" title="{{ t('User name') }}">
8-
<option value="any"{{ pred_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
9-
<option value="userdefined"{{ pred_username is null or pred_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
8+
<option value="any"{{ predefined_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
9+
<option value="userdefined"{{ predefined_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
1010
</select>
1111
</span>
1212
<input type="text" spellcheck="false" name="username" id="pma_username" class="autofocus" maxlength="{{ username_length }}" title="{{ t('User name') }}"
13-
{%- if username is not empty %} value="{{ new_username is not null ? new_username : username }}"{% endif -%}
14-
{{- pred_username is null or pred_username == 'userdefined' ? ' required' }}>
13+
{%- if username is not empty %} value="{{ username }}"{% endif -%}
14+
{{- predefined_username == 'userdefined' ? ' required' }}>
1515

1616
<div id="user_exists_warning" class="hide">
1717
{{ t('An account already exists with the same username but possibly a different hostname.')|notice }}
@@ -25,17 +25,17 @@
2525
<span class="options">
2626
<select name="pred_hostname" id="select_pred_hostname" title="{{ t('Host name') }}"
2727
{{- this_host is not null and this_host != 'localhost' and this_host != '127.0.0.1' ? ' data-thishost="' ~ this_host ~ '"' }}>
28-
<option value="any"{{ pred_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
29-
<option value="localhost"{{ pred_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
28+
<option value="any"{{ predefined_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
29+
<option value="localhost"{{ predefined_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
3030
{% if this_host is not empty %}
31-
<option value="thishost"{{ pred_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
31+
<option value="thishost"{{ predefined_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
3232
{% endif %}
33-
<option value="hosttable"{{ pred_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
34-
<option value="userdefined"{{ pred_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
33+
<option value="hosttable"{{ predefined_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
34+
<option value="userdefined"{{ predefined_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
3535
</select>
3636
</span>
3737
<input type="text" name="hostname" id="pma_hostname" maxlength="{{ hostname_length }}" value="{{ hostname|default('%') }}" title="
38-
{{- t('Host name') }}"{{ pred_hostname == 'userdefined' ? ' required' }}>
38+
{{- t('Host name') }}"{{ predefined_hostname == 'userdefined' ? ' required' }}>
3939

4040
{{ show_hint(t('When Host table is used, this field is ignored and values stored in Host table are used instead.')) }}
4141
</div>

src/ConfigStorage/Relation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ public function createPmaDatabase(string $configurationStorageDbName): bool
14501450

14511451
Current::$message = Message::error($error);
14521452

1453-
if ($GLOBALS['errno'] === 1044) {
1453+
if (DatabaseInterface::$errorNumber === 1044) {
14541454
Current::$message = Message::error(sprintf(
14551455
__(
14561456
'You do not have necessary privileges to create a database named'

src/Controllers/Database/ExportController.php

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public function __construct(
3838

3939
public function __invoke(ServerRequest $request): Response
4040
{
41-
$GLOBALS['table_select'] ??= null;
42-
$GLOBALS['unlim_num_rows'] ??= null;
43-
4441
$this->pageSettings->init('Export');
4542
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
4643
$pageSettingsHtml = $this->pageSettings->getHTML();
@@ -68,10 +65,10 @@ public function __invoke(ServerRequest $request): Response
6865
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');
6966

7067
$tableNames = $this->export->getTableNames(Current::$database);
71-
$GLOBALS['num_tables'] = count($tableNames);
68+
Current::$numTables = count($tableNames);
7269

7370
// exit if no tables in db found
74-
if ($GLOBALS['num_tables'] < 1) {
71+
if (Current::$numTables < 1) {
7572
$this->response->addHTML(
7673
Message::error(__('No tables found in database.'))->getDisplay(),
7774
);
@@ -80,30 +77,26 @@ public function __invoke(ServerRequest $request): Response
8077
}
8178

8279
$selectedTable = $request->getParsedBodyParam('selected_tbl');
83-
if (! empty($selectedTable) && empty($GLOBALS['table_select'])) {
84-
$GLOBALS['table_select'] = $selectedTable;
85-
}
86-
80+
$tableSelect = $request->getParsedBodyParam('table_select');
81+
$tableStructure = $request->getParsedBodyParam('table_structure');
82+
$tableData = $request->getParsedBodyParam('table_data');
8783
$tablesForMultiValues = [];
8884

8985
foreach ($tableNames as $tableName) {
90-
$tableSelect = $request->getParsedBodyParam('table_select');
9186
if (is_array($tableSelect)) {
9287
$isChecked = $this->export->getCheckedClause($tableName, $tableSelect);
93-
} elseif (isset($GLOBALS['table_select'])) {
94-
$isChecked = $this->export->getCheckedClause($tableName, $GLOBALS['table_select']);
88+
} elseif (is_array($selectedTable)) {
89+
$isChecked = $this->export->getCheckedClause($tableName, $selectedTable);
9590
} else {
9691
$isChecked = true;
9792
}
9893

99-
$tableStructure = $request->getParsedBodyParam('table_structure');
10094
if (is_array($tableStructure)) {
10195
$structureChecked = $this->export->getCheckedClause($tableName, $tableStructure);
10296
} else {
10397
$structureChecked = $isChecked;
10498
}
10599

106-
$tableData = $request->getParsedBodyParam('table_data');
107100
if (is_array($tableData)) {
108101
$dataChecked = $this->export->getCheckedClause($tableName, $tableData);
109102
} else {
@@ -118,20 +111,18 @@ public function __invoke(ServerRequest $request): Response
118111
];
119112
}
120113

121-
if (! isset($GLOBALS['unlim_num_rows'])) {
122-
$GLOBALS['unlim_num_rows'] = 0;
123-
}
124-
125114
$isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw';
126115
if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) {
127116
$exportType = ExportType::Raw;
128117
} else {
129118
$exportType = ExportType::Database;
130119
}
131120

132-
$GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null;
121+
if ($request->has('single_table')) {
122+
Export::$singleTable = (bool) $request->getParam('single_table');
123+
}
133124

134-
$exportList = Plugins::getExport($exportType, isset($GLOBALS['single_table']));
125+
$exportList = Plugins::getExport($exportType, Export::$singleTable);
135126

136127
if ($exportList === []) {
137128
$this->response->addHTML(Message::error(
@@ -146,8 +137,8 @@ public function __invoke(ServerRequest $request): Response
146137
Current::$database,
147138
Current::$table,
148139
Current::$sqlQuery,
149-
$GLOBALS['num_tables'],
150-
$GLOBALS['unlim_num_rows'],
140+
Current::$numTables,
141+
0,
151142
$exportList,
152143
);
153144

src/Controllers/Database/ImportController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public function __construct(
3939

4040
public function __invoke(ServerRequest $request): Response
4141
{
42-
$GLOBALS['SESSION_KEY'] ??= null;
43-
4442
$this->pageSettings->init('Import');
4543
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
4644
$pageSettingsHtml = $this->pageSettings->getHTML();
@@ -67,7 +65,7 @@ public function __invoke(ServerRequest $request): Response
6765
return $this->response->response();
6866
}
6967

70-
[$GLOBALS['SESSION_KEY'], $uploadId] = Ajax::uploadProgressSetup();
68+
[$uploadId] = Ajax::uploadProgressSetup();
7169

7270
ImportSettings::$importType = 'database';
7371
$importList = Plugins::getImport();
@@ -91,7 +89,7 @@ public function __invoke(ServerRequest $request): Response
9189

9290
$charsets = Charsets::getCharsets($this->dbi, $config->selectedServer['DisableIS']);
9391

94-
$idKey = $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getIdKey();
92+
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
9593
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'database', 'db' => Current::$database];
9694

9795
$default = $request->hasQueryParam('format')
@@ -107,7 +105,7 @@ public function __invoke(ServerRequest $request): Response
107105
'page_settings_error_html' => $pageSettingsErrorHtml,
108106
'page_settings_html' => $pageSettingsHtml,
109107
'upload_id' => $uploadId,
110-
'handler' => $_SESSION[$GLOBALS['SESSION_KEY']]['handler'],
108+
'handler' => $_SESSION[Ajax::SESSION_KEY]['handler'],
111109
'hidden_inputs' => $hiddenInputs,
112110
'db' => Current::$database,
113111
'table' => Current::$table,

src/Controllers/Database/Structure/DropTableController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use PhpMyAdmin\Http\Response;
1313
use PhpMyAdmin\Http\ServerRequest;
1414
use PhpMyAdmin\Message;
15+
use PhpMyAdmin\ResponseRenderer;
1516
use PhpMyAdmin\Util;
1617
use PhpMyAdmin\Utils\ForeignKey;
1718

@@ -28,7 +29,11 @@ public function __construct(
2829

2930
public function __invoke(ServerRequest $request): Response
3031
{
31-
$GLOBALS['reload'] = $_POST['reload'] ?? $GLOBALS['reload'] ?? null;
32+
if ($request->hasBodyParam('reload')) {
33+
$reload = $request->getParsedBodyParamAsString('reload');
34+
ResponseRenderer::$reload = $reload === '1' || $reload === 'true';
35+
}
36+
3237
$multBtn = $_POST['mult_btn'] ?? '';
3338
/** @var string[] $selected */
3439
$selected = $_POST['selected'] ?? [];
@@ -55,7 +60,7 @@ public function __invoke(ServerRequest $request): Response
5560
. Util::backquote($selectedValue);
5661
}
5762

58-
$GLOBALS['reload'] = 1;
63+
ResponseRenderer::$reload = true;
5964
}
6065

6166
if (Current::$sqlQuery !== '') {

0 commit comments

Comments
 (0)