public function retrieve($uri)
 {
     $resolver = new UriResolver();
     $parts = $resolver->parse($uri);
     $parts['fragment'] = '#';
     $uri = $resolver->generate($parts);
     return parent::retrieve($uri);
 }
Beispiel #2
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 testCombineRelativePathWithBasePath()
 {
     $this->assertEquals('/foo/bar/boo', UriResolver::combineRelativePathWithBasePath('boo', '/foo/bar/'));
     $this->assertEquals('/foo/bar/', UriResolver::combineRelativePathWithBasePath('', '/foo/bar/'));
     $this->assertEquals('/foo/bar', UriResolver::combineRelativePathWithBasePath('', '/foo/bar'));
     // ??? imho /boo
     $this->assertEquals('/foo/bar/boo', UriResolver::combineRelativePathWithBasePath('/boo', '/foo/bar/'));
     $this->assertEquals('/foo.json', UriResolver::combineRelativePathWithBasePath('', '/foo.json'));
 }
 protected function validateUri($schema, $schemaUri = null)
 {
     $resolver = new UriResolver();
     $retriever = $this->getUriRetriever();
     $jsonSchema = null;
     if ($resolver->isValid($schemaUri)) {
         $schemaId = property_exists($schema, 'id') ? $schema->id : null;
         $jsonSchema = $retriever->retrieve($schemaId, $schemaUri);
     }
     return $jsonSchema;
 }
Beispiel #5
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);
 }
Beispiel #6
0
 public function testCombineRelativePathWithBasePathNoPath()
 {
     //needed for anchor-only urls
     $this->assertEquals('/foo/bar.json', UriResolver::combineRelativePathWithBasePath('', '/foo/bar.json'));
 }
Beispiel #7
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;
 }
Beispiel #8
0
 /**
  * Resolves a URI
  *
  * @param string $uri Absolute or relative
  * @param string $baseUri Optional base URI
  * @return string
  */
 public function resolve($uri, $baseUri = null)
 {
     $components = $this->parse($uri);
     $path = $components['path'];
     if (array_key_exists('scheme', $components) && 'http' === $components['scheme']) {
         return $uri;
     }
     $baseComponents = $this->parse($baseUri);
     $basePath = $baseComponents['path'];
     $baseComponents['path'] = UriResolver::combineRelativePathWithBasePath($path, $basePath);
     return $this->generate($baseComponents);
 }
 /**
  * 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;
 }