1
0
Fork 0

Use parameter with default value to set schema file path.

pull/7833/head
Raphaël Aurières 2018-12-13 10:26:29 +01:00
parent 4301c19ce3
commit 3c01faf0e2
1 changed files with 4 additions and 3 deletions

View File

@ -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 = __DIR__ . '/../../../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 $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 = self::COMPOSER_SCHEMA_PATH)
{ {
$content = file_get_contents($this->path); $content = file_get_contents($this->path);
$data = json_decode($content); $data = json_decode($content);
@ -156,8 +159,6 @@ class JsonFile
self::validateSyntax($content, $this->path); self::validateSyntax($content, $this->path);
} }
$schemaFile = __DIR__ . '/../../../res/composer-schema.json';
// 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, '://')) {
$schemaFile = 'file://' . $schemaFile; $schemaFile = 'file://' . $schemaFile;