PHP code example of graze / config-validation

1. Go to this page and download the library: Download graze/config-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

graze / config-validation example snippets


use Respect\Validation\Validator as v;

$validator = (new ArrayValidator())
    ->:stringType()->date());

$validator = Validator::arr()
    ->:arr()
        ->optional('child', v::intVal(), 1)
        ->optional('second', v::stringType()->date()
    );
   
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' => 

$childValidator = Validate::object()
    ->e(), 'name');
$validator = Validate::object()
    ->or->validate($input);
}

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