ValidationResult
final class ValidationResult (View source)
Simple validation result class following the Result pattern
Methods
Create a successful validation result
Create a failed validation result
Create a failed validation result with multiple errors
Prepend earlier errors to a failed sub-result. The sub-result's field survives only while its error is still the first one, since the form highlights one input.
Name the record part the errors are about; a copy so shared results stay untouched
The record part the errors are about, when the validator named one
Check if validation succeeded
Get all validation error messages
Get first error message or empty string if no errors
Get data from successful validation
Check if the validation result has warnings
Get warnings from the validation result
Get first warning message or empty string if no warnings
Add a warning to the validation result
Add multiple warnings to the validation result
Details
static ValidationResult
success(mixed $data, array $warnings = [])
Create a successful validation result
static ValidationResult
failure(string|array $errors, array $warnings = [])
Create a failed validation result
static ValidationResult
errors(array $errors, array $warnings = [])
Create a failed validation result with multiple errors
static ValidationResult
mergeErrors(array $earlier, ValidationResult $failed)
Prepend earlier errors to a failed sub-result. The sub-result's field survives only while its error is still the first one, since the form highlights one input.
ValidationResult
withField(RecordField $field)
Name the record part the errors are about; a copy so shared results stay untouched
RecordField|null
getField()
The record part the errors are about, when the validator named one
bool
isValid()
Check if validation succeeded
array
getErrors()
Get all validation error messages
string
getFirstError()
Get first error message or empty string if no errors
getData()
Get data from successful validation
bool
hasWarnings()
Check if the validation result has warnings
array
getWarnings()
Get warnings from the validation result
string
getFirstWarning()
Get first warning message or empty string if no warnings
ValidationResult
addWarning(string $warning)
Add a warning to the validation result
ValidationResult
addWarnings(array $warnings)
Add multiple warnings to the validation result