ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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...
 
 setParser (Twig_Parser $parser)
 Sets the parser associated with this token parser. More...
 
 parse (Twig_Token $token)
 Parses a token and returns a node. More...
 
 getTag ()
 Gets the tag name 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 %}

@final

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.

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

References Twig_Token\test().

+ 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.

78 {
79 return 'autoescape';
80 }

Referenced by parse().

+ 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.

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
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 }
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:19
Represents an autoescape node.
Definition: AutoEscape.php:24
getTag()
Gets the tag name associated with this token parser.
Definition: AutoEscape.php:77
const BLOCK_END_TYPE
Definition: Token.php:30
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
$stream
PHP stream implementation.

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

+ Here is the call graph for this function:

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