diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 455ae6db7..4d03a4971 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -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]; - } - return $value !== 'false' && (bool) $value; + // 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 $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;