Skip to content

Commit

Permalink
Remove side effects from Config class
Browse files Browse the repository at this point in the history
Moves the side effects to the common.inc.php file.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Jan 19, 2020
1 parent ae0577a commit 33477fe
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
31 changes: 15 additions & 16 deletions libraries/classes/Config.php
Expand Up @@ -18,11 +18,6 @@
use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\Utils\HttpRequest;

/**
* Indication for error handler (see end of this file).
*/
$GLOBALS['pma_config_loading'] = false;

/**
* Configuration class
*
Expand Down Expand Up @@ -773,6 +768,8 @@ public function checkGitRevision(): void
*/
public function loadDefaults(): bool
{
global $isConfigLoading;

/** @var array<string,mixed> $cfg */
$cfg = [];
if (! @file_exists($this->default_source)) {
Expand All @@ -784,11 +781,13 @@ public function loadDefaults(): bool
if ($canUseErrorReporting) {
$oldErrorReporting = error_reporting(0);
}

ob_start();
$GLOBALS['pma_config_loading'] = true;
$isConfigLoading = true;
$eval_result = include $this->default_source;
$GLOBALS['pma_config_loading'] = false;
$isConfigLoading = false;
ob_end_clean();

if ($canUseErrorReporting) {
error_reporting($oldErrorReporting);
}
Expand Down Expand Up @@ -821,6 +820,8 @@ public function loadDefaults(): bool
*/
public function load(?string $source = null): bool
{
global $isConfigLoading;

$this->loadDefaults();

if (null !== $source) {
Expand All @@ -842,11 +843,13 @@ public function load(?string $source = null): bool
if ($canUseErrorReporting) {
$oldErrorReporting = error_reporting(0);
}

ob_start();
$GLOBALS['pma_config_loading'] = true;
$isConfigLoading = true;
$eval_result = include $this->getSource();
$GLOBALS['pma_config_loading'] = false;
$isConfigLoading = false;
ob_end_clean();

if ($canUseErrorReporting) {
error_reporting($oldErrorReporting);
}
Expand Down Expand Up @@ -1560,9 +1563,9 @@ public function issetCookie(string $cookieName): bool
*/
public static function fatalErrorHandler(): void
{
if (! isset($GLOBALS['pma_config_loading'])
|| ! $GLOBALS['pma_config_loading']
) {
global $isConfigLoading;

if (! isset($isConfigLoading) || ! $isConfigLoading) {
return;
}

Expand Down Expand Up @@ -1775,7 +1778,3 @@ public function checkServers(): void
}
}
}

if (! defined('TESTSUITE')) {
register_shutdown_function([Config::class, 'fatalErrorHandler']);
}
7 changes: 6 additions & 1 deletion libraries/common.inc.php
Expand Up @@ -51,7 +51,7 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;

global $containerBuilder, $error_handler, $PMA_Config, $server, $dbi, $lang, $cfg;
global $containerBuilder, $error_handler, $PMA_Config, $server, $dbi, $lang, $cfg, $isConfigLoading;

/**
* block attempts to directly run this script
Expand Down Expand Up @@ -127,6 +127,9 @@
/******************************************************************************/
/* parsing configuration file LABEL_parsing_config_file */

/** @var bool $isConfigLoading Indication for the error handler */
$isConfigLoading = false;

/**
* Force reading of config file, because we removed sensitive values
* in the previous iteration.
Expand All @@ -135,6 +138,8 @@
*/
$PMA_Config = $containerBuilder->get('config');

register_shutdown_function([Config::class, 'fatalErrorHandler']);

/**
* include session handling after the globals, to prevent overwriting
*/
Expand Down

0 comments on commit 33477fe

Please sign in to comment.