Browse Source

Merge remote branch 'igorw/templating-optional-globals'

* igorw/templating-optional-globals:
  [TwigBundle] Default $globals to null as in FrameworkBundle/PhpEngine
  make Templating Engine $globals optional
Fabien Potencier 14 years ago
parent
commit
79ac931358

+ 6 - 3
src/Symfony/Bundle/FrameworkBundle/Templating/PhpEngine.php

@@ -32,14 +32,17 @@ class PhpEngine extends BasePhpEngine implements EngineInterface
      * @param TemplateNameParserInterface $parser    A TemplateNameParserInterface instance
      * @param ContainerInterface          $container The DI container
      * @param LoaderInterface             $loader    A loader instance
-     * @param GlobalVariables             $globals   A GlobalVariables instance
+     * @param GlobalVariables|null        $globals   A GlobalVariables instance or null
      */
-    public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, GlobalVariables $globals)
+    public function __construct(TemplateNameParserInterface $parser, ContainerInterface $container, LoaderInterface $loader, GlobalVariables $globals = null)
     {
         $this->container = $container;
 
         parent::__construct($parser, $loader);
-        $this->addGlobal('app', $globals);
+
+        if (null !== $globals) {
+            $this->addGlobal('app', $globals);
+        }
     }
 
     /**

+ 5 - 3
src/Symfony/Bundle/TwigBundle/TwigEngine.php

@@ -32,14 +32,16 @@ class TwigEngine implements EngineInterface
      *
      * @param \Twig_Environment           $environment A \Twig_Environment instance
      * @param TemplateNameParserInterface $parser      A TemplateNameParserInterface instance
-     * @param GlobalVariables             $globals     A GlobalVariables instance
+     * @param GlobalVariables|null        $globals     A GlobalVariables instance or null
      */
-    public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, GlobalVariables $globals)
+    public function __construct(\Twig_Environment $environment, TemplateNameParserInterface $parser, GlobalVariables $globals = null)
     {
         $this->environment = $environment;
         $this->parser = $parser;
 
-        $environment->addGlobal('app', $globals);
+        if (null !== $globals) {
+            $environment->addGlobal('app', $globals);
+        }
     }
 
     /**