Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
}