Upgrade problem

This commit is contained in:
dantleech
2012-12-31 14:04:50 +00:00
committed by Fabien Potencier
parent 25f7b0c7eb
commit 9f5fa532ef
2 changed files with 18 additions and 2 deletions
+8 -2
View File
@@ -972,8 +972,14 @@ class Twig_Environment
*/
public function addGlobal($name, $value)
{
if (($this->extensionInitialized || $this->runtimeInitialized) && !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) {
if (null === $this->globals) {
$this->initGlobals();
}
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) {
+10
View File
@@ -107,6 +107,16 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
} catch (LogicException $e) {
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
}
// test adding globals after initRuntime without call to getGlobals
$twig = new Twig_Environment(new Twig_Loader_String());
$twig->initRuntime();
try {
$twig->addGlobal('bar', 'bar');
$this->fail();
} catch (LogicException $e) {
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
}
}
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()