diff --git a/ajax.php b/ajax.php index f5a31c5b08..8482bcef4a 100644 --- a/ajax.php +++ b/ajax.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\AjaxController; use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -20,12 +22,20 @@ $_GET['ajax_request'] = 'true'; require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $response->setAjax(true); $controller = new AjaxController( $response, - $GLOBALS['dbi'], + $dbi, $GLOBALS['PMA_Config'] ); diff --git a/browse_foreigners.php b/browse_foreigners.php index 367dc1ec9b..96cdc617c2 100644 --- a/browse_foreigners.php +++ b/browse_foreigners.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\BrowseForeigners; use PhpMyAdmin\Controllers\BrowseForeignersController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -21,11 +23,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; Util::checkParameters(['db', 'table', 'field'], true); -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new BrowseForeignersController( $response, - $GLOBALS['dbi'], + $dbi, new BrowseForeigners( $GLOBALS['cfg']['LimitChars'], $GLOBALS['cfg']['MaxRows'], @@ -33,7 +42,7 @@ $controller = new BrowseForeignersController( $GLOBALS['cfg']['ShowAll'], $GLOBALS['pmaThemeImage'] ), - new Relation($GLOBALS['dbi']) + new Relation($dbi) ); $response->getFooter()->setMinimal(); diff --git a/chk_rel.php b/chk_rel.php index caa7c36dcc..0f608a5bbd 100644 --- a/chk_rel.php +++ b/chk_rel.php @@ -7,6 +7,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -16,7 +18,16 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$relation = new Relation($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$relation = new Relation($dbi); // If request for creating the pmadb if (isset($_POST['create_pmadb']) && $relation->createPmaDatabase()) { @@ -34,7 +45,6 @@ if (isset($_POST['fix_pmadb'])) { $relation->fixPmaTables($cfgRelation['db']); } -$response = Response::getInstance(); $response->addHTML( $relation->getRelationsParamDiagnostic($cfgRelation) ); diff --git a/db_central_columns.php b/db_central_columns.php index c42b0cb9b4..89ebe964c8 100644 --- a/db_central_columns.php +++ b/db_central_columns.php @@ -14,17 +14,27 @@ if (! defined('ROOT_PATH')) { use PhpMyAdmin\CentralColumns; use PhpMyAdmin\Controllers\Database\CentralColumnsController; use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Response; require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$centralColumns = new CentralColumns($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$centralColumns = new CentralColumns($dbi); $controller = new CentralColumnsController( $response, - $GLOBALS['dbi'], + $dbi, $db, $centralColumns ); diff --git a/db_datadict.php b/db_datadict.php index dc5452b9ac..fb4f39447e 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\DataDictionaryController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; @@ -21,13 +23,20 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; Util::checkParameters(['db']); -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new DataDictionaryController( $response, - $GLOBALS['dbi'], + $dbi, $db, - new Relation($GLOBALS['dbi']), + new Relation($dbi), new Transformations() ); diff --git a/db_designer.php b/db_designer.php index 6362fdfe83..09ad879264 100644 --- a/db_designer.php +++ b/db_designer.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\Database\Designer; use PhpMyAdmin\Database\Designer\Common; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -17,10 +19,17 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); -$databaseDesigner = new Designer($GLOBALS['dbi']); -$designerCommon = new Common($GLOBALS['dbi']); +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$databaseDesigner = new Designer($dbi); +$designerCommon = new Common($dbi); if (isset($_REQUEST['dialog'])) { if ($_GET['dialog'] == 'edit') { diff --git a/db_events.php b/db_events.php index ab3a8b6788..26ad9fee16 100644 --- a/db_events.php +++ b/db_events.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\EventsController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -18,13 +20,20 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $_PMA_RTE = 'EVN'; $controller = new EventsController( $response, - $GLOBALS['dbi'], + $dbi, $db ); @@ -32,7 +41,7 @@ if (! $response->isAjax()) { /** * Displays the header and tabs */ - if (! empty($table) && in_array($table, $GLOBALS['dbi']->getTables($db))) { + if (! empty($table) && in_array($table, $dbi->getTables($db))) { include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; } else { $table = ''; @@ -57,7 +66,7 @@ if (! $response->isAjax()) { * create the missing $url_query variable */ if (strlen($db) > 0) { - $GLOBALS['dbi']->selectDb($db); + $dbi->selectDb($db); if (! isset($url_query)) { $url_query = Url::getCommon( [ diff --git a/db_export.php b/db_export.php index 5564be8fe4..b65b178638 100644 --- a/db_export.php +++ b/db_export.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Display\Export as DisplayExport; use PhpMyAdmin\Export; use PhpMyAdmin\Message; @@ -18,19 +20,24 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Gets some core libraries - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + PageSettings::showGroup('Export'); -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('export.js'); -$export = new Export($GLOBALS['dbi']); +$export = new Export($dbi); // $sub_part is used in Util::getDbInfo() to see if we are coming from // db_export.php, in which case we don't obey $cfg['MaxTableList'] diff --git a/db_multi_table_query.php b/db_multi_table_query.php index 10ed80fbe9..5bf9f35886 100644 --- a/db_multi_table_query.php +++ b/db_multi_table_query.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\MultiTableQueryController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -16,11 +18,18 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new MultiTableQueryController( $response, - $GLOBALS['dbi'], + $dbi, $db ); diff --git a/db_operations.php b/db_operations.php index 4af05332b9..ec952afd80 100644 --- a/db_operations.php +++ b/db_operations.php @@ -15,6 +15,7 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Display\CreateTable; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; @@ -29,25 +30,29 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * requirements - */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); $checkUserPrivileges->getPrivileges(); -// add a javascript file for jQuery functions to handle Ajax actions -$response = Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('db_operations.js'); $sql_query = ''; -$relation = new Relation($GLOBALS['dbi']); -$operations = new Operations($GLOBALS['dbi'], $relation); -$relationCleanup = new RelationCleanup($GLOBALS['dbi'], $relation); +$relation = new Relation($dbi); +$operations = new Operations($dbi, $relation); +$relationCleanup = new RelationCleanup($dbi, $relation); /** * Rename/move or copy database @@ -65,7 +70,7 @@ if (strlen($GLOBALS['db']) > 0 $message = Message::error(__('The database name is empty!')); } else { // lower_case_table_names=1 `DB` becomes `db` - if ($GLOBALS['dbi']->getLowerCaseNames() === '1') { + if ($dbi->getLowerCaseNames() === '1') { $_POST['newname'] = mb_strtolower( $_POST['newname'] ); @@ -90,9 +95,9 @@ if (strlen($GLOBALS['db']) > 0 $operations->runProcedureAndFunctionDefinitions($GLOBALS['db']); // go back to current db, just in case - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $dbi->selectDb($GLOBALS['db']); - $tables_full = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']); + $tables_full = $dbi->getTablesFull($GLOBALS['db']); // remove all foreign key constraints, otherwise we can get errors /* @var $export_sql_plugin ExportSql */ @@ -132,7 +137,7 @@ if (strlen($GLOBALS['db']) > 0 } unset($sqlConstratints); - if ($GLOBALS['dbi']->getVersion() >= 50100) { + if ($dbi->getVersion() >= 50100) { // here DELIMITER is not used because it's not part of the // language; each statement is sent one by one @@ -140,7 +145,7 @@ if (strlen($GLOBALS['db']) > 0 } // go back to current db, just in case - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $dbi->selectDb($GLOBALS['db']); // Duplicate the bookmarks for this db (done once for each db) $operations->duplicateBookmarks($_error, $GLOBALS['db']); @@ -161,7 +166,7 @@ if (strlen($GLOBALS['db']) > 0 $local_query = 'DROP DATABASE ' . Util::backquote($GLOBALS['db']) . ';'; $sql_query .= "\n" . $local_query; - $GLOBALS['dbi']->query($local_query); + $dbi->query($local_query); $message = Message::success( __('Database %1$s has been renamed to %2$s.') @@ -256,8 +261,8 @@ if (isset($message)) { unset($message); } -$db_collation = $GLOBALS['dbi']->getDbCollation($GLOBALS['db']); -$is_information_schema = $GLOBALS['dbi']->isSystemSchema($GLOBALS['db']); +$db_collation = $dbi->getDbCollation($GLOBALS['db']); +$is_information_schema = $dbi->isSystemSchema($GLOBALS['db']); if (! $is_information_schema) { if ($cfgRelation['commwork']) { @@ -282,7 +287,7 @@ if (! $is_information_schema) { // Don't even try to drop information_schema. // You won't be able to. Believe me. You won't. // Don't allow to easily drop mysql database, RFE #1327514. - if (($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) + if (($dbi->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) && ! $db_is_system_schema && $GLOBALS['db'] != 'mysql' ) { diff --git a/db_qbe.php b/db_qbe.php index e1f172a3fb..dc86f3e6d1 100644 --- a/db_qbe.php +++ b/db_qbe.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Database\Qbe; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -21,13 +23,18 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * requirements - */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$relation = new Relation($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$relation = new Relation($dbi); $template = new Template(); // Gets the relation settings @@ -144,7 +151,7 @@ if ($message_to_display) { unset($message_to_display); // create new qbe search instance -$db_qbe = new Qbe($GLOBALS['dbi'], $GLOBALS['db'], $savedSearchList, $savedSearch); +$db_qbe = new Qbe($dbi, $GLOBALS['db'], $savedSearchList, $savedSearch); $secondaryTabs = [ 'multi' => [ diff --git a/db_routines.php b/db_routines.php index 7cf998da42..98f243b50b 100644 --- a/db_routines.php +++ b/db_routines.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Controllers\Database\RoutinesController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -19,16 +21,23 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); -$checkUserPrivileges->getPrivileges(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); -$response = Response::getInstance(); +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); +$checkUserPrivileges->getPrivileges(); $_PMA_RTE = 'RTN'; $controller = new RoutinesController( $response, - $GLOBALS['dbi'], + $dbi, $db ); @@ -36,7 +45,7 @@ if (! $response->isAjax()) { /** * Displays the header and tabs */ - if (! empty($table) && in_array($table, $GLOBALS['dbi']->getTables($db))) { + if (! empty($table) && in_array($table, $dbi->getTables($db))) { include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; } else { $table = ''; @@ -61,7 +70,7 @@ if (! $response->isAjax()) { * create the missing $url_query variable */ if (strlen($db) > 0) { - $GLOBALS['dbi']->selectDb($db); + $dbi->selectDb($db); if (! isset($url_query)) { $url_query = Url::getCommon( [ diff --git a/db_search.php b/db_search.php index 09b8ce9263..4ba97f6461 100644 --- a/db_search.php +++ b/db_search.php @@ -10,6 +10,8 @@ declare(strict_types=1); use PhpMyAdmin\Database\Search; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Util; @@ -17,14 +19,19 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** -* Gets some core libraries -*/ require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('db_search.js'); $scripts->addFile('sql.js'); $scripts->addFile('makegrid.js'); @@ -44,7 +51,7 @@ $url_query .= '&goto=db_search.php'; $url_params['goto'] = 'db_search.php'; // Create a database search instance -$db_search = new Search($GLOBALS['dbi'], $GLOBALS['db']); +$db_search = new Search($dbi, $GLOBALS['db']); // Display top links if we are not in an Ajax request if (! $response->isAjax()) { diff --git a/db_sql.php b/db_sql.php index 8def0d1349..957b24acc9 100644 --- a/db_sql.php +++ b/db_sql.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\SqlController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -16,11 +18,18 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new SqlController( $response, - $GLOBALS['dbi'], + $dbi, $db ); diff --git a/db_sql_autocomplete.php b/db_sql_autocomplete.php index 7b28f283d1..bac726590c 100644 --- a/db_sql_autocomplete.php +++ b/db_sql_autocomplete.php @@ -7,6 +7,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -15,13 +17,22 @@ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) { $db = isset($_POST['db']) ? $_POST['db'] : $GLOBALS['db']; $sql_autocomplete = []; if ($db) { - $tableNames = $GLOBALS['dbi']->getTables($db); + $tableNames = $dbi->getTables($db); foreach ($tableNames as $tableName) { - $sql_autocomplete[$tableName] = $GLOBALS['dbi']->getColumns( + $sql_autocomplete[$tableName] = $dbi->getColumns( $db, $tableName ); @@ -30,5 +41,5 @@ if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) { } else { $sql_autocomplete = true; } -$response = Response::getInstance(); + $response->addJSON("tables", json_encode($sql_autocomplete)); diff --git a/db_structure.php b/db_structure.php index 9e5e9c1163..ea02cd69f0 100644 --- a/db_structure.php +++ b/db_structure.php @@ -8,6 +8,7 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\StructureController; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Replication; @@ -25,10 +26,13 @@ $container->factory(StructureController::class); $container->set(Response::class, Response::getInstance()); $container->alias('response', Response::class); +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + /* Define dependencies for the concerned controller */ $dependency_definitions = [ 'db' => $db, - 'relation' => new Relation($GLOBALS['dbi']), + 'relation' => new Relation($dbi), 'replication' => new Replication(), ]; diff --git a/db_triggers.php b/db_triggers.php index 31f84ca763..4679f6f159 100644 --- a/db_triggers.php +++ b/db_triggers.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Database\TriggersController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -18,13 +20,20 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $_PMA_RTE = 'TRI'; $controller = new TriggersController( $response, - $GLOBALS['dbi'], + $dbi, $db ); @@ -32,7 +41,7 @@ if (! $response->isAjax()) { /** * Displays the header and tabs */ - if (! empty($table) && in_array($table, $GLOBALS['dbi']->getTables($db))) { + if (! empty($table) && in_array($table, $dbi->getTables($db))) { include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; } else { $table = ''; @@ -57,7 +66,7 @@ if (! $response->isAjax()) { * create the missing $url_query variable */ if (strlen($db) > 0) { - $GLOBALS['dbi']->selectDb($db); + $dbi->selectDb($db); if (! isset($url_query)) { $url_query = Url::getCommon( [ diff --git a/export.php b/export.php index 6553ff1a20..d07482cdb9 100644 --- a/export.php +++ b/export.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Encoding; use PhpMyAdmin\Export; use PhpMyAdmin\Plugins; @@ -22,17 +24,22 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Get the variables sent or posted to this script and a core script - */ include_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('export_output.js'); -$export = new Export($GLOBALS['dbi']); +$export = new Export($dbi); //check if it's the GET request to check export time out if (isset($_GET['check_time_out'])) { @@ -421,7 +428,7 @@ if ($save_on_server) { } // end download } -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); // Fake loop just to allow skip of remain of this code by break, I'd really // need exceptions here :-) diff --git a/import.php b/import.php index 8b0f2c5265..f6785e38a0 100644 --- a/import.php +++ b/import.php @@ -9,6 +9,8 @@ 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; @@ -29,11 +31,17 @@ if (isset($_POST['format']) && $_POST['format'] == 'ldi') { define('PMA_ENABLE_LDI', 1); } -/** - * Get the variables sent or posted to this script and a core script - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $import = new Import(); if (isset($_POST['show_as_php'])) { @@ -46,8 +54,6 @@ if (isset($_POST['simulate_dml'])) { exit; } -$response = Response::getInstance(); - $sql = new Sql(); // If it's a refresh console bookmarks request @@ -72,7 +78,7 @@ if (isset($_POST['console_bookmark_add'])) { ]; $isShared = ($_POST['shared'] == 'true' ? true : false); $bookmark = Bookmark::createBookmark( - $GLOBALS['dbi'], + $dbi, $GLOBALS['cfg']['Server']['user'], $bookmarkFields, $isShared @@ -142,13 +148,13 @@ if (! empty($sql_query)) { // making sure that :param does not apply values to :param1 $sql_query = preg_replace( '/' . $quoted . '([^a-zA-Z0-9_])/', - $GLOBALS['dbi']->escapeString($replacement) . '${1}', + $dbi->escapeString($replacement) . '${1}', $sql_query ); // for parameters the appear at the end of the string $sql_query = preg_replace( '/' . $quoted . '$/', - $GLOBALS['dbi']->escapeString($replacement), + $dbi->escapeString($replacement), $sql_query ); } @@ -305,7 +311,7 @@ if (basename($_SERVER['SCRIPT_NAME']) === 'import.php') { if (strlen($db) > 0) { - $GLOBALS['dbi']->selectDb($db); + $dbi->selectDb($db); } Util::setTimeLimit(); @@ -345,7 +351,7 @@ if (! empty($_POST['id_bookmark'])) { switch ($_POST['action_bookmark']) { case 0: // bookmarked query that have to be run $bookmark = Bookmark::get( - $GLOBALS['dbi'], + $dbi, $GLOBALS['cfg']['Server']['user'], $db, $id_bookmark, @@ -381,7 +387,7 @@ if (! empty($_POST['id_bookmark'])) { break; case 1: // bookmarked query that have to be displayed $bookmark = Bookmark::get( - $GLOBALS['dbi'], + $dbi, $GLOBALS['cfg']['Server']['user'], $db, $id_bookmark @@ -400,7 +406,7 @@ if (! empty($_POST['id_bookmark'])) { break; case 2: // bookmarked query that have to be deleted $bookmark = Bookmark::get( - $GLOBALS['dbi'], + $dbi, $GLOBALS['cfg']['Server']['user'], $db, $id_bookmark @@ -520,7 +526,7 @@ if (Encoding::isSupported() && isset($charset_of_file)) { $charset_conversion = true; } } elseif (isset($charset_of_file) && $charset_of_file != 'utf-8') { - $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\''); + $dbi->query('SET NAMES \'' . $charset_of_file . '\''); // We can not show query in this case, it is in different charset $sql_query_disabled = true; $reset_charset = true; @@ -584,8 +590,8 @@ if ($file_to_unlink != '') { // Reset charset back, if we did some changes if ($reset_charset) { - $GLOBALS['dbi']->query('SET CHARACTER SET ' . $GLOBALS['charset_connection']); - $GLOBALS['dbi']->setCollationConnection($collation_connection); + $dbi->query('SET CHARACTER SET ' . $GLOBALS['charset_connection']); + $dbi->setCollation($collation_connection); } // Show correct message @@ -717,7 +723,7 @@ if ($go_sql) { if ($sql->hasNoRightsToDropDatabase( $analyzed_sql_results, $cfg['AllowUserDropDatabase'], - $GLOBALS['dbi']->isSuperuser() + $dbi->isSuperuser() )) { PhpMyAdmin\Util::mysqlDie( __('"DROP DATABASE" statements are disabled.'), @@ -800,5 +806,5 @@ if ($go_sql) { // If there is request for ROLLBACK in the end. if (isset($_POST['rollback_query'])) { - $GLOBALS['dbi']->query('ROLLBACK'); + $dbi->query('ROLLBACK'); } diff --git a/index.php b/index.php index a4f7102470..d1b08ae039 100644 --- a/index.php +++ b/index.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\HomeController; use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Url; use PhpMyAdmin\Util; @@ -56,11 +58,18 @@ if (! empty($_REQUEST['target']) exit; } -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new HomeController( $response, - $GLOBALS['dbi'], + $dbi, $GLOBALS['PMA_Config'] ); diff --git a/libraries/classes/DatabaseInterface.php b/libraries/classes/DatabaseInterface.php index 113511414b..4e85a8979c 100644 --- a/libraries/classes/DatabaseInterface.php +++ b/libraries/classes/DatabaseInterface.php @@ -3166,7 +3166,7 @@ class DatabaseInterface $GLOBALS['dbi'] = new DatabaseInterface($extension); $container = Container::getDefaultContainer(); - $container->set('PMA_DatabaseInterface', $GLOBALS['dbi']); - $container->alias('dbi', 'PMA_DatabaseInterface'); + $container->set(DatabaseInterface::class, $GLOBALS['dbi']); + $container->alias('dbi', DatabaseInterface::class); } } diff --git a/navigation.php b/navigation.php index 168b244b16..83af242330 100644 --- a/navigation.php +++ b/navigation.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Navigation\Navigation; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -18,8 +20,15 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -// Also initialises the collapsible tree class -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $navigation = new Navigation(); if (! $response->isAjax()) { $response->addHTML( @@ -35,7 +44,7 @@ if (isset($_POST['getNaviSettings']) && $_POST['getNaviSettings']) { exit(); } -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); if ($cfgRelation['navwork']) { if (isset($_POST['hideNavItem'])) { diff --git a/normalization.php b/normalization.php index 437f4d0fdc..ff0d47ef09 100644 --- a/normalization.php +++ b/normalization.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Normalization; use PhpMyAdmin\Response; use PhpMyAdmin\Url; @@ -18,7 +20,16 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$normalization = new Normalization($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$normalization = new Normalization($dbi); if (isset($_POST['getColumns'])) { $html = '' @@ -68,8 +79,6 @@ if (isset($_POST['getNewTables2NF'])) { exit; } -$response = Response::getInstance(); - if (isset($_POST['getNewTables3NF'])) { $dependencies = json_decode($_POST['pd']); $tables = json_decode($_POST['tables']); diff --git a/schema_export.php b/schema_export.php index 95a533a1c8..abe2be0b97 100644 --- a/schema_export.php +++ b/schema_export.php @@ -7,6 +7,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Export; use PhpMyAdmin\Relation; use PhpMyAdmin\Util; @@ -15,16 +17,18 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Gets some core libraries - */ require_once ROOT_PATH . 'libraries/common.inc.php'; +$container = Container::getDefaultContainer(); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + /** * get all variables needed for exporting relational schema * in $cfgRelation */ -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); if (! isset($_REQUEST['export_type'])) { @@ -35,5 +39,5 @@ if (! isset($_REQUEST['export_type'])) { * Include the appropriate Schema Class depending on $export_type * default is PDF */ -$export = new Export($GLOBALS['dbi']); +$export = new Export($dbi); $export->processExportSchema($_REQUEST['export_type']); diff --git a/server_databases.php b/server_databases.php index f46171a975..708c7b9d41 100644 --- a/server_databases.php +++ b/server_databases.php @@ -9,6 +9,7 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Controllers\Server\DatabasesController; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; @@ -19,31 +20,25 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; $container = Container::getDefaultContainer(); -$container->factory( - 'PhpMyAdmin\Controllers\Server\DatabasesController' -); -$container->alias( - 'DatabasesController', - 'PhpMyAdmin\Controllers\Server\DatabasesController' -); -$container->set('PhpMyAdmin\Response', Response::getInstance()); -$container->alias('response', 'PhpMyAdmin\Response'); +$container->factory(DatabasesController::class); +$container->set(Response::class, Response::getInstance()); +$container->alias('response', Response::class); /** @var DatabasesController $controller */ -$controller = $container->get( - 'DatabasesController', - [] -); +$controller = $container->get(DatabasesController::class); /** @var Response $response */ -$response = $container->get('response'); +$response = $container->get(Response::class); -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); $checkUserPrivileges->getPrivileges(); if (isset($_POST['drop_selected_dbs']) && $response->isAjax() - && ($GLOBALS['dbi']->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) + && ($dbi->isSuperuser() || $GLOBALS['cfg']['AllowUserDropDatabase']) ) { $response->addJSON($controller->dropDatabasesAction([ 'drop_selected_dbs' => $_POST['drop_selected_dbs'], diff --git a/server_privileges.php b/server_privileges.php index 915467c1f9..6279dabd66 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Relation; use PhpMyAdmin\RelationCleanup; @@ -21,15 +23,17 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * include common file - */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); $checkUserPrivileges->getPrivileges(); -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); /** @@ -42,8 +46,8 @@ $scripts->addFile('server_privileges.js'); $scripts->addFile('vendor/zxcvbn.js'); $template = new Template(); -$relationCleanup = new RelationCleanup($GLOBALS['dbi'], $relation); -$serverPrivileges = new Privileges($template, $GLOBALS['dbi'], $relation, $relationCleanup); +$relationCleanup = new RelationCleanup($dbi, $relation); +$serverPrivileges = new Privileges($template, $dbi, $relation, $relationCleanup); if ((isset($_GET['viewing_mode']) && $_GET['viewing_mode'] == 'server') @@ -139,7 +143,7 @@ list( /** * Checks if the user is allowed to do what he tries to... */ -if (! $GLOBALS['dbi']->isSuperuser() && ! $GLOBALS['is_grantuser'] +if (! $dbi->isSuperuser() && ! $GLOBALS['is_grantuser'] && ! $GLOBALS['is_createuser'] ) { $response->addHTML( @@ -258,7 +262,7 @@ if (! empty($_POST['update_privs'])) { * Assign users to user groups */ if (! empty($_POST['changeUserGroup']) && $cfgRelation['menuswork'] - && $GLOBALS['dbi']->isSuperuser() && $GLOBALS['is_createuser'] + && $dbi->isSuperuser() && $GLOBALS['is_createuser'] ) { $serverPrivileges->setUserGroup($username, $_POST['userGroup']); $message = Message::success(); diff --git a/server_replication.php b/server_replication.php index 7f7e854411..40d0a14355 100644 --- a/server_replication.php +++ b/server_replication.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\ReplicationController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\ReplicationGui; use PhpMyAdmin\Response; @@ -19,11 +21,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new ReplicationController( $response, - $GLOBALS['dbi'] + $dbi ); $header = $response->getHeader(); @@ -36,7 +45,7 @@ if (isset($_POST['url_params']) && is_array($_POST['url_params'])) { $GLOBALS['url_params'] = $_POST['url_params']; } -if ($GLOBALS['dbi']->isSuperuser()) { +if ($dbi->isSuperuser()) { $replicationGui = new ReplicationGui(); $replicationGui->handleControlRequest(); } diff --git a/server_sql.php b/server_sql.php index 83a9be97f8..deeb0c9a15 100644 --- a/server_sql.php +++ b/server_sql.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\SqlController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -16,11 +18,18 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new SqlController( $response, - $GLOBALS['dbi'] + $dbi ); $header = $response->getHeader(); diff --git a/server_status.php b/server_status.php index 2b7c7b16eb..53efe1e143 100644 --- a/server_status.php +++ b/server_status.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\StatusController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -19,11 +21,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new StatusController( $response, - $GLOBALS['dbi'], + $dbi, new Data() ); diff --git a/server_status_advisor.php b/server_status_advisor.php index 24b9dbbfa4..78cabe559c 100644 --- a/server_status_advisor.php +++ b/server_status_advisor.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\AdvisorController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -18,13 +20,21 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $scripts = $response->getHeader()->getScripts(); $scripts->addFile('server_status_advisor.js'); $controller = new AdvisorController( $response, - $GLOBALS['dbi'], + $dbi, new Data() ); diff --git a/server_status_monitor.php b/server_status_monitor.php index 4a07b1bafa..b76630ac68 100644 --- a/server_status_monitor.php +++ b/server_status_monitor.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\MonitorController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Server\Status\Data; use PhpMyAdmin\Server\Status\Monitor; use PhpMyAdmin\Response; @@ -20,13 +22,20 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new MonitorController( $response, - $GLOBALS['dbi'], + $dbi, new Data, - new Monitor($GLOBALS['dbi']) + new Monitor($dbi) ); /** diff --git a/server_status_processes.php b/server_status_processes.php index a4807ecb32..30ccc4d381 100644 --- a/server_status_processes.php +++ b/server_status_processes.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\ProcessesController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -19,11 +21,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new ProcessesController( $response, - $GLOBALS['dbi'], + $dbi, new Data() ); diff --git a/server_status_queries.php b/server_status_queries.php index a0b0dbe66f..982fda10ce 100644 --- a/server_status_queries.php +++ b/server_status_queries.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\QueriesController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -19,11 +21,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new QueriesController( $response, - $GLOBALS['dbi'], + $dbi, new Data() ); diff --git a/server_status_variables.php b/server_status_variables.php index 1cce87d1f5..c27b59d07f 100644 --- a/server_status_variables.php +++ b/server_status_variables.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\Status\VariablesController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Server\Status\Data; @@ -19,11 +21,18 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/server_common.inc.php'; require_once ROOT_PATH . 'libraries/replication.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new VariablesController( $response, - $GLOBALS['dbi'], + $dbi, new Data() ); diff --git a/server_user_groups.php b/server_user_groups.php index 4b9252e103..16796d8634 100644 --- a/server_user_groups.php +++ b/server_user_groups.php @@ -7,6 +7,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Server\UserGroups; @@ -18,21 +20,29 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$relation = new Relation($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$relation = new Relation($dbi); $relation->getRelationsParam(); if (! $GLOBALS['cfgRelation']['menuswork']) { exit; } -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('server_user_groups.js'); /** * Only allowed to superuser */ -if (! $GLOBALS['dbi']->isSuperuser()) { +if (! $dbi->isSuperuser()) { $response->addHTML( PhpMyAdmin\Message::error(__('No Privileges')) ->getDisplay() diff --git a/sql.php b/sql.php index 5d140e5b09..f08e2f45a7 100644 --- a/sql.php +++ b/sql.php @@ -11,6 +11,8 @@ 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; @@ -26,14 +28,22 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); $checkUserPrivileges->getPrivileges(); PageSettings::showGroup('Browse'); -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('vendor/jquery/jquery.uitablefilter.js'); $scripts->addFile('tbl_change.js'); $scripts->addFile('indexes.js'); @@ -167,7 +177,7 @@ if ($table != $table_from_sql && ! empty($table_from_sql)) { if ($sql->hasNoRightsToDropDatabase( $analyzed_sql_results, $cfg['AllowUserDropDatabase'], - $GLOBALS['dbi']->isSuperuser() + $dbi->isSuperuser() )) { Util::mysqlDie( __('"DROP DATABASE" statements are disabled.'), diff --git a/tbl_addfield.php b/tbl_addfield.php index 60a23d938d..e7ea1deab4 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\CreateAddField; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; @@ -23,9 +25,17 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('tbl_structure.js'); // Check parameters @@ -72,7 +82,7 @@ if (isset($_POST['do_save_data'])) { //tbl_structure.php below unset($_POST['do_save_data']); - $createAddField = new CreateAddField($GLOBALS['dbi']); + $createAddField = new CreateAddField($dbi); list($result, $sql_query) = $createAddField->tryColumnCreationQuery($db, $table, $err_url); diff --git a/tbl_change.php b/tbl_change.php index d64abe9a33..bbd08404ea 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Config\PageSettings; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\InsertEdit; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -23,6 +25,15 @@ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + PageSettings::showGroup('Edit'); /** @@ -30,7 +41,7 @@ PageSettings::showGroup('Edit'); */ require_once ROOT_PATH . 'libraries/db_table_exists.inc.php'; -$insertEdit = new InsertEdit($GLOBALS['dbi']); +$insertEdit = new InsertEdit($dbi); /** * Determine whether Insert or Edit and set global variables @@ -72,12 +83,8 @@ $comments_map = $insertEdit->getCommentsMap($db, $table); * START REGULAR OUTPUT */ -/** - * Load JavaScript files - */ -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('sql.js'); $scripts->addFile('tbl_change.js'); $scripts->addFile('vendor/jquery/additional-methods.js'); @@ -95,7 +102,7 @@ if (! empty($disp_message)) { $table_columns = $insertEdit->getTableColumns($db, $table); // retrieve keys into foreign fields, if any -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $foreigners = $relation->getForeigners($db, $table); // Retrieve form parameters for insert/edit form diff --git a/tbl_create.php b/tbl_create.php index 5a7e0c6846..a5a7344b68 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -9,6 +9,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; use PhpMyAdmin\CreateAddField; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; use PhpMyAdmin\Url; @@ -23,6 +25,15 @@ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + // Check parameters Util::checkParameters(['db']); @@ -41,7 +52,7 @@ if (strlen($db) === 0) { /** * Selects the database to work with */ -if (! $GLOBALS['dbi']->selectDb($db)) { +if (! $dbi->selectDb($db)) { Util::mysqlDie( sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)), '', @@ -50,7 +61,7 @@ if (! $GLOBALS['dbi']->selectDb($db)) { ); } -if ($GLOBALS['dbi']->getColumns($db, $table)) { +if ($dbi->getColumns($db, $table)) { // table exists already Util::mysqlDie( sprintf(__('Table %s already exists!'), htmlspecialchars($table)), @@ -60,7 +71,7 @@ if ($GLOBALS['dbi']->getColumns($db, $table)) { ); } -$createAddField = new CreateAddField($GLOBALS['dbi']); +$createAddField = new CreateAddField($dbi); // for libraries/tbl_columns_definition_form.inc.php // check number of fields to be created @@ -79,7 +90,7 @@ if (isset($_POST['do_save_data'])) { Core::previewSQL($sql_query); } // Executes the query - $result = $GLOBALS['dbi']->tryQuery($sql_query); + $result = $dbi->tryQuery($sql_query); if ($result) { // Update comment table for mime types [MIME] @@ -105,9 +116,8 @@ if (isset($_POST['do_save_data'])) { } } } else { - $response = Response::getInstance(); $response->setRequestStatus(false); - $response->addJSON('message', $GLOBALS['dbi']->getError()); + $response->addJSON('message', $dbi->getError()); } exit; } // end do create table diff --git a/tbl_export.php b/tbl_export.php index c815b99986..a9eec45ae6 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -8,6 +8,8 @@ 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; @@ -16,20 +18,25 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + PageSettings::showGroup('Export'); -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('export.js'); // Get the relation settings -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); $displayExport = new Export(); diff --git a/tbl_get_field.php b/tbl_get_field.php index 614657b00d..2be0b6fe66 100644 --- a/tbl_get_field.php +++ b/tbl_get_field.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Mime; use PhpMyAdmin\Response; @@ -20,9 +22,15 @@ if (! defined('ROOT_PATH')) { */ require_once ROOT_PATH . 'libraries/common.inc.php'; -// we don't want the usual PhpMyAdmin\Response-generated HTML above the column's -// data -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $response->disable(); /* Check parameters */ @@ -34,7 +42,7 @@ PhpMyAdmin\Util::checkParameters( ); /* Select database */ -if (! $GLOBALS['dbi']->selectDb($db)) { +if (! $dbi->selectDb($db)) { PhpMyAdmin\Util::mysqlDie( sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)), '', @@ -43,7 +51,7 @@ if (! $GLOBALS['dbi']->selectDb($db)) { } /* Check if table exists */ -if (! $GLOBALS['dbi']->getColumns($db, $table)) { +if (! $dbi->getColumns($db, $table)) { PhpMyAdmin\Util::mysqlDie(__('Invalid table name')); } @@ -51,7 +59,7 @@ if (! $GLOBALS['dbi']->getColumns($db, $table)) { $sql = 'SELECT ' . PhpMyAdmin\Util::backquote($_GET['transform_key']) . ' FROM ' . PhpMyAdmin\Util::backquote($table) . ' WHERE ' . $_GET['where_clause'] . ';'; -$result = $GLOBALS['dbi']->fetchValue($sql); +$result = $dbi->fetchValue($sql); /* Check return code */ if ($result === false) { diff --git a/tbl_indexes.php b/tbl_indexes.php index 112f0c98df..c20c41ade5 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -8,6 +8,7 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\IndexesController; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Di\Container; use PhpMyAdmin\Index; use PhpMyAdmin\Response; @@ -20,13 +21,15 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; $container = Container::getDefaultContainer(); $container->factory(IndexesController::class); -$container->set('PhpMyAdmin\Response', Response::getInstance()); -$container->alias('response', 'PhpMyAdmin\Response'); +$container->set(Response::class, Response::getInstance()); +$container->alias('response', Response::class); /* Define dependencies for the concerned controller */ $db = $container->get('db'); $table = $container->get('table'); -$dbi = $container->get('dbi'); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); if (! isset($_POST['create_edit_table'])) { include_once ROOT_PATH . 'libraries/tbl_common.inc.php'; diff --git a/tbl_operations.php b/tbl_operations.php index bcd702fddd..1d2ccc0d08 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\CheckUserPrivileges; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Index; use PhpMyAdmin\Message; use PhpMyAdmin\Partition; @@ -23,17 +25,22 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$checkUserPrivileges = new CheckUserPrivileges($GLOBALS['dbi']); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$checkUserPrivileges = new CheckUserPrivileges($dbi); $checkUserPrivileges->getPrivileges(); $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']); -/** - * Load JavaScript files - */ -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('tbl_operations.js'); /** @@ -46,19 +53,19 @@ $url_params['goto'] = $url_params['back'] = 'tbl_operations.php'; /** * Gets relation settings */ -$relation = new Relation($GLOBALS['dbi']); -$operations = new Operations($GLOBALS['dbi'], $relation); +$relation = new Relation($dbi); +$operations = new Operations($dbi, $relation); $cfgRelation = $relation->getRelationsParam(); // reselect current db (needed in some cases probably due to // the calling of PhpMyAdmin\Relation) -$GLOBALS['dbi']->selectDb($GLOBALS['db']); +$dbi->selectDb($GLOBALS['db']); /** * Gets tables information */ -$pma_table = $GLOBALS['dbi']->getTable( +$pma_table = $dbi->getTable( $GLOBALS['db'], $GLOBALS['table'] ); @@ -92,7 +99,7 @@ if ($pma_table->isEngine('ARIA')) { $create_options['page_checksum'] = isset($create_options['page_checksum']) ? $create_options['page_checksum'] : ''; } -$pma_table = $GLOBALS['dbi']->getTable( +$pma_table = $dbi->getTable( $GLOBALS['db'], $GLOBALS['table'] ); @@ -141,7 +148,7 @@ if (isset($_POST['submitoptions'])) { // Reselect the original DB $GLOBALS['db'] = $oldDb; - $GLOBALS['dbi']->selectDb($oldDb); + $dbi->selectDb($oldDb); $_message .= $pma_table->getLastMessage(); $result = true; $GLOBALS['table'] = $pma_table->getName(); @@ -189,7 +196,7 @@ if (isset($_POST['submitoptions'])) { . Util::backquote($GLOBALS['table']); $sql_query .= "\r\n" . implode("\r\n", $table_alters); $sql_query .= ';'; - $result = $GLOBALS['dbi']->query($sql_query) ? true : false; + $result = $dbi->query($sql_query) ? true : false; $reread_info = true; unset($table_alters); $warning_messages = $operations->getWarningMessagesArray(); @@ -226,8 +233,8 @@ if (isset($_POST['submit_partition']) if ($reread_info) { // to avoid showing the old value (for example the AUTO_INCREMENT) after // a change, clear the cache - $GLOBALS['dbi']->clearTableCache(); - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $dbi->clearTableCache(); + $dbi->selectDb($GLOBALS['db']); $GLOBALS['showtable'] = $pma_table->getStatusInfo(null, true); if ($pma_table->isView()) { $tbl_is_view = true; @@ -310,7 +317,7 @@ $url_params['goto'] /** * Get columns names */ -$columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']); +$columns = $dbi->getColumns($GLOBALS['db'], $GLOBALS['table']); /** * Displays the page @@ -472,7 +479,7 @@ unset($partition_names); // this choice (InnoDB maintains integrity by itself) if ($cfgRelation['relwork'] && ! $pma_table->isEngine("INNODB")) { - $GLOBALS['dbi']->selectDb($GLOBALS['db']); + $dbi->selectDb($GLOBALS['db']); $foreign = $relation->getForeigners($GLOBALS['db'], $GLOBALS['table'], '', 'internal'); if (! empty($foreign)) { diff --git a/tbl_relation.php b/tbl_relation.php index 299042f507..deefc6099d 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -16,6 +16,7 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\RelationController; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; @@ -30,20 +31,23 @@ require_once ROOT_PATH . 'libraries/common.inc.php'; $container = Container::getDefaultContainer(); $container->factory(RelationController::class); -$container->set('PhpMyAdmin\Response', Response::getInstance()); -$container->alias('response', 'PhpMyAdmin\Response'); +$container->set(Response::class, Response::getInstance()); +$container->alias('response', Response::class); /* Define dependencies for the concerned controller */ $db = $container->get('db'); $table = $container->get('table'); -$dbi = $container->get('dbi'); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $options_array = [ 'CASCADE' => 'CASCADE', 'SET_NULL' => 'SET NULL', 'NO_ACTION' => 'NO ACTION', 'RESTRICT' => 'RESTRICT', ]; -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); $tbl_storage_engine = mb_strtoupper( $dbi->getTable($db, $table)->getStatusInfo('Engine') diff --git a/tbl_replace.php b/tbl_replace.php index 1bbc5e2b43..324b650545 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -14,6 +14,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\File; use PhpMyAdmin\InsertEdit; use PhpMyAdmin\Message; @@ -28,24 +30,29 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Gets some core libraries - */ +global $url_params; + require_once ROOT_PATH . 'libraries/common.inc.php'; -global $url_params; +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); // Check parameters Util::checkParameters(['db', 'table', 'goto']); -$GLOBALS['dbi']->selectDb($GLOBALS['db']); +$dbi->selectDb($GLOBALS['db']); /** * Initializes some variables */ $goto_include = false; -$response = Response::getInstance(); $header = $response->getHeader(); $scripts = $header->getScripts(); $scripts->addFile('makegrid.js'); @@ -54,9 +61,9 @@ $scripts->addFile('sql.js'); $scripts->addFile('indexes.js'); $scripts->addFile('gis_data_editor.js'); -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $transformations = new Transformations(); -$insertEdit = new InsertEdit($GLOBALS['dbi']); +$insertEdit = new InsertEdit($dbi); // check whether insert row mode, if so include tbl_change.php $insertEdit->isInsertRow(); diff --git a/tbl_select.php b/tbl_select.php index 78537390dd..ed44f6c346 100644 --- a/tbl_select.php +++ b/tbl_select.php @@ -18,16 +18,13 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Gets some core libraries - */ require_once ROOT_PATH . 'libraries/common.inc.php'; require_once ROOT_PATH . 'libraries/tbl_common.inc.php'; $container = Container::getDefaultContainer(); $container->factory(SearchController::class); -$container->set('PhpMyAdmin\Response', Response::getInstance()); -$container->alias('response', 'PhpMyAdmin\Response'); +$container->set(Response::class, Response::getInstance()); +$container->alias('response', Response::class); /* Define dependencies for the concerned controller */ $dependency_definitions = [ diff --git a/tbl_sql.php b/tbl_sql.php index b9eec13e4f..5bf941c837 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\SqlController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; if (! defined('ROOT_PATH')) { @@ -16,11 +18,18 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); $controller = new SqlController( $response, - $GLOBALS['dbi'], + $dbi, $db, $table ); diff --git a/tbl_structure.php b/tbl_structure.php index 63356f759b..e1af542364 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -9,6 +9,7 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Table\StructureController; +use PhpMyAdmin\DatabaseInterface; use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; @@ -16,17 +17,21 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } +global $db, $table, $db_is_system_schema, $tbl_is_view, $tbl_storage_engine; +global $table_info_num_rows, $tbl_collation, $showtable; + require_once ROOT_PATH . 'libraries/common.inc.php'; $container = Container::getDefaultContainer(); $container->factory(StructureController::class); -$container->set('PhpMyAdmin\Response', Response::getInstance()); -$container->alias('response', 'PhpMyAdmin\Response'); +$container->set(Response::class, Response::getInstance()); +$container->alias('response', Response::class); -global $db, $table, $db_is_system_schema, $tbl_is_view, $tbl_storage_engine, - $table_info_num_rows, $tbl_collation, $showtable; -$GLOBALS['dbi']->selectDb($GLOBALS['db']); -$table_class_object = $GLOBALS['dbi']->getTable( +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$dbi->selectDb($GLOBALS['db']); +$table_class_object = $dbi->getTable( $GLOBALS['db'], $GLOBALS['table'] ); diff --git a/transformation_overview.php b/transformation_overview.php index a046f3a1e6..c370e8b128 100644 --- a/transformation_overview.php +++ b/transformation_overview.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\TransformationOverviewController; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; @@ -17,13 +19,21 @@ if (! defined('ROOT_PATH')) { require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $header = $response->getHeader(); $header->disableMenuAndConsole(); $controller = new TransformationOverviewController( $response, - $GLOBALS['dbi'], + $dbi, new Transformations() ); diff --git a/transformation_wrapper.php b/transformation_wrapper.php index 0fc15f3148..308fc86dca 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -8,6 +8,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Transformations; @@ -16,18 +18,21 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * - */ define('IS_TRANSFORMATION_WRAPPER', true); -/** - * Gets a core script and starts output buffering work - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $transformations = new Transformations(); -$relation = new Relation($GLOBALS['dbi']); +$relation = new Relation($dbi); $cfgRelation = $relation->getRelationsParam(); /** @@ -67,22 +72,22 @@ foreach ($request_params as $one_request_param) { /** * Get the list of the fields of the current table */ -$GLOBALS['dbi']->selectDb($db); +$dbi->selectDb($db); if (isset($where_clause)) { - $result = $GLOBALS['dbi']->query( + $result = $dbi->query( 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table) . ' WHERE ' . $where_clause . ';', PhpMyAdmin\DatabaseInterface::CONNECT_USER, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); - $row = $GLOBALS['dbi']->fetchAssoc($result); + $row = $dbi->fetchAssoc($result); } else { - $result = $GLOBALS['dbi']->query( + $result = $dbi->query( 'SELECT * FROM ' . PhpMyAdmin\Util::backquote($table) . ' LIMIT 1;', PhpMyAdmin\DatabaseInterface::CONNECT_USER, PhpMyAdmin\DatabaseInterface::QUERY_STORE ); - $row = $GLOBALS['dbi']->fetchAssoc($result); + $row = $dbi->fetchAssoc($result); } // No row returned @@ -106,8 +111,6 @@ if ($cfgRelation['commwork'] && $cfgRelation['mimework']) { } } -// Only output the http headers -$response = Response::getInstance(); $response->getHeader()->sendHttpHeaders(); // [MIME] diff --git a/user_password.php b/user_password.php index 13c330132f..40caa5d207 100644 --- a/user_password.php +++ b/user_password.php @@ -8,6 +8,8 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Display\ChangePassword; use PhpMyAdmin\Message; use PhpMyAdmin\Server\Privileges; @@ -21,21 +23,26 @@ if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * Gets some core libraries - */ require_once ROOT_PATH . 'libraries/common.inc.php'; -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$container = Container::getDefaultContainer(); +$container->set(Response::class, Response::getInstance()); + +/** @var Response $response */ +$response = $container->get(Response::class); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('server_privileges.js'); $scripts->addFile('vendor/zxcvbn.js'); $template = new Template(); -$relation = new Relation($GLOBALS['dbi']); -$relationCleanup = new RelationCleanup($GLOBALS['dbi'], $relation); -$serverPrivileges = new Privileges($template, $GLOBALS['dbi'], $relation, $relationCleanup); +$relation = new Relation($dbi); +$relationCleanup = new RelationCleanup($dbi, $relation); +$serverPrivileges = new Privileges($template, $dbi, $relation, $relationCleanup); $userPassword = new UserPassword($serverPrivileges); /** @@ -43,7 +50,7 @@ $userPassword = new UserPassword($serverPrivileges); * script */ if (! $GLOBALS['cfg']['ShowChgPassword']) { - $GLOBALS['cfg']['ShowChgPassword'] = $GLOBALS['dbi']->selectDb('mysql'); + $GLOBALS['cfg']['ShowChgPassword'] = $dbi->selectDb('mysql'); } if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) { Message::error( diff --git a/view_create.php b/view_create.php index 6cb492968f..9a9500559c 100644 --- a/view_create.php +++ b/view_create.php @@ -10,6 +10,8 @@ declare(strict_types=1); use PhpMyAdmin\Core; +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Response; use PhpMyAdmin\Template; @@ -20,16 +22,20 @@ if (! defined('ROOT_PATH')) { } require_once ROOT_PATH . 'libraries/common.inc.php'; - -/** - * Runs common work - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $url_params['goto'] = 'tbl_structure.php'; $url_params['back'] = 'view_create.php'; -$response = Response::getInstance(); - $template = new Template(); $view_algorithm_options = [ @@ -112,9 +118,9 @@ if (isset($_POST['createview']) || isset($_POST['alterview'])) { } } - if (! $GLOBALS['dbi']->tryQuery($sql_query)) { + if (! $dbi->tryQuery($sql_query)) { if (! isset($_POST['ajax_dialog'])) { - $message = Message::rawError($GLOBALS['dbi']->getError()); + $message = Message::rawError($dbi->getError()); return; } @@ -122,7 +128,7 @@ if (isset($_POST['createview']) || isset($_POST['alterview'])) { 'message', Message::error( "" . htmlspecialchars($sql_query) . "

" - . $GLOBALS['dbi']->getError() + . $dbi->getError() ) ); $response->setRequestStatus(false); @@ -135,12 +141,12 @@ if (isset($_POST['createview']) || isset($_POST['alterview'])) { $view_columns = explode(',', $_POST['view']['column_names']); } - $column_map = $GLOBALS['dbi']->getColumnMapFromSql( + $column_map = $dbi->getColumnMapFromSql( $_POST['view']['as'], $view_columns ); - $systemDb = $GLOBALS['dbi']->getSystemDatabase(); + $systemDb = $dbi->getSystemDatabase(); $pma_transformation_data = $systemDb->getExistingTransformationData( $GLOBALS['db'] ); @@ -156,7 +162,7 @@ if (isset($_POST['createview']) || isset($_POST['alterview'])) { // Store new transformations if ($new_transformations_sql != '') { - $GLOBALS['dbi']->tryQuery($new_transformations_sql); + $dbi->tryQuery($new_transformations_sql); } } unset($pma_transformation_data); @@ -195,18 +201,18 @@ $view = [ // Used to prefill the fields when editing a view if (isset($_GET['db']) && isset($_GET['table'])) { - $item = $GLOBALS['dbi']->fetchSingleRow( + $item = $dbi->fetchSingleRow( sprintf( "SELECT `VIEW_DEFINITION`, `CHECK_OPTION`, `DEFINER`, `SECURITY_TYPE` FROM `INFORMATION_SCHEMA`.`VIEWS` WHERE TABLE_SCHEMA='%s' AND TABLE_NAME='%s';", - $GLOBALS['dbi']->escapeString($_GET['db']), - $GLOBALS['dbi']->escapeString($_GET['table']) + $dbi->escapeString($_GET['db']), + $dbi->escapeString($_GET['table']) ) ); - $createView = $GLOBALS['dbi']->getTable($_GET['db'], $_GET['table']) + $createView = $dbi->getTable($_GET['db'], $_GET['table']) ->showCreate(); // CREATE ALGORITHM= DE... diff --git a/view_operations.php b/view_operations.php index e4a1a81445..16f8c90a35 100644 --- a/view_operations.php +++ b/view_operations.php @@ -7,32 +7,35 @@ */ declare(strict_types=1); +use PhpMyAdmin\DatabaseInterface; +use PhpMyAdmin\Di\Container; use PhpMyAdmin\Message; use PhpMyAdmin\Operations; use PhpMyAdmin\Relation; use PhpMyAdmin\Response; use PhpMyAdmin\Table; use PhpMyAdmin\Template; -use PhpMyAdmin\Url; use PhpMyAdmin\Util; if (! defined('ROOT_PATH')) { define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); } -/** - * - */ 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); + +/** @var DatabaseInterface $dbi */ +$dbi = $container->get(DatabaseInterface::class); + $pma_table = new Table($GLOBALS['table'], $GLOBALS['db']); -/** - * Load JavaScript files - */ -$response = Response::getInstance(); -$header = $response->getHeader(); -$scripts = $header->getScripts(); +$header = $response->getHeader(); +$scripts = $header->getScripts(); $scripts->addFile('tbl_operations.js'); $template = new Template(); @@ -44,8 +47,8 @@ require ROOT_PATH . 'libraries/tbl_common.inc.php'; $url_query .= '&goto=view_operations.php&back=view_operations.php'; $url_params['goto'] = $url_params['back'] = 'view_operations.php'; -$relation = new Relation($GLOBALS['dbi']); -$operations = new Operations($GLOBALS['dbi'], $relation); +$relation = new Relation($dbi); +$operations = new Operations($dbi, $relation); /** * Updates if required