From 45cfd21d4cae71489eb7398673753d6aeb536d8b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Wed, 15 Dec 2010 13:31:15 +0100 Subject: [PATCH] simplified code --- lib/Twig/Compiler.php | 9 +-------- lib/Twig/Environment.php | 3 --- lib/Twig/Lexer.php | 11 ++--------- lib/Twig/Parser.php | 9 +-------- 4 files changed, 4 insertions(+), 28 deletions(-) diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php index 7eb90d0..aef6a87 100644 --- a/lib/Twig/Compiler.php +++ b/lib/Twig/Compiler.php @@ -28,14 +28,7 @@ class Twig_Compiler implements Twig_CompilerInterface * * @param Twig_Environment $env The twig environment instance */ - public function __construct(Twig_Environment $env = null) - { - if (null !== $env) { - $this->setEnvironment($env); - } - } - - public function setEnvironment(Twig_Environment $env) + public function __construct(Twig_Environment $env) { $this->env = $env; } diff --git a/lib/Twig/Environment.php b/lib/Twig/Environment.php index 136f148..4de0a99 100644 --- a/lib/Twig/Environment.php +++ b/lib/Twig/Environment.php @@ -261,7 +261,6 @@ class Twig_Environment public function setLexer(Twig_LexerInterface $lexer) { $this->lexer = $lexer; - $lexer->setEnvironment($this); } public function tokenize($source, $name = null) @@ -281,7 +280,6 @@ class Twig_Environment public function setParser(Twig_ParserInterface $parser) { $this->parser = $parser; - $parser->setEnvironment($this); } public function parse(Twig_TokenStream $tokens) @@ -301,7 +299,6 @@ class Twig_Environment public function setCompiler(Twig_CompilerInterface $compiler) { $this->compiler = $compiler; - $compiler->setEnvironment($this); } public function compile(Twig_NodeInterface $node) diff --git a/lib/Twig/Lexer.php b/lib/Twig/Lexer.php index a119e1e..9fc4690 100644 --- a/lib/Twig/Lexer.php +++ b/lib/Twig/Lexer.php @@ -38,11 +38,9 @@ class Twig_Lexer implements Twig_LexerInterface const REGEX_STRING = '/(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')/Asm'; const REGEX_PUNCTUATION = '/[\[\](){}?:.,|]/A'; - public function __construct(Twig_Environment $env = null, array $options = array()) + public function __construct(Twig_Environment $env, array $options = array()) { - if (null !== $env) { - $this->setEnvironment($env); - } + $this->env = $env; $this->options = array_merge(array( 'tag_comment' => array('{#', '#}'), @@ -91,11 +89,6 @@ class Twig_Lexer implements Twig_LexerInterface return new Twig_TokenStream($tokens, $this->filename); } - public function setEnvironment(Twig_Environment $env) - { - $this->env = $env; - } - /** * Parses the next token and returns it. */ diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 8ae97cd..31f0e81 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -21,14 +21,7 @@ class Twig_Parser implements Twig_ParserInterface protected $macros; protected $env; - public function __construct(Twig_Environment $env = null) - { - if (null !== $env) { - $this->setEnvironment($env); - } - } - - public function setEnvironment(Twig_Environment $env) + public function __construct(Twig_Environment $env) { $this->env = $env; } -- 1.7.2.5