PHP code example of phpnomad / opis-json-schema-integration
1. Go to this page and download the library: Download phpnomad/opis-json-schema-integration 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/ */
phpnomad / opis-json-schema-integration example snippets
use PHPNomad\JsonSchema\Exceptions\ValidationError;
use PHPNomad\OpisJsonSchema\Integration\Strategies\OpisJsonSchemaValidator;
$validator = new OpisJsonSchemaValidator();
try {
$validator->validate(
['name' => 'Alice', 'age' => 30],
'/path/to/person.schema.json',
);
} catch (ValidationError $e) {
foreach ($e->failures as $failure) {
printf(
"%s: %s [%s]\n",
$failure->path,
$failure->message,
$failure->keyword,
);
}
}
use Opis\JsonSchema\Validator as OpisValidator;
use PHPNomad\OpisJsonSchema\Integration\Strategies\OpisJsonSchemaValidator;
final class MySiteJsonSchemaValidator extends OpisJsonSchemaValidator
{
protected function buildValidator(): OpisValidator
{
$validator = parent::buildValidator();
$validator->resolver()->registerPrefix('https://my-site.example/', '/path/to/schemas');
return $validator;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.