From c0910bd4f9020e6b1410a1b8f8fd2903f7e8bcb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=99=E7=A0=81=E7=94=9F=E8=8A=B1?= <18523774412@qq.com> Date: Sun, 24 Dec 2023 01:32:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E7=BC=96=E7=A8=8B=E5=BC=8F=E5=88=A0?= =?UTF-8?q?=E9=99=A4=20composer=20=E9=85=8D=E7=BD=AE=E9=A1=B9=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/ba/Depends.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/extend/ba/Depends.php b/extend/ba/Depends.php index d231170f..9bd078e2 100644 --- a/extend/ba/Depends.php +++ b/extend/ba/Depends.php @@ -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); + } } \ No newline at end of file