ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
AutoEscape.php
Go to the documentation of this file.
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 
33 {
34  public function parse(Twig_Token $token)
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  }
71 
72  public function decideBlockEnd(Twig_Token $token)
73  {
74  return $token->test('endautoescape');
75  }
76 
77  public function getTag()
78  {
79  return 'autoescape';
80  }
81 }
82 
83 class_alias('Twig_TokenParser_AutoEscape', 'Twig\TokenParser\AutoEscapeTokenParser', false);
Represents an autoescape node.
Definition: AutoEscape.php:23
getTag()
Gets the tag name associated with this token parser.
Definition: AutoEscape.php:77
test($type, $values=null)
Tests the current token for a type and/or a value.
Definition: Token.php:70
$stream
PHP stream implementation.
Exception thrown when a syntax error occurs during lexing or parsing of a template.
Definition: Syntax.php:18
decideBlockEnd(Twig_Token $token)
Definition: AutoEscape.php:72
Base class for all token parsers.
Definition: TokenParser.php:17
parse(Twig_Token $token)
Parses a token and returns a node.
Definition: AutoEscape.php:34
Create styles array
The data for the language used.
Marks a section of a template to be escaped or not.
Definition: AutoEscape.php:32
getLine()
Definition: Token.php:87
const NAME_TYPE
Definition: Token.php:32
const BLOCK_END_TYPE
Definition: Token.php:30