Skip to content

Commit b783681

Browse files
committed
Remove Config::fatalErrorHandler() method
Since there is an error handler register already, error_get_last is always empty. Also adds a try-catch to catch exceptions from the config file. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent ad5e2ab commit b783681

3 files changed

Lines changed: 10 additions & 49 deletions

File tree

libraries/classes/Common.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
use function mb_strrpos;
4141
use function mb_substr;
4242
use function ob_start;
43-
use function register_shutdown_function;
4443
use function restore_error_handler;
4544
use function session_id;
4645
use function sprintf;
@@ -87,7 +86,6 @@ final class Common
8786
public static function run(bool $isSetupPage = false): void
8887
{
8988
$GLOBALS['lang'] = $GLOBALS['lang'] ?? null;
90-
$GLOBALS['isConfigLoading'] = $GLOBALS['isConfigLoading'] ?? null;
9189
$GLOBALS['auth_plugin'] = $GLOBALS['auth_plugin'] ?? null;
9290
$GLOBALS['theme'] = $GLOBALS['theme'] ?? null;
9391
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
@@ -115,13 +113,6 @@ public static function run(bool $isSetupPage = false): void
115113
self::configurePhpSettings();
116114
self::cleanupPathInfo();
117115

118-
/* parsing configuration file LABEL_parsing_config_file */
119-
120-
/** Indication for the error handler */
121-
$GLOBALS['isConfigLoading'] = false;
122-
123-
register_shutdown_function([Config::class, 'fatalErrorHandler']);
124-
125116
/** @var Config $config */
126117
$config = $GLOBALS['containerBuilder']->get('config');
127118
$GLOBALS['config'] = $config;

libraries/classes/Config.php

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Config\Settings;
88
use PhpMyAdmin\Exceptions\ConfigException;
9+
use Throwable;
910

1011
use function __;
1112
use function array_filter;
@@ -14,7 +15,6 @@
1415
use function array_slice;
1516
use function count;
1617
use function defined;
17-
use function error_get_last;
1818
use function error_reporting;
1919
use function explode;
2020
use function fclose;
@@ -348,8 +348,6 @@ public function loadDefaults(): void
348348
*/
349349
public function load(?string $source = null): bool
350350
{
351-
$GLOBALS['isConfigLoading'] = $GLOBALS['isConfigLoading'] ?? null;
352-
353351
$this->loadDefaults();
354352

355353
if ($source !== null) {
@@ -373,10 +371,13 @@ public function load(?string $source = null): bool
373371
}
374372

375373
ob_start();
376-
$GLOBALS['isConfigLoading'] = true;
377-
/** @psalm-suppress UnresolvableInclude */
378-
$eval_result = include $this->getSource();
379-
$GLOBALS['isConfigLoading'] = false;
374+
try {
375+
/** @psalm-suppress UnresolvableInclude */
376+
$eval_result = include $this->getSource();
377+
} catch (Throwable $exception) {
378+
throw new ConfigException('Failed to load phpMyAdmin configuration.');
379+
}
380+
380381
ob_end_clean();
381382

382383
if ($canUseErrorReporting) {
@@ -1028,35 +1029,6 @@ public function issetCookie(string $cookieName): bool
10281029
return isset($_COOKIE[$this->getCookieName($cookieName)]);
10291030
}
10301031

1031-
/**
1032-
* Error handler to catch fatal errors when loading configuration
1033-
* file
1034-
*/
1035-
public static function fatalErrorHandler(): void
1036-
{
1037-
if (! isset($GLOBALS['isConfigLoading']) || ! $GLOBALS['isConfigLoading']) {
1038-
return;
1039-
}
1040-
1041-
$error = error_get_last();
1042-
if ($error === null) {
1043-
return;
1044-
}
1045-
1046-
echo (new Template())->render('error/generic', [
1047-
'lang' => $GLOBALS['lang'] ?? 'en',
1048-
'dir' => $GLOBALS['text_dir'] ?? 'ltr',
1049-
'error_message' => sprintf(
1050-
'Failed to load phpMyAdmin configuration (%s:%s): %s',
1051-
Error::relPath($error['file']),
1052-
$error['line'],
1053-
$error['message']
1054-
),
1055-
]);
1056-
1057-
exit;
1058-
}
1059-
10601032
/**
10611033
* Wrapper for footer/header rendering
10621034
*

psalm-baseline.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,9 @@
222222
<code>$GLOBALS['cfg']['MysqlMinVersion']['internal']</code>
223223
<code>$GLOBALS['cfg']['Server']['user']</code>
224224
</MixedArrayAccess>
225-
<MixedAssignment occurrences="7">
225+
<MixedAssignment occurrences="6">
226226
<code>$GLOBALS['auth_plugin']</code>
227227
<code>$GLOBALS['back']</code>
228-
<code>$GLOBALS['isConfigLoading']</code>
229228
<code>$GLOBALS['theme']</code>
230229
<code>$controlLink</code>
231230
<code>$sqlDelimiter</code>
@@ -296,9 +295,8 @@
296295
<code>$this-&gt;settings['Servers'][$server]</code>
297296
<code>$this-&gt;settings['Servers'][$this-&gt;settings['ServerDefault']]</code>
298297
</MixedArrayOffset>
299-
<MixedAssignment occurrences="28">
298+
<MixedAssignment occurrences="27">
300299
<code>$GLOBALS['cfg']['LoginCookieValidity']</code>
301-
<code>$GLOBALS['isConfigLoading']</code>
302300
<code>$collation_connection</code>
303301
<code>$config_data</code>
304302
<code>$default_value</code>

0 commit comments

Comments
 (0)