class FindingVisitor
This visitor can be used to find and collect all nodes satisfying some criterion determined by a filter callback.
Hierarchy
- class \PhpParser\NodeVisitorAbstract implements \PhpParser\NodeVisitor
- class \PhpParser\NodeVisitor\FindingVisitor extends \PhpParser\NodeVisitorAbstract
Expanded class hierarchy of FindingVisitor
1 file declares its use of FindingVisitor
- NodeFinder.php in vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeFinder.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeVisitor/ FindingVisitor.php, line 12
Namespace
PhpParser\NodeVisitorView source
class FindingVisitor extends NodeVisitorAbstract {
/** @var callable Filter callback */
protected $filterCallback;
/** @var Node[] Found nodes */
protected array $foundNodes;
public function __construct(callable $filterCallback) {
$this->filterCallback = $filterCallback;
}
/**
* Get found nodes satisfying the filter callback.
*
* Nodes are returned in pre-order.
*
* @return Node[] Found nodes
*/
public function getFoundNodes() : array {
return $this->foundNodes;
}
public function beforeTraverse(array $nodes) : ?array {
$this->foundNodes = [];
return null;
}
public function enterNode(Node $node) {
$filterCallback = $this->filterCallback;
if ($filterCallback($node)) {
$this->foundNodes[] = $node;
}
return null;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
FindingVisitor::$filterCallback | protected | property | @var callable Filter callback | ||
FindingVisitor::$foundNodes | protected | property | @var Node[] Found nodes | ||
FindingVisitor::beforeTraverse | public | function | Called once before traversal. | Overrides NodeVisitorAbstract::beforeTraverse | |
FindingVisitor::enterNode | public | function | Called when entering a node. | Overrides NodeVisitorAbstract::enterNode | |
FindingVisitor::getFoundNodes | public | function | Get found nodes satisfying the filter callback. | ||
FindingVisitor::__construct | public | function | |||
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 |
NodeVisitorAbstract::leaveNode | public | function | Called when leaving a node. | Overrides NodeVisitor::leaveNode | 2 |