2017 © Pedro Peláez
 

library rvalidate

Recursive array validator

image

z7zmey/rvalidate

Recursive array validator

  • Friday, June 17, 2016
  • by z7zmey
  • Repository
  • 1 Watchers
  • 0 Stars
  • 5 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

RValidate

Library for the validation nested arrays with indicating the location and type of each pattern mismatch., (*1)

Installation

The best way to install RValidate is using Composer:, (*2)

$ composer require z7zmey/rvalidate

Examples:

Basic example

use RValidate\Validator;
use RValidate\Sub;
use RValidate\Validators as V;
use RValidate\Filters as F;

$data = [
    'login' => 'Nick',
    'email' => 'nick@example.com',
    'password' => '*****'
];

$pattern = [
    new V\IsArray(),
    new V\keys(['login', 'email', 'password', 'name']),
    new Sub('login', [new V\IsString(), new V\Min(5)]),
    new Sub('email', new V\Email()),
    new Sub('password', new V\Regex('/[A-Za-z[:punct:] ]{6,}/')),
];

try {
    $result = Validator::run($data, $pattern);
} catch (\RValidate\Exceptions\ValidateException $e) {
    foreach ($e->getErrorsIterator() as $error) {
        echo $error . PHP_EOL;
    }
}

output

[] -> must contain keys [login, email, password, name]
[][login] -> must be minimal 5
[][password] -> must match /[A-Za-z[:punct:] ]{6,}/

Nested example:

$data = [
    'id_user' => 1011,
    'roles' => [
        'admin' => false,
        'moderator' => true,
        'tester' => false
    ]
];

$pattern = [
    new V\IsArray(),
    new V\keys(['id_user', 'roles']),
    new Sub(new F\Key\Equal('id_user'), [new V\IsInteger()]),
    new Sub(new F\Key\Equal('roles'),   [
        new V\Keys(['admin', 'moderator', 'tester']),
        new Sub(new F\Key\Equal('admin'),     [new V\IsBoolean()]),
        new Sub(new F\Key\Equal('moderator'), [new V\IsBoolean()]),
        new Sub(new F\Key\Equal('tester'),    [new V\IsBoolean()]),
    ]),
];

Filter example:

$data = [
    'String1'  => 'some string',
    'String2'  => 'some string',
    'String3'  => '',
    'Number1'  => 1,
    'Number2'  => 2,
    'Number44' => 44,
    'Alnum1'   => 'alpha1'
];

$pattern = [
    new V\IsArray(),
    new Sub(new F\Key\Regex('/^String\d+$/'), [new V\IsString()]),
    new Sub(new F\Key\Regex('/^Number\d+$/'), [new V\IsInteger()]),
    new Sub(new F\Key\Regex('/^Alnum\d+$/'), [new V\Alnum(), new V\NotEmpty()]),
];

The Versions

17/06 2016

dev-master

9999999-dev https://github.com/z7zmey/RValidate

Recursive array validator

  Sources   Download

BSD

The Requires

  • php >=5.6

 

The Development Requires

by Vadim Slizov

schema validator validation array pattern validate recursive nested matcher complex rvalidate z7zmey

17/06 2016

0.0.5

0.0.5.0 https://github.com/z7zmey/RValidate

Recursive array validator

  Sources   Download

BSD

The Requires

  • php >=5.6

 

The Development Requires

by Vadim Slizov

schema validator validation array pattern validate recursive nested matcher complex rvalidate z7zmey

07/10 2015

0.0.4

0.0.4.0 https://github.com/z7zmey/RValidate

Recursive array validator

  Sources   Download

BSD

The Requires

  • php >=5.6

 

The Development Requires

by Vadim Slizov

schema validator validation array pattern validate recursive nested matcher complex rvalidate z7zmey