2017 © Pedro Peláez
 

library config-validation

validate and populate arrays and objects

image

graze/config-validation

validate and populate arrays and objects

  • Thursday, December 14, 2017
  • by graze
  • Repository
  • 9 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

config-validation

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads, (*1)

Config Validation checks an input against a code defined schema for validation using short notation syntax., (*2)

It then populates optional fields with default data., (*3)

Install

Via Composer, (*4)

composer require graze/config-validation

Usage

Long path definition

use Respect\Validation\Validator as v;

$validator = (new ArrayValidator())
    ->required('key', v::stringType())
    ->optional('parent.child', v::intVal(), 1)
    ->optional('parent.second', v::stringType()->date());

Using children

$validator = Validator::arr()
    ->required('key', v::stringType())
    ->addChild('parent', Validator::arr()
        ->optional('child', v::intVal(), 1)
        ->optional('second', v::stringType()->date()
    );

Validating with your validator

function thing (array $input) {
    return $validator->validate($input);
}

thing(['key' => 'value'])
// ['key' => 'value', 'parent' => ['child' => 1, 'second' => null]]
thing();
// throws new ConfigValidationFailed
thing(['key' => 'input', ['parent' => ['child' => 2]])
// ['key' => 'input', ['parent' => ['child' => 2, 'second' => null]]
thing(['key' => 'input', ['parent' => ['second' => '111']])
// throws new ConfigValidationFailed('expected data for parent.second')
thing(['key' => 'input', ['parent' => ['second' => 

Validating array items with variable keys

$childValidator = Validate::object()
    ->required('key->item', v::intVal()->min(2)->max(4))
    ->optional('key->second', v::stringType(), 'name');
$validator = Validate::object()
    ->required('items', v::arrayVal()->each(
        $childValidator->getValidator()
    ));

function thing ($input) {
    return $validator->validate($input);
}

thing((object) ['items' => [
    (object) ['key' => 3],
    ]]);
// (object) ['items' => [
//     (object) ['key' => (object) ['item' => 3, 'second' => 'name']]
// ]]

Testing

make build test

Contributing

Please see CONTRIBUTING for details., (*5)

Security

If you discover any security related issues, please email security@graze.com instead of using the issue tracker., (*6)

Credits

License

The MIT License (MIT). Please see License File for more information., (*7)

The Versions

14/12 2017

dev-container-update

dev-container-update https://github.com/graze/config-validation

validate and populate arrays and objects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harry Bragg

graze config-validation

23/11 2017

dev-master

9999999-dev https://github.com/graze/config-validation

validate and populate arrays and objects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harry Bragg

graze config-validation

02/10 2017

dev-fix-lowest

dev-fix-lowest https://github.com/graze/config-validation

validate and populate arrays and objects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harry Bragg

graze config-validation

02/10 2017

0.1.1

0.1.1.0 https://github.com/graze/config-validation

validate and populate arrays and objects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harry Bragg

graze config-validation

02/10 2017

0.1

0.1.0.0 https://github.com/graze/config-validation

validate and populate arrays and objects

  Sources   Download

MIT

The Requires

 

The Development Requires

by Harry Bragg

graze config-validation