@@ 14-32 (lines=19) @@ | ||
11 | * @param Language $language |
|
12 | * @return bool |
|
13 | */ |
|
14 | public function isValid(Language $language) : bool |
|
15 | { |
|
16 | // empty the `errors` array |
|
17 | $this->emptyErrors(); |
|
18 | ||
19 | /** @var \PluginSimpleValidate\Contracts\Rule $rule */ |
|
20 | foreach ($this->rules as $ruleName => $rule) { |
|
21 | if (!$rule->isValid($language, $this->value)) { |
|
22 | $this->status = false; |
|
23 | $this->errors[] = $rule->getError(); |
|
24 | } |
|
25 | } |
|
26 | ||
27 | if (empty($this->errors)) { |
|
28 | $this->status = true; |
|
29 | } |
|
30 | ||
31 | return $this->status; |
|
32 | } |
|
33 | ||
34 | /** |
|
35 | * @param string $rulesMethod |
@@ 22-40 (lines=19) @@ | ||
19 | * @param Language $language |
|
20 | * @return bool |
|
21 | */ |
|
22 | public function isValid(Language $language) : bool |
|
23 | { |
|
24 | // empty the `errors` array |
|
25 | $this->emptyErrors(); |
|
26 | ||
27 | /** @var RuleWithValue $rule */ |
|
28 | foreach ($this->rules as $ruleName => $rule) { |
|
29 | if (!$rule->isValid($language, $rule->getValue())) { |
|
30 | $this->status = false; |
|
31 | $this->errors[] = $rule->getError(); |
|
32 | } |
|
33 | } |
|
34 | ||
35 | if (empty($this->errors)) { |
|
36 | $this->status = true; |
|
37 | } |
|
38 | ||
39 | return $this->status; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @param string $rulesMethod |
@@ 57-81 (lines=25) @@ | ||
54 | * @param bool $break_when_error |
|
55 | * @return bool |
|
56 | */ |
|
57 | public function run($break_when_error = false) : bool |
|
58 | { |
|
59 | $this->emptyErrors(); |
|
60 | ||
61 | /** @var Field $field */ |
|
62 | foreach ($this->fields as $field) { |
|
63 | if (!$field->isValid($this->language)) { |
|
64 | $this->status = false; |
|
65 | $this->errors[$field->getName()] = $field->getErrors(); |
|
66 | ||
67 | /** |
|
68 | * break when there is any field error |
|
69 | */ |
|
70 | if ($break_when_error) { |
|
71 | break; |
|
72 | } |
|
73 | } |
|
74 | } |
|
75 | ||
76 | if (empty($this->errors)) { |
|
77 | $this->status = true; |
|
78 | } |
|
79 | ||
80 | return $this->status; |
|
81 | } |
|
82 | ||
83 | /** |
|
84 | * @return array |