function Config::merge
Merges new config values with the existing ones (overriding)
Parameters
array{config?: array<string, mixed>, repositories?: array<mixed>} $config:
File
-
vendor/
composer/ composer/ src/ Composer/ Config.php, line 189
Class
- Config
- @author Jordi Boggiano <j.boggiano@seld.be>
Namespace
ComposerCode
public function merge(array $config, string $source = self::SOURCE_UNKNOWN) : void {
// override defaults with given config
if (!empty($config['config']) && is_array($config['config'])) {
foreach ($config['config'] as $key => $val) {
if (in_array($key, [
'bitbucket-oauth',
'github-oauth',
'gitlab-oauth',
'gitlab-token',
'http-basic',
'bearer',
], true) && isset($this->config[$key])) {
$this->config[$key] = array_merge($this->config[$key], $val);
$this->setSourceOfConfigValue($val, $key, $source);
}
elseif (in_array($key, [
'allow-plugins',
], true) && isset($this->config[$key]) && is_array($this->config[$key]) && is_array($val)) {
// merging $val first to get the local config on top of the global one, then appending the global config,
// then merging local one again to make sure the values from local win over global ones for keys present in both
$this->config[$key] = array_merge($val, $this->config[$key], $val);
$this->setSourceOfConfigValue($val, $key, $source);
}
elseif (in_array($key, [
'gitlab-domains',
'github-domains',
], true) && isset($this->config[$key])) {
$this->config[$key] = array_unique(array_merge($this->config[$key], $val));
$this->setSourceOfConfigValue($val, $key, $source);
}
elseif ('preferred-install' === $key && isset($this->config[$key])) {
if (is_array($val) || is_array($this->config[$key])) {
if (is_string($val)) {
$val = [
'*' => $val,
];
}
if (is_string($this->config[$key])) {
$this->config[$key] = [
'*' => $this->config[$key],
];
$this->sourceOfConfigValue[$key . '*'] = $source;
}
$this->config[$key] = array_merge($this->config[$key], $val);
$this->setSourceOfConfigValue($val, $key, $source);
// the full match pattern needs to be last
if (isset($this->config[$key]['*'])) {
$wildcard = $this->config[$key]['*'];
unset($this->config[$key]['*']);
$this->config[$key]['*'] = $wildcard;
}
}
else {
$this->config[$key] = $val;
$this->setSourceOfConfigValue($val, $key, $source);
}
}
elseif ('audit' === $key) {
$currentIgnores = $this->config['audit']['ignore'];
$this->config[$key] = array_merge($this->config['audit'], $val);
$this->setSourceOfConfigValue($val, $key, $source);
$this->config['audit']['ignore'] = array_merge($currentIgnores, $val['ignore'] ?? []);
}
else {
$this->config[$key] = $val;
$this->setSourceOfConfigValue($val, $key, $source);
}
}
}
if (!empty($config['repositories']) && is_array($config['repositories'])) {
$this->repositories = array_reverse($this->repositories, true);
$newRepos = array_reverse($config['repositories'], true);
foreach ($newRepos as $name => $repository) {
// disable a repository by name
if (false === $repository) {
$this->disableRepoByName((string) $name);
continue;
}
// disable a repository with an anonymous {"name": false} repo
if (is_array($repository) && 1 === count($repository) && false === current($repository)) {
$this->disableRepoByName((string) key($repository));
continue;
}
// auto-deactivate the default packagist.org repo if it gets redefined
if (isset($repository['type'], $repository['url']) && $repository['type'] === 'composer' && Preg::isMatch('{^https?://(?:[a-z0-9-.]+\\.)?packagist.org(/|$)}', $repository['url'])) {
$this->disableRepoByName('packagist.org');
}
// store repo
if (is_int($name)) {
$this->repositories[] = $repository;
$this->setSourceOfConfigValue($repository, 'repositories.' . array_search($repository, $this->repositories, true), $source);
}
else {
if ($name === 'packagist') {
// BC support for default "packagist" named repo
$this->repositories[$name . '.org'] = $repository;
$this->setSourceOfConfigValue($repository, 'repositories.' . $name . '.org', $source);
}
else {
$this->repositories[$name] = $repository;
$this->setSourceOfConfigValue($repository, 'repositories.' . $name, $source);
}
}
}
$this->repositories = array_reverse($this->repositories, true);
}
}