PHP code example of danielz / shape-validator-php

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

    

danielz / shape-validator-php example snippets


try {
    $shape = [
        'name' => '        'notes' => 'string',
        'data' => 'any',
    ];
    $shape_validator = new ShapeValidator($shape);
    $shape_validator->validate([
        'name' => 'Hello, world!', // valid
        'extra' => null, // this will trigger an error    
    ]);
} catch(ShapeException $exception) {
    // getValidationErrors() returns an array like ['field name' => 'error message']
    log($exception->getValidationErrors());
}