1 | <?php namespace Limoncello\Validation\Expressions; |
||
26 | abstract class IterateRules extends BaseExpression |
||
27 | { |
||
28 | /** |
||
29 | * @var RuleInterface[] |
||
30 | */ |
||
31 | private $rules; |
||
32 | |||
33 | /** |
||
34 | * @var null|bool |
||
35 | */ |
||
36 | private $isStateless = null; |
||
37 | |||
38 | /** |
||
39 | * @param array $rules |
||
40 | */ |
||
41 | 12 | public function __construct(array $rules) |
|
45 | |||
46 | /** |
||
47 | * @inheritdoc |
||
48 | */ |
||
49 | 2 | public function isStateless() |
|
50 | { |
||
51 | 2 | if ($this->isStateless !== null) { |
|
52 | 1 | return $this->isStateless; |
|
53 | } |
||
54 | |||
55 | 2 | foreach ($this->getRules() as $rule) { |
|
56 | 2 | if ($rule->isStateless() === false) { |
|
57 | 2 | return $this->isStateless = false; |
|
58 | } |
||
59 | } |
||
60 | |||
61 | 1 | return $this->isStateless = true; |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | 12 | public function onFinish(ErrorAggregatorInterface $aggregator) |
|
75 | |||
76 | /** |
||
77 | * @return RuleInterface[] |
||
78 | */ |
||
79 | 12 | protected function getRules() |
|
83 | } |
||
84 |