[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/twig/twig/src/TokenParser/ -> AutoEscapeTokenParser.php (source)

   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  
  12  namespace Twig\TokenParser;
  13  
  14  use Twig\Error\SyntaxError;
  15  use Twig\Node\AutoEscapeNode;
  16  use Twig\Node\Expression\ConstantExpression;
  17  use Twig\Token;
  18  
  19  /**
  20   * Marks a section of a template to be escaped or not.
  21   */
  22  final class AutoEscapeTokenParser extends AbstractTokenParser
  23  {
  24      public function parse(Token $token)
  25      {
  26          $lineno = $token->getLine();
  27          $stream = $this->parser->getStream();
  28  
  29          if ($stream->test(/* Token::BLOCK_END_TYPE */ 3)) {
  30              $value = 'html';
  31          } else {
  32              $expr = $this->parser->getExpressionParser()->parseExpression();
  33              if (!$expr instanceof ConstantExpression) {
  34                  throw new SyntaxError('An escaping strategy must be a string or false.', $stream->getCurrent()->getLine(), $stream->getSourceContext());
  35              }
  36              $value = $expr->getAttribute('value');
  37          }
  38  
  39          $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  40          $body = $this->parser->subparse([$this, 'decideBlockEnd'], true);
  41          $stream->expect(/* Token::BLOCK_END_TYPE */ 3);
  42  
  43          return new AutoEscapeNode($value, $body, $lineno, $this->getTag());
  44      }
  45  
  46      public function decideBlockEnd(Token $token)
  47      {
  48          return $token->test('endautoescape');
  49      }
  50  
  51      public function getTag()
  52      {
  53          return 'autoescape';
  54      }
  55  }
  56  
  57  class_alias('Twig\TokenParser\AutoEscapeTokenParser', 'Twig_TokenParser_AutoEscape');


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1