1<?php 2 3declare(strict_types=1); 4 5/* 6 * This file is part of the league/commonmark package. 7 * 8 * (c) Colin O'Dell <colinodell@gmail.com> 9 * 10 * For the full copyright and license information, please view the LICENSE 11 * file that was distributed with this source code. 12 */ 13 14namespace League\CommonMark\Node\Query; 15 16use League\CommonMark\Node\Node; 17 18/** 19 * @internal 20 */ 21final class OrExpr implements ExpressionInterface 22{ 23 /** 24 * @var callable[] 25 * @psalm-var list<callable(Node): bool> 26 */ 27 private array $conditions; 28 29 /** 30 * @psalm-param callable(Node): bool $expressions 31 */ 32 public function __construct(callable ...$expressions) 33 { 34 $this->conditions = \array_values($expressions); 35 } 36 37 /** 38 * @param callable(Node): bool $expression 39 */ 40 public function add(callable $expression): void 41 { 42 $this->conditions[] = $expression; 43 } 44 45 public function __invoke(Node $node): bool 46 { 47 foreach ($this->conditions as $condition) { 48 if ($condition($node)) { 49 return true; 50 } 51 } 52 53 return false; 54 } 55} 56