@@ 76-94 (lines=19) @@ | ||
73 | * @param Language $language |
|
74 | * @return bool |
|
75 | */ |
|
76 | public function isValid(Language $language) : bool |
|
77 | { |
|
78 | // empty the `errors` array |
|
79 | $this->emptyErrors(); |
|
80 | ||
81 | /** @var \PluginSimpleValidate\Contracts\Rule $rule */ |
|
82 | foreach ($this->rules as $ruleName => $rule) { |
|
83 | if (!$rule->isValid($language, $this->value)) { |
|
84 | $this->status = false; |
|
85 | $this->errors[] = $rule->getError(); |
|
86 | } |
|
87 | } |
|
88 | ||
89 | if (empty($this->errors)) { |
|
90 | $this->status = true; |
|
91 | } |
|
92 | ||
93 | return $this->status; |
|
94 | } |
|
95 | ||
96 | /** |
|
97 | * @return string |
@@ 56-80 (lines=25) @@ | ||
53 | * @param bool $break_when_error |
|
54 | * @return bool |
|
55 | */ |
|
56 | public function run($break_when_error = false) : bool |
|
57 | { |
|
58 | $this->emptyErrors(); |
|
59 | ||
60 | /** @var Field $field */ |
|
61 | foreach ($this->fields as $field) { |
|
62 | if (!$field->isValid($this->language)) { |
|
63 | $this->status = false; |
|
64 | $this->errors[$field->getName()] = $field->getErrors(); |
|
65 | ||
66 | /** |
|
67 | * break when there is any field error |
|
68 | */ |
|
69 | if ($break_when_error) { |
|
70 | break; |
|
71 | } |
|
72 | } |
|
73 | } |
|
74 | ||
75 | if (empty($this->errors)) { |
|
76 | $this->status = true; |
|
77 | } |
|
78 | ||
79 | return $this->status; |
|
80 | } |
|
81 | ||
82 | /** |
|
83 | * @return array |