Skip to content

🚔 Validate data, decoupled from your front end presentation.

License

Notifications You must be signed in to change notification settings

graze/data-validator

Repository files navigation

graze/data-validator Build Status Latest Version MIT Licensed

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.

About

🚔 Validate data, decoupled from your front end presentation.

Resources

License

Stars

Watchers

Forks

Packages

No packages published