function UriRetriever::resolvePointer
Resolve a schema based on pointer
URIs can have a fragment at the end in the format of #/path/to/object and we are to look up the 'path' property of the first object then the 'to' and 'object' properties.
Parameters
object $jsonSchema JSON Schema contents:
string $uri JSON Schema URI:
Return value
object JSON Schema after walking down the fragment pieces
Throws
1 call to UriRetriever::resolvePointer()
- UriRetriever::retrieve in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Uri/ UriRetriever.php - Retrieve a URI
File
-
vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Uri/ UriRetriever.php, line 126
Class
- UriRetriever
- Retrieves JSON Schema URIs
Namespace
JsonSchema\UriCode
public function resolvePointer($jsonSchema, $uri) {
$resolver = new UriResolver();
$parsed = $resolver->parse($uri);
if (empty($parsed['fragment'])) {
return $jsonSchema;
}
$path = explode('/', $parsed['fragment']);
while ($path) {
$pathElement = array_shift($path);
if (!empty($pathElement)) {
$pathElement = str_replace('~1', '/', $pathElement);
$pathElement = str_replace('~0', '~', $pathElement);
if (!empty($jsonSchema->{$pathElement})) {
$jsonSchema = $jsonSchema->{$pathElement};
}
else {
throw new ResourceNotFoundException('Fragment "' . $parsed['fragment'] . '" not found' . ' in ' . $uri);
}
if (!is_object($jsonSchema)) {
throw new ResourceNotFoundException('Fragment part "' . $pathElement . '" is no object ' . ' in ' . $uri);
}
}
}
return $jsonSchema;
}