public function parseFilterExpression($node)
{
$lineno = $this->parser->getCurrentToken()->getLine();
+
+ $this->parser->getStream()->next();
+
+ return new Twig_Node_Expression_Filter($node, $this->parseFilterExpressionRaw(), $lineno);
+ }
+
+ public function parseFilterExpressionRaw()
+ {
$filters = array();
- while ($this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '|'))
+ while (true)
{
- $this->parser->getStream()->next();
$token = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE);
$filters[] = array($token->getValue(), $this->parseArguments());
+
+ if (!$this->parser->getStream()->test(Twig_Token::OPERATOR_TYPE, '|'))
+ {
+ break;
+ }
+
+ $this->parser->getStream()->next();
}
- return new Twig_Node_Expression_Filter($node, $filters, $lineno);
+ return $filters;
}
public function parseArguments()
$this->filters[] = $filter;
}
+ public function appendFilters(array $filters)
+ {
+ $this->filters = array_merge($this->filters, $filters);
+ }
+
public function hasFilter($name)
{
foreach ($this->filters as $filter)
*/
class Twig_Node_Filter extends Twig_Node implements Twig_NodeListInterface
{
- protected $filter;
+ protected $filters;
protected $body;
- public function __construct($filter, Twig_NodeList $body, $lineno, $tag = null)
+ public function __construct($filters, Twig_NodeList $body, $lineno, $tag = null)
{
parent::__construct($lineno, $tag);
- $this->filter = $filter;
+ $this->filters = $filters;
$this->body = $body;
}
public function __toString()
{
- return get_class($this).'('.$this->filter.')';
+ return get_class($this).'('.$this->filters.')';
}
public function getNodes()
$compiler->subcompile($this->body);
}
- public function getFilter()
+ public function getFilters()
{
- return $this->filter;
+ return $this->filters;
}
}
// filter?
if ($node instanceof Twig_Node_Filter)
{
- $this->statusStack[] = $node->getFilter();
+ $this->statusStack[] = $node->getFilters();
$node = $this->visitDeep($node);
return $this->visitDeep($node);
}
- if (false === $filter = $this->getCurrentFilter())
+ if (false === $filters = $this->getCurrentFilters())
{
return $node;
}
$expression = $node->getExpression();
}
- // filter
+ // filters
if ($expression instanceof Twig_Node_Expression_Filter)
{
- $expression->appendFilter(array($filter, array()));
+ $expression->appendFilters($filters);
return $node;
}
else
{
return new Twig_Node_Print(
- new Twig_Node_Expression_Filter($expression, array(array($filter, array())), $node->getLine())
+ new Twig_Node_Expression_Filter($expression, $filters, $node->getLine())
, $node->getLine()
);
}
}
- protected function getCurrentFilter()
+ protected function getCurrentFilters()
{
return count($this->statusStack) ? $this->statusStack[count($this->statusStack) - 1] : false;
}
public function parse(Twig_Token $token)
{
$lineno = $token->getLine();
- $filter = $this->parser->getStream()->expect(Twig_Token::NAME_TYPE)->getValue();
+ $filters = $this->parser->getExpressionParser()->parseFilterExpressionRaw();
$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);
- return new Twig_Node_Filter($filter, $body, $lineno, $this->getTag());
+ return new Twig_Node_Filter($filters, $body, $lineno, $this->getTag());
}
public function decideBlockEnd($token)