Skip to content

Commit

Permalink
[TwigBundle] Moved the registration of the app global to the environment
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stof authored and fabpot committed Dec 3, 2012
1 parent 9be270e commit ae3d531
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
5 changes: 4 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -23,6 +23,10 @@
<service id="twig" class="%twig.class%">
<argument type="service" id="twig.loader" />
<argument>%twig.options%</argument>
<call method="addGlobal">
<argument>app</argument>
<argument type="service" id="templating.globals" />
</call>
</service>

<service id="twig.cache_warmer" class="%twig.cache_warmer.class%" public="false">
Expand All @@ -39,7 +43,6 @@
<service id="templating.engine.twig" class="%templating.engine.twig.class%" public="false">
<argument type="service" id="twig" />
<argument type="service" id="templating.name_parser" />
<argument type="service" id="templating.globals" />
</service>

<service id="twig.extension.trans" class="%twig.extension.trans.class%" public="false">
Expand Down
8 changes: 1 addition & 7 deletions src/Symfony/Bundle/TwigBundle/TwigEngine.php
Expand Up @@ -12,7 +12,6 @@
namespace Symfony\Bundle\TwigBundle;

use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables;
use Symfony\Component\Templating\TemplateNameParserInterface;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -31,16 +30,11 @@ class TwigEngine implements EngineInterface
*
* @param \Twig_Environment $environment A \Twig_Environment instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param GlobalVariables|null $globals A GlobalVariables instance or null
*/
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, GlobalVariables $globals = null)
public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser)
{
$this->environment = $environment;
$this->parser = $parser;

if (null !== $globals) {
$environment->addGlobal('app', $globals);
}
}

/**
Expand Down

0 comments on commit ae3d531

Please sign in to comment.