From f24545e633b797090b97b4f88f32d4b1a571cba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 6 Jun 2018 15:47:00 -0300 Subject: [PATCH] Refactor Config/FormDisplayTemplate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces $GLOBALS['PMA_Config'] with DI Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Config/FormDisplay.php | 2 +- .../classes/Config/FormDisplayTemplate.php | 22 ++++++++++++--- setup/frames/config.inc.php | 2 +- setup/frames/index.inc.php | 2 +- .../Config/FormDisplayTemplateTest.php | 27 ++++++++++--------- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/libraries/classes/Config/FormDisplay.php b/libraries/classes/Config/FormDisplay.php index 05ef691dd1..39a3a51b5c 100644 --- a/libraries/classes/Config/FormDisplay.php +++ b/libraries/classes/Config/FormDisplay.php @@ -102,7 +102,7 @@ class FormDisplay */ public function __construct(ConfigFile $cf) { - $this->formDisplayTemplate = new FormDisplayTemplate(); + $this->formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']); $this->_jsLangStrings = [ 'error_nan_p' => __('Not a positive number!'), 'error_nan_nneg' => __('Not a non-negative number!'), diff --git a/libraries/classes/Config/FormDisplayTemplate.php b/libraries/classes/Config/FormDisplayTemplate.php index 3c0dfaa945..c96395a17f 100644 --- a/libraries/classes/Config/FormDisplayTemplate.php +++ b/libraries/classes/Config/FormDisplayTemplate.php @@ -9,6 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Config; +use PhpMyAdmin\Config; use PhpMyAdmin\Sanitize; use PhpMyAdmin\Template; use PhpMyAdmin\Url; @@ -26,6 +27,21 @@ class FormDisplayTemplate */ public $group; + /** + * @var Config + */ + protected $config; + + /** + * FormDisplayTemplate constructor. + * + * @param Config $config + */ + public function __construct(Config $config) + { + $this->config = $config; + } + /** * Displays top part of the form * @@ -165,7 +181,7 @@ class FormDisplayTemplate $icons = null; } - $isSetupScript = $GLOBALS['PMA_Config']->get('is_setup'); + $isSetupScript = $this->config->get('is_setup'); if ($icons === null) { // if the static variables have not been initialised $icons = []; // Icon definitions: @@ -389,7 +405,7 @@ class FormDisplayTemplate if ($headerText === '') { return ''; } - $colspan = $GLOBALS['PMA_Config']->get('is_setup') ? 3 : 2; + $colspan = $this->config->get('is_setup') ? 3 : 2; return Template::get('config/form_display/group_header')->render([ 'group' => $this->group, @@ -419,7 +435,7 @@ class FormDisplayTemplate { return Template::get('config/form_display/fieldset_bottom')->render([ 'show_buttons' => $showButtons, - 'is_setup' => $GLOBALS['PMA_Config']->get('is_setup'), + 'is_setup' => $this->config->get('is_setup'), ]); } diff --git a/setup/frames/config.inc.php b/setup/frames/config.inc.php index 5e6bd380b3..a7c344f08c 100644 --- a/setup/frames/config.inc.php +++ b/setup/frames/config.inc.php @@ -15,7 +15,7 @@ if (!defined('PHPMYADMIN')) { exit; } -$formDisplayTemplate = new FormDisplayTemplate(); +$formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']); echo '

' , __('Configuration file') , '

'; diff --git a/setup/frames/index.inc.php b/setup/frames/index.inc.php index 25f5c5f553..0511a7a88b 100644 --- a/setup/frames/index.inc.php +++ b/setup/frames/index.inc.php @@ -43,7 +43,7 @@ if (isset($_GET['version_check'])) { $configChecker = new ServerConfigChecks($GLOBALS['ConfigFile']); $configChecker->performConfigChecks(); -$formDisplayTemplate = new FormDisplayTemplate(); +$formDisplayTemplate = new FormDisplayTemplate($GLOBALS['PMA_Config']); // // Https connection warning (check done on the client side) diff --git a/test/classes/Config/FormDisplayTemplateTest.php b/test/classes/Config/FormDisplayTemplateTest.php index b038eb22a2..6102644a82 100644 --- a/test/classes/Config/FormDisplayTemplateTest.php +++ b/test/classes/Config/FormDisplayTemplateTest.php @@ -1,7 +1,7 @@ formDisplayTemplate = new FormDisplayTemplate(); - $GLOBALS['PMA_Config'] = new Config(); + $this->config = new Config(); + $this->formDisplayTemplate = new FormDisplayTemplate($this->config); } /** @@ -155,7 +159,6 @@ class FormDisplayTemplateTest extends TestCase */ public function testDisplayInput() { - $GLOBALS['_FormDislayGroup'] = 1; $opts = []; $opts['errors'] = ['e1']; $opts['userprefs_allow'] = false; @@ -229,8 +232,7 @@ class FormDisplayTemplateTest extends TestCase // second case - $GLOBALS['PMA_Config']->set('is_setup', true); - $GLOBALS['_FormDislayGroup'] = 0; + $this->config->set('is_setup', true); $opts = []; $opts['errors'] = []; $opts['setvalue'] = 'setVal'; @@ -278,7 +280,6 @@ class FormDisplayTemplateTest extends TestCase ); // short_text - $GLOBALS['_FormDislayGroup'] = 0; $opts = []; $opts['errors'] = []; @@ -412,7 +413,7 @@ class FormDisplayTemplateTest extends TestCase $this->formDisplayTemplate->group = 3; - $GLOBALS['PMA_Config']->set('is_setup', true); + $this->config->set('is_setup', true); $result = $this->formDisplayTemplate->displayGroupHeader('headerText'); @@ -422,7 +423,7 @@ class FormDisplayTemplateTest extends TestCase ); // without PMA_SETUP - $GLOBALS['PMA_Config']->set('is_setup', false); + $this->config->set('is_setup', false); $this->formDisplayTemplate->group = 3; @@ -457,7 +458,7 @@ class FormDisplayTemplateTest extends TestCase public function testDisplayFieldsetBottom() { // with PMA_SETUP - $GLOBALS['PMA_Config']->set('is_setup', true); + $this->config->set('is_setup', true); $result = $this->formDisplayTemplate->displayFieldsetBottom(); @@ -482,7 +483,7 @@ class FormDisplayTemplateTest extends TestCase ); // without PMA_SETUP - $GLOBALS['PMA_Config']->set('is_setup', false); + $this->config->set('is_setup', false); $result = $this->formDisplayTemplate->displayFieldsetBottom();