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

Breadcrumb

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

function SchemaStorage::addSchema

Overrides SchemaStorageInterface::addSchema

1 call to SchemaStorage::addSchema()
SchemaStorage::getSchema in vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php
Returns schema for given identifier, or null if it does not exist

File

vendor/justinrainbow/json-schema/src/JsonSchema/SchemaStorage.php, line 46

Class

SchemaStorage

Namespace

JsonSchema

Code

public function addSchema($id, $schema = null) {
    if (is_null($schema) && $id !== self::INTERNAL_PROVIDED_SCHEMA_URI) {
        // if the schema was user-provided to Validator and is still null, then assume this is
        // what the user intended, as there's no way for us to retrieve anything else. User-supplied
        // schemas do not have an associated URI when passed via Validator::validate().
        $schema = $this->uriRetriever
            ->retrieve($id);
    }
    // cast array schemas to object
    if (is_array($schema)) {
        $schema = BaseConstraint::arrayToObjectRecursive($schema);
    }
    // workaround for bug in draft-03 & draft-04 meta-schemas (id & $ref defined with incorrect format)
    // see https://github.com/json-schema-org/JSON-Schema-Test-Suite/issues/177#issuecomment-293051367
    if (is_object($schema) && property_exists($schema, 'id')) {
        if ($schema->id == 'http://json-schema.org/draft-04/schema#') {
            $schema->properties->id->format = 'uri-reference';
        }
        elseif ($schema->id == 'http://json-schema.org/draft-03/schema#') {
            $schema->properties->id->format = 'uri-reference';
            $schema->properties->{'$ref'}->format = 'uri-reference';
        }
    }
    // resolve references
    $this->expandRefs($schema, $id);
    $this->schemas[$id] = $schema;
}

API Navigation

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