Visitar URL original
Merge pull request #18788 from MauricioFauth/container-builder-global · phpmyadmin/phpmyadmin@2b0dd75 · GitHub
Skip to content

Commit 2b0dd75

Browse files
Merge pull request #18788 from MauricioFauth/container-builder-global
Remove containerBuilder global variable
2 parents e9dfabf + e036ec6 commit 2b0dd75

32 files changed

Lines changed: 128 additions & 242 deletions

‎app/services_controllers.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,10 @@
13521352
'$transformations' => '@transformations',
13531353
'$relation' => '@relation',
13541354
'$dbi' => '@dbi',
1355+
'$sqlController' => '@' . Sql\SqlController::class,
1356+
'$databaseSqlController' => '@' . Database\SqlController::class,
1357+
'$changeController' => '@' . Table\ChangeController::class,
1358+
'$tableSqlController' => '@' . Table\SqlController::class,
13551359
],
13561360
],
13571361
Table\SearchController::class => [

‎phpstan-baseline.neon‎

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -8325,11 +8325,6 @@ parameters:
83258325
count: 1
83268326
path: src/Core.php
83278327

8328-
-
8329-
message: "#^Parameter \\#1 \\$name of method Symfony\\\\Component\\\\DependencyInjection\\\\Container\\:\\:setParameter\\(\\) expects string, \\(int\\|string\\) given\\.$#"
8330-
count: 1
8331-
path: src/Core.php
8332-
83338328
-
83348329
message: "#^Parameter \\#1 \\$pattern of function preg_match expects string, mixed given\\.$#"
83358330
count: 1
@@ -8355,11 +8350,6 @@ parameters:
83558350
count: 1
83568351
path: src/Core.php
83578352

8358-
-
8359-
message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\Container\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#"
8360-
count: 1
8361-
path: src/Core.php
8362-
83638353
-
83648354
message: "#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#"
83658355
count: 3
@@ -11260,21 +11250,11 @@ parameters:
1126011250
count: 1
1126111251
path: src/Http/Middleware/CurrentServerGlobalSetting.php
1126211252

11263-
-
11264-
message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#"
11265-
count: 1
11266-
path: src/Http/Middleware/CurrentServerGlobalSetting.php
11267-
1126811253
-
1126911254
message: "#^Cannot access offset 'table' on mixed\\.$#"
1127011255
count: 1
1127111256
path: src/Http/Middleware/DatabaseAndTableSetting.php
1127211257

11273-
-
11274-
message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#"
11275-
count: 1
11276-
path: src/Http/Middleware/DatabaseAndTableSetting.php
11277-
1127811258
-
1127911259
message: "#^Cannot cast mixed to string\\.$#"
1128011260
count: 1
@@ -11305,11 +11285,6 @@ parameters:
1130511285
count: 2
1130611286
path: src/Http/Middleware/UrlParamsSetting.php
1130711287

11308-
-
11309-
message: "#^Parameter \\#2 \\$value of method Symfony\\\\Component\\\\DependencyInjection\\\\ContainerInterface\\:\\:setParameter\\(\\) expects array\\|bool\\|float\\|int\\|string\\|UnitEnum\\|null, mixed given\\.$#"
11310-
count: 3
11311-
path: src/Http/Middleware/UrlParamsSetting.php
11312-
1131311288
-
1131411289
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
1131511290
count: 1
@@ -19440,21 +19415,6 @@ parameters:
1944019415
count: 2
1944119416
path: test/classes/AbstractTestCase.php
1944219417

19443-
-
19444-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19445-
count: 4
19446-
path: test/classes/AbstractTestCase.php
19447-
19448-
-
19449-
message: "#^Cannot call method set\\(\\) on mixed\\.$#"
19450-
count: 2
19451-
path: test/classes/AbstractTestCase.php
19452-
19453-
-
19454-
message: "#^Cannot call method setAlias\\(\\) on mixed\\.$#"
19455-
count: 2
19456-
path: test/classes/AbstractTestCase.php
19457-
1945819418
-
1945919419
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with 'formula' and array\\{id\\: non\\-empty\\-string, name\\: string, precondition\\?\\: non\\-empty\\-string, formula\\: non\\-empty\\-string, test\\: non\\-empty\\-string, issue\\: string, recommendation\\: string, justification\\: string, \\.\\.\\.\\} will always evaluate to true\\.$#"
1946019420
count: 1
@@ -19785,11 +19745,6 @@ parameters:
1978519745
count: 1
1978619746
path: test/classes/ConfigTest.php
1978719747

19788-
-
19789-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19790-
count: 1
19791-
path: test/classes/Controllers/Database/MultiTableQuery/TablesControllerTest.php
19792-
1979319748
-
1979419749
message: "#^Parameter \\#1 \\$needle of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
1979519750
count: 1
@@ -19835,16 +19790,6 @@ parameters:
1983519790
count: 1
1983619791
path: test/classes/Controllers/Database/StructureControllerTest.php
1983719792

19838-
-
19839-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19840-
count: 1
19841-
path: test/classes/Controllers/Database/StructureControllerTest.php
19842-
19843-
-
19844-
message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#"
19845-
count: 2
19846-
path: test/classes/Controllers/Database/StructureControllerTest.php
19847-
1984819793
-
1984919794
message: "#^Cannot use array destructuring on mixed\\.$#"
1985019795
count: 8
@@ -19865,16 +19810,6 @@ parameters:
1986519810
count: 1
1986619811
path: test/classes/Controllers/Database/StructureControllerTest.php
1986719812

19868-
-
19869-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19870-
count: 1
19871-
path: test/classes/Controllers/Import/ImportControllerTest.php
19872-
19873-
-
19874-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19875-
count: 2
19876-
path: test/classes/Controllers/NavigationControllerTest.php
19877-
1987819813
-
1987919814
message: "#^Parameter \\#2 \\$haystack of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertStringContainsString\\(\\) expects string, mixed given\\.$#"
1988019815
count: 4
@@ -19945,36 +19880,6 @@ parameters:
1994519880
count: 7
1994619881
path: test/classes/Controllers/Server/VariablesControllerTest.php
1994719882

19948-
-
19949-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19950-
count: 2
19951-
path: test/classes/Controllers/Sql/EnumValuesControllerTest.php
19952-
19953-
-
19954-
message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#"
19955-
count: 4
19956-
path: test/classes/Controllers/Sql/EnumValuesControllerTest.php
19957-
19958-
-
19959-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19960-
count: 2
19961-
path: test/classes/Controllers/Sql/SetValuesControllerTest.php
19962-
19963-
-
19964-
message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#"
19965-
count: 4
19966-
path: test/classes/Controllers/Sql/SetValuesControllerTest.php
19967-
19968-
-
19969-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
19970-
count: 1
19971-
path: test/classes/Controllers/Table/OperationsControllerTest.php
19972-
19973-
-
19974-
message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#"
19975-
count: 2
19976-
path: test/classes/Controllers/Table/OperationsControllerTest.php
19977-
1997819883
-
1997919884
message: "#^Property PhpMyAdmin\\\\Config\\:\\:\\$settings \\(array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\) does not accept array\\{PmaAbsoluteUri\\: string, AuthLog\\: string, AuthLogSuccess\\: bool, PmaNoRelation_DisableWarning\\: bool, SuhosinDisableWarning\\: bool, LoginCookieValidityDisableWarning\\: bool, ReservedWordDisableWarning\\: bool, TranslationWarningThreshold\\: int, \\.\\.\\.\\}\\.$#"
1998019885
count: 1
@@ -20010,21 +19915,11 @@ parameters:
2001019915
count: 1
2001119916
path: test/classes/Controllers/Table/SearchControllerTest.php
2001219917

20013-
-
20014-
message: "#^Cannot call method get\\(\\) on mixed\\.$#"
20015-
count: 1
20016-
path: test/classes/Controllers/Table/SearchControllerTest.php
20017-
2001819918
-
2001919919
message: "#^Cannot call method method\\(\\) on mixed\\.$#"
2002019920
count: 1
2002119921
path: test/classes/Controllers/Table/SearchControllerTest.php
2002219922

20023-
-
20024-
message: "#^Cannot call method setParameter\\(\\) on mixed\\.$#"
20025-
count: 2
20026-
path: test/classes/Controllers/Table/SearchControllerTest.php
20027-
2002819923
-
2002919924
message: "#^Cannot call method willReturn\\(\\) on mixed\\.$#"
2003019925
count: 1

‎psalm-baseline.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4509,7 +4509,6 @@
45094509
</MixedReturnStatement>
45104510
<PossiblyInvalidArgument>
45114511
<code>$postKey</code>
4512-
<code>$postKey</code>
45134512
</PossiblyInvalidArgument>
45144513
<PossiblyInvalidArrayOffset>
45154514
<code>$path[$depth - 1]</code>

‎psalm.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
compression: 'none'|'zip'|'gzip',
5252
conn_error: string,
5353
ConfigFile: PhpMyAdmin\Config\ConfigFile,
54-
containerBuilder: Symfony\Component\DependencyInjection\ContainerBuilder,
5554
csv_columns: bool,
5655
csv_enclosed: string,
5756
csv_escaped: string,

‎src/Controllers/Table/ReplaceController.php‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function __construct(
4949
private Transformations $transformations,
5050
private Relation $relation,
5151
private DatabaseInterface $dbi,
52+
private readonly SqlController $sqlController,
53+
private readonly DatabaseSqlController $databaseSqlController,
54+
private readonly ChangeController $changeController,
55+
private readonly TableSqlController $tableSqlController,
5256
) {
5357
parent::__construct($response, $template);
5458
}
@@ -475,44 +479,25 @@ private function doTransformations(array $mimeMap, ServerRequest $request): void
475479
private function moveBackToCallingScript(string $gotoInclude, ServerRequest $request): void
476480
{
477481
$GLOBALS['active_page'] = $gotoInclude;
478-
$container = Core::getContainerBuilder();
479482
if ($gotoInclude === '/sql') {
480-
/** @var SqlController $controller */
481-
$controller = $container->get(SqlController::class);
482-
$controller($request);
483+
($this->sqlController)($request);
483484

484485
return;
485486
}
486487

487488
if ($gotoInclude === '/database/sql') {
488-
/** @var DatabaseSqlController $controller */
489-
$controller = $container->get(DatabaseSqlController::class);
490-
$controller($request);
491-
492-
return;
493-
}
494-
495-
if ($gotoInclude === '/table/change') {
496-
/** @var ChangeController $controller */
497-
$controller = $container->get(ChangeController::class);
498-
$controller($request);
489+
($this->databaseSqlController)($request);
499490

500491
return;
501492
}
502493

503494
if ($gotoInclude === '/table/sql') {
504-
/** @var TableSqlController $controller */
505-
$controller = $container->get(TableSqlController::class);
506-
$controller($request);
495+
($this->tableSqlController)($request);
507496

508497
return;
509498
}
510499

511-
/**
512-
* Load target page.
513-
*/
514-
/** @psalm-suppress UnresolvableInclude */
515-
require ROOT_PATH . Core::securePath($gotoInclude);
500+
($this->changeController)($request);
516501
}
517502

518503
/**

‎src/Controllers/Table/SqlController.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Table SQL executor
2626
*/
27-
final class SqlController extends AbstractController
27+
class SqlController extends AbstractController
2828
{
2929
public function __construct(
3030
ResponseRenderer $response,

‎src/Core.php‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
*/
5858
class Core
5959
{
60+
public static ContainerBuilder|null $containerBuilder = null;
61+
6062
/**
6163
* Removes insecure parts in a path; used before include() or
6264
* require() when a part of the path comes from an insecure source
@@ -560,15 +562,13 @@ static function ($item) use (&$empty): void {
560562
*/
561563
public static function setPostAsGlobal(array $postPatterns): void
562564
{
563-
$container = self::getContainerBuilder();
564565
foreach (array_keys($_POST) as $postKey) {
565566
foreach ($postPatterns as $onePostPattern) {
566567
if (! preg_match($onePostPattern, $postKey)) {
567568
continue;
568569
}
569570

570571
$GLOBALS[$postKey] = $_POST[$postKey];
571-
$container->setParameter($postKey, $GLOBALS[$postKey]);
572572
}
573573
}
574574
}
@@ -764,18 +764,15 @@ public static function checkSqlQuerySignature(string $sqlQuery, string $signatur
764764

765765
public static function getContainerBuilder(): ContainerBuilder
766766
{
767-
$containerBuilder = $GLOBALS['containerBuilder'] ?? null;
768-
if ($containerBuilder instanceof ContainerBuilder) {
769-
return $containerBuilder;
767+
if (self::$containerBuilder !== null) {
768+
return self::$containerBuilder;
770769
}
771770

772-
$containerBuilder = new ContainerBuilder();
773-
$loader = new PhpFileLoader($containerBuilder, new FileLocator(ROOT_PATH . 'app'));
771+
self::$containerBuilder = new ContainerBuilder();
772+
$loader = new PhpFileLoader(self::$containerBuilder, new FileLocator(ROOT_PATH . 'app'));
774773
$loader->load('services_loader.php');
775774

776-
$GLOBALS['containerBuilder'] = $containerBuilder;
777-
778-
return $containerBuilder;
775+
return self::$containerBuilder;
779776
}
780777

781778
public static function populateRequestWithEncryptedQueryParams(ServerRequest $request): ServerRequest

‎src/Http/Middleware/CurrentServerGlobalSetting.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,5 @@ private function setCurrentServerGlobal(
3838
$server = $config->selectServer($serverParamFromRequest);
3939
$GLOBALS['server'] = $server;
4040
$GLOBALS['urlParams']['server'] = $server;
41-
$container->setParameter('server', $server);
42-
$container->setParameter('url_params', $GLOBALS['urlParams']);
4341
}
4442
}

‎src/Http/Middleware/DatabaseAndTableSetting.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,5 @@ private function setDatabaseAndTableFromRequest(ContainerInterface $container, S
4444

4545
$GLOBALS['urlParams']['db'] = $GLOBALS['db'];
4646
$GLOBALS['urlParams']['table'] = $GLOBALS['table'];
47-
$container->setParameter('url_params', $GLOBALS['urlParams']);
4847
}
4948
}

‎src/Http/Middleware/SqlQueryGlobalSetting.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@ private function setSQLQueryGlobalFromRequest(ContainerInterface $container, Ser
3838
}
3939

4040
$GLOBALS['sql_query'] = $sqlQuery;
41-
$container->setParameter('sql_query', $sqlQuery);
4241
}
4342
}

0 commit comments

Comments
 (0)