コード例 #1
0
ファイル: UriRetriever.php プロジェクト: VicDeo/poc
 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;
 }
コード例 #2
0
 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'));
 }
コード例 #3
0
ファイル: RefResolver.php プロジェクト: araines/json-schema
 /**
  * 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);
 }
コード例 #4
0
ファイル: UriRetriever.php プロジェクト: araines/json-schema
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }