feat:编程式删除 composer 配置项的方法实现

This commit is contained in:
妙码生花 2023-12-24 01:32:40 +08:00
parent 8437fe4a9d
commit c0910bd4f9

View File

@ -182,4 +182,31 @@ class Depends
}
$this->setContent($content);
}
/**
* 删除 composer 配置项
* @throws Throwable
*/
public function removeComposerConfig(array $config): void
{
if (!$config) return;
$content = $this->getContent(true);
foreach ($config as $key => $item) {
if (isset($content['config'][$key])) {
if (is_array($item)) {
foreach ($item as $configKey => $configItem) {
if (isset($content['config'][$key][$configKey])) unset($content['config'][$key][$configKey]);
}
// 没有子级配置项了
if (!$content['config'][$key]) {
unset($content['config'][$key]);
}
} else {
unset($content['config'][$key]);
}
}
}
$this->setContent($content);
}
}