Validator
in package
Class Validator
This class is responsible for handling validation logic within the application. It provides methods to validate data against specific rules and constraints.
Table of Contents
Properties
- $data : array<string|int, mixed>
Methods
- __construct() : mixed
- validate() : array<string, mixed>
- Validates the provided data against the given validation rules and returns the validated data.
Properties
$data
protected
array<string|int, mixed>
$data
Methods
__construct()
public
__construct(array<string|int, mixed> $data) : mixed
Parameters
- $data : array<string|int, mixed>
validate()
Validates the provided data against the given validation rules and returns the validated data.
public
validate(array<string, array<string|int, ValidationRule>> $validationRules[, array<string|int, mixed> $messages = [] ]) : array<string, mixed>
Parameters
- $validationRules : array<string, array<string|int, ValidationRule>>
-
An associative array where the keys are field names and the values are either a single validation rule or an array of validation rules.
- $messages : array<string|int, mixed> = []
-
An optional associative array of custom error messages. The keys should be field names, and the values should be arrays where the keys are validation rule class names and the values are the corresponding error messages.
Return values
array<string, mixed> —An array containing the validated data. Fields that pass validation will be included.