ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Twig_TokenParser_AutoEscape Class Reference

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

+ Inheritance diagram for Twig_TokenParser_AutoEscape:
+ Collaboration diagram for Twig_TokenParser_AutoEscape:

Public Member Functions

 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 decideBlockEnd (Twig_Token $token)
 
 getTag ()
 Gets the tag name associated with this token parser. More...
 
- Public Member Functions inherited from Twig_TokenParser
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 

Additional Inherited Members

- Protected Attributes inherited from Twig_TokenParser
 $parser
 

Detailed Description

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

{% autoescape true %}
  Everything will be automatically escaped in this block
{% endautoescape %}
{% autoescape false %}
  Everything will be outputed as is in this block
{% endautoescape %}
{% autoescape true js %}
  Everything will be automatically escaped in this block
  using the js escaping strategy
{% endautoescape %}

Definition at line 32 of file AutoEscape.php.

Member Function Documentation

◆ decideBlockEnd()

Twig_TokenParser_AutoEscape::decideBlockEnd ( Twig_Token  $token)

Definition at line 72 of file AutoEscape.php.

References Twig_Token\test().

73  {
74  return $token->test('endautoescape');
75  }
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
+ Here is the call graph for this function:

◆ getTag()

Twig_TokenParser_AutoEscape::getTag ( )

Gets the tag name associated with this token parser.

Returns
string The tag name

Implements Twig_TokenParserInterface.

Definition at line 77 of file AutoEscape.php.

Referenced by parse().

78  {
79  return 'autoescape';
80  }
+ Here is the caller graph for this function:

◆ parse()

Twig_TokenParser_AutoEscape::parse ( Twig_Token  $token)

Parses a token and returns a node.

Returns
Twig_NodeInterface
Exceptions
Twig_Error_Syntax

Implements Twig_TokenParserInterface.

Definition at line 34 of file AutoEscape.php.

References $compat, GuzzleHttp\Psr7\$stream, Twig_Token\BLOCK_END_TYPE, Twig_Token\getLine(), getTag(), and Twig_Token\NAME_TYPE.

35  {
36  $lineno = $token->getLine();
37  $stream = $this->parser->getStream();
38 
40  $value = 'html';
41  } else {
42  $expr = $this->parser->getExpressionParser()->parseExpression();
43  if (!$expr instanceof Twig_Node_Expression_Constant) {
44  throw new Twig_Error_Syntax('An escaping strategy must be a string or a bool.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
45  }
46  $value = $expr->getAttribute('value');
47 
48  $compat = true === $value || false === $value;
49 
50  if (true === $value) {
51  $value = 'html';
52  }
53 
54  if ($compat && $stream->test(Twig_Token::NAME_TYPE)) {
55  @trigger_error('Using the autoescape tag with "true" or "false" before the strategy name is deprecated since version 1.21.', E_USER_DEPRECATED);
56 
57  if (false === $value) {
58  throw new Twig_Error_Syntax('Unexpected escaping strategy as you set autoescaping to false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
59  }
60 
61  $value = $stream->next()->getValue();
62  }
63  }
64 
66  $body = $this->parser->subparse(array($this, 'decideBlockEnd'), true);
68 
69  return new Twig_Node_AutoEscape($value, $body, $lineno, $this->getTag());
70  }
Represents an autoescape node.
Definition: AutoEscape.php:23
getTag()
Gets the tag name associated with this token parser.
Definition: AutoEscape.php:77
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: