8000 [TwigBundle] Moved the registration of the app global to the environment · symfony/symfony@ae3d531 · GitHub
[go: up one dir, main page]

Skip to content

Commit ae3d531

Browse files
stoffabpot
authored andcommitted
[TwigBundle] Moved the registration of the app global to the environment
This makes the app global variable available also when accessing the Twig environment directly instead of using the TwigEngine. Conflicts: src/Symfony/Bridge/Twig/CHANGELOG.md src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml src/Symfony/Bundle/TwigBundle/TwigEngine.php
1 parent 9be270e commit ae3d531

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<service id="twig" class="%twig.class%">
2424
<argument type="service" id="twig.loader" />
2525
<argument>%twig.options%</argument>
26+
<call method="addGlobal">
27+
<argument>app</argument>
28+
<argument type="service" id="templating.globals" />
29+
</call>
2630
</service>
2731

2832
<service id="twig.cache_warmer" class="%twig.cache_warmer.class%" public="false">
@@ -39,7 +43,6 @@
3943
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
4044
<argument type="service" id="twig" />
4145
<argument type="service" id="templating.name_parser" />
42-
<argument type="service" id="templating.globals" />
4346
</service>
4447

4548
<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">

src/Symfony/Bundle/TwigBundle/TwigEngine.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\TwigBundle;
1313

1414
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
15-
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
1615
use Symfony\Component\Templating\TemplateNameParserInterface;
1716
use Symfony\Component\HttpFoundation\Response;
1817

@@ -31,16 +30,11 @@ class TwigEngine implements EngineInterface
3130
*
3231
* @param \Twig_Environment $environment A \Twig_Environment instance
3332
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
34-
* @param GlobalVariables|null $globals A GlobalVariables instance or null
3533
*/
36-
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, GlobalVariables $globals = null)
34+
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser)
3735
{
3836
$this->environment = $environment;
3937
$this->parser = $parser;
40-
41-
if (null !== $globals) {
42-
$environment->addGlobal('app', $globals);
43-
}
4438
}
4539

4640
/**

0 commit comments

Comments
 (0)
0