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

Breadcrumb

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

class CheckToStringNode

Checks if casting an expression to __toString() is allowed by the sandbox.

For instance, when there is a simple Print statement, like {{ article }}, and if the sandbox is enabled, we need to check that the __toString() method is allowed if 'article' is an object. The same goes for {{ article|upper }} or {{ random(article) }}

@author Fabien Potencier <fabien@symfony.com>

Hierarchy

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

Expanded class hierarchy of CheckToStringNode

4 files declare their use of CheckToStringNode
RemoveCheckToStringNodeVisitor.php in core/lib/Drupal/Core/Template/RemoveCheckToStringNodeVisitor.php
SandboxNodeVisitor.php in vendor/twig/twig/src/NodeVisitor/SandboxNodeVisitor.php
TwigNodeTrans.php in core/lib/Drupal/Core/Template/TwigNodeTrans.php
TwigSimpleCheckToStringNode.php in core/lib/Drupal/Core/Template/TwigSimpleCheckToStringNode.php

File

vendor/twig/twig/src/Node/CheckToStringNode.php, line 28

Namespace

Twig\Node
View source
class CheckToStringNode extends AbstractExpression {
    public function __construct(AbstractExpression $expr) {
        parent::__construct([
            'expr' => $expr,
        ], [], $expr->getTemplateLine());
    }
    public function compile(Compiler $compiler) : void {
        $expr = $this->getNode('expr');
        $compiler->raw('$this->sandbox->ensureToStringAllowed(')
            ->subcompile($expr)
            ->raw(', ')
            ->repr($expr->getTemplateLine())
            ->raw(', $this->source)');
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AbstractExpression::hasExplicitParentheses public function
AbstractExpression::isGenerator public function
AbstractExpression::setExplicitParentheses public function
CheckToStringNode::compile public function Overrides Node::compile 1
CheckToStringNode::__construct public function Overrides Node::__construct
Node::$attributeNameDeprecations private property @var array&lt;string, NameDeprecation&gt;
Node::$attributes protected property
Node::$lineno protected property
Node::$nodeNameDeprecations private property @var array&lt;string, NameDeprecation&gt;
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
RSS feed
Powered by Drupal