예제 #1
0
파일: Http.php 프로젝트: seytar/psx
 public function resolve(Uri $uri, Document $source, RefResolver $resolver)
 {
     if (!$uri->isAbsolute()) {
         $uri = UriResolver::resolve($source->getBaseUri(), $uri);
     }
     $request = new GetRequest($uri, array('Accept' => 'application/schema+json'));
     $response = $this->httpClient->request($request);
     if ($response->getStatusCode() == 200) {
         $schema = (string) $response->getBody();
         $data = Json::decode($schema);
         $document = new Document($data, $resolver, null, $uri);
         return $document;
     } else {
         throw new RuntimeException('Could not load external schema ' . $uri->toString() . ' received ' . $response->getStatusCode());
     }
 }
예제 #2
0
파일: File.php 프로젝트: seytar/psx
 public function resolve(Uri $uri, Document $source, RefResolver $resolver)
 {
     if ($source->isRemote()) {
         throw new RuntimeException('Can not resolve file scheme from remote source');
     }
     $path = str_replace('/', DIRECTORY_SEPARATOR, ltrim($uri->getPath(), '/'));
     $path = $source->getBasePath() !== null ? $source->getBasePath() . DIRECTORY_SEPARATOR . $path : $path;
     if (is_file($path)) {
         $basePath = pathinfo($path, PATHINFO_DIRNAME);
         $schema = file_get_contents($path);
         $data = Json::decode($schema);
         $document = new Document($data, $resolver, $basePath, $uri);
         return $document;
     } else {
         throw new RuntimeException('Could not load external schema ' . $path);
     }
 }
예제 #3
0
파일: RefResolver.php 프로젝트: seytar/psx
 /**
  * Extracts an array part from the document
  *
  * @param \PSX\Data\Schema\Parser\JsonSchema\Document $document
  * @param \PSX\Uri $ref
  * @return array
  */
 public function extract(Document $document, Uri $ref)
 {
     $uri = $this->resolver->resolve($document->getBaseUri(), $ref);
     $doc = $this->getDocument($uri, $document);
     $result = $doc->pointer($uri->getFragment());
     $baseUri = $doc->getBaseUri();
     // the extracted fragment gets merged into the root document so we must
     // resolve all $ref keys to the base uri so that the root document knows
     // where to find the $ref values
     array_walk_recursive($result, function (&$item, $key) use($baseUri) {
         if ($key == '$ref') {
             $item = $this->resolver->resolve($baseUri, new Uri($item))->toString();
         }
     });
     return $result;
 }