NodeTraverser
in package
Inspired by https://github.com/nikic/PHP-Parser/tree/36a6dcd04e7b0285e8f0868f44bd4927802f7df1
Copyright (c) 2011, Nikita Popov All rights reserved.
Table of Contents
- DONT_TRAVERSE_CHILDREN = 1
- If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes of the current node will not be traversed for any visitors.
- DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4
- If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes of the current node will not be traversed for any visitors.
- REMOVE_NODE = 3
- If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs in an array, it will be removed from the array.
- STOP_TRAVERSAL = 2
- If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns STOP_TRAVERSAL, traversal is aborted.
- $stopTraversal : bool
- $visitors : array<int, NodeVisitor>
- __construct() : mixed
- traverse() : array<string|int, Node>
- Traverses an array of nodes using the registered visitors.
- ensureReplacementReasonable() : void
- traverseArray() : array<string|int, mixed>
- Recursively traverse array (usually of nodes).
- traverseNode() : Node
- Recursively traverse a node.
Constants
DONT_TRAVERSE_CHILDREN
If NodeVisitor::enterNode() returns DONT_TRAVERSE_CHILDREN, child nodes of the current node will not be traversed for any visitors.
public
mixed
DONT_TRAVERSE_CHILDREN
= 1
For subsequent visitors enterNode() will still be called on the current node and leaveNode() will also be invoked for the current node.
DONT_TRAVERSE_CURRENT_AND_CHILDREN
If NodeVisitor::enterNode() returns DONT_TRAVERSE_CURRENT_AND_CHILDREN, child nodes of the current node will not be traversed for any visitors.
public
mixed
DONT_TRAVERSE_CURRENT_AND_CHILDREN
= 4
For subsequent visitors enterNode() will not be called as well. leaveNode() will be invoked for visitors that has enterNode() method invoked.
REMOVE_NODE
If NodeVisitor::leaveNode() returns REMOVE_NODE for a node that occurs in an array, it will be removed from the array.
public
mixed
REMOVE_NODE
= 3
For subsequent visitors leaveNode() will still be invoked for the removed node.
STOP_TRAVERSAL
If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns STOP_TRAVERSAL, traversal is aborted.
public
mixed
STOP_TRAVERSAL
= 2
The afterTraverse() method will still be invoked.
Properties
$stopTraversal
private
bool
$stopTraversal
Whether traversal should be stopped
$visitors
private
array<int, NodeVisitor>
$visitors
= []
Visitors
Methods
__construct()
public
__construct(array<int, NodeVisitor> $visitors) : mixed
Parameters
- $visitors : array<int, NodeVisitor>
Return values
mixed —traverse()
Traverses an array of nodes using the registered visitors.
public
traverse(array<string|int, Node> $nodes) : array<string|int, Node>
Parameters
- $nodes : array<string|int, Node>
-
Array of nodes
Return values
array<string|int, Node> —Traversed array of nodes
ensureReplacementReasonable()
private
ensureReplacementReasonable(Node $old, Node $new) : void
Parameters
Return values
void —traverseArray()
Recursively traverse array (usually of nodes).
private
traverseArray(array<string|int, mixed> $nodes) : array<string|int, mixed>
Parameters
- $nodes : array<string|int, mixed>
-
Array to traverse
Return values
array<string|int, mixed> —Result of traversal (may be original array or changed one)
traverseNode()
Recursively traverse a node.
private
traverseNode(Node $node) : Node
Parameters
- $node : Node
-
Node to traverse.
Return values
Node —Result of traversal (may be original node or new one)