1 | <?php |
||
7 | class IfElseControlNode extends Node |
||
8 | { |
||
9 | /** |
||
10 | * @var IfControlNode[] |
||
11 | */ |
||
12 | protected array $conditionalExpressions = []; |
||
|
|||
13 | protected ?Node $elseStatement; |
||
14 | |||
15 | /** |
||
16 | * @param IfControlNode[] $conditionalExpressions |
||
17 | */ |
||
18 | public function __construct(array $conditionalExpressions, Node $elseStatement = null) |
||
19 | { |
||
20 | $this->conditionalExpressions = $conditionalExpressions; |
||
21 | $this->elseStatement = $elseStatement; |
||
22 | } |
||
23 | |||
24 | public function evaluate() |
||
25 | { |
||
26 | foreach ($this->conditionalExpressions as $conditionalExpression) { |
||
27 | if ($conditionalExpression->evaluate()) { |
||
28 | return; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | if ($this->elseStatement) { |
||
33 | $this->elseStatement->evaluate(); |
||
34 | } |
||
35 | } |
||
36 | } |
||
37 |