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

Breadcrumb

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

function Node::__toString

Same name in this branch
  1. 11.1.x vendor/phpstan/phpdoc-parser/src/Ast/Node.php \PHPStan\PhpDocParser\Ast\Node::__toString()

File

vendor/twig/twig/src/Node/Node.php, line 68

Class

Node
Represents a node in the AST.

Namespace

Twig\Node

Code

public function __toString() {
    $repr = static::class;
    if ($this->tag) {
        $repr .= \sprintf("\n  tag: %s", $this->tag);
    }
    $attributes = [];
    foreach ($this->attributes as $name => $value) {
        if (\is_callable($value)) {
            $v = '\\Closure';
        }
        elseif ($value instanceof \Stringable) {
            $v = (string) $value;
        }
        else {
            $v = str_replace("\n", '', var_export($value, true));
        }
        $attributes[] = \sprintf('%s: %s', $name, $v);
    }
    if ($attributes) {
        $repr .= \sprintf("\n  attributes:\n    %s", implode("\n    ", $attributes));
    }
    if (\count($this->nodes)) {
        $repr .= "\n  nodes:";
        foreach ($this->nodes as $name => $node) {
            $len = \strlen($name) + 6;
            $noderepr = [];
            foreach (explode("\n", (string) $node) as $line) {
                $noderepr[] = str_repeat(' ', $len) . $line;
            }
            $repr .= \sprintf("\n    %s: %s", $name, ltrim(implode("\n", $noderepr)));
        }
    }
    return $repr;
}

API Navigation

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