You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Unify validator API and refine error reporting
This commit introduces several improvements to the validator library:
- **Unified API for FieldValidator**: The now includes a method, aligning its API with . The method now calls and throws an exception on failure, ensuring consistent behavior across all validators.
- **Refined Error Reporting**: Removed redundant field names from error messages. Error messages are now generic (e.g., "Value is required."), with the field context provided by the error object's key. This results in a cleaner, more structured, and easier-to-parse error output.
These changes enhance the library's consistency, predictability, and overall developer experience.
if ($this->oneOf && !in_array($value, $this->oneOf, true)) {
87
-
thrownewValidationException([$key ? "Field '$key' must be one of: " . json_encode($this->oneOf) : 'Value must be one of: ' . json_encode($this->oneOf)]);
107
+
return [false, $value, ['Value must be one of: ' . json_encode($this->oneOf)]];
0 commit comments