PHP code example of hunomina / data-validator

1. Go to this page and download the library: Download hunomina/data-validator 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/ */

    

hunomina / data-validator example snippets


use hunomina\Validator\Json\Schema\Json\JsonSchema;

$schema = new JsonSchema([
    'success' => ['type' => 'bool'],
    'error' => ['type' => 'string', 'null' => true],
    'user' => ['type' => 'object', 'null' => true, 'optional' => true, 'schema' => [
        'name' => ['type' => 'string'],
        'age' => ['type' => 'int']
    ]]
]);

use hunomina\Validator\Json\Data\Json\JsonData;

$data = new JsonData([
    'success' => true,
    'error' => null,
    'user' => [
        'name' => 'test',
        'age' => 10
    ]
]);

use hunomina\Validator\Json\Data\Json\JsonData;

$data = new JsonData([
    'success' => true,
    'error' => null,
    'user' => 'test'
]);

use hunomina\Validator\Json\Schema\Json\JsonSchema;

$schema = new JsonSchema([
    'name' => ['type' => 'string', 'pattern' => '/^[a-z]+$/'],
    'geolocation' => ['type' => 'integer-list', 'length' => 2]
]);