Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AutoEscapeTokenParser.php

class AutoEscapeTokenParser

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

@internal

Hierarchy

  • class \Twig\TokenParser\AbstractTokenParser implements \Twig\TokenParser\TokenParserInterface
    • class \Twig\TokenParser\AutoEscapeTokenParser extends \Twig\TokenParser\AbstractTokenParser

Expanded class hierarchy of AutoEscapeTokenParser

1 file declares its use of AutoEscapeTokenParser
EscaperExtension.php in vendor/twig/twig/src/Extension/EscaperExtension.php

File

vendor/twig/twig/src/TokenParser/AutoEscapeTokenParser.php, line 25

Namespace

Twig\TokenParser
View source
final class AutoEscapeTokenParser extends AbstractTokenParser {
    public function parse(Token $token) : Node {
        $lineno = $token->getLine();
        $stream = $this->parser
            ->getStream();
        if ($stream->test(Token::BLOCK_END_TYPE)) {
            $value = 'html';
        }
        else {
            $expr = $this->parser
                ->getExpressionParser()
                ->parseExpression();
            if (!$expr instanceof ConstantExpression) {
                throw new SyntaxError('An escaping strategy must be a string or false.', $stream->getCurrent()
                    ->getLine(), $stream->getSourceContext());
            }
            $value = $expr->getAttribute('value');
        }
        $stream->expect(Token::BLOCK_END_TYPE);
        $body = $this->parser
            ->subparse([
            $this,
            'decideBlockEnd',
        ], true);
        $stream->expect(Token::BLOCK_END_TYPE);
        return new AutoEscapeNode($value, $body, $lineno);
    }
    public function decideBlockEnd(Token $token) : bool {
        return $token->test('endautoescape');
    }
    public function getTag() : string {
        return 'autoescape';
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
AbstractTokenParser::$parser protected property
AbstractTokenParser::setParser public function Sets the parser associated with this token parser. Overrides TokenParserInterface::setParser
AutoEscapeTokenParser::decideBlockEnd public function
AutoEscapeTokenParser::getTag public function Gets the tag name associated with this token parser. Overrides TokenParserInterface::getTag
AutoEscapeTokenParser::parse public function Parses a token and returns a node. Overrides TokenParserInterface::parse

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal