Documentation

FindingVisitor extends NodeVisitorAbstract
in package

This visitor can be used to find and collect all nodes satisfying some criterion determined by a filter callback.

Table of Contents

$filterCallback  : callable
$foundNodes  : array<string|int, Node>
__construct()  : mixed
afterTraverse()  : null|array<string|int, Node>
Called once after traversal.
beforeTraverse()  : null|array<string|int, Node>
Called once before traversal.
enterNode()  : null|int|Node
Called when entering a node.
getFoundNodes()  : array<string|int, Node>
Get found nodes satisfying the filter callback.
leaveNode()  : null|int|Node|array<string|int, Node>
Called when leaving a node.

Properties

$filterCallback

protected callable $filterCallback

Filter callback

Methods

__construct()

public __construct(callable $filterCallback) : mixed
Parameters
$filterCallback : callable
Return values
mixed

afterTraverse()

Called once after traversal.

public afterTraverse(array<string|int, mixed> $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, mixed>

Array of nodes

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

Array of nodes

beforeTraverse()

Called once before traversal.

public beforeTraverse(array<string|int, mixed> $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, mixed>

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

Return value semantics:

  • null => $node stays as-is
  • NodeTraverser::DONT_TRAVERSE_CHILDREN => Children of $node are not traversed. $node stays as-is
  • NodeTraverser::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

Replacement node (or special return value)

getFoundNodes()

Get found nodes satisfying the filter callback.

public getFoundNodes() : array<string|int, Node>

Nodes are returned in pre-order.

Return values
array<string|int, Node>

Found nodes

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
  • NodeTraverser::REMOVE_NODE => $node is removed from the parent array
  • NodeTraverser::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)

Search results