Refactor config file loading

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-01-01 22:13:43 +00:00
parent be55c6c9a7
commit e994e2db58
3 changed files with 7 additions and 45 deletions

View File

@ -213,7 +213,6 @@
<code><![CDATA[$configData]]></code>
<code><![CDATA[$defaultValue]]></code>
<code><![CDATA[$defaultValue]]></code>
<code><![CDATA[$evalResult]]></code>
<code><![CDATA[$path]]></code>
<code><![CDATA[$prefsType]]></code>
<code><![CDATA[$prefsType]]></code>

View File

@ -21,7 +21,6 @@ use function array_replace_recursive;
use function array_slice;
use function count;
use function defined;
use function error_reporting;
use function explode;
use function fclose;
use function file_exists;
@ -92,8 +91,6 @@ class Config
/** @var int source modification time */
public int $sourceMtime = 0;
public bool $errorConfigFile = false;
private bool $isHttps = false;
public Settings $config;
@ -357,36 +354,21 @@ class Config
/** @var mixed $cfg */
$cfg = [];
/**
* Parses the configuration file, we throw away any errors or
* output.
*/
$canUseErrorReporting = function_exists('error_reporting');
$oldErrorReporting = null;
if ($canUseErrorReporting) {
$oldErrorReporting = error_reporting(0);
}
ob_start();
try {
/** @psalm-suppress UnresolvableInclude */
$evalResult = include $this->getSource();
/**
* Suppress any warnings generated by require or inside the included file
*
* @psalm-suppress UnresolvableInclude
*/
@require $this->getSource();
} catch (Throwable) {
throw new ConfigException('Failed to load phpMyAdmin configuration.');
}
ob_end_clean();
if ($canUseErrorReporting) {
error_reporting($oldErrorReporting);
}
if ($evalResult === false) {
$this->errorConfigFile = true;
} else {
$this->errorConfigFile = false;
$this->sourceMtime = (int) filemtime($this->getSource());
}
$this->sourceMtime = (int) filemtime($this->getSource());
if (is_array($cfg)) {
$this->config = new Settings($cfg);
@ -656,24 +638,6 @@ class Config
throw new ConfigException(__('Wrong permissions on configuration file, should not be world writable!'));
}
/**
* Checks for errors (must be called after config.inc.php has been merged)
*
* @throws ConfigException
*/
public function checkErrors(): void
{
if (! $this->errorConfigFile) {
return;
}
$error = '[strong]' . __('Failed to read configuration file!') . '[/strong]'
. '[br][br]'
. __('This usually means there is a syntax error in it.');
throw new ConfigException(Sanitize::convertBBCode($error));
}
/**
* returns specific config setting
*

View File

@ -31,7 +31,6 @@ final class ConfigErrorAndPermissionChecking implements MiddlewareInterface
{
try {
$this->config->checkPermissions();
$this->config->checkErrors();
} catch (ConfigException $exception) {
$response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR);