Reorg config class a little

main
Jordi Boggiano 4 years ago
parent 6186c7f36f
commit 875a4784ed
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -211,6 +211,7 @@ class Config
public function get($key, $flags = 0)
{
switch ($key) {
// strings/paths with env var and {$refs} support
case 'vendor-dir':
case 'bin-dir':
case 'process-timeout':
@ -234,20 +235,33 @@ class Config
return (($flags & self::RELATIVE_PATHS) == self::RELATIVE_PATHS) ? $val : $this->realpath($val);
// booleans with env var support
case 'htaccess-protect':
$value = $this->getComposerEnv('COMPOSER_HTACCESS_PROTECT');
if (false === $value) {
$value = $this->config[$key];
// convert foo-bar to COMPOSER_FOO_BAR and check if it exists since it overrides the local config
$env = 'COMPOSER_' . strtoupper(strtr($key, '-', '_'));
$val = $this->getComposerEnv($env);
if (false === $val) {
$val = $this->config[$key];
}
return $value !== 'false' && (bool) $value;
return $val !== 'false' && (bool) $val;
// booleans without env var support
case 'disable-tls':
case 'secure-http':
case 'use-github-api':
case 'lock':
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
// ints without env var support
case 'cache-ttl':
return (int) $this->config[$key];
// numbers with kb/mb/gb support, without env var support
case 'cache-files-maxsize':
if (!preg_match('/^\s*([0-9.]+)\s*(?:([kmg])(?:i?b)?)?\s*$/i', $this->config[$key], $matches)) {
throw new \RuntimeException(
"Could not parse the value of 'cache-files-maxsize': {$this->config[$key]}"
"Could not parse the value of '$key': {$this->config[$key]}"
);
}
$size = $matches[1];
@ -269,6 +283,7 @@ class Config
return $size;
// special cases below
case 'cache-files-ttl':
if (isset($this->config[$key])) {
return (int) $this->config[$key];
@ -326,14 +341,6 @@ class Config
return $protos;
case 'disable-tls':
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
case 'secure-http':
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
case 'use-github-api':
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
case 'lock':
return $this->config[$key] !== 'false' && (bool) $this->config[$key];
default:
if (!isset($this->config[$key])) {
return null;

Loading…
Cancel
Save