Skip to content

Commit 975e88c

Browse files
committed
Remove the containerBuilder global var from the Template class
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
1 parent 361fcc0 commit 975e88c

3 files changed

Lines changed: 6 additions & 12 deletions

File tree

libraries/classes/Core.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -963,11 +963,13 @@ public static function checkSqlQuerySignature($sqlQuery, $signature): bool
963963
return hash_equals($hmac, $signature);
964964
}
965965

966-
/**
967-
* Get the container builder
968-
*/
969966
public static function getContainerBuilder(): ContainerBuilder
970967
{
968+
$containerBuilder = $GLOBALS['containerBuilder'] ?? null;
969+
if ($containerBuilder instanceof ContainerBuilder) {
970+
return $containerBuilder;
971+
}
972+
971973
$containerBuilder = new ContainerBuilder();
972974
$loader = new PhpFileLoader($containerBuilder, new FileLocator(ROOT_PATH . 'libraries'));
973975
$loader->load('services_loader.php');

libraries/classes/Template.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ public function __construct()
6363

6464
public static function getTwigEnvironment(?string $cacheDir): Environment
6565
{
66-
$GLOBALS['containerBuilder'] = $GLOBALS['containerBuilder'] ?? null;
67-
6866
/* Twig expects false when cache is not configured */
6967
if ($cacheDir === null) {
7068
$cacheDir = false;
@@ -76,7 +74,7 @@ public static function getTwigEnvironment(?string $cacheDir): Environment
7674
'cache' => $cacheDir,
7775
]);
7876

79-
$twig->addRuntimeLoader(new ContainerRuntimeLoader($GLOBALS['containerBuilder']));
77+
$twig->addRuntimeLoader(new ContainerRuntimeLoader(Core::getContainerBuilder()));
8078

8179
if (is_array($GLOBALS['cfg']) && ($GLOBALS['cfg']['environment'] ?? '') === 'development') {
8280
$twig->enableDebug();

psalm-baseline.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13245,12 +13245,6 @@
1324513245
</PossiblyNullOperand>
1324613246
</file>
1324713247
<file src="libraries/classes/Template.php">
13248-
<PossiblyNullArgument occurrences="1">
13249-
<code>$GLOBALS['containerBuilder']</code>
13250-
</PossiblyNullArgument>
13251-
<PossiblyUndefinedArrayOffset occurrences="1">
13252-
<code>$GLOBALS['cfg']['environment']</code>
13253-
</PossiblyUndefinedArrayOffset>
1325413248
<RedundantCondition occurrences="1">
1325513249
<code>is_array($GLOBALS['cfg'])</code>
1325613250
</RedundantCondition>

0 commit comments

Comments
 (0)