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()); } }
/** * 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; }