PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / EndpointV2 / Rule / TreeRule.php
transferito / vendor / aws / aws-sdk-php / src / EndpointV2 / Rule Last commit date
AbstractRule.php 11 months ago EndpointRule.php 11 months ago ErrorRule.php 11 months ago RuleCreator.php 11 months ago TreeRule.php 11 months ago
TreeRule.php
62 lines
1 <?php
2
3 namespace Aws\EndpointV2\Rule;
4
5 use Aws\EndpointV2\Ruleset\RulesetStandardLibrary;
6
7 class TreeRule extends AbstractRule
8 {
9 /** @var array */
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 * @return array
20 */
21 public function getRules()
22 {
23 return $this->rules;
24 }
25
26 /**
27 * If a tree rule's conditions evaluate successfully, iterate over its
28 * subordinate rules and return a result if there is one. If any of the
29 * subsequent rules are trees, the function will recurse until it reaches
30 * an error or an endpoint rule
31 *
32 * @return mixed
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 }
62