| 1 |
<?php |
| 2 |
|
| 3 |
namespace Aws\EndpointV2\Rule; |
| 4 |
|
| 5 |
use Aws\EndpointV2\Ruleset\RulesetStandardLibrary; |
| 6 |
|
| 7 |
class TreeRule extends AbstractRule |
| 8 |
{ |
| 9 |
|
| 10 |
private $rules; |
| 11 |
|
| 12 |
public function __construct(array $definition) |
| 13 |
{ |
| 14 |
parent::__construct($definition); |
| 15 |
$this->rules = $this->createRules($definition['rules']); |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
public function getRules() |
| 22 |
{ |
| 23 |
return $this->rules; |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
public function evaluate( |
| 35 |
array $inputParameters, |
| 36 |
RulesetStandardLibrary $standardLibrary |
| 37 |
) |
| 38 |
{ |
| 39 |
if ($this->evaluateConditions($inputParameters, $standardLibrary)) { |
| 40 |
foreach($this->rules as $rule) { |
| 41 |
$inputParametersCopy = $inputParameters; |
| 42 |
$evaluation = $rule->evaluate($inputParametersCopy, $standardLibrary); |
| 43 |
if ($evaluation !== false) { |
| 44 |
return $evaluation; |
| 45 |
} |
| 46 |
} |
| 47 |
} |
| 48 |
return false; |
| 49 |
} |
| 50 |
|
| 51 |
private function createRules(array $rules) |
| 52 |
{ |
| 53 |
$rulesList = []; |
| 54 |
|
| 55 |
forEach($rules as $rule) { |
| 56 |
$ruleType = RuleCreator::create($rule['type'], $rule); |
| 57 |
$rulesList[] = $ruleType; |
| 58 |
} |
| 59 |
return $rulesList; |
| 60 |
} |
| 61 |
} |