Reduce usage of the containerBuilder global variable
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
parent
f54cc49f86
commit
bb97ed988f
@ -3,6 +3,7 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use PhpMyAdmin\Common;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Routing;
|
||||
|
||||
if (! defined('ROOT_PATH')) {
|
||||
@ -37,4 +38,4 @@ require AUTOLOAD_FILE;
|
||||
|
||||
Common::run();
|
||||
|
||||
Routing::callControllerForRoute(Common::getRequest(), Routing::getDispatcher(), $GLOBALS['containerBuilder']);
|
||||
Routing::callControllerForRoute(Common::getRequest(), Routing::getDispatcher(), Core::getContainerBuilder());
|
||||
|
||||
@ -82,7 +82,6 @@ final class Common
|
||||
*/
|
||||
public static function run(): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
$GLOBALS['server'] = $GLOBALS['server'] ?? null;
|
||||
$GLOBALS['lang'] = $GLOBALS['lang'] ?? null;
|
||||
$GLOBALS['isConfigLoading'] = $GLOBALS['isConfigLoading'] ?? null;
|
||||
|
||||
@ -48,7 +48,6 @@ final class ExportController extends AbstractController
|
||||
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
$GLOBALS['export_type'] = $GLOBALS['export_type'] ?? null;
|
||||
$GLOBALS['filename_template'] = $GLOBALS['filename_template'] ?? null;
|
||||
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
|
||||
@ -335,7 +334,7 @@ final class ExportController extends AbstractController
|
||||
);
|
||||
$GLOBALS['active_page'] = Url::getFromRoute('/database/export');
|
||||
/** @var DatabaseExportController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(DatabaseExportController::class);
|
||||
$controller = Core::getContainerBuilder()->get(DatabaseExportController::class);
|
||||
$controller($request);
|
||||
exit;
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ namespace PhpMyAdmin\Controllers\Table;
|
||||
|
||||
use PhpMyAdmin\Controllers\AbstractController;
|
||||
use PhpMyAdmin\Controllers\Sql\SqlController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
use PhpMyAdmin\RecentFavoriteTable;
|
||||
|
||||
@ -18,8 +19,6 @@ class RecentFavoriteController extends AbstractController
|
||||
{
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
|
||||
$db = isset($_REQUEST['db']) && is_string($_REQUEST['db']) ? $_REQUEST['db'] : '';
|
||||
$table = isset($_REQUEST['table']) && is_string($_REQUEST['table']) ? $_REQUEST['table'] : '';
|
||||
|
||||
@ -27,7 +26,7 @@ class RecentFavoriteController extends AbstractController
|
||||
RecentFavoriteTable::getInstance('favorite')->removeIfInvalid($db, $table);
|
||||
|
||||
/** @var SqlController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
|
||||
$controller = Core::getContainerBuilder()->get(SqlController::class);
|
||||
$controller($request);
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,7 +70,6 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
public function __invoke(ServerRequest $request): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
|
||||
$GLOBALS['message'] = $GLOBALS['message'] ?? null;
|
||||
$this->checkParameters(['db', 'table', 'goto']);
|
||||
@ -95,7 +94,7 @@ final class ReplaceController extends AbstractController
|
||||
]);
|
||||
$GLOBALS['cfg']['InsertRows'] = $_POST['insert_rows'];
|
||||
/** @var ChangeController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(ChangeController::class);
|
||||
$controller = Core::getContainerBuilder()->get(ChangeController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -503,10 +502,10 @@ final class ReplaceController extends AbstractController
|
||||
private function moveBackToCallingScript(string $gotoInclude, ServerRequest $request): void
|
||||
{
|
||||
$GLOBALS['active_page'] = $gotoInclude;
|
||||
|
||||
$container = Core::getContainerBuilder();
|
||||
if ($gotoInclude === '/sql') {
|
||||
/** @var SqlController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
|
||||
$controller = $container->get(SqlController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -514,7 +513,7 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
if ($gotoInclude === '/database/sql') {
|
||||
/** @var DatabaseSqlController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(DatabaseSqlController::class);
|
||||
$controller = $container->get(DatabaseSqlController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -522,7 +521,7 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
if ($gotoInclude === '/table/change') {
|
||||
/** @var ChangeController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(ChangeController::class);
|
||||
$controller = $container->get(ChangeController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -530,7 +529,7 @@ final class ReplaceController extends AbstractController
|
||||
|
||||
if ($gotoInclude === '/table/sql') {
|
||||
/** @var TableSqlController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(TableSqlController::class);
|
||||
$controller = $container->get(TableSqlController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
|
||||
@ -6,6 +6,7 @@ namespace PhpMyAdmin\Controllers\View;
|
||||
|
||||
use PhpMyAdmin\Controllers\AbstractController;
|
||||
use PhpMyAdmin\Controllers\Table\StructureController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Http\ServerRequest;
|
||||
@ -59,7 +60,6 @@ class CreateController extends AbstractController
|
||||
$GLOBALS['column_map'] = $GLOBALS['column_map'] ?? null;
|
||||
$GLOBALS['systemDb'] = $GLOBALS['systemDb'] ?? null;
|
||||
$GLOBALS['pma_transformation_data'] = $GLOBALS['pma_transformation_data'] ?? null;
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
$GLOBALS['new_transformations_sql'] = $GLOBALS['new_transformations_sql'] ?? null;
|
||||
$GLOBALS['view'] = $GLOBALS['view'] ?? null;
|
||||
$GLOBALS['item'] = $GLOBALS['item'] ?? null;
|
||||
@ -204,7 +204,7 @@ class CreateController extends AbstractController
|
||||
if (! isset($_POST['ajax_dialog'])) {
|
||||
$GLOBALS['message'] = Message::success();
|
||||
/** @var StructureController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(StructureController::class);
|
||||
$controller = Core::getContainerBuilder()->get(StructureController::class);
|
||||
$controller($request);
|
||||
} else {
|
||||
$this->response->addJSON(
|
||||
|
||||
@ -758,8 +758,7 @@ class Core
|
||||
*/
|
||||
public static function setPostAsGlobal(array $post_patterns): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
|
||||
$container = self::getContainerBuilder();
|
||||
foreach (array_keys($_POST) as $post_key) {
|
||||
foreach ($post_patterns as $one_post_pattern) {
|
||||
if (! preg_match($one_post_pattern, $post_key)) {
|
||||
@ -767,7 +766,7 @@ class Core
|
||||
}
|
||||
|
||||
$GLOBALS[$post_key] = $_POST[$post_key];
|
||||
$GLOBALS['containerBuilder']->setParameter($post_key, $GLOBALS[$post_key]);
|
||||
$container->setParameter($post_key, $GLOBALS[$post_key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,8 +70,6 @@ final class DbTableExists
|
||||
|
||||
private static function checkTable(string $db, string $table, bool $isTransformationWrapper): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
|
||||
if (! empty($GLOBALS['is_table']) || defined('PMA_SUBMIT_MULT') || defined('TABLE_MAY_BE_ABSENT')) {
|
||||
return;
|
||||
}
|
||||
@ -109,7 +107,7 @@ final class DbTableExists
|
||||
}
|
||||
|
||||
/** @var SqlController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
|
||||
$controller = Core::getContainerBuilder()->get(SqlController::class);
|
||||
$controller(Common::getRequest());
|
||||
|
||||
exit;
|
||||
|
||||
@ -1078,13 +1078,12 @@ class Export
|
||||
public function showPage(string $exportType): void
|
||||
{
|
||||
$GLOBALS['active_page'] = $GLOBALS['active_page'] ?? null;
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
$request = Common::getRequest();
|
||||
|
||||
$container = Core::getContainerBuilder();
|
||||
if ($exportType === 'server') {
|
||||
$GLOBALS['active_page'] = Url::getFromRoute('/server/export');
|
||||
/** @var ServerExportController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(ServerExportController::class);
|
||||
$controller = $container->get(ServerExportController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -1093,7 +1092,7 @@ class Export
|
||||
if ($exportType === 'database') {
|
||||
$GLOBALS['active_page'] = Url::getFromRoute('/database/export');
|
||||
/** @var DatabaseExportController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(DatabaseExportController::class);
|
||||
$controller = $container->get(DatabaseExportController::class);
|
||||
$controller($request);
|
||||
|
||||
return;
|
||||
@ -1101,7 +1100,7 @@ class Export
|
||||
|
||||
$GLOBALS['active_page'] = Url::getFromRoute('/table/export');
|
||||
/** @var TableExportController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(TableExportController::class);
|
||||
$controller = $container->get(TableExportController::class);
|
||||
$controller($request);
|
||||
}
|
||||
|
||||
|
||||
@ -68,13 +68,13 @@ class Plugins
|
||||
}
|
||||
|
||||
if ($type === 'export') {
|
||||
/**
|
||||
* @psalm-suppress InvalidArrayOffset, MixedAssignment, MixedMethodCall
|
||||
*/
|
||||
$container = Core::getContainerBuilder();
|
||||
|
||||
/** @psalm-suppress MixedMethodCall */
|
||||
return new $class(
|
||||
$GLOBALS['containerBuilder']->get('relation'),
|
||||
$GLOBALS['containerBuilder']->get('export'),
|
||||
$GLOBALS['containerBuilder']->get('transformations')
|
||||
$container->get('relation'),
|
||||
$container->get('export'),
|
||||
$container->get('transformations')
|
||||
);
|
||||
}
|
||||
|
||||
@ -157,10 +157,11 @@ class Plugins
|
||||
}
|
||||
|
||||
if ($type === 'Export' && is_subclass_of($class, ExportPlugin::class)) {
|
||||
$container = Core::getContainerBuilder();
|
||||
$plugins[] = new $class(
|
||||
$GLOBALS['containerBuilder']->get('relation'),
|
||||
$GLOBALS['containerBuilder']->get('export'),
|
||||
$GLOBALS['containerBuilder']->get('transformations')
|
||||
$container->get('relation'),
|
||||
$container->get('export'),
|
||||
$container->get('transformations')
|
||||
);
|
||||
} elseif ($type === 'Import' && is_subclass_of($class, ImportPlugin::class)) {
|
||||
$plugins[] = new $class();
|
||||
|
||||
@ -6,6 +6,7 @@ namespace PhpMyAdmin\Table;
|
||||
|
||||
use PhpMyAdmin\Common;
|
||||
use PhpMyAdmin\Controllers\Table\StructureController;
|
||||
use PhpMyAdmin\Core;
|
||||
use PhpMyAdmin\DatabaseInterface;
|
||||
use PhpMyAdmin\Html\Generator;
|
||||
use PhpMyAdmin\Index;
|
||||
@ -45,8 +46,6 @@ final class Indexes
|
||||
*/
|
||||
public function doSaveData(Index $index, bool $renameMode, string $db, string $table): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
|
||||
$error = false;
|
||||
if ($renameMode && Compatibility::isCompatibleRenameIndex($this->dbi->getVersion())) {
|
||||
$oldIndexName = $_POST['old_index'];
|
||||
@ -107,7 +106,7 @@ final class Indexes
|
||||
);
|
||||
} else {
|
||||
/** @var StructureController $controller */
|
||||
$controller = $GLOBALS['containerBuilder']->get(StructureController::class);
|
||||
$controller = Core::getContainerBuilder()->get(StructureController::class);
|
||||
$controller(Common::getRequest());
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -19,11 +19,10 @@ final class UrlRedirector
|
||||
*/
|
||||
public static function redirect(): void
|
||||
{
|
||||
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
|
||||
|
||||
// Load database service because services.php is not available here
|
||||
$GLOBALS['dbi'] = DatabaseInterface::load();
|
||||
$GLOBALS['containerBuilder']->set(DatabaseInterface::class, $GLOBALS['dbi']);
|
||||
$container = Core::getContainerBuilder();
|
||||
$container->set(DatabaseInterface::class, $GLOBALS['dbi']);
|
||||
|
||||
// Only output the http headers
|
||||
$response = ResponseRenderer::getInstance();
|
||||
@ -46,7 +45,7 @@ final class UrlRedirector
|
||||
*
|
||||
* @var Template $template
|
||||
*/
|
||||
$template = $GLOBALS['containerBuilder']->get('template');
|
||||
$template = $container->get('template');
|
||||
echo $template->render('javascript/redirect', [
|
||||
'url' => Sanitize::escapeJsString((string) $_GET['url']),
|
||||
]);
|
||||
|
||||
@ -13,7 +13,7 @@ use PhpMyAdmin\Template;
|
||||
use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use PhpMyAdmin\Tests\Stubs\DbiDummy;
|
||||
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @covers \PhpMyAdmin\Controllers\Table\RecentFavoriteController
|
||||
@ -52,7 +52,7 @@ class RecentFavoriteControllerTest extends AbstractTestCase
|
||||
$controller = $this->createMock(SqlController::class);
|
||||
$controller->expects($this->once())->method('__invoke');
|
||||
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container = $this->createMock(ContainerBuilder::class);
|
||||
$container->expects($this->once())->method('get')->with(SqlController::class)->willReturn($controller);
|
||||
$GLOBALS['containerBuilder'] = $container;
|
||||
|
||||
@ -87,7 +87,7 @@ class RecentFavoriteControllerTest extends AbstractTestCase
|
||||
$controller = $this->createMock(SqlController::class);
|
||||
$controller->expects($this->once())->method('__invoke');
|
||||
|
||||
$container = $this->createMock(ContainerInterface::class);
|
||||
$container = $this->createMock(ContainerBuilder::class);
|
||||
$container->expects($this->once())->method('get')->with(SqlController::class)->willReturn($controller);
|
||||
$GLOBALS['containerBuilder'] = $container;
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ use PhpMyAdmin\Tests\AbstractTestCase;
|
||||
use PhpMyAdmin\Tests\Stubs\DbiDummy;
|
||||
use PhpMyAdmin\Tests\Stubs\ResponseRenderer;
|
||||
use PhpMyAdmin\Transformations;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
|
||||
/**
|
||||
* @covers \PhpMyAdmin\Controllers\Table\ReplaceController
|
||||
@ -136,7 +136,7 @@ class ReplaceControllerTest extends AbstractTestCase
|
||||
new CheckUserPrivileges($dbi),
|
||||
$dbi
|
||||
);
|
||||
$GLOBALS['containerBuilder'] = $this->createStub(ContainerInterface::class);
|
||||
$GLOBALS['containerBuilder'] = $this->createStub(ContainerBuilder::class);
|
||||
$GLOBALS['containerBuilder']->method('get')->willReturn($sqlController);
|
||||
|
||||
$GLOBALS['goto'] = 'index.php?route=/sql';
|
||||
@ -181,7 +181,7 @@ class ReplaceControllerTest extends AbstractTestCase
|
||||
|
||||
$request = $this->createStub(ServerRequest::class);
|
||||
$changeController = new ChangeController($response, $template, $insertEdit, $relation);
|
||||
$GLOBALS['containerBuilder'] = $this->createStub(ContainerInterface::class);
|
||||
$GLOBALS['containerBuilder'] = $this->createStub(ContainerBuilder::class);
|
||||
$GLOBALS['containerBuilder']->method('get')->willReturn($changeController);
|
||||
|
||||
$dummyDbi->addSelectDb('my_db');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user