Skip to content

Commit

Permalink
Merge pull request #25 from thewilkybarkid/cache-resolver
Browse files Browse the repository at this point in the history
Use same RefResolver
  • Loading branch information
webmozart authored Aug 15, 2016
2 parents c0696e3 + 16d05c9 commit 22e45e6
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions src/JsonValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use JsonSchema\Exception\InvalidArgumentException;
use JsonSchema\Exception\ResourceNotFoundException;
use JsonSchema\RefResolver;
use JsonSchema\Uri\Retrievers\UriRetrieverInterface;
use JsonSchema\Uri\UriResolver;
use JsonSchema\Uri\UriRetriever;
use JsonSchema\UriResolverInterface;
Expand Down Expand Up @@ -49,18 +48,11 @@ class JsonValidator
private $validator;

/**
* URI retriever for fetching JSON schemas.
* Reference resolver.
*
* @var UriRetrieverInterface
* @var RefResolver
*/
private $uriRetriever;

/**
* URI resolver for JSON schemas.
*
* @var UriResolverInterface
*/
private $uriResolver;
private $resolver;

/**
* JsonValidator constructor.
Expand All @@ -74,8 +66,7 @@ class JsonValidator
public function __construct(Validator $validator = null, UriRetriever $uriRetriever = null, UriResolverInterface $uriResolver = null)
{
$this->validator = $validator ?: new Validator();
$this->uriRetriever = $uriRetriever ?: new UriRetriever();
$this->uriResolver = $uriResolver ?: new UriResolver();
$this->resolver = new RefResolver($uriRetriever ?: new UriRetriever(), $uriResolver ?: new UriResolver());
}

/**
Expand Down Expand Up @@ -170,10 +161,8 @@ private function loadSchema($file)
}

// Resolve references to other schemas
$resolver = new RefResolver($this->uriRetriever, $this->uriResolver);

try {
$schema = $resolver->resolve($file);
$schema = $this->resolver->resolve($file);
} catch (ResourceNotFoundException $e) {
throw new InvalidSchemaException(sprintf(
'The schema %s does not exist.',
Expand Down

0 comments on commit 22e45e6

Please sign in to comment.