Merge pull request #7833 from RaphaelAurieres/master
Allows the JsonFile class to be used for other json files than composer.jsonpull/7853/head
commit
ebde0bab7e
|
@ -34,6 +34,8 @@ class JsonFile
|
||||||
const JSON_PRETTY_PRINT = 128;
|
const JSON_PRETTY_PRINT = 128;
|
||||||
const JSON_UNESCAPED_UNICODE = 256;
|
const JSON_UNESCAPED_UNICODE = 256;
|
||||||
|
|
||||||
|
const COMPOSER_SCHEMA_PATH = '/../../../res/composer-schema.json';
|
||||||
|
|
||||||
private $path;
|
private $path;
|
||||||
private $rfs;
|
private $rfs;
|
||||||
private $io;
|
private $io;
|
||||||
|
@ -144,10 +146,11 @@ class JsonFile
|
||||||
* Validates the schema of the current json file according to composer-schema.json rules
|
* Validates the schema of the current json file according to composer-schema.json rules
|
||||||
*
|
*
|
||||||
* @param int $schema a JsonFile::*_SCHEMA constant
|
* @param int $schema a JsonFile::*_SCHEMA constant
|
||||||
|
* @param string|null $schemaFile a path to the schema file
|
||||||
* @throws JsonValidationException
|
* @throws JsonValidationException
|
||||||
* @return bool true on success
|
* @return bool true on success
|
||||||
*/
|
*/
|
||||||
public function validateSchema($schema = self::STRICT_SCHEMA)
|
public function validateSchema($schema = self::STRICT_SCHEMA, $schemaFile = null)
|
||||||
{
|
{
|
||||||
$content = file_get_contents($this->path);
|
$content = file_get_contents($this->path);
|
||||||
$data = json_decode($content);
|
$data = json_decode($content);
|
||||||
|
@ -156,7 +159,9 @@ class JsonFile
|
||||||
self::validateSyntax($content, $this->path);
|
self::validateSyntax($content, $this->path);
|
||||||
}
|
}
|
||||||
|
|
||||||
$schemaFile = __DIR__ . '/../../../res/composer-schema.json';
|
if (null === $schemaFile) {
|
||||||
|
$schemaFile = __DIR__ . self::COMPOSER_SCHEMA_PATH;
|
||||||
|
}
|
||||||
|
|
||||||
// Prepend with file:// only when not using a special schema already (e.g. in the phar)
|
// Prepend with file:// only when not using a special schema already (e.g. in the phar)
|
||||||
if (false === strpos($schemaFile, '://')) {
|
if (false === strpos($schemaFile, '://')) {
|
||||||
|
|
Loading…
Reference in New Issue