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

Breadcrumb

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

class TestExpression

Hierarchy

  • class \Twig\Node\Node implements \Twig\Node\Countable, \Twig\Node\IteratorAggregate
    • class \Twig\Node\Expression\AbstractExpression extends \Twig\Node\Node
      • class \Twig\Node\Expression\CallExpression extends \Twig\Node\Expression\AbstractExpression
        • class \Twig\Node\Expression\TestExpression extends \Twig\Node\Expression\CallExpression

Expanded class hierarchy of TestExpression

9 files declare their use of TestExpression
ConstantTest.php in vendor/twig/twig/src/Node/Expression/Test/ConstantTest.php
DefinedTest.php in vendor/twig/twig/src/Node/Expression/Test/DefinedTest.php
DivisiblebyTest.php in vendor/twig/twig/src/Node/Expression/Test/DivisiblebyTest.php
EvenTest.php in vendor/twig/twig/src/Node/Expression/Test/EvenTest.php
ExpressionParser.php in vendor/twig/twig/src/ExpressionParser.php

... See full list

File

vendor/twig/twig/src/Node/Expression/TestExpression.php, line 20

Namespace

Twig\Node\Expression
View source
class TestExpression extends CallExpression {
    public function __construct(Node $node, string|TwigTest $test, ?Node $arguments, int $lineno) {
        if (!$node instanceof AbstractExpression) {
            trigger_deprecation('twig/twig', '3.15', 'Not passing a "%s" instance to the "node" argument of "%s" is deprecated ("%s" given).', AbstractExpression::class, static::class, get_class($node));
        }
        $nodes = [
            'node' => $node,
        ];
        if (null !== $arguments) {
            $nodes['arguments'] = $arguments;
        }
        if ($test instanceof TwigTest) {
            $name = $test->getName();
        }
        else {
            $name = $test;
            trigger_deprecation('twig/twig', '3.12', 'Not passing an instance of "TwigTest" when creating a "%s" test of type "%s" is deprecated.', $name, static::class);
        }
        parent::__construct($nodes, [
            'name' => $name,
            'type' => 'test',
        ], $lineno);
        if ($test instanceof TwigTest) {
            $this->setAttribute('twig_callable', $test);
        }
        $this->deprecateAttribute('arguments', new NameDeprecation('twig/twig', '3.12'));
        $this->deprecateAttribute('callable', new NameDeprecation('twig/twig', '3.12'));
        $this->deprecateAttribute('is_variadic', new NameDeprecation('twig/twig', '3.12'));
        $this->deprecateAttribute('dynamic_name', new NameDeprecation('twig/twig', '3.12'));
    }
    public function compile(Compiler $compiler) : void {
        $name = $this->getAttribute('name');
        if ($this->hasAttribute('twig_callable')) {
            $name = $this->getAttribute('twig_callable')
                ->getName();
            if ($name !== $this->getAttribute('name')) {
                trigger_deprecation('twig/twig', '3.12', 'Changing the value of a "test" node in a NodeVisitor class is not supported anymore.');
                $this->removeAttribute('twig_callable');
            }
        }
        if (!$this->hasAttribute('twig_callable')) {
            $this->setAttribute('twig_callable', $compiler->getEnvironment()
                ->getTest($this->getAttribute('name')));
        }
        $this->compileCallable($compiler);
    }

}

Members

Title Sort descending Deprecated Modifiers Object type Summary Overriden Title Overrides
AbstractExpression::hasExplicitParentheses public function
AbstractExpression::isGenerator public function
AbstractExpression::setExplicitParentheses public function
CallExpression::$reflector private property
CallExpression::compileArguments protected function
CallExpression::compileCallable protected function
CallExpression::getArguments Deprecated protected function
CallExpression::getCallableParameters private function
CallExpression::getTwigCallable private function Overrides the Twig callable based on attributes (as potentially, attributes changed between the creation and the compilation of the node).
CallExpression::normalizeName Deprecated protected function
CallExpression::reflectCallable private function
Node::$attributeNameDeprecations private property @var array<string, NameDeprecation>
Node::$attributes protected property
Node::$lineno protected property
Node::$nodeNameDeprecations private property @var array<string, NameDeprecation>
Node::$nodes protected property
Node::$sourceContext private property
Node::$tag protected property
Node::count public function
Node::deprecateAttribute public function
Node::deprecateNode public function
Node::getAttribute public function
Node::getIterator public function
Node::getNode public function
Node::getNodeTag public function
Node::getSourceContext public function
Node::getTemplateLine public function
Node::getTemplateName public function
Node::hasAttribute public function
Node::hasNode public function
Node::removeAttribute public function
Node::removeNode public function
Node::setAttribute public function
Node::setNode public function 1
Node::setNodeTag public function @internal
Node::setSourceContext public function
Node::__toString public function
TestExpression::compile public function Overrides Node::compile 7
TestExpression::__construct public function Overrides Node::__construct 1
RSS feed
Powered by Drupal