annotate vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FirstFindingVisitor.php @ 13:5fb285c0d0e3

Update Drupal core to 8.4.7 via Composer. Security update; I *think* we've been lucky to get away with this so far, as we don't support self-registration which seems to be used by the so-called "drupalgeddon 2" attack that 8.4.5 was vulnerable to.
author Chris Cannam
date Mon, 23 Apr 2018 09:33:26 +0100
parents
children
rev   line source
Chris@13 1 <?php declare(strict_types=1);
Chris@13 2
Chris@13 3 namespace PhpParser\NodeVisitor;
Chris@13 4
Chris@13 5 use PhpParser\Node;
Chris@13 6 use PhpParser\NodeTraverser;
Chris@13 7 use PhpParser\NodeVisitorAbstract;
Chris@13 8
Chris@13 9 /**
Chris@13 10 * This visitor can be used to find the first node satisfying some criterion determined by
Chris@13 11 * a filter callback.
Chris@13 12 */
Chris@13 13 class FirstFindingVisitor extends NodeVisitorAbstract
Chris@13 14 {
Chris@13 15 /** @var callable Filter callback */
Chris@13 16 protected $filterCallback;
Chris@13 17 /** @var null|Node Found node */
Chris@13 18 protected $foundNode;
Chris@13 19
Chris@13 20 public function __construct(callable $filterCallback) {
Chris@13 21 $this->filterCallback = $filterCallback;
Chris@13 22 }
Chris@13 23
Chris@13 24 /**
Chris@13 25 * Get found node satisfying the filter callback.
Chris@13 26 *
Chris@13 27 * Returns null if no node satisfies the filter callback.
Chris@13 28 *
Chris@13 29 * @return null|Node Found node (or null if not found)
Chris@13 30 */
Chris@13 31 public function getFoundNode() {
Chris@13 32 return $this->foundNode;
Chris@13 33 }
Chris@13 34
Chris@13 35 public function beforeTraverse(array $nodes) {
Chris@13 36 $this->foundNode = null;
Chris@13 37
Chris@13 38 return null;
Chris@13 39 }
Chris@13 40
Chris@13 41 public function enterNode(Node $node) {
Chris@13 42 $filterCallback = $this->filterCallback;
Chris@13 43 if ($filterCallback($node)) {
Chris@13 44 $this->foundNode = $node;
Chris@13 45 return NodeTraverser::STOP_TRAVERSAL;
Chris@13 46 }
Chris@13 47
Chris@13 48 return null;
Chris@13 49 }
Chris@13 50 }