Twig_TokenParser_AutoEscape

Marks a section of a template to be escaped or not.

Defined (1)

The class is defined in the following location(s).

/vendor/twig/twig/lib/Twig/TokenParser/AutoEscape.php  
  1. class Twig_TokenParser_AutoEscape extends Twig_TokenParser 
  2. public function parse(Twig_Token $token) 
  3. $lineno = $token->getLine(); 
  4. $stream = $this->parser->getStream(); 
  5.  
  6. if ($stream->test(Twig_Token::BLOCK_END_TYPE)) { 
  7. $value = 'html'; 
  8. } else { 
  9. $expr = $this->parser->getExpressionParser()->parseExpression(); 
  10. if (!$expr instanceof Twig_Node_Expression_Constant) { 
  11. throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); 
  12. $value = $expr->getAttribute('value'); 
  13.  
  14. $compat = true === $value || false === $value; 
  15.  
  16. if (true === $value) { 
  17. $value = 'html'; 
  18.  
  19. if ($compat && $stream->test(Twig_Token::NAME_TYPE)) { 
  20. @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED); 
  21.  
  22. if (false === $value) { 
  23. throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext()); 
  24.  
  25. $value = $stream->next()->getValue(); 
  26.  
  27. $stream->expect(Twig_Token::BLOCK_END_TYPE); 
  28. $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true); 
  29. $stream->expect(Twig_Token::BLOCK_END_TYPE); 
  30.  
  31. return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag()); 
  32.  
  33. public function decideBlockEnd(Twig_Token $token) 
  34. return $token->test('endautoescape'); 
  35.  
  36. public function getTag() 
  37. return 'autoescape';