quartet / contextual-validator
Installs: 18 364
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 9
Forks: 0
Open Issues: 1
Requires
- php: >=5.5.0
- phpmentors/domain-kata: 1.4.*
- symfony/property-access: ^2.5
Requires (Dev)
- phpunit/phpunit: ~4.6
README
Installation
$ php composer.phar require quartet/contextual-validator
Usage
Single Entity/Row validation
$builder = new ValidatorBuilder(); $builder ->defaultContext() ->target('name') ->rule(new NotBlank()) ->target('email') ->rule(new NotBlank()) ->context('create') ->target('name') ->rule(new NotBlank()) ->target('email') ->rule(new NotBlank()) ->context('edit') ->target('name') ->rule(new NotBlank()) ->target('email') ->rule(new NotBlank()) ; $validator = $builder->getValidator(); $entity = ... $result = $validator->validate($entity); if ($result->hasError()) { echo 'validation failed'; }
Multiple Entities/Rows validation
$builder = new ValidatorBuilder(); $builder... ; $validator = $builder->getValidator(); $entity = ... $runner = new ValidationRunner(); $runner->addRowValidator($validator); $result = $runner->run(); if ($result->hasError()) { foreach ($result as $error) { echo $error->getPosition() . $error->getMessage() . PHP_EOL; } }
Support
If you find a bug or have a question, or want to request a feature, create an issue or pull request for it on Issues.
Copyright
Copyright (c) 2015 GOTO Hidenori, All rights reserved.