From 3c01faf0e2823ce00c81b839977cae14567c42d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Auri=C3=A8res?= Date: Thu, 13 Dec 2018 10:26:29 +0100 Subject: [PATCH 1/3] Use parameter with default value to set schema file path. --- src/Composer/Json/JsonFile.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index b84791420..45d638a96 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -34,6 +34,8 @@ class JsonFile const JSON_PRETTY_PRINT = 128; const JSON_UNESCAPED_UNICODE = 256; + const COMPOSER_SCHEMA_PATH = __DIR__ . '/../../../res/composer-schema.json'; + private $path; private $rfs; private $io; @@ -144,10 +146,11 @@ class JsonFile * Validates the schema of the current json file according to composer-schema.json rules * * @param int $schema a JsonFile::*_SCHEMA constant + * @param string $schemaFile a path to the schema file * @throws JsonValidationException * @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); $data = json_decode($content); @@ -156,8 +159,6 @@ class JsonFile 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) if (false === strpos($schemaFile, '://')) { $schemaFile = 'file://' . $schemaFile; From a8f27bf097448160cd6a9433ad3398afde3c9689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Auri=C3=A8res?= Date: Thu, 13 Dec 2018 11:36:57 +0100 Subject: [PATCH 2/3] Fix constant usage to be compatible with PHP 5.3 --- src/Composer/Json/JsonFile.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 45d638a96..ad73a8169 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -34,7 +34,7 @@ class JsonFile const JSON_PRETTY_PRINT = 128; const JSON_UNESCAPED_UNICODE = 256; - const COMPOSER_SCHEMA_PATH = __DIR__ . '/../../../res/composer-schema.json'; + const COMPOSER_SCHEMA_PATH = '/../../../res/composer-schema.json'; private $path; private $rfs; @@ -150,7 +150,7 @@ class JsonFile * @throws JsonValidationException * @return bool true on success */ - public function validateSchema($schema = self::STRICT_SCHEMA, $schemaFile = self::COMPOSER_SCHEMA_PATH) + public function validateSchema($schema = self::STRICT_SCHEMA, $schemaFile = null) { $content = file_get_contents($this->path); $data = json_decode($content); @@ -159,6 +159,10 @@ class JsonFile self::validateSyntax($content, $this->path); } + 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) if (false === strpos($schemaFile, '://')) { $schemaFile = 'file://' . $schemaFile; From 6725d1d244836b6a1a199278c93f3531d9ba4823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Auri=C3=A8res?= Date: Thu, 13 Dec 2018 11:39:20 +0100 Subject: [PATCH 3/3] Fix docblock. --- src/Composer/Json/JsonFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index ad73a8169..f2d950004 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -146,7 +146,7 @@ class JsonFile * Validates the schema of the current json file according to composer-schema.json rules * * @param int $schema a JsonFile::*_SCHEMA constant - * @param string $schemaFile a path to the schema file + * @param string|null $schemaFile a path to the schema file * @throws JsonValidationException * @return bool true on success */