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

Breadcrumb

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

function JsonFile::validateSchema

Validates the schema of the current json file according to composer-schema.json rules

@phpstan-param self::*_SCHEMA $schema

Parameters

int $schema a JsonFile::*_SCHEMA constant:

string|null $schemaFile a path to the schema file:

Return value

true true on success

Throws

JsonValidationException

ParsingException

File

vendor/composer/composer/src/Composer/Json/JsonFile.php, line 203

Class

JsonFile
Reads/writes json files.

Namespace

Composer\Json

Code

public function validateSchema(int $schema = self::STRICT_SCHEMA, ?string $schemaFile = null) : bool {
    if (!Filesystem::isReadable($this->path)) {
        throw new \RuntimeException('The file "' . $this->path . '" is not readable.');
    }
    $content = file_get_contents($this->path);
    $data = json_decode($content);
    if (null === $data && 'null' !== $content) {
        self::validateSyntax($content, $this->path);
    }
    return self::validateJsonSchema($this->path, $data, $schema, $schemaFile);
}
RSS feed
Powered by Drupal