3 namespace JsonSchema\Uri\Retrievers;
5 use JsonSchema\Validator;
8 * URI retrieved based on a predefined array of schemas
12 * $retriever = new PredefinedArray(array(
13 * 'http://acme.com/schemas/person#' => '{ ... }',
14 * 'http://acme.com/schemas/address#' => '{ ... }',
17 * $schema = $retriever->retrieve('http://acme.com/schemas/person#');
19 class PredefinedArray extends AbstractRetriever
22 * Contains schemas as URI => JSON
31 * @param array $schemas
32 * @param string $contentType
34 public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE)
36 $this->schemas = $schemas;
37 $this->contentType = $contentType;
43 * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
45 public function retrieve($uri)
47 if (!array_key_exists($uri, $this->schemas)) {
48 throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf(
49 'The JSON schema "%s" was not found.',
54 return $this->schemas[$uri];