class FirstFindingVisitor
This visitor can be used to find the first node satisfying some criterion determined by a filter callback.
Hierarchy
- class \PhpParser\NodeVisitorAbstract implements \PhpParser\NodeVisitor
- class \PhpParser\NodeVisitor\FirstFindingVisitor extends \PhpParser\NodeVisitorAbstract
Expanded class hierarchy of FirstFindingVisitor
1 file declares its use of FirstFindingVisitor
- NodeFinder.php in vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeFinder.php
File
-
vendor/
nikic/ php-parser/ lib/ PhpParser/ NodeVisitor/ FirstFindingVisitor.php, line 13
Namespace
PhpParser\NodeVisitorView source
class FirstFindingVisitor extends NodeVisitorAbstract {
/** @var callable Filter callback */
protected $filterCallback;
/** @var null|Node Found node */
protected ?Node $foundNode;
public function __construct(callable $filterCallback) {
$this->filterCallback = $filterCallback;
}
/**
* Get found node satisfying the filter callback.
*
* Returns null if no node satisfies the filter callback.
*
* @return null|Node Found node (or null if not found)
*/
public function getFoundNode() : ?Node {
return $this->foundNode;
}
public function beforeTraverse(array $nodes) : ?array {
$this->foundNode = null;
return null;
}
public function enterNode(Node $node) {
$filterCallback = $this->filterCallback;
if ($filterCallback($node)) {
$this->foundNode = $node;
return NodeVisitor::STOP_TRAVERSAL;
}
return null;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
FirstFindingVisitor::$filterCallback | protected | property | @var callable Filter callback | ||
FirstFindingVisitor::$foundNode | protected | property | @var null|Node Found node | ||
FirstFindingVisitor::beforeTraverse | public | function | Called once before traversal. | Overrides NodeVisitorAbstract::beforeTraverse | |
FirstFindingVisitor::enterNode | public | function | Called when entering a node. | Overrides NodeVisitorAbstract::enterNode | |
FirstFindingVisitor::getFoundNode | public | function | Get found node satisfying the filter callback. | ||
FirstFindingVisitor::__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 |