quartet/contextual-validator

This package is abandoned and no longer maintained. No replacement package was suggested.

v1.1.8 2015-06-23 06:59 UTC

This package is not auto-updated.

Last update: 2023-02-09 18:52:58 UTC


README

Build Status SensioLabsInsight Total Downloads Latest Stable Version Latest Unstable Version

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.

License

The BSD 2-Clause License