graze / data-validator
Validate data, decoupled from your front end presentation.
Installs: 23 718
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 13
Forks: 0
Open Issues: 0
Requires
- php: ^5.5 || ^7.0
Requires (Dev)
- graze/hamcrest-test-listener: ^1.0.1
- mockery/mockery: ^0.9.4
- phpunit/phpunit: ^4.0 || ^5.1.1
- respect/validation: ^1.0
- symfony/validator: ^2.6.2
- zendframework/zend-validator: ^2.3
Suggests
- respect/validation: Use Respect validators through Graze\DataValidator\Adapter\RespectValidationAdapter
This package is auto-updated.
Last update: 2024-12-20 05:00:59 UTC
README
Validate data, decoupled from your front end presentation.
Installation
We recommend installing this library with Composer.
$ composer require graze/data-validator
Usage
use Graze\DataValidator\DataValidator; $validator = new DataValidator(); // Add a processor to roughly capitalize first names. $validator->addProcessor(function (array $data) { $data['first_name'] = ucfirst($data['first_name']); return $data; }); // Add a validator to check against a 'reserved' list. $validator->addValidator(function (array $data) { if (in_array($data['first_name'], ['Sam', 'John', 'Ray'])) { return 'reserved_name'; } }); /** @var array */ $processed = $validator->process(['first_name' => 'sam']); /** @var array */ $failures = $validator->validate($processed); var_dump($failures);
The above would output:
array(1) {
["reserved_name"]=>
bool(true)
}
License
The content of this library is released under the MIT License by Nature Delivered Ltd.
You can find a copy of this license at http://www.opensource.org/licenses/mit or in LICENSE
.