codin / validation
Input validator
dev-master
2020-11-19 19:31 UTC
Requires
- php: >=7.3
- ext-mbstring: *
- codin/dot: @stable
- egulias/email-validator: @stable
Requires (Dev)
- friendsofphp/php-cs-fixer: @stable
- phpspec/phpspec: @stable
- phpstan/phpstan: @stable
This package is not auto-updated.
Last update: 2024-11-16 13:44:04 UTC
README
Symfony like array validation
$validator = new Validation\ArrayValidator();
$validator->addConstraint('first_name', new Validation\Assert\Length(['min' => 3]));
$validator->addConstraint('last_name', new Validation\Assert\Present());
$violations = $validator->validate(['first_name' => 'me']);
echo $violations->count(); // 1
echo count($violations); // 1
print_r($violations->getMessages());
Array
(
[first_name] => Array
(
[0] => first name must be greater than or equal to 3 characters
)
[last_name] => Array
(
[0] => last name must be present
)
)