From e5a86464810748e7b18bdde14f03ff041e6aa6ce Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 3 Dec 2010 18:01:12 +0100 Subject: [PATCH] made lexer/parser/compiler lazy-loaded --- lib/Twig/Environment.php | 26 +++++++++++++++++++++++--- 1 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index b8117bb..a56c935 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -69,9 +69,17 @@ class Twig_Environment $this->setLoader($loader); } - $this->setLexer(null !== $lexer ? $lexer : new Twig_Lexer()); - $this->setParser(null !== $parser ? $parser : new Twig_Parser()); - $this->setCompiler(null !== $compiler ? $compiler : new Twig_Compiler()); + if (null !== $lexer) { + $this->setLexer($lexer); + } + + if (null !== $parser) { + $this->setParser($parser); + } + + if (null !== $compiler) { + $this->setCompiler($compiler); + } $this->debug = isset($options['debug']) ? (bool) $options['debug'] : false; $this->charset = isset($options['charset']) ? $options['charset'] : 'UTF-8'; @@ -211,6 +219,10 @@ class Twig_Environment public function getLexer() { + if (null === $this->lexer) { + $this->lexer = new Twig_Lexer($this); + } + return $this->lexer; } @@ -227,6 +239,10 @@ class Twig_Environment public function getParser() { + if (null === $this->parser) { + $this->parser = new Twig_Parser($this); + } + return $this->parser; } @@ -243,6 +259,10 @@ class Twig_Environment public function getCompiler() { + if (null === $this->compiler) { + $this->compiler = new Twig_Compiler($this); + } + return $this->compiler; } -- 1.7.2.5