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

Breadcrumb

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

class ParentConnectingVisitor

Visitor that connects a child node to its parent node.

On the child node, the parent node can be accessed through <code>$node->getAttribute('parent')</code>.

Hierarchy

  • class \PhpParser\NodeVisitorAbstract implements \PhpParser\NodeVisitor
    • class \PhpParser\NodeVisitor\ParentConnectingVisitor extends \PhpParser\NodeVisitorAbstract

Expanded class hierarchy of ParentConnectingVisitor

2 files declare their use of ParentConnectingVisitor
Calculator.php in vendor/sebastian/complexity/src/Calculator.php
ParsingFileAnalyser.php in vendor/phpunit/php-code-coverage/src/StaticAnalysis/ParsingFileAnalyser.php

File

vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php, line 17

Namespace

PhpParser\NodeVisitor
View source
final class ParentConnectingVisitor extends NodeVisitorAbstract {
    
    /**
     * @var Node[]
     */
    private array $stack = [];
    public function beforeTraverse(array $nodes) {
        $this->stack = [];
    }
    public function enterNode(Node $node) {
        if (!empty($this->stack)) {
            $node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
        }
        $this->stack[] = $node;
    }
    public function leaveNode(Node $node) {
        array_pop($this->stack);
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
NodeVisitor::DONT_TRAVERSE_CHILDREN public constant If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes
of the current node will not be traversed for any visitors.
NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN public constant If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes
of the current node will not be traversed for any visitors.
NodeVisitor::REMOVE_NODE public constant If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs
in an array, it will be removed from the array.
NodeVisitor::REPLACE_WITH_NULL public constant If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns REPLACE_WITH_NULL,
the node will be replaced with null. This is not a legal return value if the node is part
of an array, rather than another node.
NodeVisitor::STOP_TRAVERSAL public constant If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns
STOP_TRAVERSAL, traversal is aborted.
NodeVisitorAbstract::afterTraverse public function Called once after traversal. Overrides NodeVisitor::afterTraverse 1
ParentConnectingVisitor::$stack private property
ParentConnectingVisitor::beforeTraverse public function Called once before traversal. Overrides NodeVisitorAbstract::beforeTraverse
ParentConnectingVisitor::enterNode public function Called when entering a node. Overrides NodeVisitorAbstract::enterNode
ParentConnectingVisitor::leaveNode public function Called when leaving a node. Overrides NodeVisitorAbstract::leaveNode

API Navigation

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