Pārlūkot izejas kodu

[Templating] tweaked previous commit

Fabien Potencier 14 gadi atpakaļ
vecāks
revīzija
ed359af543

+ 2 - 12
src/Symfony/Component/Templating/Engine.php

@@ -52,6 +52,7 @@ class Engine implements \ArrayAccess
         $this->stack     = array();
         $this->charset   = 'UTF-8';
         $this->cache     = array();
+        $this->globals   = array();
 
         $this->addHelpers($helpers);
 
@@ -407,27 +408,16 @@ class Engine implements \ArrayAccess
      */
     public function addGlobal($name, $value)
     {
-        if (null === $this->globals) {
-            $this->getGlobals();
-        }
-
         $this->globals[$name] = $value;
     }
 
     /**
-     * Returns the assigned globals. If no globals are set yet it calls all assigned helpers for theirs.
+     * Returns the assigned globals.
      *
      * @return array
      */
     public function getGlobals()
     {
-        if (null === $this->globals) {
-            $this->globals = array();
-            foreach ($this->helpers as $helper) {
-                $this->globals = array_replace($this->globals, $helper->getGlobals());
-            }
-        }
-
         return $this->globals;
     }
 

+ 0 - 10
src/Symfony/Component/Templating/Helper/Helper.php

@@ -42,14 +42,4 @@ abstract class Helper implements HelperInterface
     {
         return $this->charset;
     }
-
-    /**
-     * Get global variables for templates
-     *
-     * @return array
-     */
-    public function getGlobals()
-    {
-        return array();
-    }
 }

+ 0 - 8
src/Symfony/Component/Templating/Helper/HelperInterface.php

@@ -38,12 +38,4 @@ interface HelperInterface
      * @return string The default charset
      */
     function getCharset();
-
-    /**
-     * Returns a key value array with variables that should be accessible
-     * in templates.
-     *
-     * @return array
-     */
-    function getGlobals();
 }

+ 0 - 23
tests/Symfony/Tests/Component/Templating/EngineTest.php

@@ -142,29 +142,6 @@ class EngineTest extends \PHPUnit_Framework_TestCase
         ), $engine->getGlobals());
     }
 
-    public function testGlobalVariablesGetPassedFromHelpers()
-    {
-        $engine = new ProjectTemplateEngine(self::$loader);
-        $engine->set(new \SimpleHelper('value'));
-        $engine->addGlobal('global_variable', 'lorem ipsum');
-
-        $this->assertEquals(array(
-            'global_variable' => 'lorem ipsum',
-            'global_from_helper' => 'helper lorem ipsum',
-        ), $engine->getGlobals());
-    }
-
-    public function testEngineGlobalOverwritesHelperGlobals()
-    {
-        $engine = new ProjectTemplateEngine(self::$loader);
-        $engine->set(new \SimpleHelper('value'));
-        $engine->addGlobal('global_from_helper', 'engine wins');
-
-        $this->assertEquals(array(
-            'global_from_helper' => 'engine wins',
-        ), $engine->getGlobals());
-    }
-
     public function testGlobalsGetPassedToTemplate()
     {
         $engine = new ProjectTemplateEngine(self::$loader);

+ 0 - 7
tests/Symfony/Tests/Component/Templating/Fixtures/SimpleHelper.php

@@ -20,11 +20,4 @@ class SimpleHelper extends Helper
     {
         return 'foo';
     }
-
-    public function getGlobals()
-    {
-        return array(
-            'global_from_helper' => 'helper lorem ipsum',
-        );
-    }
 }