mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Upgrade problem
This commit is contained in:
committed by
Fabien Potencier
parent
25f7b0c7eb
commit
9f5fa532ef
@@ -972,8 +972,14 @@ class Twig_Environment
|
|||||||
*/
|
*/
|
||||||
public function addGlobal($name, $value)
|
public function addGlobal($name, $value)
|
||||||
{
|
{
|
||||||
if (($this->extensionInitialized || $this->runtimeInitialized) && !array_key_exists($name, $this->globals)) {
|
if ($this->extensionInitialized || $this->runtimeInitialized) {
|
||||||
throw new LogicException(sprintf('Unable to add global "%s" as the runtime or the extensions have already been initialized.', $name));
|
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) {
|
if ($this->extensionInitialized || $this->runtimeInitialized) {
|
||||||
|
|||||||
@@ -107,6 +107,16 @@ class Twig_Tests_EnvironmentTest extends PHPUnit_Framework_TestCase
|
|||||||
} catch (LogicException $e) {
|
} catch (LogicException $e) {
|
||||||
$this->assertFalse(array_key_exists('bar', $twig->getGlobals()));
|
$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()
|
public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()
|
||||||
|
|||||||
Reference in New Issue
Block a user