relaxed globals management to avoid a BC break (closes #965)

This commit is contained in:
Fabien Potencier
2013-01-15 20:48:33 +01:00
parent 3111e1265d
commit 5abad16081
4 changed files with 13 additions and 1 deletions
+1
View File
@@ -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)
+7
View 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).
+3 -1
View 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) {
+2
View 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()