1<?php 2 3/* 4 * This file is part of Twig. 5 * 6 * (c) Fabien Potencier 7 * 8 * For the full copyright and license information, please view the LICENSE 9 * file that was distributed with this source code. 10 */ 11 12namespace Twig\TokenParser; 13 14use Twig\Node\BlockNode; 15use Twig\Node\Expression\BlockReferenceExpression; 16use Twig\Node\Expression\ConstantExpression; 17use Twig\Node\PrintNode; 18use Twig\Token; 19 20/** 21 * Filters a section of a template by applying filters. 22 * 23 * {% filter upper %} 24 * This text becomes uppercase 25 * {% endfilter %} 26 * 27 * @deprecated since Twig 2.9, to be removed in 3.0 (use the "apply" tag instead) 28 */ 29final class FilterTokenParser extends AbstractTokenParser 30{ 31 public function parse(Token $token) 32 { 33 $stream = $this->parser->getStream(); 34 $lineno = $token->getLine(); 35 36 @trigger_error(sprintf('The "filter" tag in "%s" at line %d is deprecated since Twig 2.9, use the "apply" tag instead.', $stream->getSourceContext()->getName(), $lineno), \E_USER_DEPRECATED); 37 38 $name = $this->parser->getVarName(); 39 $ref = new BlockReferenceExpression(new ConstantExpression($name, $lineno), null, $lineno, $this->getTag()); 40 41 $filter = $this->parser->getExpressionParser()->parseFilterExpressionRaw($ref, $this->getTag()); 42 $stream->expect(/* Token::BLOCK_END_TYPE */ 3); 43 44 $body = $this->parser->subparse([$this, 'decideBlockEnd'], true); 45 $stream->expect(/* Token::BLOCK_END_TYPE */ 3); 46 47 $block = new BlockNode($name, $body, $lineno); 48 $this->parser->setBlock($name, $block); 49 50 return new PrintNode($filter, $lineno, $this->getTag()); 51 } 52 53 public function decideBlockEnd(Token $token) 54 { 55 return $token->test('endfilter'); 56 } 57 58 public function getTag() 59 { 60 return 'filter'; 61 } 62} 63 64class_alias('Twig\TokenParser\FilterTokenParser', 'Twig_TokenParser_Filter'); 65