Particle\Validator is a very small validation library, with the easiest and most usable API we could possibly create.
$v = new Validator;
$v->required('first_name')->length(5);
$result = $v->validate(['first_name' => 'Berry']);
$result->isValid(); // bool(true).
$result->getMessages(); // array(0)
$result = $v->validate(['first_name' => 'Rick']);
$result->isValid(); // bool(false).
$result->getMessages();
/**
* array(1) {
* ["first_name"]=> array(1) {
* ["Length::TOO_SHORT"]=> string(53) "first_name is too short and must be 5 characters long"
* }
* }
*/
- Validate an array of data and get an array of error messages
- Override the error messages
- Get the validated data array
- Validate different contexts (insert, update, ect)
- IDE auto-completion for easy development
===
Find more information and advanced usage examples at validator.particle-php.com