public function Twig_Node::__toString

File

drupal/core/vendor/twig/twig/lib/Twig/Node.php, line 44

Class

Twig_Node
Represents a node in the AST.

Code

public function __toString() {
  $attributes = array();
  foreach ($this->attributes as $name => $value) {
    $attributes[] = sprintf('%s: %s', $name, str_replace("\n", '', var_export($value, true)));
  }
  $repr = array(
    get_class($this) . '(' . implode(', ', $attributes),
  );
  if (count($this->nodes)) {
    foreach ($this->nodes as $name => $node) {
      $len = strlen($name) + 4;
      $noderepr = array();
      foreach (explode("\n", (string) $node) as $line) {
        $noderepr[] = str_repeat(' ', $len) . $line;
      }
      $repr[] = sprintf('  %s: %s', $name, ltrim(implode("\n", $noderepr)));
    }
    $repr[] = ')';
  }
  else {
    $repr[0] .= ')';
  }
  return implode("\n", $repr);
}