function ExpressionParser::parseTestExpression
2 calls to ExpressionParser::parseTestExpression()
- ExpressionParser::parseExpression in vendor/
twig/ twig/ src/ ExpressionParser.php - ExpressionParser::parseNotTestExpression in vendor/
twig/ twig/ src/ ExpressionParser.php
File
-
vendor/
twig/ twig/ src/ ExpressionParser.php, line 740
Class
- ExpressionParser
- Parses expressions.
Namespace
TwigCode
private function parseTestExpression(Node $node) : TestExpression {
$stream = $this->parser
->getStream();
$test = $this->getTest($node->getTemplateLine());
$arguments = null;
if ($stream->test(Token::PUNCTUATION_TYPE, '(')) {
$arguments = $this->parseOnlyArguments();
}
elseif ($test->hasOneMandatoryArgument()) {
$arguments = new Nodes([
0 => $this->getPrimary(),
]);
}
if ('defined' === $test->getName() && $node instanceof NameExpression && null !== ($alias = $this->parser
->getImportedSymbol('function', $node->getAttribute('name')))) {
$node = new MacroReferenceExpression($alias['node']->getNode('var'), $alias['name'], new ArrayExpression([], $node->getTemplateLine()), $node->getTemplateLine());
}
$ready = $test instanceof TwigTest;
if (!isset($this->readyNodes[$class = $test->getNodeClass()])) {
$this->readyNodes[$class] = (bool) (new \ReflectionClass($class))->getConstructor()
->getAttributes(FirstClassTwigCallableReady::class);
}
if (!($ready = $this->readyNodes[$class])) {
trigger_deprecation('twig/twig', '3.12', 'Twig node "%s" is not marked as ready for passing a "TwigTest" in the constructor instead of its name; please update your code and then add #[FirstClassTwigCallableReady] attribute to the constructor.', $class);
}
return new $class($node, $ready ? $test : $test->getName(), $arguments, $this->parser
->getCurrentToken()
->getLine());
}