Skip to content

Commit bb97ed9

Browse files
committed
Reduce usage of the containerBuilder global variable
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent f54cc49 commit bb97ed9

14 files changed

Lines changed: 41 additions & 49 deletions

index.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use PhpMyAdmin\Common;
6+
use PhpMyAdmin\Core;
67
use PhpMyAdmin\Routing;
78

89
if (! defined('ROOT_PATH')) {
@@ -37,4 +38,4 @@
3738

3839
Common::run();
3940

40-
Routing::callControllerForRoute(Common::getRequest(), Routing::getDispatcher(), $GLOBALS['containerBuilder']);
41+
Routing::callControllerForRoute(Common::getRequest(), Routing::getDispatcher(), Core::getContainerBuilder());

libraries/classes/Common.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ final class Common
8282
*/
8383
public static function run(): void
8484
{
85-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
8685
$GLOBALS['server'] = $GLOBALS['server'] ?? null;
8786
$GLOBALS['lang'] = $GLOBALS['lang'] ?? null;
8887
$GLOBALS['isConfigLoading'] = $GLOBALS['isConfigLoading'] ?? null;

libraries/classes/Controllers/Export/ExportController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public function __construct(ResponseRenderer $response, Template $template, Expo
4848

4949
public function __invoke(ServerRequest $request): void
5050
{
51-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
5251
$GLOBALS['export_type'] = $GLOBALS['export_type'] ?? null;
5352
$GLOBALS['filename_template'] = $GLOBALS['filename_template'] ?? null;
5453
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
@@ -335,7 +334,7 @@ public function __invoke(ServerRequest $request): void
335334
);
336335
$GLOBALS['active_page'] = Url::getFromRoute('/database/export');
337336
/** @var DatabaseExportController $controller */
338-
$controller = $GLOBALS['containerBuilder']->get(DatabaseExportController::class);
337+
$controller = Core::getContainerBuilder()->get(DatabaseExportController::class);
339338
$controller($request);
340339
exit;
341340
}

libraries/classes/Controllers/Table/RecentFavoriteController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Controllers\AbstractController;
88
use PhpMyAdmin\Controllers\Sql\SqlController;
9+
use PhpMyAdmin\Core;
910
use PhpMyAdmin\Http\ServerRequest;
1011
use PhpMyAdmin\RecentFavoriteTable;
1112

@@ -18,16 +19,14 @@ class RecentFavoriteController extends AbstractController
1819
{
1920
public function __invoke(ServerRequest $request): void
2021
{
21-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
22-
2322
$db = isset($_REQUEST['db']) && is_string($_REQUEST['db']) ? $_REQUEST['db'] : '';
2423
$table = isset($_REQUEST['table']) && is_string($_REQUEST['table']) ? $_REQUEST['table'] : '';
2524

2625
RecentFavoriteTable::getInstance('recent')->removeIfInvalid($db, $table);
2726
RecentFavoriteTable::getInstance('favorite')->removeIfInvalid($db, $table);
2827

2928
/** @var SqlController $controller */
30-
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
29+
$controller = Core::getContainerBuilder()->get(SqlController::class);
3130
$controller($request);
3231
}
3332
}

libraries/classes/Controllers/Table/ReplaceController.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public function __construct(
7070

7171
public function __invoke(ServerRequest $request): void
7272
{
73-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
7473
$GLOBALS['urlParams'] = $GLOBALS['urlParams'] ?? null;
7574
$GLOBALS['message'] = $GLOBALS['message'] ?? null;
7675
$this->checkParameters(['db', 'table', 'goto']);
@@ -95,7 +94,7 @@ public function __invoke(ServerRequest $request): void
9594
]);
9695
$GLOBALS['cfg']['InsertRows'] = $_POST['insert_rows'];
9796
/** @var ChangeController $controller */
98-
$controller = $GLOBALS['containerBuilder']->get(ChangeController::class);
97+
$controller = Core::getContainerBuilder()->get(ChangeController::class);
9998
$controller($request);
10099

101100
return;
@@ -503,34 +502,34 @@ private function doTransformations(array $mimeMap): void
503502
private function moveBackToCallingScript(string $gotoInclude, ServerRequest $request): void
504503
{
505504
$GLOBALS['active_page'] = $gotoInclude;
506-
505+
$container = Core::getContainerBuilder();
507506
if ($gotoInclude === '/sql') {
508507
/** @var SqlController $controller */
509-
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
508+
$controller = $container->get(SqlController::class);
510509
$controller($request);
511510

512511
return;
513512
}
514513

515514
if ($gotoInclude === '/database/sql') {
516515
/** @var DatabaseSqlController $controller */
517-
$controller = $GLOBALS['containerBuilder']->get(DatabaseSqlController::class);
516+
$controller = $container->get(DatabaseSqlController::class);
518517
$controller($request);
519518

520519
return;
521520
}
522521

523522
if ($gotoInclude === '/table/change') {
524523
/** @var ChangeController $controller */
525-
$controller = $GLOBALS['containerBuilder']->get(ChangeController::class);
524+
$controller = $container->get(ChangeController::class);
526525
$controller($request);
527526

528527
return;
529528
}
530529

531530
if ($gotoInclude === '/table/sql') {
532531
/** @var TableSqlController $controller */
533-
$controller = $GLOBALS['containerBuilder']->get(TableSqlController::class);
532+
$controller = $container->get(TableSqlController::class);
534533
$controller($request);
535534

536535
return;

libraries/classes/Controllers/View/CreateController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpMyAdmin\Controllers\AbstractController;
88
use PhpMyAdmin\Controllers\Table\StructureController;
9+
use PhpMyAdmin\Core;
910
use PhpMyAdmin\DatabaseInterface;
1011
use PhpMyAdmin\Html\Generator;
1112
use PhpMyAdmin\Http\ServerRequest;
@@ -59,7 +60,6 @@ public function __invoke(ServerRequest $request): void
5960
$GLOBALS['column_map'] = $GLOBALS['column_map'] ?? null;
6061
$GLOBALS['systemDb'] = $GLOBALS['systemDb'] ?? null;
6162
$GLOBALS['pma_transformation_data'] = $GLOBALS['pma_transformation_data'] ?? null;
62-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
6363
$GLOBALS['new_transformations_sql'] = $GLOBALS['new_transformations_sql'] ?? null;
6464
$GLOBALS['view'] = $GLOBALS['view'] ?? null;
6565
$GLOBALS['item'] = $GLOBALS['item'] ?? null;
@@ -204,7 +204,7 @@ public function __invoke(ServerRequest $request): void
204204
if (! isset($_POST['ajax_dialog'])) {
205205
$GLOBALS['message'] = Message::success();
206206
/** @var StructureController $controller */
207-
$controller = $GLOBALS['containerBuilder']->get(StructureController::class);
207+
$controller = Core::getContainerBuilder()->get(StructureController::class);
208208
$controller($request);
209209
} else {
210210
$this->response->addJSON(

libraries/classes/Core.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -758,16 +758,15 @@ static function ($item) use (&$empty): void {
758758
*/
759759
public static function setPostAsGlobal(array $post_patterns): void
760760
{
761-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
762-
761+
$container = self::getContainerBuilder();
763762
foreach (array_keys($_POST) as $post_key) {
764763
foreach ($post_patterns as $one_post_pattern) {
765764
if (! preg_match($one_post_pattern, $post_key)) {
766765
continue;
767766
}
768767

769768
$GLOBALS[$post_key] = $_POST[$post_key];
770-
$GLOBALS['containerBuilder']->setParameter($post_key, $GLOBALS[$post_key]);
769+
$container->setParameter($post_key, $GLOBALS[$post_key]);
771770
}
772771
}
773772
}

libraries/classes/DbTableExists.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ private static function checkDatabase(string $db, bool $isTransformationWrapper)
7070

7171
private static function checkTable(string $db, string $table, bool $isTransformationWrapper): void
7272
{
73-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
74-
7573
if (! empty($GLOBALS['is_table']) || defined('PMA_SUBMIT_MULT') || defined('TABLE_MAY_BE_ABSENT')) {
7674
return;
7775
}
@@ -109,7 +107,7 @@ private static function checkTable(string $db, string $table, bool $isTransforma
109107
}
110108

111109
/** @var SqlController $controller */
112-
$controller = $GLOBALS['containerBuilder']->get(SqlController::class);
110+
$controller = Core::getContainerBuilder()->get(SqlController::class);
113111
$controller(Common::getRequest());
114112

115113
exit;

libraries/classes/Export.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,13 +1078,12 @@ public function exportTable(
10781078
public function showPage(string $exportType): void
10791079
{
10801080
$GLOBALS['active_page'] = $GLOBALS['active_page'] ?? null;
1081-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
10821081
$request = Common::getRequest();
1083-
1082+
$container = Core::getContainerBuilder();
10841083
if ($exportType === 'server') {
10851084
$GLOBALS['active_page'] = Url::getFromRoute('/server/export');
10861085
/** @var ServerExportController $controller */
1087-
$controller = $GLOBALS['containerBuilder']->get(ServerExportController::class);
1086+
$controller = $container->get(ServerExportController::class);
10881087
$controller($request);
10891088

10901089
return;
@@ -1093,15 +1092,15 @@ public function showPage(string $exportType): void
10931092
if ($exportType === 'database') {
10941093
$GLOBALS['active_page'] = Url::getFromRoute('/database/export');
10951094
/** @var DatabaseExportController $controller */
1096-
$controller = $GLOBALS['containerBuilder']->get(DatabaseExportController::class);
1095+
$controller = $container->get(DatabaseExportController::class);
10971096
$controller($request);
10981097

10991098
return;
11001099
}
11011100

11021101
$GLOBALS['active_page'] = Url::getFromRoute('/table/export');
11031102
/** @var TableExportController $controller */
1104-
$controller = $GLOBALS['containerBuilder']->get(TableExportController::class);
1103+
$controller = $container->get(TableExportController::class);
11051104
$controller($request);
11061105
}
11071106

libraries/classes/Plugins.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ public static function getPlugin(string $type, string $format, $param = null): ?
6868
}
6969

7070
if ($type === 'export') {
71-
/**
72-
* @psalm-suppress InvalidArrayOffset, MixedAssignment, MixedMethodCall
73-
*/
71+
$container = Core::getContainerBuilder();
72+
73+
/** @psalm-suppress MixedMethodCall */
7474
return new $class(
75-
$GLOBALS['containerBuilder']->get('relation'),
76-
$GLOBALS['containerBuilder']->get('export'),
77-
$GLOBALS['containerBuilder']->get('transformations')
75+
$container->get('relation'),
76+
$container->get('export'),
77+
$container->get('transformations')
7878
);
7979
}
8080

@@ -157,10 +157,11 @@ private static function getPlugins(string $type): array
157157
}
158158

159159
if ($type === 'Export' && is_subclass_of($class, ExportPlugin::class)) {
160+
$container = Core::getContainerBuilder();
160161
$plugins[] = new $class(
161-
$GLOBALS['containerBuilder']->get('relation'),
162-
$GLOBALS['containerBuilder']->get('export'),
163-
$GLOBALS['containerBuilder']->get('transformations')
162+
$container->get('relation'),
163+
$container->get('export'),
164+
$container->get('transformations')
164165
);
165166
} elseif ($type === 'Import' && is_subclass_of($class, ImportPlugin::class)) {
166167
$plugins[] = new $class();

0 commit comments

Comments
 (0)