Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. UriRetriever.php

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

ResourceNotFoundException

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\Uri

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal