From 7cb9159e85323dabccd619f047df45dbb854be57 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 6 Jan 2011 08:18:55 +0100 Subject: [PATCH] optimized filter tag implementation --- lib/Twig/TokenParser/Filter.php | 13 ++++--------- 1 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lib/Twig/TokenParser/Filter.php b/lib/Twig/TokenParser/Filter.php index 35d3b54..2e0e31c 100644 --- a/lib/Twig/TokenParser/Filter.php +++ b/lib/Twig/TokenParser/Filter.php @@ -20,23 +20,18 @@ class Twig_TokenParser_Filter extends Twig_TokenParser public function parse(Twig_Token $token) { $name = str_replace('.', '_', uniqid('_tmp_', true)); - $node = new Twig_Node_Expression_Name($name, $token->getLine()); - - $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($node, $this->getTag()); + $ref = new Twig_Node_Expression_BlockReference(new Twig_Node_Expression_Constant($name, $token->getLine()), $token->getLine(), $this->getTag()); + $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); - $ref = new Twig_Node_BlockReference($name, $token->getLine(), $this->getTag()); - $block = new Twig_Node_Block($name, $body, $token->getLine()); $this->parser->setBlock($name, $block); - $set = new Twig_Node_Set(true, new Twig_Node(array(new Twig_Node_Expression_AssignName($name, $token->getLine()))), new Twig_Node(array($ref)), $token->getLine(), $this->getTag()); - $filter = new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); - - return new Twig_Node(array($set, $filter)); + return new Twig_Node_Print($filter, $token->getLine(), $this->getTag()); } public function decideBlockEnd($token) -- 1.7.2.5