|
|
|
@ -134,8 +134,11 @@ EOT
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$input->getArgument('setting-key')) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the user enters in a config variable, parse it and save to file
|
|
|
|
|
if ($input->getArgument('setting-key')) {
|
|
|
|
|
if (array() !== $input->getArgument('setting-value') && $input->getOption('unset')) {
|
|
|
|
|
throw new \RuntimeException('You can not combine a setting value with --unset');
|
|
|
|
|
}
|
|
|
|
@ -150,10 +153,7 @@ EOT
|
|
|
|
|
$configSettings = $this->configFile->read(); // what is current in the config
|
|
|
|
|
$values = $input->getArgument('setting-value'); // what the user is trying to add/change
|
|
|
|
|
|
|
|
|
|
// Checking for each known config value is going to make this method very large
|
|
|
|
|
// what is a better way to do this?
|
|
|
|
|
|
|
|
|
|
// repositories.foo
|
|
|
|
|
// handle repositories
|
|
|
|
|
if (preg_match('/^repos?(?:itories)?\.(.+)/', $input->getArgument('setting-key'), $matches)) {
|
|
|
|
|
if ($input->getOption('unset')) {
|
|
|
|
|
unset($configSettings['repositories'][$matches[1]]);
|
|
|
|
@ -171,25 +171,83 @@ EOT
|
|
|
|
|
$configSettings = array_merge_recursive($configSettings, $setting);
|
|
|
|
|
$this->validateSchema($configSettings);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// handle config values
|
|
|
|
|
$uniqueConfigValues = array(
|
|
|
|
|
'process-timeout' => array('is_numeric', 'intval'),
|
|
|
|
|
'vendor-dir' => array('is_string', function ($val) { return $val; }),
|
|
|
|
|
'bin-dir' => array('is_string', function ($val) { return $val; }),
|
|
|
|
|
'notify-on-install' => array(
|
|
|
|
|
function ($val) { return true; },
|
|
|
|
|
function ($val) { return $val !== 'false' && (bool) $val; }
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
$multiConfigValues = array(
|
|
|
|
|
'github-protocols' => array(
|
|
|
|
|
function ($vals) {
|
|
|
|
|
if (!is_array($vals)) {
|
|
|
|
|
return 'array expected';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($vals as $val) {
|
|
|
|
|
if (!in_array($val, array('git', 'https', 'http'))) {
|
|
|
|
|
return 'valid protocols include: git, https, http';
|
|
|
|
|
}
|
|
|
|
|
// process-timeout
|
|
|
|
|
elseif (preg_match('/^process-timeout/', $input->getArgument('setting-key'))) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
},
|
|
|
|
|
function ($vals) {
|
|
|
|
|
return $vals;
|
|
|
|
|
}
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$settingKey = $input->getArgument('setting-key');
|
|
|
|
|
foreach ($uniqueConfigValues as $name => $callbacks) {
|
|
|
|
|
if ($settingKey === $name) {
|
|
|
|
|
list($validator, $normalizer) = $callbacks;
|
|
|
|
|
if ($input->getOption('unset')) {
|
|
|
|
|
unset($configSettings['config']['process-timeout']);
|
|
|
|
|
unset($configSettings['config'][$settingKey]);
|
|
|
|
|
} else {
|
|
|
|
|
if (1 !== count($values)) {
|
|
|
|
|
throw new \RuntimeException('You can only pass one value. Example: php composer.phar config process-timeout 300');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!is_numeric($values[0])) {
|
|
|
|
|
throw new \RuntimeException(sprintf('"%s" is not a number.', $values[0]));
|
|
|
|
|
if (true !== $validation = $validator($values[0])) {
|
|
|
|
|
throw new \RuntimeException(sprintf(
|
|
|
|
|
'"%s" is an invalid value'.($validation ? ' ('.$validation.')' : ''),
|
|
|
|
|
$values[0]
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$setting = $this->parseSetting('config.'.$input->getArgument('setting-key'), (integer) $values[0]);
|
|
|
|
|
$setting = $this->parseSetting('config.'.$settingKey, $normalizer($values[0]));
|
|
|
|
|
$configSettings = array_merge($configSettings, $setting);
|
|
|
|
|
$this->validateSchema($configSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($multiConfigValues as $name => $callbacks) {
|
|
|
|
|
if ($settingKey === $name) {
|
|
|
|
|
list($validator, $normalizer) = $callbacks;
|
|
|
|
|
if ($input->getOption('unset')) {
|
|
|
|
|
unset($configSettings['config'][$settingKey]);
|
|
|
|
|
} else {
|
|
|
|
|
if (true !== $validation = $validator($values)) {
|
|
|
|
|
throw new \RuntimeException(sprintf(
|
|
|
|
|
'%s is an invalid value'.($validation ? ' ('.$validation.')' : ''),
|
|
|
|
|
json_encode($values)
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$setting = $this->parseSetting('config.'.$settingKey, $normalizer($values));
|
|
|
|
|
$configSettings = array_merge($configSettings, $setting);
|
|
|
|
|
$this->validateSchema($configSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clean up empty sections
|
|
|
|
|
if (empty($configSettings['repositories'])) {
|
|
|
|
@ -211,7 +269,6 @@ EOT
|
|
|
|
|
|
|
|
|
|
$this->configFile->write($configSettings);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display the contents of the file in a pretty formatted way
|
|
|
|
|