From d13027d163c4d446fb86e9dc87bedae828a22fbd Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 8 Feb 2013 18:01:47 +0100 Subject: [PATCH] fixed globals when getGlobals is called early on (closes #990) --- lib/Twig/Environment.php | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index bdda8b4..e78218c 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -998,7 +998,7 @@ class Twig_Environment { if ($this->extensionInitialized || $this->runtimeInitialized) { if (null === $this->globals) { - $this->initGlobals(); + $this->globals = $this->initGlobals(); } /* This condition must be uncommented in Twig 2.0 @@ -1023,8 +1023,12 @@ class Twig_Environment */ public function getGlobals() { - if (null === $this->globals || !($this->runtimeInitialized || $this->extensionInitialized)) { - $this->initGlobals(); + if (!$this->runtimeInitialized && !$this->extensionInitialized) { + return $this->initGlobals(); + } + + if (null === $this->globals) { + $this->globals = $this->initGlobals(); } return $this->globals; @@ -1094,11 +1098,12 @@ class Twig_Environment protected function initGlobals() { - $this->globals = array(); + $globals = array(); foreach ($this->extensions as $extension) { - $this->globals = array_merge($this->globals, $extension->getGlobals()); + $globals = array_merge($globals, $extension->getGlobals()); } - $this->globals = array_merge($this->globals, $this->staging->getGlobals()); + + return array_merge($globals, $this->staging->getGlobals()); } protected function initExtensions() -- 1.7.2.5