vendor/twig/twig/src/TokenParser/FilterTokenParser.php line 31

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