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

Breadcrumb

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

function ExpressionParser::getTest

1 call to ExpressionParser::getTest()
ExpressionParser::parseTestExpression in vendor/twig/twig/src/ExpressionParser.php

File

vendor/twig/twig/src/ExpressionParser.php, line 768

Class

ExpressionParser
Parses expressions.

Namespace

Twig

Code

private function getTest(int $line) : TwigTest {
    $stream = $this->parser
        ->getStream();
    $name = $stream->expect(Token::NAME_TYPE)
        ->getValue();
    if ($stream->test(Token::NAME_TYPE)) {
        // try 2-words tests
        $name = $name . ' ' . $this->parser
            ->getCurrentToken()
            ->getValue();
        if ($test = $this->env
            ->getTest($name)) {
            $stream->next();
        }
    }
    else {
        $test = $this->env
            ->getTest($name);
    }
    if (!$test) {
        if ($this->parser
            ->shouldIgnoreUnknownTwigCallables()) {
            return new TwigTest($name, fn() => '');
        }
        $e = new SyntaxError(\sprintf('Unknown "%s" test.', $name), $line, $stream->getSourceContext());
        $e->addSuggestions($name, array_keys($this->env
            ->getTests()));
        throw $e;
    }
    if ($test->isDeprecated()) {
        $stream = $this->parser
            ->getStream();
        $src = $stream->getSourceContext();
        $test->triggerDeprecation($src->getPath() ?: $src->getName(), $stream->getCurrent()
            ->getLine());
    }
    return $test;
}

API Navigation

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