1. Go to this page and download the library: Download chubbyphp/chubbyphp-parsing 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/ */
use Chubbyphp\Parsing\Parser;
$p = new Parser();
$schema = $p->literal('email'); // supports string|float|int|bool
$data = $schema->parse('email');
use Chubbyphp\Parsing\Parser;
$p = new Parser();
$schema = $p->object(['name' => $p->string()]);
// stdClass object
$data = $schema->parse(['name' => 'example']);
// SampleClass object
$data = $schema->parse(['name' => 'example'], SampleNamespace\SampleClass::class);
// if the key 'name' does not exist on input, it won't exists on the output
$schema->optional(['name']);
// validations
$schema->strict();
$schema->strict(['_id']); // strip _id if given, but complain about any other additional field
// transformations
// conversions
use Chubbyphp\Parsing\Parser;
$p = new Parser();
$schema = $p->record($p->string());
$data = $schema->parse([
'key1' => 'value1',
'key2' => 'value2'
]);
use Chubbyphp\Parsing\Parser;
use Respect\Validation\Validator as v;
$p = new Parser();
$schema = $p->respectValidation(v::numericVal()->positive()->between(1, 255));
$data = $schema->parse(5);