Exemple #1
0
 public function retrieve($uri, $baseUri = null)
 {
     $resolver = new UriResolver();
     $resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri);
     $arParts = $resolver->parse($resolvedUri);
     if (isset($arParts['fragment'])) {
         unset($arParts['fragment']);
         $fetchUri = $resolver->generate($arParts);
     }
     $jsonSchema = $this->loadSchema($fetchUri);
     $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
     $jsonSchema->id = $resolvedUri;
     return $jsonSchema;
 }
 function testResolveWithValidFileBaseUri()
 {
     $resolver = new UriResolver();
     $this->assertEquals('file:///base/uri/foo.json', $resolver->resolve('foo.json', 'file:///base/uri/dir.json'));
     $this->assertEquals('file:///other-dir/foo.json', $resolver->resolve('file:///other-dir/foo.json', 'file:///base/uri/dir.json'));
 }
Exemple #3
0
 /**
  * Enters a new resolution scope for the given schema.  Inspects the
  * partial for the presence of 'id' and then returns that as a absolute
  * uri.  Returns the new scope.
  *
  * @param  object $schemaPartial JSON Schema to get the resolution scope for
  * @param  string $sourceUri     URI where this schema was located
  * @return string
  */
 private function enterResolutionScope($schemaPartial, $sourceUri)
 {
     if (count($this->scopes) === 0) {
         $this->scopes[] = self::SELF_REF_LOCATION;
         $this->schemas[self::SELF_REF_LOCATION] = $schemaPartial;
     }
     if (!empty($schemaPartial->id)) {
         $resolver = new UriResolver();
         $this->scopes[] = $resolver->resolve($schemaPartial->id, $sourceUri);
     } else {
         $this->scopes[] = end($this->scopes);
     }
     return end($this->scopes);
 }
Exemple #4
0
 /**
  * Retrieve a URI
  *
  * @param string $uri JSON Schema URI
  * @param string|null $baseUri
  * @return object JSON Schema contents
  */
 public function retrieve($uri, $baseUri = null)
 {
     $resolver = new UriResolver();
     $resolvedUri = $fetchUri = $resolver->resolve($uri, $baseUri);
     //fetch URL without #fragment
     $arParts = $this->parse($resolvedUri);
     if (isset($arParts['fragment'])) {
         unset($arParts['fragment']);
         $fetchUri = $this->generate($arParts);
     }
     $jsonSchema = $this->loadSchema($fetchUri);
     // Use the JSON pointer if specified
     $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
     if ($jsonSchema instanceof \stdClass) {
         $jsonSchema->id = $resolvedUri;
     }
     return $jsonSchema;
 }
 /**
  * Retrieve a URI
  *
  * @param string $uri JSON Schema URI
  * @return object JSON Schema contents
  * @throws InvalidSchemaMediaType for invalid media tyeps
  */
 public function retrieve($uri, $baseUri = null)
 {
     $resolver = new UriResolver();
     $resolvedUri = $resolver->resolve($uri, $baseUri);
     $uriRetriever = $this->getUriRetriever();
     $contents = $this->uriRetriever->retrieve($resolvedUri);
     $this->confirmMediaType($uriRetriever);
     $jsonSchema = json_decode($contents);
     if (JSON_ERROR_NONE < ($error = json_last_error())) {
         throw new JsonDecodingException($error);
     }
     // Use the JSON pointer if specified
     $jsonSchema = $this->resolvePointer($jsonSchema, $resolvedUri);
     $jsonSchema->id = $resolvedUri;
     return $jsonSchema;
 }