Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. NodeFinder.php

function NodeFinder::findFirst

Find first node satisfying a filter callback.

Parameters

Node|Node[] $nodes Single node or array of nodes to search in:

callable $filter Filter callback: function(Node $node) : bool:

Return value

null|Node Found node (or null if none found)

1 call to NodeFinder::findFirst()
NodeFinder::findFirstInstanceOf in vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php
Find first node that is an instance of a certain class.

File

vendor/nikic/php-parser/lib/PhpParser/NodeFinder.php, line 58

Class

NodeFinder

Namespace

PhpParser

Code

public function findFirst($nodes, callable $filter) : ?Node {
    if ($nodes === []) {
        return null;
    }
    if (!is_array($nodes)) {
        $nodes = [
            $nodes,
        ];
    }
    $visitor = new FirstFindingVisitor($filter);
    $traverser = new NodeTraverser($visitor);
    $traverser->traverse($nodes);
    return $visitor->getFoundNode();
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal