PHP code example of phindmarsh / statham

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

    

phindmarsh / statham example snippets



// schemas used during validation
$schemas = [
  "http://json-schema.org/draft-04/schema#"
  "http://swagger.io/v2/schema.json#"
];

$statham = new \Statham\Statham();

// download each schema and add to internal cache
foreach($schemas as $schema_url){
    $schema = json_decode(file_get_contents($schema_url));
    $statham->setRemoteReference($schema_url, $schema);
}

// just validate the schema (no data)
$statham->validateSchema($schemas[1]);

// validate $json_to_validate against a given schema
$statham->validate($json_to_validate, $schemas[1]);