From 04f3340b97d06489cf640a7096222439f3b0f3a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:37:53 -0300 Subject: [PATCH 01/18] Remove old DI container in tbl_change.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- services.yml | 4 ++++ tbl_change.php | 11 ++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/services.yml b/services.yml index 174aa4db0a..87c63c524d 100644 --- a/services.yml +++ b/services.yml @@ -54,6 +54,10 @@ services: import: class: 'PhpMyAdmin\Import' + insert_edit: + class: 'PhpMyAdmin\InsertEdit' + arguments: ['@dbi'] + di_migration: factory: 'PhpMyAdmin\Di\Migration::getInstance' arguments: ['@service_container'] diff --git a/tbl_change.php b/tbl_change.php index a17b6e646f..3ce05eac0d 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\InsertEdit; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -24,14 +23,11 @@ global $cfg, $db, $table, $text_dir; require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); PageSettings::showGroup('Edit'); @@ -40,7 +36,8 @@ PageSettings::showGroup('Edit'); */ require_once ROOT_PATH . 'libraries/db_table_exists.inc.php'; -$insertEdit = new InsertEdit($dbi); +/** @var InsertEdit $insertEdit */ +$insertEdit = $containerBuilder->get('insert_edit'); /** * Determine whether Insert or Edit and set global variables From 9321e5cd2e47f3dd34f48ee47a2bca170fa916fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:44:28 -0300 Subject: [PATCH 02/18] Remove old DI container in tbl_export.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- services.yml | 3 +++ tbl_export.php | 11 ++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/services.yml b/services.yml index 87c63c524d..4845d18a64 100644 --- a/services.yml +++ b/services.yml @@ -34,6 +34,9 @@ services: dbi: '@dbi' relation: '@relation' + display_export: + class: 'PhpMyAdmin\Display\Export' + error_handler: class: 'PhpMyAdmin\ErrorHandler' diff --git a/tbl_export.php b/tbl_export.php index 71172fa0a7..b70966a6cd 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Display\Export; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -22,14 +21,11 @@ global $db, $url_query; require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); PageSettings::showGroup('Export'); @@ -42,7 +38,8 @@ $scripts->addFile('export.js'); $relation = $containerBuilder->get('relation'); $cfgRelation = $relation->getRelationsParam(); -$displayExport = new Export(); +/** @var Export $displayExport */ +$displayExport = $containerBuilder->get('display_export'); // handling export template actions if (isset($_POST['templateAction']) && $cfgRelation['exporttemplateswork']) { From 72bcb678f6ef8f8989c2857ee3ffa5689f67d308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:47:57 -0300 Subject: [PATCH 03/18] Remove old DI container in tbl_replace.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- tbl_replace.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/tbl_replace.php b/tbl_replace.php index 2c1e9aa03b..74a872ab3c 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -15,7 +15,6 @@ declare(strict_types=1); use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\File; use PhpMyAdmin\InsertEdit; use PhpMyAdmin\Message; @@ -34,14 +33,11 @@ global $db, $table, $url_params; require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); // Check parameters Util::checkParameters(['db', 'table', 'goto']); @@ -65,7 +61,8 @@ $scripts->addFile('gis_data_editor.js'); $relation = $containerBuilder->get('relation'); /** @var Transformations $transformations */ $transformations = $containerBuilder->get('transformations'); -$insertEdit = new InsertEdit($dbi); +/** @var InsertEdit $insertEdit */ +$insertEdit = $containerBuilder->get('insert_edit'); // check whether insert row mode, if so include tbl_change.php $insertEdit->isInsertRow(); From dcee7d50035f72fe6311095cdc7ce07f9295c2e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:51:21 -0300 Subject: [PATCH 04/18] Remove old DI container in tbl_select.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- tbl_select.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tbl_select.php b/tbl_select.php index be56cd57dc..af63aeb766 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -11,8 +11,6 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\SearchController; -use PhpMyAdmin\Di\Container; -use PhpMyAdmin\Response; use Symfony\Component\DependencyInjection\Definition; if (! defined('ROOT_PATH')) { @@ -24,14 +22,8 @@ global $url_query; require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); -$container->alias('response', Response::class); - /* Define dependencies for the concerned controller */ $dependency_definitions = [ - 'db' => $container->get('db'), - 'table' => $container->get('table'), 'searchType' => 'normal', 'url_query' => &$url_query, ]; From 8d0df78d4582be4fb3ded1b659964376fce0110c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:54:24 -0300 Subject: [PATCH 05/18] Remove old DI container in tbl_zoom_select.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- tbl_zoom_select.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index 60894aa36f..fc458ca458 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -10,8 +10,6 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\SearchController; -use PhpMyAdmin\Di\Container; -use PhpMyAdmin\Response; use Symfony\Component\DependencyInjection\Definition; if (! defined('ROOT_PATH')) { @@ -23,14 +21,8 @@ global $url_query; require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); -$container->alias('response', Response::class); - /* Define dependencies for the concerned controller */ $dependency_definitions = [ - 'db' => $container->get('db'), - 'table' => $container->get('table'), 'searchType' => 'zoom', 'url_query' => &$url_query, ]; From 89bce5a782894ef8075bf149a3cad3c31ad2679b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 20:56:29 -0300 Subject: [PATCH 06/18] Remove old DI container in transformation_overview.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- transformation_overview.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/transformation_overview.php b/transformation_overview.php index d8241c9871..5ba6c1fff1 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\TransformationOverviewController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -18,14 +17,11 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); $header = $response->getHeader(); $header->disableMenuAndConsole(); From b739e204c2978c8acc121534d6301ac2643db88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 21:14:15 -0300 Subject: [PATCH 07/18] Remove old DI container in user_password.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- services.yml | 12 ++++++++++++ user_password.php | 21 ++++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/services.yml b/services.yml index 4845d18a64..cad542d2ba 100644 --- a/services.yml +++ b/services.yml @@ -87,6 +87,10 @@ services: class: 'PhpMyAdmin\Relation' arguments: ['@dbi', '@template'] + relation_cleanup: + class: 'PhpMyAdmin\RelationCleanup' + arguments: ['@dbi', '@relation'] + replication: class: 'PhpMyAdmin\Replication' @@ -99,6 +103,10 @@ services: response: factory: 'PhpMyAdmin\Response::getInstance' + server_privileges: + class: 'PhpMyAdmin\Server\Privileges' + arguments: ['@template', '@dbi', '@relation', '@relation_cleanup'] + sql_query_form: class: 'PhpMyAdmin\SqlQueryForm' @@ -122,6 +130,10 @@ services: transformations: class: 'PhpMyAdmin\Transformations' + user_password: + class: 'PhpMyAdmin\UserPassword' + arguments: ['@server_privileges'] + #Aliases PhpMyAdmin\Response: '@response' diff --git a/user_password.php b/user_password.php index 73a000c5e4..8176160dcc 100644 --- a/user_password.php +++ b/user_password.php @@ -9,14 +9,9 @@ declare(strict_types=1); use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Display\ChangePassword; use PhpMyAdmin\Message; -use PhpMyAdmin\Relation; -use PhpMyAdmin\RelationCleanup; use PhpMyAdmin\Response; -use PhpMyAdmin\Server\Privileges; -use PhpMyAdmin\Template; use PhpMyAdmin\UserPassword; if (! defined('ROOT_PATH')) { @@ -27,27 +22,19 @@ global $cfg; require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('server/privileges.js'); $scripts->addFile('vendor/zxcvbn.js'); -/** @var Template $template */ -$template = $containerBuilder->get('template'); -/** @var Relation $relation */ -$relation = $containerBuilder->get('relation'); -$relationCleanup = new RelationCleanup($dbi, $relation); -$serverPrivileges = new Privileges($template, $dbi, $relation, $relationCleanup); -$userPassword = new UserPassword($serverPrivileges); +/** @var UserPassword $userPassword */ +$userPassword = $containerBuilder->get('user_password'); /** * Displays an error message and exits if the user isn't allowed to use this From d2c80393e072b21bf1c564aefc41b2435b655e7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 21:14:43 -0300 Subject: [PATCH 08/18] Remove old DI container in view_create.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- view_create.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/view_create.php b/view_create.php index 7e557640d3..1335e2bbf0 100644 --- a/view_create.php +++ b/view_create.php @@ -11,7 +11,6 @@ declare(strict_types=1); use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Response; use PhpMyAdmin\Template; @@ -26,14 +25,11 @@ global $text_dir; require_once ROOT_PATH . 'libraries/common.inc.php'; require ROOT_PATH . 'libraries/db_common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); $url_params['goto'] = 'tbl_structure.php'; $url_params['back'] = 'view_create.php'; From 2d620addfad11cdb7cff4407effb5244fabb79fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 21:25:18 -0300 Subject: [PATCH 09/18] Remove old DI container in sql.php, db_sql.php and tbl_sql.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- db_sql.php | 4 ---- services.yml | 3 +++ sql.php | 14 ++++++-------- tbl_sql.php | 5 ----- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/db_sql.php b/db_sql.php index 84ce7b5be8..0612aa75ba 100644 --- a/db_sql.php +++ b/db_sql.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\SqlController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\SqlQueryForm; @@ -19,9 +18,6 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ $response = $containerBuilder->get(Response::class); diff --git a/services.yml b/services.yml index cad542d2ba..488c99a885 100644 --- a/services.yml +++ b/services.yml @@ -107,6 +107,9 @@ services: class: 'PhpMyAdmin\Server\Privileges' arguments: ['@template', '@dbi', '@relation', '@relation_cleanup'] + sql: + class: 'PhpMyAdmin\Sql' + sql_query_form: class: 'PhpMyAdmin\SqlQueryForm' diff --git a/sql.php b/sql.php index 087f931be4..36a04a52d1 100644 --- a/sql.php +++ b/sql.php @@ -12,7 +12,6 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Config\PageSettings; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\Response; use PhpMyAdmin\Sql; @@ -27,16 +26,14 @@ global $cfg, $pmaThemeImage; require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ -$response = $container->get(Response::class); +$response = $containerBuilder->get(Response::class); /** @var DatabaseInterface $dbi */ -$dbi = $container->get(DatabaseInterface::class); +$dbi = $containerBuilder->get(DatabaseInterface::class); -$checkUserPrivileges = new CheckUserPrivileges($dbi); +/** @var CheckUserPrivileges $checkUserPrivileges */ +$checkUserPrivileges = $containerBuilder->get('check_user_privileges'); $checkUserPrivileges->getPrivileges(); PageSettings::showGroup('Browse'); @@ -49,7 +46,8 @@ $scripts->addFile('indexes.js'); $scripts->addFile('gis_data_editor.js'); $scripts->addFile('multi_column_sort.js'); -$sql = new Sql(); +/** @var Sql $sql */ +$sql = $containerBuilder->get('sql'); /** * Set ajax_reload in the response if it was already set diff --git a/tbl_sql.php b/tbl_sql.php index 25dd7f3786..cb1cf82f93 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -9,10 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\SqlController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\SqlQueryForm; -use Symfony\Component\DependencyInjection\Definition; if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); @@ -20,9 +18,6 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$container = Container::getDefaultContainer(); -$container->set(Response::class, Response::getInstance()); - /** @var Response $response */ $response = $containerBuilder->get(Response::class); From 2033507ce4ca94096dca9bf582c7c7f4ccf3e043 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 22:09:51 -0300 Subject: [PATCH 10/18] Remove old DI container in db structure controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Database/StructureControllerTest.php | 102 ++++++++---------- .../Server/VariablesControllerTest.php | 1 + 2 files changed, 43 insertions(+), 60 deletions(-) diff --git a/test/classes/Controllers/Database/StructureControllerTest.php b/test/classes/Controllers/Database/StructureControllerTest.php index a62d4561b0..0102d05a2a 100644 --- a/test/classes/Controllers/Database/StructureControllerTest.php +++ b/test/classes/Controllers/Database/StructureControllerTest.php @@ -13,11 +13,9 @@ namespace PhpMyAdmin\Tests\Controllers\Database; use PhpMyAdmin\Controllers\Database\StructureController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\RecentFavoriteTable; use PhpMyAdmin\Relation; use PhpMyAdmin\Replication; -use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\PmaTestCase; @@ -48,6 +46,11 @@ class StructureControllerTest extends PmaTestCase */ private $replication; + /** + * @var Template + */ + private $template; + /** * Prepares environment for the test. * @@ -82,15 +85,8 @@ class StructureControllerTest extends PmaTestCase $GLOBALS['dbi'] = $dbi; - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $container->set('dbi', $GLOBALS['dbi']); - $container->set('template', new Template()); + $this->template = new Template(); $this->response = new ResponseStub(); - $container->set(Response::class, $this->response); - $container->alias('response', Response::class); - $this->relation = new Relation($dbi); $this->replication = new Replication(); } @@ -103,22 +99,14 @@ class StructureControllerTest extends PmaTestCase */ public function testGetValuesForInnodbTable() { - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $container->set('dbi', $GLOBALS['dbi']); - $response = new ResponseStub(); - $container->set(Response::class, $response); - $container->alias('response', Response::class); - $class = new ReflectionClass(StructureController::class); $method = $class->getMethod('getValuesForInnodbTable'); $method->setAccessible(true); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -176,10 +164,10 @@ class StructureControllerTest extends PmaTestCase // Not showing statistics $is_show_stats = false; $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -217,16 +205,15 @@ class StructureControllerTest extends PmaTestCase */ public function testGetValuesForAriaTable() { - $container = Container::getDefaultContainer(); $class = new ReflectionClass(StructureController::class); $method = $class->getMethod('getValuesForAriaTable'); $method->setAccessible(true); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -285,10 +272,10 @@ class StructureControllerTest extends PmaTestCase $this->assertEquals(0, $overheadSize); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -307,10 +294,10 @@ class StructureControllerTest extends PmaTestCase $this->assertEquals(0, $sumSize); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -337,16 +324,15 @@ class StructureControllerTest extends PmaTestCase */ public function testHasTable() { - $container = Container::getDefaultContainer(); $class = new ReflectionClass(StructureController::class); $method = $class->getMethod('hasTable'); $method->setAccessible(true); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -384,16 +370,15 @@ class StructureControllerTest extends PmaTestCase */ public function testCheckFavoriteTable() { - $container = Container::getDefaultContainer(); $class = new ReflectionClass(StructureController::class); $method = $class->getMethod('checkFavoriteTable'); $method->setAccessible(true); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -424,7 +409,6 @@ class StructureControllerTest extends PmaTestCase */ public function testSynchronizeFavoriteTables() { - $container = Container::getDefaultContainer(); $favoriteInstance = $this->getMockBuilder(RecentFavoriteTable::class) ->disableOriginalConstructor() ->getMock(); @@ -443,10 +427,10 @@ class StructureControllerTest extends PmaTestCase $method->setAccessible(true); $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); @@ -476,13 +460,11 @@ class StructureControllerTest extends PmaTestCase */ public function testHandleRealRowCountRequestAction() { - $container = Container::getDefaultContainer(); - $controller = new StructureController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), + $this->response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], $this->relation, $this->replication ); diff --git a/test/classes/Controllers/Server/VariablesControllerTest.php b/test/classes/Controllers/Server/VariablesControllerTest.php index 656768dceb..07f8f9276b 100644 --- a/test/classes/Controllers/Server/VariablesControllerTest.php +++ b/test/classes/Controllers/Server/VariablesControllerTest.php @@ -154,6 +154,7 @@ class VariablesControllerTest extends TestCase $method->setAccessible(true); $container = Container::getDefaultContainer(); + $container->set('template', new Template()); $container->factory(VariablesController::class); $controller = $container->get(VariablesController::class); From d74fca7cade11676722ee2c233f44476d173db81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 22:22:35 -0300 Subject: [PATCH 11/18] Remove old DI container in VariablesControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Controllers/Server/VariablesControllerTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/classes/Controllers/Server/VariablesControllerTest.php b/test/classes/Controllers/Server/VariablesControllerTest.php index 07f8f9276b..7afaa2fe5b 100644 --- a/test/classes/Controllers/Server/VariablesControllerTest.php +++ b/test/classes/Controllers/Server/VariablesControllerTest.php @@ -12,7 +12,6 @@ namespace PhpMyAdmin\Tests\Controllers\Server; use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\Server\VariablesController; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Template; use PhpMyAdmin\Url; @@ -153,10 +152,11 @@ class VariablesControllerTest extends TestCase $method = $class->getMethod('formatVariable'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('template', new Template()); - $container->factory(VariablesController::class); - $controller = $container->get(VariablesController::class); + $controller = new VariablesController( + Response::getInstance(), + $GLOBALS['dbi'], + new Template() + ); $nameForValueByte = 'byte_variable'; $nameForValueNotByte = 'not_a_byte_variable'; From 9aa85d058b6692d84d8e90f75626dd16a1d61e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 22:27:25 -0300 Subject: [PATCH 12/18] Remove old DI container in Table\IndexesControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Table/IndexesControllerTest.php | 34 ++++++------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/test/classes/Controllers/Table/IndexesControllerTest.php b/test/classes/Controllers/Table/IndexesControllerTest.php index b6ef6666f6..8dee0aaa93 100644 --- a/test/classes/Controllers/Table/IndexesControllerTest.php +++ b/test/classes/Controllers/Table/IndexesControllerTest.php @@ -96,21 +96,14 @@ class IndexesControllerTest extends PmaTestCase $GLOBALS['dbi']->expects($this->any())->method('getTable') ->will($this->returnValue($table)); - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $container->set('template', new Template()); - $container->set('dbi', $GLOBALS['dbi']); $response = new ResponseStub(); - $container->set('PhpMyAdmin\Response', $response); - $container->alias('response', 'PhpMyAdmin\Response'); $ctrl = new IndexesController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), - $container->get('table'), + $response, + $GLOBALS['dbi'], + new Template(), + $GLOBALS['db'], + $GLOBALS['table'], null ); @@ -156,22 +149,15 @@ class IndexesControllerTest extends PmaTestCase $GLOBALS['dbi']->expects($this->any())->method('getTable') ->will($this->returnValue($table)); - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $container->set('template', new Template()); - $container->set('dbi', $GLOBALS['dbi']); $response = new ResponseStub(); - $container->set('PhpMyAdmin\Response', $response); - $container->alias('response', 'PhpMyAdmin\Response'); $index = new Index(); $ctrl = new IndexesController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), - $container->get('table'), + $response, + $GLOBALS['dbi'], + new Template(), + $GLOBALS['db'], + $GLOBALS['table'], $index ); From d984b07ba6e7bde13080c213cb74b92ae7f41893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 15 Jun 2019 23:00:56 -0300 Subject: [PATCH 13/18] Remove old DI container in Table\SearchControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Table/SearchControllerTest.php | 96 +++++++++---------- 1 file changed, 47 insertions(+), 49 deletions(-) diff --git a/test/classes/Controllers/Table/SearchControllerTest.php b/test/classes/Controllers/Table/SearchControllerTest.php index ab8f4a0bea..c45a53f73a 100644 --- a/test/classes/Controllers/Table/SearchControllerTest.php +++ b/test/classes/Controllers/Table/SearchControllerTest.php @@ -10,7 +10,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table; use PhpMyAdmin\Controllers\Table\SearchController; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\PmaTestCase; @@ -31,6 +30,11 @@ class SearchControllerTest extends PmaTestCase */ private $_response; + /** + * @var Template + */ + private $template; + /** * Setup function for test cases * @@ -45,8 +49,8 @@ class SearchControllerTest extends PmaTestCase $_POST['zoom_submit'] = 'zoom'; $GLOBALS['server'] = 1; - $GLOBALS['db'] = 'db'; - $GLOBALS['table'] = 'table'; + $GLOBALS['db'] = 'PMA'; + $GLOBALS['table'] = 'PMA_BookMark'; $GLOBALS['PMA_PHP_SELF'] = 'index.php'; $relation = new Relation($GLOBALS['dbi']); $GLOBALS['cfgRelation'] = $relation->getRelationsParam(); @@ -94,16 +98,7 @@ class SearchControllerTest extends PmaTestCase $relation->dbi = $dbi; $this->_response = new ResponseStub(); - - $container = Container::getDefaultContainer(); - $container->set('db', 'PMA'); - $container->set('table', 'PMA_BookMark'); - $template = new Template(); - $container->set('template', $template); - $container->set('dbi', $GLOBALS['dbi']); - $container->set('response', $this->_response); - $container->set('searchType', 'replace'); - $container->set('relation', new Relation($dbi, $template)); + $this->template = new Template(); } /** @@ -123,17 +118,15 @@ class SearchControllerTest extends PmaTestCase */ public function testReplace() { - $container = Container::getDefaultContainer(); - $tableSearch = new SearchController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), - $container->get('table'), + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], "zoom", null, - new Relation($container->get('dbi'), $container->get('template')) + new Relation($GLOBALS['dbi'], $this->template) ); $columnIndex = 0; $find = "Field"; @@ -172,20 +165,18 @@ class SearchControllerTest extends PmaTestCase $_POST['order'] = "asc"; $_POST['customWhereClause'] = "name='pma'"; - $container = Container::getDefaultContainer(); - $class = new ReflectionClass(SearchController::class); $method = $class->getMethod('_buildSqlQuery'); $method->setAccessible(true); $tableSearch = new SearchController( - $container->get('response'), - $container->get('dbi'), - $container->get('template'), - $container->get('db'), - $container->get('table'), + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], "zoom", null, - new Relation($container->get('dbi'), $container->get('template')) + new Relation($GLOBALS['dbi'], $this->template) ); $sql = $method->invoke($tableSearch); @@ -273,14 +264,16 @@ class SearchControllerTest extends PmaTestCase $GLOBALS['dbi']->expects($this->any())->method('fetchSingleRow') ->will($this->returnArgument(0)); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory('PhpMyAdmin\Controllers\Table\SearchController'); - $container->alias( - 'SearchController', - 'PhpMyAdmin\Controllers\Table\SearchController' + $ctrl = new SearchController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + 'replace', + null, + new Relation($GLOBALS['dbi'], $this->template) ); - $ctrl = $container->get('SearchController'); $result = $ctrl->getColumnMinMax('column'); $expected = 'SELECT MIN(`column`) AS `min`, ' @@ -310,13 +303,16 @@ class SearchControllerTest extends PmaTestCase $method = $class->getMethod('_generateWhereClause'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->factory('\PhpMyAdmin\Controllers\Table\SearchController'); - $container->alias( - 'SearchController', - 'PhpMyAdmin\Controllers\Table\SearchController' + $ctrl = new SearchController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + 'replace', + null, + new Relation($GLOBALS['dbi'], $this->template) ); - $ctrl = $container->get('SearchController'); $_POST['customWhereClause'] = '`table` = \'PMA_BookMark\''; $result = $method->invoke($ctrl); @@ -402,14 +398,16 @@ class SearchControllerTest extends PmaTestCase ) ); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory('\PhpMyAdmin\Controllers\Table\SearchController'); - $container->alias( - 'SearchController', - 'PhpMyAdmin\Controllers\Table\SearchController' + $ctrl = new SearchController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + 'replace', + null, + new Relation($GLOBALS['dbi'], $this->template) ); - $ctrl = $container->get('SearchController'); $_POST['db'] = 'PMA'; $_POST['table'] = 'PMA_BookMark'; From b793fbd5b9909cff68e96dae48bd7d4be5e0b5a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 17 Jun 2019 14:23:33 -0300 Subject: [PATCH 14/18] Declare $containerBuilder global in some files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As these may be imported files, it is necessary to add this. Signed-off-by: Maurício Meneghini Fauth --- db_sql.php | 2 ++ sql.php | 2 +- tbl_change.php | 2 +- tbl_export.php | 2 +- tbl_replace.php | 2 +- tbl_select.php | 2 +- tbl_sql.php | 2 ++ 7 files changed, 9 insertions(+), 5 deletions(-) diff --git a/db_sql.php b/db_sql.php index 0612aa75ba..d0235075bf 100644 --- a/db_sql.php +++ b/db_sql.php @@ -16,6 +16,8 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } +global $containerBuilder; + require_once ROOT_PATH . 'libraries/common.inc.php'; /** @var Response $response */ diff --git a/sql.php b/sql.php index 36a04a52d1..15f4152bc3 100644 --- a/sql.php +++ b/sql.php @@ -22,7 +22,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $cfg, $pmaThemeImage; +global $cfg, $containerBuilder, $pmaThemeImage; require_once ROOT_PATH . 'libraries/common.inc.php'; diff --git a/tbl_change.php b/tbl_change.php index 3ce05eac0d..35bff5c8ab 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -19,7 +19,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $cfg, $db, $table, $text_dir; +global $cfg, $containerBuilder, $db, $table, $text_dir; require_once ROOT_PATH . 'libraries/common.inc.php'; diff --git a/tbl_export.php b/tbl_export.php index b70966a6cd..6fec76b340 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -17,7 +17,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $db, $url_query; +global $containerBuilder, $db, $url_query; require_once ROOT_PATH . 'libraries/common.inc.php'; diff --git a/tbl_replace.php b/tbl_replace.php index 74a872ab3c..8e6ac76202 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -29,7 +29,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $db, $table, $url_params; +global $containerBuilder, $db, $table, $url_params; require_once ROOT_PATH . 'libraries/common.inc.php'; diff --git a/tbl_select.php b/tbl_select.php index af63aeb766..23b2ad295a 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -17,7 +17,7 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -global $url_query; +global $containerBuilder, $url_query; require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; diff --git a/tbl_sql.php b/tbl_sql.php index cb1cf82f93..35dacd21ec 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -16,6 +16,8 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } +global $containerBuilder; + require_once ROOT_PATH . 'libraries/common.inc.php'; /** @var Response $response */ From 54667a0085b80d79712285e51534330658aae29d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 17 Jun 2019 14:43:06 -0300 Subject: [PATCH 15/18] Remove old DI container in Table\RelationControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Table/RelationControllerTest.php | 94 ++++++++++++------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/test/classes/Controllers/Table/RelationControllerTest.php b/test/classes/Controllers/Table/RelationControllerTest.php index 60403b5ca2..61222cbbc1 100644 --- a/test/classes/Controllers/Table/RelationControllerTest.php +++ b/test/classes/Controllers/Table/RelationControllerTest.php @@ -9,9 +9,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table; use PhpMyAdmin\Controllers\Table\RelationController; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; -use PhpMyAdmin\Response; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\PmaTestCase; use PhpMyAdmin\Tests\Stubs\Response as ResponseStub; @@ -28,6 +26,11 @@ class RelationControllerTest extends PmaTestCase */ private $_response; + /** + * @var Template + */ + private $template; + /** * Configures environment * @@ -83,16 +86,8 @@ class RelationControllerTest extends PmaTestCase $GLOBALS['dbi'] = $dbi; - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $template = new Template(); - $container->set('template', $template); - $container->set('relation', new Relation($dbi, $template)); - $container->set('dbi', $GLOBALS['dbi']); $this->_response = new ResponseStub(); - $container->set(Response::class, $this->_response); - $container->alias('response', Response::class); + $this->template = new Template(); } /** @@ -123,13 +118,20 @@ class RelationControllerTest extends PmaTestCase $GLOBALS['dbi']->expects($this->any())->method('getTable') ->will($this->returnValue($tableMock)); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory(RelationController::class); - /** - * @var RelationController $ctrl - */ - $ctrl = $container->get(RelationController::class); + $ctrl = new RelationController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template) + ); $ctrl->getDropdownValueForTableAction(); $json = $this->_response->getJSONResult(); @@ -165,10 +167,20 @@ class RelationControllerTest extends PmaTestCase $GLOBALS['dbi']->expects($this->any())->method('getTable') ->will($this->returnValue($tableMock)); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory(RelationController::class); - $ctrl = $container->get(RelationController::class); + $ctrl = new RelationController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template) + ); $ctrl->getDropdownValueForTableAction(); $json = $this->_response->getJSONResult(); @@ -206,12 +218,19 @@ class RelationControllerTest extends PmaTestCase ) ); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory(RelationController::class); - $ctrl = $container->get( - RelationController::class, - ['tbl_storage_engine' => 'INNODB'] + $ctrl = new RelationController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + 'INNODB', + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template) ); $_POST['foreign'] = 'true'; @@ -248,12 +267,19 @@ class RelationControllerTest extends PmaTestCase ) ); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory(RelationController::class); - $ctrl = $container->get( - RelationController::class, - ['tbl_storage_engine' => 'INNODB'] + $ctrl = new RelationController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + 'INNODB', + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template) ); $_POST['foreign'] = 'false'; From 5c519cc819b0c220a53942192f727a71708e74b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 17 Jun 2019 14:51:54 -0300 Subject: [PATCH 16/18] Remove old DI container in Table\StructureControllerTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- .../Table/StructureControllerTest.php | 131 +++++++++++------- 1 file changed, 83 insertions(+), 48 deletions(-) diff --git a/test/classes/Controllers/Table/StructureControllerTest.php b/test/classes/Controllers/Table/StructureControllerTest.php index 268a0a0023..16c5a104ab 100644 --- a/test/classes/Controllers/Table/StructureControllerTest.php +++ b/test/classes/Controllers/Table/StructureControllerTest.php @@ -13,9 +13,7 @@ namespace PhpMyAdmin\Tests\Controllers\Table; use PhpMyAdmin\Controllers\Table\StructureController; use PhpMyAdmin\CreateAddField; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; -use PhpMyAdmin\Response; use PhpMyAdmin\Template; use PhpMyAdmin\Tests\PmaTestCase; use PhpMyAdmin\Tests\Stubs\Response as ResponseStub; @@ -37,6 +35,11 @@ class StructureControllerTest extends PmaTestCase */ private $_response; + /** + * @var Template + */ + private $template; + /** * Prepares environment for the test. * @@ -63,18 +66,8 @@ class StructureControllerTest extends PmaTestCase $GLOBALS['dbi'] = $dbi; - $container = Container::getDefaultContainer(); - $container->set('db', 'db'); - $container->set('table', 'table'); - $template = new Template(); - $container->set('template', $template); - $container->set('dbi', $GLOBALS['dbi']); $this->_response = new ResponseStub(); - $container->set(Response::class, $this->_response); - $container->alias('response', Response::class); - $container->set('relation', new Relation($dbi, $template)); - $container->set('transformations', new Transformations()); - $container->set('createAddField', new CreateAddField($dbi)); + $this->template = new Template(); } /** @@ -94,14 +87,23 @@ class StructureControllerTest extends PmaTestCase $method = $class->getMethod('getKeyForTablePrimary'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory(StructureController::class); - $container->alias( - 'StructureController', - StructureController::class + $ctrl = new StructureController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template), + new Transformations(), + new CreateAddField($GLOBALS['dbi']) ); - $ctrl = $container->get('StructureController'); + // No primary key in db.table2 $this->assertEquals( '', @@ -143,14 +145,23 @@ class StructureControllerTest extends PmaTestCase $method = $class->getMethod('getKeyForTablePrimary'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory('PhpMyAdmin\Controllers\Table\StructureController'); - $container->alias( - 'StructureController', - 'PhpMyAdmin\Controllers\Table\StructureController' + $ctrl = new StructureController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template), + new Transformations(), + new CreateAddField($GLOBALS['dbi']) ); - $ctrl = $container->get('StructureController'); + // With db.table, it has a primary key `column` $this->assertEquals( 'column, ', @@ -170,14 +181,22 @@ class StructureControllerTest extends PmaTestCase $method = $class->getMethod('adjustColumnPrivileges'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory('PhpMyAdmin\Controllers\Table\StructureController'); - $container->alias( - 'StructureController', - 'PhpMyAdmin\Controllers\Table\StructureController' + $ctrl = new StructureController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template), + new Transformations(), + new CreateAddField($GLOBALS['dbi']) ); - $ctrl = $container->get('StructureController'); $this->assertEquals( false, @@ -197,14 +216,22 @@ class StructureControllerTest extends PmaTestCase $method = $class->getMethod('getMultipleFieldCommandType'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('dbi', $GLOBALS['dbi']); - $container->factory('PhpMyAdmin\Controllers\Table\StructureController'); - $container->alias( - 'StructureController', - 'PhpMyAdmin\Controllers\Table\StructureController' + $ctrl = new StructureController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template), + new Transformations(), + new CreateAddField($GLOBALS['dbi']) ); - $ctrl = $container->get('StructureController'); $this->assertEquals( null, @@ -261,14 +288,22 @@ class StructureControllerTest extends PmaTestCase $method = $class->getMethod('getDataForSubmitMult'); $method->setAccessible(true); - $container = Container::getDefaultContainer(); - $container->set('dbi', $dbi); - $container->factory('PhpMyAdmin\Controllers\Table\StructureController'); - $container->alias( - 'StructureController', - 'PhpMyAdmin\Controllers\Table\StructureController' + $ctrl = new StructureController( + $this->_response, + $GLOBALS['dbi'], + $this->template, + $GLOBALS['db'], + $GLOBALS['table'], + null, + null, + null, + null, + null, + null, + new Relation($GLOBALS['dbi'], $this->template), + new Transformations(), + new CreateAddField($GLOBALS['dbi']) ); - $ctrl = $container->get('StructureController'); $submit_mult = "index"; $db = "PMA_db"; From 7ef47312db8baf09a1c44782a618493bee554442 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 17 Jun 2019 15:02:08 -0300 Subject: [PATCH 17/18] Remove remaining calls to old DI container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maurício Meneghini Fauth --- import.php | 1 - libraries/classes/DatabaseInterface.php | 1 - libraries/common.inc.php | 6 ------ tbl_gis_visualization.php | 2 -- test/bootstrap-dist.php | 5 +---- test/bootstrap-phpstan.php | 5 +---- test/classes/Controllers/Table/IndexesControllerTest.php | 1 - 7 files changed, 2 insertions(+), 19 deletions(-) diff --git a/import.php b/import.php index 2a6ac70664..dbbb99482f 100644 --- a/import.php +++ b/import.php @@ -10,7 +10,6 @@ declare(strict_types=1); use PhpMyAdmin\Bookmark; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Encoding; use PhpMyAdmin\File; use PhpMyAdmin\Import; diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index ba578ddccf..7ffbaeda99 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -14,7 +14,6 @@ use PhpMyAdmin\Database\DatabaseList; use PhpMyAdmin\Dbi\DbiDummy; use PhpMyAdmin\Dbi\DbiExtension; use PhpMyAdmin\Dbi\DbiMysqli; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\SqlParser\Context; /** diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 8a845735d6..8ee67e78d3 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -35,7 +35,6 @@ declare(strict_types=1); use PhpMyAdmin\Config; use PhpMyAdmin\Core; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Di\Migration; use PhpMyAdmin\ErrorHandler; use PhpMyAdmin\LanguageManager; @@ -97,9 +96,6 @@ $loader->load('../services_controllers.yml'); /** @var Migration $diMigration */ $diMigration = $containerBuilder->get('di_migration'); -/** @var Container $oldContainer */ -$oldContainer = Container::getDefaultContainer(); - /** * Load gettext functions. */ @@ -333,8 +329,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { */ $containerBuilder->set(DatabaseInterface::class, DatabaseInterface::load()); $containerBuilder->setAlias('dbi', DatabaseInterface::class); - $oldContainer->set(DatabaseInterface::class, $containerBuilder->get(DatabaseInterface::class)); - $oldContainer->alias('dbi', DatabaseInterface::class); // get LoginCookieValidity from preferences cache // no generic solution for loading preferences from cache as some settings diff --git a/tbl_gis_visualization.php b/tbl_gis_visualization.php index 2f08e14d30..70a39053ea 100644 --- a/tbl_gis_visualization.php +++ b/tbl_gis_visualization.php @@ -8,8 +8,6 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\GisVisualizationController; -use PhpMyAdmin\Di\Container; -use PhpMyAdmin\Response; use PhpMyAdmin\Util; use Symfony\Component\DependencyInjection\Definition; diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 1d3fd1f612..34901a50b9 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Config; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\LanguageManager; use PhpMyAdmin\MoTranslator\Loader; use PhpMyAdmin\Theme; @@ -80,9 +79,7 @@ define('PMA_MAJOR_VERSION', $GLOBALS['PMA_Config']->get('PMA_MAJOR_VERSION')); LanguageManager::getInstance()->getLanguage('en')->activate(); /* Load Database interface */ -$oldContainer = Container::getDefaultContainer(); -$oldContainer->set(DatabaseInterface::class, DatabaseInterface::load()); -$oldContainer->alias('dbi', DatabaseInterface::class); +$GLOBALS['dbi'] = DatabaseInterface::load(); // Set proxy information from env, if available $http_proxy = getenv('http_proxy'); diff --git a/test/bootstrap-phpstan.php b/test/bootstrap-phpstan.php index dfe1147a1e..0303e3c2ea 100644 --- a/test/bootstrap-phpstan.php +++ b/test/bootstrap-phpstan.php @@ -9,7 +9,6 @@ declare(strict_types=1); use PhpMyAdmin\Config; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\MoTranslator\Loader; if (! defined('ROOT_PATH')) { @@ -39,6 +38,4 @@ $GLOBALS['PMA_Config']->enableBc();// Defines constants, phpstan:level=1 Loader::loadFunctions(); -$oldContainer = Container::getDefaultContainer(); -$oldContainer->set(DatabaseInterface::class, DatabaseInterface::load()); -$oldContainer->alias('dbi', DatabaseInterface::class); +$GLOBALS['dbi'] = DatabaseInterface::load(); diff --git a/test/classes/Controllers/Table/IndexesControllerTest.php b/test/classes/Controllers/Table/IndexesControllerTest.php index 8dee0aaa93..b361c24d1a 100644 --- a/test/classes/Controllers/Table/IndexesControllerTest.php +++ b/test/classes/Controllers/Table/IndexesControllerTest.php @@ -9,7 +9,6 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Controllers\Table; use PhpMyAdmin\Controllers\Table\IndexesController; -use PhpMyAdmin\Di\Container; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Response; From 6c99653797b6dc0b5f1409edd3c30e015d040153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Mon, 17 Jun 2019 15:09:26 -0300 Subject: [PATCH 18/18] Remove custom dependency injection container MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In favor of Symfony Dependency Injection Container Signed-off-by: Maurício Meneghini Fauth --- composer.json | 1 - libraries/classes/Di/AliasItem.php | 50 ----- libraries/classes/Di/Container.php | 191 -------------------- libraries/classes/Di/ContainerException.php | 23 --- libraries/classes/Di/FactoryItem.php | 31 ---- libraries/classes/Di/Item.php | 27 --- libraries/classes/Di/NotFoundException.php | 22 --- libraries/classes/Di/ReflectorItem.php | 145 --------------- libraries/classes/Di/ServiceItem.php | 36 ---- libraries/classes/Di/ValueItem.php | 43 ----- test/classes/Di/ContainerExceptionTest.php | 76 -------- test/classes/Di/ContainerTest.php | 94 ---------- test/classes/Di/NotFoundExceptionTest.php | 89 --------- 13 files changed, 828 deletions(-) delete mode 100644 libraries/classes/Di/AliasItem.php delete mode 100644 libraries/classes/Di/Container.php delete mode 100644 libraries/classes/Di/ContainerException.php delete mode 100644 libraries/classes/Di/FactoryItem.php delete mode 100644 libraries/classes/Di/Item.php delete mode 100644 libraries/classes/Di/NotFoundException.php delete mode 100644 libraries/classes/Di/ReflectorItem.php delete mode 100644 libraries/classes/Di/ServiceItem.php delete mode 100644 libraries/classes/Di/ValueItem.php delete mode 100644 test/classes/Di/ContainerExceptionTest.php delete mode 100644 test/classes/Di/ContainerTest.php delete mode 100644 test/classes/Di/NotFoundExceptionTest.php diff --git a/composer.json b/composer.json index e7731a4691..1172a45734 100644 --- a/composer.json +++ b/composer.json @@ -50,7 +50,6 @@ "phpmyadmin/shapefile": "^2.0", "phpmyadmin/sql-parser": "^5.0", "phpseclib/phpseclib": "^2.0", - "psr/container": "^1.0", "symfony/config": "^4.2.8", "symfony/dependency-injection": "^4.2.8", "symfony/expression-language": "^4.2", diff --git a/libraries/classes/Di/AliasItem.php b/libraries/classes/Di/AliasItem.php deleted file mode 100644 index 02ebedb252..0000000000 --- a/libraries/classes/Di/AliasItem.php +++ /dev/null @@ -1,50 +0,0 @@ -container = $container; - $this->target = $target; - } - - /** - * Get the target item - * - * @param array $params Parameters - * @return mixed - * @throws ContainerException - * @throws NotFoundException - */ - public function get(array $params = []) - { - return $this->container->get($this->target, $params); - } -} diff --git a/libraries/classes/Di/Container.php b/libraries/classes/Di/Container.php deleted file mode 100644 index 78ecaa34b6..0000000000 --- a/libraries/classes/Di/Container.php +++ /dev/null @@ -1,191 +0,0 @@ -content = $base->content; - } else { - $this->alias('container', 'Container'); - } - $this->set('Container', $this); - } - - /** - * Get an object with given name and parameters - * - * @param string $name Name - * @param array $params Parameters - * - * @throws NotFoundException No entry was found for **this** identifier. - * @throws ContainerException Error while retrieving the entry. - * - * @return mixed - */ - public function get($name, array $params = []) - { - if (! $this->has($name)) { - throw new NotFoundException("No entry was found for $name identifier."); - } - - if (isset($this->content[$name])) { - return $this->content[$name]->get($params); - } elseif (isset($GLOBALS[$name])) { - return $GLOBALS[$name]; - } else { - throw new ContainerException("Error while retrieving the entry."); - } - } - - /** - * Returns true if the container can return an entry for the given identifier. - * Returns false otherwise. - * - * `has($name)` returning true does not mean that `get($name)` will not throw an exception. - * It does however mean that `get($name)` will not throw a `NotFoundException`. - * - * @param string $name Identifier of the entry to look for. - * - * @return bool - */ - public function has($name) - { - return isset($this->content[$name]) || isset($GLOBALS[$name]); - } - - /** - * Remove an object from container - * - * @param string $name Name - * - * @return void - */ - public function remove($name) - { - unset($this->content[$name]); - } - - /** - * Rename an object in container - * - * @param string $name Name - * @param string $newName New name - * - * @return void - */ - public function rename($name, $newName) - { - $this->content[$newName] = $this->content[$name]; - $this->remove($name); - } - - /** - * Set values in the container - * - * @param string|array $name Name - * @param mixed $value Value - * - * @return void - */ - public function set($name, $value = null) - { - if (is_array($name)) { - foreach ($name as $key => $val) { - $this->set($key, $val); - } - return; - } - $this->content[$name] = new ValueItem($value); - } - - /** - * Register a service in the container - * - * @param string $name Name - * @param mixed $service Service - * - * @return void - */ - public function service($name, $service = null) - { - if (! isset($service)) { - $service = $name; - } - $this->content[$name] = new ServiceItem($this, $service); - } - - /** - * Register a factory in the container - * - * @param string $name Name - * @param mixed $factory Factory - * - * @return void - */ - public function factory($name, $factory = null) - { - if (! isset($factory)) { - $factory = $name; - } - $this->content[$name] = new FactoryItem($this, $factory); - } - - /** - * Register an alias in the container - * - * @param string $name Name - * @param string $target Target - * - * @return void - */ - public function alias($name, $target) - { - // The target may be not defined yet - $this->content[$name] = new AliasItem($this, $target); - } - - /** - * Get the global default container - * - * @return Container - */ - public static function getDefaultContainer() - { - if (! isset(static::$defaultContainer)) { - static::$defaultContainer = new Container(); - } - return static::$defaultContainer; - } -} diff --git a/libraries/classes/Di/ContainerException.php b/libraries/classes/Di/ContainerException.php deleted file mode 100644 index ff8a97e0fb..0000000000 --- a/libraries/classes/Di/ContainerException.php +++ /dev/null @@ -1,23 +0,0 @@ -invoke($params); - } -} diff --git a/libraries/classes/Di/Item.php b/libraries/classes/Di/Item.php deleted file mode 100644 index 1da8614d62..0000000000 --- a/libraries/classes/Di/Item.php +++ /dev/null @@ -1,27 +0,0 @@ -_container = $container; - $this->_reflector = self::_resolveReflector($definition); - } - - /** - * Invoke the reflector with given parameters - * - * @param array $params Parameters - * @return mixed - * @throws ContainerException - */ - protected function invoke(array $params = []) - { - $args = []; - $reflector = $this->_reflector; - if ($reflector instanceof ReflectionClass) { - $constructor = $reflector->getConstructor(); - if (isset($constructor)) { - $args = $this->_resolveArgs( - $constructor->getParameters(), - $params - ); - } - return $reflector->newInstanceArgs($args); - } - /** @var ReflectionFunctionAbstract $reflector */ - $args = $this->_resolveArgs( - $reflector->getParameters(), - $params - ); - if ($reflector instanceof ReflectionMethod) { - /** @var ReflectionMethod $reflector */ - return $reflector->invokeArgs(null, $args); - } - /** @var ReflectionFunction $reflector */ - return $reflector->invokeArgs($args); - } - - /** - * Getting required arguments with given parameters - * - * @param ReflectionParameter[] $required Arguments - * @param array $params Parameters - * - * @return array - * @throws ContainerException - */ - private function _resolveArgs($required, array $params = []) - { - $args = []; - foreach ($required as $param) { - $name = $param->getName(); - $type = $param->getClass(); - if (isset($type)) { - $type = $type->getName(); - } - if (isset($params[$name])) { - $args[] = $params[$name]; - } elseif (is_string($type) && isset($params[$type])) { - $args[] = $params[$type]; - } else { - try { - $content = $this->_container->get($name); - if (isset($content)) { - $args[] = $content; - } elseif (is_string($type)) { - $args[] = $this->_container->get($type); - } else { - $args[] = null; - } - } catch (NotFoundException $e) { - $args[] = null; - } - } - } - return $args; - } - - /** - * Resolve the reflection - * - * @param mixed $definition Definition - * - * @return Reflector - * @throws ReflectionException - */ - private static function _resolveReflector($definition) - { - if (function_exists($definition)) { - return new ReflectionFunction($definition); - } - if (is_string($definition)) { - $definition = explode('::', $definition); - } - if (! isset($definition[1])) { - return new ReflectionClass($definition[0]); - } - return new ReflectionMethod($definition[0], $definition[1]); - } -} diff --git a/libraries/classes/Di/ServiceItem.php b/libraries/classes/Di/ServiceItem.php deleted file mode 100644 index 08b325418c..0000000000 --- a/libraries/classes/Di/ServiceItem.php +++ /dev/null @@ -1,36 +0,0 @@ -instance)) { - $this->instance = $this->invoke(); - } - return $this->instance; - } -} diff --git a/libraries/classes/Di/ValueItem.php b/libraries/classes/Di/ValueItem.php deleted file mode 100644 index 7a40cb3d10..0000000000 --- a/libraries/classes/Di/ValueItem.php +++ /dev/null @@ -1,43 +0,0 @@ -value = $value; - } - - /** - * Get the value - * - * @param array $params Parameters - * @return mixed - */ - public function get(array $params = []) - { - return $this->value; - } -} diff --git a/test/classes/Di/ContainerExceptionTest.php b/test/classes/Di/ContainerExceptionTest.php deleted file mode 100644 index 7e59a70aed..0000000000 --- a/test/classes/Di/ContainerExceptionTest.php +++ /dev/null @@ -1,76 +0,0 @@ -exception = new ContainerException(); - } - - /** - * Tears down the fixture. - * This method is called after a test is executed. - * - * @access protected - * @return void - */ - protected function tearDown(): void - { - unset($this->exception); - } - - /** - * Test for ContainerException - * - * @return void - */ - public function testContainerExceptionImplementsInteface() - { - $this->assertInstanceOf( - 'Psr\Container\ContainerExceptionInterface', - $this->exception - ); - } - - /** - * Test for ContainerException - * - * @return void - */ - public function testContainerExceptionExtendsException() - { - $this->assertInstanceOf( - 'Exception', - $this->exception - ); - } -} diff --git a/test/classes/Di/ContainerTest.php b/test/classes/Di/ContainerTest.php deleted file mode 100644 index 433796c6a1..0000000000 --- a/test/classes/Di/ContainerTest.php +++ /dev/null @@ -1,94 +0,0 @@ -container = new Container(); - } - - /** - * Tears down the fixture. - * This method is called after a test is executed. - * - * @access protected - * @return void - */ - protected function tearDown(): void - { - unset($this->container); - } - - /** - * Test for get - * - * @return void - */ - public function testGetWithValidEntry() - { - $this->container->set('name', 'value'); - $this->assertSame('value', $this->container->get('name')); - } - - /** - * Test for get - * - * @return void - */ - public function testGetThrowsNotFoundException() - { - $this->expectException(NotFoundExceptionInterface::class); - $this->container->get('name'); - } - - /** - * Test for has - * - * @return void - */ - public function testHasReturnsTrueForValidEntry() - { - $this->container->set('name', 'value'); - $this->assertTrue($this->container->has('name')); - } - - /** - * Test for has - * - * @return void - */ - public function testHasReturnsFalseForInvalidEntry() - { - $this->assertFalse($this->container->has('name')); - } -} diff --git a/test/classes/Di/NotFoundExceptionTest.php b/test/classes/Di/NotFoundExceptionTest.php deleted file mode 100644 index be4590f41f..0000000000 --- a/test/classes/Di/NotFoundExceptionTest.php +++ /dev/null @@ -1,89 +0,0 @@ -exception = new NotFoundException(); - } - - /** - * Tears down the fixture. - * This method is called after a test is executed. - * - * @access protected - * @return void - */ - protected function tearDown(): void - { - unset($this->exception); - } - - /** - * Test for NotFoundException - * - * @return void - */ - public function testNotFoundExceptionImplementsInteface() - { - $this->assertInstanceOf( - 'Psr\Container\NotFoundExceptionInterface', - $this->exception - ); - } - - /** - * Test for NotFoundException - * - * @return void - */ - public function testNotFoundExceptionExtendsContainerExceptionInteface() - { - $this->assertInstanceOf( - 'Psr\Container\ContainerExceptionInterface', - $this->exception - ); - } - - /** - * Test for NotFoundException - * - * @return void - */ - public function testContainerExceptionExtendsException() - { - $this->assertInstanceOf( - 'Exception', - $this->exception - ); - } -}