1 | <?php |
||
29 | class Result |
||
30 | { |
||
31 | /** |
||
32 | * @var bool Whether the validation passed |
||
33 | */ |
||
34 | private $passed; |
||
35 | /** |
||
36 | * @var array The result errors |
||
37 | */ |
||
38 | private $errors; |
||
39 | |||
40 | /** |
||
41 | * Creates a new validation result. |
||
42 | * |
||
43 | * @param array $errors Associative array of field name to error |
||
44 | */ |
||
45 | 1 | public function __construct(array $errors) |
|
50 | |||
51 | /** |
||
52 | * Whether the validation passed. |
||
53 | * |
||
54 | * @return bool |
||
55 | */ |
||
56 | 1 | public function hasErrors(): bool |
|
60 | |||
61 | /** |
||
62 | * Gets all errors. |
||
63 | * |
||
64 | * ``` |
||
65 | * [ |
||
66 | * 'name' => 'REQUIRED', |
||
67 | * 'phone' => 'CANNOT_BE_EMPTY' |
||
68 | * ] |
||
69 | * ``` |
||
70 | * |
||
71 | * @return array Associative array of field name to error |
||
72 | */ |
||
73 | 1 | public function getErrors(): array |
|
77 | |||
78 | /** |
||
79 | * Gets the errors as a JSON string. |
||
80 | * |
||
81 | * @return string The errors as a JSON string |
||
82 | */ |
||
83 | 1 | public function __toString(): string |
|
87 | } |
||
88 |