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
File
-
vendor/
composer/ composer/ src/ Composer/ Json/ JsonFile.php, line 203
Class
- JsonFile
- Reads/writes json files.
Namespace
Composer\JsonCode
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);
}