relaxed globals management to avoid a BC break (closes #965)
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 15 Jan 2013 19:48:33 +0000 (20:48 +0100)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 15 Jan 2013 19:48:33 +0000 (20:48 +0100)
CHANGELOG
doc/deprecated.rst
lib/Twig/Environment.php
test/Twig/Tests/EnvironmentTest.php

index 5165e76..83656dd 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,6 @@
 * 1.12.1 (2013-XX-XX)
 
+ * relaxed globals management to avoid a BC break
  * added support for {{ some_string[:2] }}
 
 * 1.12.0 (2013-01-08)
index 3b2df29..f0a3a0f 100644 (file)
@@ -89,3 +89,10 @@ Interfaces
 * ``Twig_ParserInterface``       (use ``Twig_Parser`` instead)
 * ``Twig_ExistsLoaderInterface`` (merged with ``Twig_LoaderInterface``)
 * ``Twig_TemplateInterface``     (use ``Twig_Template`` instead)
+
+Globals
+-------
+
+* As of Twig 2.x, the ability to register a global variable after the runtime
+  or the extensions have been initialized is not possible anymore (but
+  changing the value of an already registered global is possible).
index ea2b98f..90f4aa3 100644 (file)
@@ -996,10 +996,12 @@ class Twig_Environment
             if (null === $this->globals) {
                 $this->initGlobals();
             }
-            
+
+            /* This condition must be uncommented in Twig 2.0
             if (!array_key_exists($name, $this->globals)) {
                 throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
             }
+            */
         }
 
         if ($this->extensionInitialized || $this->runtimeInitialized) {
index 5ec28d6..fc2cef8 100644 (file)
@@ -71,6 +71,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
         $globals = $twig->getGlobals();
         $this->assertEquals('bar', $globals['foo']);
 
+        /* to be uncomment in Twig 2.0
         // globals cannot be added after runtime init
         $twig = new Twig_Environment(new Twig_Loader_String());
         $twig->addGlobal('foo', 'foo');
@@ -117,6 +118,7 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
         } catch (LogicException $e) {
             $this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
         }
+        */
     }
 
     public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()