From: Fabien Potencier Date: Thu, 6 Jan 2011 07:18:55 +0000 (+0100) Subject: optimized filter tag implementation X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=7cb9159e85323dabccd619f047df45dbb854be57;p=web%2Fkonrad%2Ftwig.git optimized filter tag implementation --- 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)