function JsonConfigSource::addRepository
@inheritDoc
Overrides ConfigSourceInterface::addRepository
File
-
vendor/
composer/ composer/ src/ Composer/ Config/ JsonConfigSource.php, line 60
Class
- JsonConfigSource
- JSON Configuration Source
Namespace
Composer\ConfigCode
public function addRepository(string $name, $config, bool $append = true) : void {
$this->manipulateJson('addRepository', static function (&$config, $repo, $repoConfig) use ($append) : void {
// if converting from an array format to hashmap format, and there is a {"packagist.org":false} repo, we have
// to convert it to "packagist.org": false key on the hashmap otherwise it fails schema validation
if (isset($config['repositories'])) {
foreach ($config['repositories'] as $index => $val) {
if ($index === $repo) {
continue;
}
if (is_numeric($index) && ($val === [
'packagist' => false,
] || $val === [
'packagist.org' => false,
])) {
unset($config['repositories'][$index]);
$config['repositories']['packagist.org'] = false;
break;
}
}
}
if ($append) {
$config['repositories'][$repo] = $repoConfig;
}
else {
$config['repositories'] = [
$repo => $repoConfig,
] + $config['repositories'];
}
}, $name, $config, $append);
}