PHP code example of cmpayments / schemavalidator
1. Go to this page and download the library: Download cmpayments/schemavalidator 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/ */
cmpayments / schemavalidator example snippets
try {
$data = ["length" => 7.0, "superfluousProperty" => 12.0];
$schema = '{"type": "array","items": {"type": "number"}}';
$validator = new SchemaValidator((($data)), json_decode($schema));
var_dump('Example 5:', $validator->isValid()); // true
//var_dump($validator->getErrors());
} catch (\Exception $e) {
var_dump('Example 5', $e->getMessage());
}
try {
$data = true;
$schema = '{"type": "boolean"}';
$validator = new SchemaValidator((($data)), json_decode($schema));
var_dump('Example 6:', $validator->isValid()); // true
// var_dump($validator->getErrors());
} catch (\Exception $e) {
var_dump('Example 6:', $e->getMessage());
}
try {
$data = 22;
$schema = '{"type": "number"}';
$validator = new SchemaValidator((($data)), json_decode($schema));
var_dump('Example 8:', $validator->isValid()); // true
//var_dump($validator->getErrors());
} catch (\Exception $e) {
var_dump('Example 8:', $e->getMessage());
}