From d0bbd20accb43f04a93efcc0cd98ed1f0d4d6393 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Tue, 28 Feb 2023 23:00:07 +0800 Subject: [PATCH] add composer metadata writer --- src/ZM/Utils/ZMUtil.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/ZM/Utils/ZMUtil.php b/src/ZM/Utils/ZMUtil.php index c71f6853..2b7e45bb 100644 --- a/src/ZM/Utils/ZMUtil.php +++ b/src/ZM/Utils/ZMUtil.php @@ -16,4 +16,15 @@ class ZMUtil { return json_decode(file_get_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json'), true, 512, JSON_THROW_ON_ERROR); } + + /** + * 写入 composer.json + * + * @param null|string $path 路径 + * @param array $content 内容数组 + */ + public static function putComposerMetadata(?string $path = null, array $content = []): false|int + { + return file_put_contents(($path ?? SOURCE_ROOT_DIR) . '/composer.json', json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); + } }