annotate vendor/nikic/php-parser/lib/PhpParser/NodeVisitor/FindingVisitor.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\NodeVisitorAbstract;
Chris@13 7
Chris@13 8 /**
Chris@13 9 * This visitor can be used to find and collect all nodes satisfying some criterion determined by
Chris@13 10 * a filter callback.
Chris@13 11 */
Chris@13 12 class FindingVisitor extends NodeVisitorAbstract
Chris@13 13 {
Chris@13 14 /** @var callable Filter callback */
Chris@13 15 protected $filterCallback;
Chris@13 16 /** @var Node[] Found nodes */
Chris@13 17 protected $foundNodes;
Chris@13 18
Chris@13 19 public function __construct(callable $filterCallback) {
Chris@13 20 $this->filterCallback = $filterCallback;
Chris@13 21 }
Chris@13 22
Chris@13 23 /**
Chris@13 24 * Get found nodes satisfying the filter callback.
Chris@13 25 *
Chris@13 26 * Nodes are returned in pre-order.
Chris@13 27 *
Chris@13 28 * @return Node[] Found nodes
Chris@13 29 */
Chris@13 30 public function getFoundNodes() : array {
Chris@13 31 return $this->foundNodes;
Chris@13 32 }
Chris@13 33
Chris@13 34 public function beforeTraverse(array $nodes) {
Chris@13 35 $this->foundNodes = [];
Chris@13 36
Chris@13 37 return null;
Chris@13 38 }
Chris@13 39
Chris@13 40 public function enterNode(Node $node) {
Chris@13 41 $filterCallback = $this->filterCallback;
Chris@13 42 if ($filterCallback($node)) {
Chris@13 43 $this->foundNodes[] = $node;
Chris@13 44 }
Chris@13 45
Chris@13 46 return null;
Chris@13 47 }
Chris@13 48 }