From 61abc3d01f5a09016cbc739bfc87ef7d0b4bb169 Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Wed, 16 Mar 2011 13:11:29 +0100 Subject: [PATCH] Added the global variable in PHP templates too --- .../FrameworkBundle/Resources/config/templating_php.xml | 5 +++++ .../Templating}/GlobalVariables.php | 2 +- .../Bundle/FrameworkBundle/Templating/PhpEngine.php | 3 ++- src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml | 7 +------ src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php | 2 +- src/Symfony/Bundle/TwigBundle/TwigEngine.php | 1 + 6 files changed, 11 insertions(+), 9 deletions(-) rename src/Symfony/Bundle/{TwigBundle => FrameworkBundle/Templating}/GlobalVariables.php (97%) diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml index 1d3323aa3a..b9b30b83b3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/templating_php.xml @@ -15,6 +15,7 @@ Symfony\Bundle\FrameworkBundle\Templating\Helper\CodeHelper Symfony\Bundle\FrameworkBundle\Templating\Helper\TranslatorHelper Symfony\Bundle\FrameworkBundle\Templating\Helper\FormHelper + Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables @@ -71,5 +72,9 @@ + + + + diff --git a/src/Symfony/Bundle/TwigBundle/GlobalVariables.php b/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php similarity index 97% rename from src/Symfony/Bundle/TwigBundle/GlobalVariables.php rename to src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php index 1b493bf9ba..8eeb010fb3 100644 --- a/src/Symfony/Bundle/TwigBundle/GlobalVariables.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/GlobalVariables.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace Symfony\Bundle\TwigBundle; +namespace Symfony\Bundle\FrameworkBundle\Templating; use Symfony\Component\DependencyInjection\ContainerInterface; diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php b/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php index 6bcf917f49..64d89aadc5 100755 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php @@ -33,11 +33,12 @@ class PhpEngine extends BasePhpEngine implements EngineInterface * @param ContainerInterface $container The DI container * @param LoaderInterface $loader A loader instance */ - public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader) + public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, GlobalVariables $globals) { $this->container = $container; parent::__construct($parser, $loader); + $this->addGlobal('app', $globals); } /** diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 6283e3ea70..2220db3fae 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -7,7 +7,6 @@ Twig_Environment Symfony\Bundle\TwigBundle\Loader\FilesystemLoader - Symfony\Bundle\TwigBundle\GlobalVariables Symfony\Bundle\TwigBundle\TwigEngine Symfony\Bundle\TwigBundle\CacheWarmer\TemplateCacheCacheWarmer @@ -30,11 +29,7 @@ - - - - - + diff --git a/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php b/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php index c66496d551..23889abd7a 100644 --- a/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php +++ b/src/Symfony/Bundle/TwigBundle/Tests/TwigEngineTest.php @@ -17,7 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session; use Symfony\Component\HttpFoundation\SessionStorage\ArraySessionStorage; use Symfony\Component\Templating\TemplateNameParser; -use Symfony\Bundle\TwigBundle\GlobalVariables; +use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables; class TwigEngineTest extends TestCase { diff --git a/src/Symfony/Bundle/TwigBundle/TwigEngine.php b/src/Symfony/Bundle/TwigBundle/TwigEngine.php index 83ad8542f6..5d3f9181ee 100644 --- a/src/Symfony/Bundle/TwigBundle/TwigEngine.php +++ b/src/Symfony/Bundle/TwigBundle/TwigEngine.php @@ -12,6 +12,7 @@ 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; use Symfony\Component\DependencyInjection\ContainerInterface;