Documentation

NodeVisitor

Table of Contents

Constants

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.
REPLACE_WITH_NULL  = 5
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.
STOP_TRAVERSAL  = 2
If NodeVisitor::enterNode() or NodeVisitor::leaveNode() returns STOP_TRAVERSAL, traversal is aborted.

Methods

afterTraverse()  : null|array<string|int, Node>
Called once after traversal.
beforeTraverse()  : null|array<string|int, Node>
Called once before traversal.
enterNode()  : null|int|Node|array<string|int, Node>
Called when entering a node.
leaveNode()  : null|int|Node|array<string|int, Node>
Called when leaving 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.

REPLACE_WITH_NULL

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.

public mixed REPLACE_WITH_NULL = 5

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.

Methods

afterTraverse()

Called once after traversal.

public afterTraverse(array<string|int, Node$nodes) : null|array<string|int, Node>

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, Node>

Array of nodes

Return values
null|array<string|int, Node>

Array of nodes

beforeTraverse()

Called once before traversal.

public beforeTraverse(array<string|int, Node$nodes) : null|array<string|int, Node>

Return value semantics:

  • null: $nodes stays as-is
  • otherwise: $nodes is set to the return value
Parameters
$nodes : array<string|int, Node>

Array of nodes

Return values
null|array<string|int, Node>

Array of nodes

enterNode()

Called when entering a node.

public enterNode(Node $node) : null|int|Node|array<string|int, Node>

Return value semantics:

  • null => $node stays as-is
  • array (of Nodes) => The return value is merged into the parent array (at the position of the $node)
  • NodeVisitor::REMOVE_NODE => $node is removed from the parent array
  • NodeVisitor::REPLACE_WITH_NULL => $node is replaced with null
  • NodeVisitor::DONT_TRAVERSE_CHILDREN => Children of $node are not traversed. $node stays as-is
  • NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN => Further visitors for the current node are skipped, and its children are not traversed. $node stays as-is.
  • NodeVisitor::STOP_TRAVERSAL => Traversal is aborted. $node stays as-is
  • otherwise => $node is set to the return value
Parameters
$node : Node

Node

Return values
null|int|Node|array<string|int, Node>

Replacement node (or special return value)

leaveNode()

Called when leaving a node.

public leaveNode(Node $node) : null|int|Node|array<string|int, Node>

Return value semantics:

  • null => $node stays as-is
  • NodeVisitor::REMOVE_NODE => $node is removed from the parent array
  • NodeVisitor::REPLACE_WITH_NULL => $node is replaced with null
  • NodeVisitor::STOP_TRAVERSAL => Traversal is aborted. $node stays as-is
  • array (of Nodes) => The return value is merged into the parent array (at the position of the $node)
  • otherwise => $node is set to the return value
Parameters
$node : Node

Node

Return values
null|int|Node|array<string|int, Node>

Replacement node (or special return value)


        
On this page

Search results