]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - vendor/justinrainbow/json-schema/src/JsonSchema/Uri/Retrievers/PredefinedArray.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / vendor / justinrainbow / json-schema / src / JsonSchema / Uri / Retrievers / PredefinedArray.php
1 <?php
2
3 namespace JsonSchema\Uri\Retrievers;
4
5 use JsonSchema\Validator;
6
7 /**
8  * URI retrieved based on a predefined array of schemas
9  *
10  * @example
11  *
12  *      $retriever = new PredefinedArray(array(
13  *          'http://acme.com/schemas/person#'  => '{ ... }',
14  *          'http://acme.com/schemas/address#' => '{ ... }',
15  *      ))
16  *
17  *      $schema = $retriever->retrieve('http://acme.com/schemas/person#');
18  */
19 class PredefinedArray extends AbstractRetriever
20 {
21     /**
22      * Contains schemas as URI => JSON
23      *
24      * @var array
25      */
26     private $schemas;
27
28     /**
29      * Constructor
30      *
31      * @param array  $schemas
32      * @param string $contentType
33      */
34     public function __construct(array $schemas, $contentType = Validator::SCHEMA_MEDIA_TYPE)
35     {
36         $this->schemas     = $schemas;
37         $this->contentType = $contentType;
38     }
39
40     /**
41      * {@inheritdoc}
42      *
43      * @see \JsonSchema\Uri\Retrievers\UriRetrieverInterface::retrieve()
44      */
45     public function retrieve($uri)
46     {
47         if (!array_key_exists($uri, $this->schemas)) {
48             throw new \JsonSchema\Exception\ResourceNotFoundException(sprintf(
49                 'The JSON schema "%s" was not found.',
50                 $uri
51             ));
52         }
53
54         return $this->schemas[$uri];
55     }
56 }