Fixed display of empty objects showing [] instead of {} in config command, fixes #11302
parent
91b7b0ff3b
commit
8b0a185d5d
|
@ -324,6 +324,16 @@ EOT
|
|||
$value = $data;
|
||||
} elseif (isset($data['config'][$settingKey])) {
|
||||
$value = $this->config->get($settingKey, $input->getOption('absolute') ? 0 : Config::RELATIVE_PATHS);
|
||||
// ensure we get {} output for properties which are objects
|
||||
if ($value === []) {
|
||||
$schema = JsonFile::parseJson((string) file_get_contents(JsonFile::COMPOSER_SCHEMA_PATH));
|
||||
if (
|
||||
isset($schema['properties']['config']['properties'][$settingKey]['type'])
|
||||
&& in_array('object', (array) $schema['properties']['config']['properties'][$settingKey]['type'], true)
|
||||
) {
|
||||
$value = new \stdClass;
|
||||
}
|
||||
}
|
||||
} elseif (isset($rawData[$settingKey]) && in_array($settingKey, $properties, true)) {
|
||||
$value = $rawData[$settingKey];
|
||||
$source = $this->configFile->getPath();
|
||||
|
@ -334,7 +344,7 @@ EOT
|
|||
throw new \RuntimeException($settingKey.' is not defined');
|
||||
}
|
||||
|
||||
if (is_array($value) || is_bool($value)) {
|
||||
if (is_array($value) || is_object($value) || is_bool($value)) {
|
||||
$value = JsonFile::encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ final class ConfigReturnTypeExtension implements DynamicMethodReturnTypeExtensio
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$schema = JsonFile::parseJson((string) file_get_contents(__DIR__.'/../../../res/composer-schema.json'));
|
||||
$schema = JsonFile::parseJson((string) file_get_contents(JsonFile::COMPOSER_SCHEMA_PATH));
|
||||
/**
|
||||
* @var string $prop
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\Json;
|
||||
|
||||
use Composer\Json\JsonFile;
|
||||
use JsonSchema\Validator;
|
||||
use Composer\Test\TestCase;
|
||||
|
||||
|
@ -96,7 +97,7 @@ class ComposerSchemaTest extends TestCase
|
|||
private function check(string $json)
|
||||
{
|
||||
$validator = new Validator();
|
||||
$validator->check(json_decode($json), (object) ['$ref' => 'file://' . __DIR__ . '/../../../../res/composer-schema.json']);
|
||||
$validator->check(json_decode($json), (object) ['$ref' => 'file://' . JsonFile::COMPOSER_SCHEMA_PATH]);
|
||||
|
||||
if (!$validator->isValid()) {
|
||||
$errors = $validator->getErrors();
|
||||
|
|
Loading…
Reference in New Issue