Commit f99dcab2 authored by Kevin Herrera's avatar Kevin Herrera

Supporting inline schema references.

parent 55764bf3
......@@ -3,6 +3,8 @@
namespace KHerGe\JSON;
use Exception;
use JsonSchema\Constraints\Factory;
use JsonSchema\SchemaStorage;
use JsonSchema\Validator;
use KHerGe\File\File;
use KHerGe\JSON\Exception\Decode\ControlCharacterException;
......@@ -37,13 +39,6 @@ class JSON implements JSONInterface
*/
private $linter;
/**
* The JSON validator.
*
* @var Validator
*/
private $validator;
/**
* {@inheritdoc}
*/
......@@ -229,19 +224,20 @@ class JSON implements JSONInterface
*/
public function validate($schema, $decoded)
{
if (null === $this->validator) {
$this->validator = new Validator();
}
$storage = new SchemaStorage();
$storage->addSchema('file://schema', $schema);
$validator = new Validator(new Factory($storage));
$this->validator->check($decoded, $schema);
$validator->check($decoded, $schema);
if ($this->validator->isValid()) {
if ($validator->isValid()) {
return null;
}
$errors = [];
foreach ($this->validator->getErrors() as $error) {
foreach ($validator->getErrors() as $error) {
$errors[] = sprintf(
'[%s] %s',
$error['property'],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment