Refactored ConfigFile class so that it is no longer a singleton

Fixes bug #4123 Double config including
This commit is contained in:
Piotr Przybylski 2013-11-03 12:54:20 +01:00
parent a75b5a6e2c
commit a67e41a646
29 changed files with 443 additions and 740 deletions

View File

@ -48,6 +48,7 @@ phpMyAdmin - ChangeLog
+ Added an Error Reporting Component
+ Javascript files are no longer uglified
- bug #4145 Config screen fails to validate MemoryLimit = -1 (new default)
- bug #4123 Double config including
4.0.10.0 (not yet released)
- bug #4150 Clicking database name in query window opens a new tab

View File

@ -32,6 +32,11 @@ class PMA_Config
*/
var $default = array();
/**
* @var array configuration settings, without user preferences applied
*/
var $base_settings = array();
/**
* @var array configuration settings
*/
@ -93,6 +98,8 @@ class PMA_Config
$this->checkSystem();
$this->isHttps();
$this->base_settings = $this->settings;
}
/**

View File

@ -18,13 +18,7 @@ class ConfigFile
* Stores default PMA config from config.default.php
* @var array
*/
private $_cfg;
/**
* Stores original PMA_Config object, not modified by user preferences
* @var PMA_Config
*/
private $_orgCfgObject;
private $_defaultCfg;
/**
* Stores allowed values for non-standard fields
@ -32,6 +26,18 @@ class ConfigFile
*/
private $_cfgDb;
/**
* Stores original PMA config, not modified by user preferences
* @var PMA_Config
*/
private $_baseCfg;
/**
* Whether we are currently working in PMA Setup context
* @var bool
*/
private $_isInSetup;
/**
* Keys which will be always written to config file
* @var array
@ -65,25 +71,18 @@ class ConfigFile
private $_flattenArrayResult;
/**
* ConfigFile instance
* @var ConfigFile
*/
private static $_instance;
/**
* Private constructor, use {@link getInstance()}
* Constructor
*
* @param array $base_config base configuration read from {@link PMA_Config::$base_config},
* use only when not in PMA Setup
*/
private function __construct()
public function __construct(array $base_config = null)
{
// load default config values
$cfg = &$this->_cfg;
$cfg = &$this->_defaultCfg;
include './libraries/config.default.php';
$cfg['fontsize'] = '82%';
// create PMA_Config to read config.inc.php values
$this->_orgCfgObject = new PMA_Config(CONFIG_FILE);
// load additional config information
$cfg_db = &$this->_cfgDb;
include './libraries/config.values.php';
@ -95,35 +94,14 @@ class ConfigFile
}
}
$this->_baseCfg = $base_config;
$this->_isInSetup = is_null($base_config);
$this->_id = 'ConfigFile' . $GLOBALS['server'];
if (!isset($_SESSION[$this->_id])) {
$_SESSION[$this->_id] = array();
}
}
/**
* Returns class instance
*
* @return ConfigFile
*/
public static function getInstance()
{
if (is_null(self::$_instance)) {
self::$_instance = new ConfigFile();
}
return self::$_instance;
}
/**
* Returns PMA_Config without user preferences applied
*
* @return PMA_Config
*/
public function getOrgConfigObj()
{
return $this->_orgCfgObject;
}
/**
* Sets names of config options which will be placed in config file even if
* they are set to their default values (use only full paths)
@ -132,7 +110,7 @@ class ConfigFile
*
* @return void
*/
public function setPersistKeys($keys)
public function setPersistKeys(array $keys)
{
// checking key presence is much faster than searching so move values
// to keys
@ -225,21 +203,25 @@ class ConfigFile
) {
return;
}
// remove if the path isn't protected and it's empty or has a default
// value
// if the path isn't protected it may be removed
if (!isset($this->_persistKeys[$canonical_path])) {
$default_value = $this->getDefault($canonical_path);
// we need original config values not overwritten by user
// preferences to allow for overwriting options set in
// config.inc.php with default values
$instance_default_value = PMA_arrayRead(
$canonical_path,
$this->_orgCfgObject->settings
);
if (($value === $default_value && (defined('PMA_SETUP')
|| $instance_default_value === $default_value))
|| (empty($value) && empty($default_value) && (defined('PMA_SETUP')))
) {
$remove_path = $value === $default_value;
if ($this->_isInSetup) {
// remove if it has a default value or is empty
$remove_path = $remove_path || (empty($value) && empty($default_value));
} else {
// get original config values not overwritten by user
// preferences to allow for overwriting options set in
// config.inc.php with default values
$instance_default_value = PMA_arrayRead(
$canonical_path,
$this->_baseCfg
);
// remove if it has a default value and base config (config.inc.php) uses default value
$remove_path = $remove_path && ($instance_default_value === $default_value);
}
if ($remove_path) {
PMA_arrayRemove($path, $_SESSION[$this->_id]);
return;
}
@ -277,7 +259,7 @@ class ConfigFile
public function getFlatDefaultConfig()
{
$this->_flattenArrayResult = array();
array_walk($this->_cfg, array($this, '_flattenArray'), '');
array_walk($this->_defaultCfg, array($this, '_flattenArray'), '');
$flat_cfg = $this->_flattenArrayResult;
$this->_flattenArrayResult = null;
return $flat_cfg;
@ -335,7 +317,7 @@ class ConfigFile
*/
public function getDefault($canonical_path, $default = null)
{
return PMA_arrayRead($canonical_path, $this->_cfg, $default);
return PMA_arrayRead($canonical_path, $this->_defaultCfg, $default);
}
/**
@ -481,7 +463,7 @@ class ConfigFile
unset($_SESSION[$this->_id]['Servers'][$last_server]);
if (isset($_SESSION[$this->_id]['ServerDefault'])
&& $_SESSION[$this->_id]['ServerDefault'] >= 0
&& $_SESSION[$this->_id]['ServerDefault'] == $last_server
) {
unset($_SESSION[$this->_id]['ServerDefault']);
}
@ -511,8 +493,10 @@ class ConfigFile
{
$c = $_SESSION[$this->_id];
foreach ($this->_cfgUpdateReadMapping as $map_to => $map_from) {
PMA_arrayWrite($map_to, $c, PMA_arrayRead($map_from, $c));
PMA_arrayRemove($map_from, $c);
if (PMA_arrayKeyExists($map_to, $c)) {
PMA_arrayWrite($map_to, $c, PMA_arrayRead($map_from, $c));
PMA_arrayRemove($map_from, $c);
}
}
return $c;
}
@ -534,7 +518,7 @@ class ConfigFile
array_keys($c)
);
foreach ($persistKeys as $k) {
$c[$k] = $this->getDefault($k);
$c[$k] = $this->getDefault($this->getCanonicalPath($k));
}
foreach ($this->_cfgUpdateReadMapping as $map_to => $map_from) {

View File

@ -44,16 +44,24 @@ class Form
*/
private $_fieldsTypes;
/**
* ConfigFile instance
* @var ConfigFile
*/
private $_configFile;
/**
* Constructor, reads default config values
*
* @param string $form_name Form name
* @param array $form Form data
* @param ConfigFile $cf Config file instance
* @param int $index arbitrary index, stored in Form::$index
*/
public function __construct($form_name, array $form, $index = null)
public function __construct($form_name, array $form, ConfigFile $cf, $index = null)
{
$this->index = $index;
$this->_configFile = $cf;
$this->loadForm($form_name, $form);
}
@ -81,7 +89,7 @@ class Form
*/
public function getOptionValueList($option_path)
{
$value = ConfigFile::getInstance()->getDbEntry($option_path);
$value = $this->_configFile->getDbEntry($option_path);
if ($value === null) {
trigger_error("$option_path - select options not defined", E_USER_ERROR);
return array();
@ -175,7 +183,7 @@ class Form
*/
protected function readTypes()
{
$cf = ConfigFile::getInstance();
$cf = $this->_configFile;
foreach ($this->fields as $name => $path) {
if (strpos($name, ':group:') === 0) {
$this->_fieldsTypes[$name] = 'group';

View File

@ -27,6 +27,12 @@ require_once './libraries/js_escape.lib.php';
*/
class FormDisplay
{
/**
* ConfigFile instance
* @var ConfigFile
*/
private $_configFile;
/**
* Form list
* @var Form[]
@ -81,8 +87,10 @@ class FormDisplay
/**
* Constructor
*
* @param ConfigFile $cf Config file instance
*/
public function __construct()
public function __construct(ConfigFile $cf)
{
$this->_jsLangStrings = array(
'error_nan_p' => __('Not a positive number'),
@ -90,8 +98,19 @@ class FormDisplay
'error_incorrect_port' => __('Not a valid port number'),
'error_invalid_value' => __('Incorrect value'),
'error_value_lte' => __('Value must be equal or lower than %s'));
$this->_configFile = $cf;
// initialize validators
PMA_Validator::getValidators();
PMA_Validator::getValidators($this->_configFile);
}
/**
* Returns {@link ConfigFile} associated with this instance
*
* @return ConfigFile
*/
public function getConfigFile()
{
return $this->_configFile;
}
/**
@ -105,7 +124,7 @@ class FormDisplay
*/
public function registerForm($form_name, array $form, $server_id = null)
{
$this->_forms[$form_name] = new Form($form_name, $form, $server_id);
$this->_forms[$form_name] = new Form($form_name, $form, $this->_configFile, $server_id);
$this->_isValidated = false;
foreach ($this->_forms[$form_name]->fields as $path) {
$work_path = $server_id === null
@ -149,7 +168,6 @@ class FormDisplay
return;
}
$cf = ConfigFile::getInstance();
$paths = array();
$values = array();
foreach ($this->_forms as $form) {
@ -158,13 +176,13 @@ class FormDisplay
// collect values and paths
foreach ($form->fields as $path) {
$work_path = array_search($path, $this->_systemPaths);
$values[$path] = $cf->getValue($work_path);
$values[$path] = $this->_configFile->getValue($work_path);
$paths[] = $path;
}
}
// run validation
$errors = PMA_Validator::validate($paths, $values, false);
$errors = PMA_Validator::validate($this->_configFile, $paths, $values, false);
// change error keys from canonical paths to work paths
if (is_array($errors) && count($errors) > 0) {
@ -198,7 +216,7 @@ class FormDisplay
$js = array();
$js_default = array();
$tabbed_form = $tabbed_form && (count($this->_forms) > 1);
$validators = PMA_Validator::getValidators();
$validators = PMA_Validator::getValidators($this->_configFile);
PMA_displayFormTop();
@ -315,9 +333,8 @@ class FormDisplay
$name = PMA_langName($system_path);
$description = PMA_langName($system_path, 'desc', '');
$cf = ConfigFile::getInstance();
$value = $cf->get($work_path);
$value_default = $cf->getDefault($system_path);
$value = $this->_configFile->get($work_path);
$value_default = $this->_configFile->getDefault($system_path);
$value_is_default = false;
if ($value === null || $value === $value_default) {
$value = $value_default;
@ -456,7 +473,7 @@ class FormDisplay
return;
}
$cf = ConfigFile::getInstance();
$cf = $this->_configFile;
foreach (array_keys($this->_errors) as $work_path) {
if (!isset($this->_systemPaths[$work_path])) {
continue;
@ -508,7 +525,6 @@ class FormDisplay
public function save($forms, $allow_partial_save = true)
{
$result = true;
$cf = ConfigFile::getInstance();
$forms = (array) $forms;
$values = array();
@ -528,7 +544,7 @@ class FormDisplay
}
// get current server id
$change_index = $form->index === 0
? $cf->getServerCount() + 1
? $this->_configFile->getServerCount() + 1
: false;
// grab POST values
foreach ($form->fields as $field => $system_path) {
@ -646,10 +662,10 @@ class FormDisplay
}
$values[$path] = $proxies;
}
$cf->set($work_path, $values[$path], $path);
$this->_configFile->set($work_path, $values[$path], $path);
}
if ($is_setup_script) {
$cf->set(
$this->_configFile->set(
'UserprefsDisallow',
array_keys($this->_userprefsDisallow)
);
@ -744,7 +760,7 @@ class FormDisplay
$this->_userprefsKeys = array_flip(PMA_readUserprefsFieldNames());
// read real config for user preferences display
$userprefs_disallow = defined('PMA_SETUP')
? ConfigFile::getInstance()->get('UserprefsDisallow', array())
? $this->_configFile->get('UserprefsDisallow', array())
: $GLOBALS['cfg']['UserprefsDisallow'];
$this->_userprefsDisallow = array_flip($userprefs_disallow);
}

View File

@ -25,21 +25,20 @@ class PMA_Validator
/**
* Returns validator list
*
* @param ConfigFile $cf Config file instance
* @return array
*/
public static function getValidators()
public static function getValidators(ConfigFile $cf)
{
static $validators = null;
if ($validators === null) {
$cf = ConfigFile::getInstance();
$validators = $cf->getDbEntry('_validators', array());
if (!defined('PMA_SETUP')) {
// not in setup script: load additional validators for user
// preferences we need original config values not overwritten
// by user preferences, creating a new PMA_Config instance is a
// better idea than hacking into its code
$org_cfg = $cf->getOrgConfigObj();
$uvs = $cf->getDbEntry('_userValidators', array());
foreach ($uvs as $field => $uv_list) {
$uv_list = (array)$uv_list;
@ -50,7 +49,7 @@ class PMA_Validator
for ($i = 1; $i < count($uv); $i++) {
if (substr($uv[$i], 0, 6) == 'value:') {
$uv[$i] = PMA_arrayRead(
substr($uv[$i], 6), $org_cfg->settings
substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings
);
}
}
@ -73,6 +72,7 @@ class PMA_Validator
* cleanup in HTML documen
* o false - when no validators match name(s) given by $validator_id
*
* @param ConfigFile $cf Config file instance
* @param string|array $validator_id ID of validator(s) to run
* @param array &$values Values to validate
* @param bool $isPostSource tells whether $values are directly from
@ -80,13 +80,12 @@ class PMA_Validator
*
* @return bool|array
*/
public static function validate($validator_id, &$values, $isPostSource)
public static function validate(ConfigFile $cf, $validator_id, &$values, $isPostSource)
{
// find validators
$validator_id = (array) $validator_id;
$validators = static::getValidators();
$validators = static::getValidators($cf);
$vids = array();
$cf = ConfigFile::getInstance();
foreach ($validator_id as &$vid) {
$vid = $cf->getCanonicalPath($vid);
if (isset($validators[$vid])) {

View File

@ -654,6 +654,28 @@ function PMA_downloadHeader($filename, $mimetype, $length = 0, $no_cache = true)
}
}
/**
* Checks whether element given by $path exists in $array.
* $path is a string describing position of an element in an associative array,
* eg. Servers/1/host refers to $array[Servers][1][host]
*
* @param string $path path in the arry
* @param array $array the array
*
* @return mixed array element or $default
*/
function PMA_arrayKeyExists($path, $array)
{
$keys = explode('/', $path);
$value =& $array;
foreach ($keys as $key) {
if (! isset($value[$key])) {
return false;
}
$value =& $value[$key];
}
return true;
}
/**
* Returns value of an element in $array given by $path.

View File

@ -47,7 +47,7 @@ if (!empty($_GET['saved'])) {
}
/* debug code
$arr = ConfigFile::getInstance()->getConfigArray();
$arr = $cf->getConfigArray();
$arr2 = array();
foreach ($arr as $k => $v) {
$arr2[] = "<b>$k</b> " . var_export($v, true);

View File

@ -12,12 +12,12 @@ if (! defined('PHPMYADMIN')) {
/**
* Common initialization for user preferences modification pages
*
* @param ConfigFile $cf Config file instance
* @return void
*/
function PMA_userprefsPageInit()
function PMA_userprefsPageInit(ConfigFile $cf)
{
$forms_all_keys = PMA_readUserprefsFieldNames($GLOBALS['forms']);
$cf = ConfigFile::getInstance();
$cf->resetConfigData(); // start with a clean instance
$cf->setAllowedKeys($forms_all_keys);
$cf->setCfgUpdateReadMapping(

View File

@ -18,7 +18,8 @@ require_once 'libraries/config/Form.class.php';
require_once 'libraries/config/FormDisplay.class.php';
require 'libraries/config/user_preferences.forms.php';
PMA_userprefsPageInit();
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
PMA_userprefsPageInit($cf);
// handle form processing
@ -28,7 +29,7 @@ if (! isset($forms[$form_param])) {
$form_param = array_shift($forms_keys);
}
$form_display = new FormDisplay();
$form_display = new FormDisplay($cf);
foreach ($forms[$form_param] as $form_name => $form) {
// skip Developer form if no setting is available
if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) {
@ -52,7 +53,7 @@ if (isset($_POST['revert'])) {
$error = null;
if ($form_display->process(false) && !$form_display->hasErrors()) {
// save settings
$result = PMA_saveUserprefs(ConfigFile::getInstance()->getConfigArray());
$result = PMA_saveUserprefs($cf->getConfigArray());
if ($result === true) {
// reload config
$GLOBALS['PMA_Config']->loadUserPreferences();

View File

@ -18,7 +18,8 @@ require_once 'libraries/config/Form.class.php';
require_once 'libraries/config/FormDisplay.class.php';
require 'libraries/config/user_preferences.forms.php';
PMA_userprefsPageInit();
$cf = new ConfigFile($GLOBALS['PMA_Config']->base_settings);
PMA_userprefsPageInit($cf);
$error = '';
if (isset($_POST['submit_export'])
@ -82,13 +83,12 @@ if (isset($_POST['submit_export'])
} else {
// sanitize input values: treat them as though
// they came from HTTP POST request
$form_display = new FormDisplay();
$form_display = new FormDisplay($cf);
foreach ($forms as $formset_id => $formset) {
foreach ($formset as $form_name => $form) {
$form_display->registerForm($formset_id . ': ' . $form_name, $form);
}
}
$cf = ConfigFile::getInstance();
$new_config = $cf->getFlatDefaultConfig();
if (!empty($_POST['import_merge'])) {
$new_config = array_merge($new_config, $cf->getConfigArray());
@ -238,7 +238,7 @@ PMA_printJsValue("PMA_messages['strSavedOn']", __('Saved on: @DATE@'));
<h2><?php echo __('Import') ?></h2>
<form class="group-cnt prefs-form disableAjax" name="prefs_import" action="prefs_manage.php" method="post" enctype="multipart/form-data">
<?php
echo PMA_Util::generateHiddenMaxFileSize($max_upload_size) . "\n";
echo PMA_Util::generateHiddenMaxFileSize($GLOBALS['max_upload_size']) . "\n";
echo PMA_URL_getHiddenInputs() . "\n";
?>
<input type="hidden" name="json" value="" />

View File

@ -16,10 +16,10 @@ require_once './setup/lib/ConfigGenerator.class.php';
require './libraries/config/setup.forms.php';
$form_display = new FormDisplay();
$form_display = new FormDisplay($GLOBALS['ConfigFile']);
$form_display->registerForm('_config.php', $forms['_config.php']);
$form_display->save('_config.php');
$config_file_path = ConfigFile::getInstance()->getFilePath();
$config_file_path = $GLOBALS['ConfigFile']->getFilePath();
if (isset($_POST['eol'])) {
$_SESSION['eol'] = ($_POST['eol'] == 'unix') ? 'unix' : 'win';
@ -29,7 +29,7 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
//
// Clear current config and return to main page
//
ConfigFile::getInstance()->resetConfigData();
$GLOBALS['ConfigFile']->resetConfigData();
// drop post data
header('HTTP/1.1 303 See Other');
header('Location: index.php');
@ -39,13 +39,13 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
// Output generated config file
//
PMA_downloadHeader('config.inc.php', 'text/plain');
echo ConfigGenerator::getConfigFile();
echo ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']);
exit;
} elseif (PMA_ifSetOr($_POST['submit_save'], '')) {
//
// Save generated config file on the server
//
file_put_contents($config_file_path, ConfigGenerator::getConfigFile());
file_put_contents($config_file_path, ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']));
header('HTTP/1.1 303 See Other');
header('Location: index.php?action_done=config_saved');
exit;
@ -55,7 +55,7 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
//
$cfg = array();
include_once $config_file_path;
ConfigFile::getInstance()->setConfigData($cfg);
$GLOBALS['ConfigFile']->setConfigData($cfg);
header('HTTP/1.1 303 See Other');
header('Location: index.php');
exit;

View File

@ -26,12 +26,12 @@ echo '<h2>' . __('Configuration file') . '</h2>';
PMA_displayFormTop('config.php');
echo '<input type="hidden" name="eol" value="'
. htmlspecialchars(PMA_ifSetOr($_GET['eol'], 'unix')) . '" />';
PMA_displayFieldsetTop('', '', null, array('class' => 'simple'));
PMA_displayFieldsetTop('config.inc.php', '', null, array('class' => 'simple'));
echo '<tr>';
echo '<td>';
echo '<textarea cols="50" rows="20" name="textconfig" '
. 'id="textconfig" spellcheck="false">';
echo htmlspecialchars(ConfigGenerator::getConfigFile());
echo htmlspecialchars(ConfigGenerator::getConfigFile($GLOBALS['ConfigFile']));
echo '</textarea>';
echo '</td>';
echo '</tr>';

View File

@ -28,7 +28,7 @@ if (! isset($forms[$formset_id])) {
if (isset($GLOBALS['strConfigFormset_' . $formset_id])) {
echo '<h2>' . $GLOBALS['strConfigFormset_' . $formset_id] . '</h2>';
}
$form_display = new FormDisplay();
$form_display = new FormDisplay($GLOBALS['ConfigFile']);
foreach ($forms[$formset_id] as $form_name => $form) {
$form_display->registerForm($form_name, $form);
}

View File

@ -21,7 +21,7 @@ require_once './setup/lib/index.lib.php';
$all_languages = PMA_langList();
uasort($all_languages, 'PMA_languageCmp');
$cf = ConfigFile::getInstance();
$cf = $GLOBALS['ConfigFile'];
$separator = PMA_URL_getArgSeparator('html');
// message handling
@ -211,7 +211,7 @@ echo '<fieldset class="simple"><legend>' . __('Configuration file') . '</legend>
//
// Display config file settings and load/save form
//
$form_display = new FormDisplay();
$form_display = new FormDisplay($cf);
PMA_displayFormTop('config.php');
echo '<table width="100%" cellspacing="0">';

View File

@ -22,7 +22,7 @@ require './libraries/config/setup.forms.php';
$mode = filter_input(INPUT_GET, 'mode');
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
$cf = ConfigFile::getInstance();
$cf = $GLOBALS['ConfigFile'];
$server_exists = !empty($id) && $cf->get("Servers/$id") !== null;
if ($mode == 'edit' && $server_exists) {
@ -42,7 +42,7 @@ if ($mode == 'edit' && $server_exists) {
if (isset($page_title)) {
echo '<h2>' . $page_title . '</h2>';
}
$form_display = new FormDisplay();
$form_display = new FormDisplay($cf);
foreach ($forms['Servers'] as $form_name => $form) {
$form_display->registerForm($form_name, $form, $id);
}

View File

@ -16,12 +16,11 @@ class ConfigGenerator
/**
* Creates config file
*
* @param ConfigFile $cf Config file instance
* @return string
*/
public static function getConfigFile()
public static function getConfigFile(ConfigFile $cf)
{
$cf = ConfigFile::getInstance();
$crlf = (isset($_SESSION['eol']) && $_SESSION['eol'] == 'win') ? "\r\n" : "\n";
$c = $cf->getConfig();

View File

@ -32,7 +32,8 @@ restore_error_handler();
// Save current language in a cookie, required since we use PMA_MINIMUM_COMMON
$GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
ConfigFile::getInstance()->setPersistKeys(
$GLOBALS['ConfigFile'] = new ConfigFile();
$GLOBALS['ConfigFile']->setPersistKeys(
array(
'DefaultLang',
'ServerDefault',

View File

@ -40,7 +40,7 @@ function process_formset(FormDisplay $form_display)
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT);
if ($id === null && $page == 'servers') {
// we've just added a new server, get it's id
$id = ConfigFile::getInstance()->getServerCount();
$id = $form_display->getConfigFile()->getServerCount();
}
$id = $id ? "{$separator}id=$id" : '';
?>

View File

@ -186,7 +186,7 @@ function PMA_versionCheck()
*/
function PMA_checkConfigRw(&$is_readable, &$is_writable, &$file_exists)
{
$file_path = ConfigFile::getInstance()->getFilePath();
$file_path = $GLOBALS['ConfigFile']->getFilePath();
$file_dir = dirname($file_path);
$is_readable = true;
$is_writable = is_dir($file_dir);
@ -210,7 +210,7 @@ function PMA_checkConfigRw(&$is_readable, &$is_writable, &$file_exists)
*/
function PMA_performConfigChecks()
{
$cf = ConfigFile::getInstance();
$cf = $GLOBALS['ConfigFile'];
$blowfish_secret = $cf->get('blowfish_secret');
$blowfish_secret_set = false;
$cookie_auth_used = false;

View File

@ -22,7 +22,7 @@ if (!($values instanceof stdClass)) {
PMA_fatalError(__('Wrong data'));
}
$values = (array)$values;
$result = PMA_Validator::validate($vids, $values, true);
$result = PMA_Validator::validate($GLOBALS['ConfigFile'], $vids, $values, true);
if ($result === false) {
$result = 'Wrong data or no validation for ' . $vids;
}

View File

@ -7,7 +7,9 @@
*/
require_once 'libraries/config/ConfigFile.class.php';
require_once 'libraries/config/Form.class.php';
require_once 'libraries/config/FormDisplay.class.php';
require_once 'libraries/config/config_functions.lib.php';
require_once 'libraries/Util.class.php';
require_once 'libraries/Theme.class.php';
require_once 'libraries/Config.class.php';
@ -21,6 +23,9 @@ require_once 'libraries/user_preferences.lib.php';
*/
class PMA_FormDisplay_Test extends PHPUnit_Framework_TestCase
{
/**
* @var FormDisplay
*/
protected $object;
/**
@ -36,7 +41,7 @@ class PMA_FormDisplay_Test extends PHPUnit_Framework_TestCase
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$this->object = new FormDisplay();
$this->object = new FormDisplay(new ConfigFile());
}
/**
@ -512,7 +517,7 @@ class PMA_FormDisplay_Test extends PHPUnit_Framework_TestCase
);
$comment = '';
if (!function_exists("gzopen")) {
if (!function_exists("bzopen")) {
$comment = 'Compressed import will not work due to missing function ' .
'bzopen.';
}

View File

@ -20,6 +20,9 @@ require_once 'libraries/php-gettext/gettext.inc';
*/
class PMA_Form_Test extends PHPUnit_Framework_TestCase
{
/**
* @var Form
*/
protected $object;
/**
@ -35,7 +38,7 @@ class PMA_Form_Test extends PHPUnit_Framework_TestCase
$GLOBALS['PMA_Config'] = new PMA_Config();
$GLOBALS['PMA_Config']->enableBc();
$GLOBALS['server'] = 0;
$this->object = new Form('pma_form_name', array('pma_form1','pma_form2'), 1);
$this->object = new Form('pma_form_name', array('pma_form1','pma_form2'), new ConfigFile(), 1);
}
/**

View File

@ -903,9 +903,13 @@ class PMA_AuthenticationCookie_Test extends PHPUnit_Framework_TestCase
isset($_COOKIE['pmaServer-2'])
);
// target can be "phpunit" or "ide-phpunut.php", depending on testing environment
$this->assertStringStartsWith(
'Location: http://phpmyadmin.net/index.php?target=',
$GLOBALS['header'][0]
);
$this->assertContains(
'Location: http://phpmyadmin.net/index.php?target=phpunit&server=2' .
'&lang=en&collation_connection=utf-8&token=token&PHPSESSID=',
'&server=2&lang=en&collation_connection=utf-8&token=token&PHPSESSID=',
$GLOBALS['header'][0]
);

View File

@ -22,6 +22,9 @@ require_once 'libraries/Error_Handler.class.php';
*/
class PMA_AuthenticationHttp_Test extends PHPUnit_Framework_TestCase
{
/**
* @var AuthenticationHttp
*/
protected $object;
/**

File diff suppressed because it is too large Load Diff

View File

@ -30,15 +30,10 @@ class PMA_ConfigGenerator_Test extends PHPUnit_Framework_TestCase
public function testGetConfigFile()
{
$GLOBALS['cfg']['AvailableCharsets'] = array();
$GLOBALS['PMA_Config'] = new PMA_Config();
unset($_SESSION['eol']);
$attr_instance = new ReflectionProperty("ConfigFile", "_instance");
$attr_instance->setAccessible(true);
$attr_instance->setValue(null, null);
$GLOBALS['server'] = 0;
$cf = ConfigFile::getInstance();
$cf = new ConfigFile();
$_SESSION['ConfigFile0'] = array('a', 'b', 'c');
$_SESSION['ConfigFile0']['Servers'] = array(
array(1, 2, 3)
@ -46,7 +41,7 @@ class PMA_ConfigGenerator_Test extends PHPUnit_Framework_TestCase
$cf->setPersistKeys(array("1/", 2));
$result = ConfigGenerator::getConfigFile();
$result = ConfigGenerator::getConfigFile($cf);
$this->assertContains(
"<?php\n" .

View File

@ -9,10 +9,13 @@
/*
* Include to test
*/
require_once 'setup/lib/index.lib.php';
include_once 'libraries/php-gettext/gettext.inc';
include_once 'libraries/sanitizing.lib.php';
require_once 'libraries/config/config_functions.lib.php';
require_once 'libraries/config/ConfigFile.class.php';
require_once 'libraries/core.lib.php';
require_once 'libraries/Util.class.php';
require_once 'setup/lib/index.lib.php';
/**
* tests for methods under setup/lib/index.lib.php
@ -318,6 +321,8 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
$redefine = null;
$GLOBALS['cfg']['AvailableCharsets'] = array();
$GLOBALS['server'] = 0;
$GLOBALS['ConfigFile'] = new ConfigFile();
if (!defined('SETUP_CONFIG_FILE')) {
define('SETUP_CONFIG_FILE', 'test/test_data/configfile');
} else {
@ -381,8 +386,11 @@ class PMA_SetupIndex_Test extends PHPUnit_Framework_TestCase
$GLOBALS['cfg']['AvailableCharsets'] = array();
$GLOBALS['cfg']['ServerDefault'] = 0;
$GLOBALS['server'] = 0;
$cf = new ConfigFile();
$GLOBALS['ConfigFile'] = $cf;
$cf = ConfigFile::getInstance();
$reflection = new \ReflectionProperty('ConfigFile', '_id');
$reflection->setAccessible(true);
$sessionID = $reflection->getValue($cf);

View File

@ -53,7 +53,7 @@ class PMA_User_Preferences_Test extends PHPUnit_Framework_TestCase
)
);
PMA_userprefsPageInit();
PMA_userprefsPageInit(new ConfigFile());
$this->assertEquals(
array(