Documentation

NodeTraverser
in package
implements NodeTraverserInterface

Interfaces, Classes and Traits

NodeTraverserInterface

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<string|int, NodeVisitor>
__construct()  : mixed
addVisitor()  : mixed
Adds a visitor.
removeVisitor()  : mixed
Removes an added visitor.
traverse()  : array<string|int, Node>
Traverses an array of nodes using the registered visitors.
traverseArray()  : array<string|int, mixed>
Recursively traverse array (usually of nodes).
traverseNode()  : Node
Recursively traverse a node.
ensureReplacementReasonable()  : mixed

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

protected bool $stopTraversal

Whether traversal should be stopped

Methods

__construct()

public __construct() : mixed
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

traverseArray()

Recursively traverse array (usually of nodes).

protected 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.

protected traverseNode(Node $node) : Node
Parameters
$node : Node

Node to traverse.

Return values
Node

Result of traversal (may be original node or new one)

ensureReplacementReasonable()

private ensureReplacementReasonable(mixed $old, mixed $new) : mixed
Parameters
$old : mixed
$new : mixed
Return values
mixed

Search results