@@ 56-78 (lines=23) @@ | ||
53 | * @param bool $break_when_error |
|
54 | * @return bool |
|
55 | */ |
|
56 | public function run($break_when_error = false) : bool |
|
57 | { |
|
58 | /** @var Field $field */ |
|
59 | foreach ($this->fields as $field) { |
|
60 | if (!$field->isValid($this->language)) { |
|
61 | $this->status = false; |
|
62 | $this->errors[$field->getName()] = $field->getErrors(); |
|
63 | ||
64 | /** |
|
65 | * break when there is any field error |
|
66 | */ |
|
67 | if ($break_when_error) { |
|
68 | break; |
|
69 | } |
|
70 | } |
|
71 | } |
|
72 | ||
73 | if (empty($this->errors)) { |
|
74 | $this->status = true; |
|
75 | } |
|
76 | ||
77 | return $this->status; |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * @return array |
@@ 63-78 (lines=16) @@ | ||
60 | * @param Language $language |
|
61 | * @return bool |
|
62 | */ |
|
63 | public function isValid(Language $language) : bool |
|
64 | { |
|
65 | /** @var \PluginSimpleValidate\Contracts\Rule $rule */ |
|
66 | foreach ($this->rules as $ruleName => $rule) { |
|
67 | if (!$rule->isValid($language, $this->value)) { |
|
68 | $this->status = false; |
|
69 | $this->errors[] = $rule->getError(); |
|
70 | } |
|
71 | } |
|
72 | ||
73 | if (empty($this->errors)) { |
|
74 | $this->status = true; |
|
75 | } |
|
76 | ||
77 | return $this->status; |
|
78 | } |
|
79 | ||
80 | /** |
|
81 | * @return string |