From 1a1c65afce19c8a6d6e044c7d8fb226d82d8b5eb Mon Sep 17 00:00:00 2001 From: sunxyw Date: Sat, 20 Aug 2022 18:40:54 +0800 Subject: [PATCH] fix code styles --- src/ZM/Config/RefactoredConfig.php | 118 +++++++++++------------ tests/ZM/Config/RefactoredConfigTest.php | 19 +++- 2 files changed, 73 insertions(+), 64 deletions(-) diff --git a/src/ZM/Config/RefactoredConfig.php b/src/ZM/Config/RefactoredConfig.php index d830b012..f8cced12 100644 --- a/src/ZM/Config/RefactoredConfig.php +++ b/src/ZM/Config/RefactoredConfig.php @@ -42,8 +42,8 @@ class RefactoredConfig /** * 构造配置实例 * - * @param array $config_paths 配置文件路径 - * @param string $environment 环境 + * @param array $config_paths 配置文件路径 + * @param string $environment 环境 * * @throws ConfigException 配置文件加载出错 */ @@ -107,6 +107,63 @@ class RefactoredConfig } } + /** + * 合并传入的配置数组至指定的配置项 + * + * @param string $key 目标配置项,必须为数组 + * @param array $config 要合并的配置数组 + */ + public function merge(string $key, array $config): void + { + $original = $this->get($key, []); + $this->set($key, array_merge($original, $config)); + } + + /** + * 获取配置项 + * + * @param string $key 配置项名称,可使用.访问数组 + * @param mixed $default 默认值 + * + * @return null|array|mixed + */ + public function get(string $key, $default = null) + { + return $this->holder->get($key, $default); + } + + /** + * 设置配置项 + * 仅在本次运行期间生效,不会保存到配置文件中哦 + * + * @param string $key 配置项名称,可使用.访问数组 + * @param mixed $value 要写入的值,传入 null 会进行删除 + */ + public function set(string $key, $value): void + { + $this->holder->set($key, $value); + } + + /** + * 获取内部配置容器 + */ + public function getHolder(): Config + { + return $this->holder; + } + + /** + * 重载配置文件 + * 运行期间新增的配置文件不会被加载哟~ + * + * @throws ConfigException + */ + public function reload(): void + { + $this->holder = new Config([]); + $this->loadFiles(); + } + /** * 获取文件元信息 * @@ -224,61 +281,4 @@ class RefactoredConfig // 加入配置 $this->merge($group, $config); } - - /** - * 合并传入的配置数组至指定的配置项 - * - * @param string $key 目标配置项,必须为数组 - * @param array $config 要合并的配置数组 - */ - public function merge(string $key, array $config): void - { - $original = $this->get($key, []); - $this->set($key, array_merge($original, $config)); - } - - /** - * 获取配置项 - * - * @param string $key 配置项名称,可使用.访问数组 - * @param mixed $default 默认值 - * - * @return null|array|mixed - */ - public function get(string $key, $default = null) - { - return $this->holder->get($key, $default); - } - - /** - * 设置配置项 - * 仅在本次运行期间生效,不会保存到配置文件中哦 - * - * @param string $key 配置项名称,可使用.访问数组 - * @param mixed $value 要写入的值,传入 null 会进行删除 - */ - public function set(string $key, $value): void - { - $this->holder->set($key, $value); - } - - /** - * 获取内部配置容器 - */ - public function getHolder(): Config - { - return $this->holder; - } - - /** - * 重载配置文件 - * 运行期间新增的配置文件不会被加载哟~ - * - * @throws ConfigException - */ - public function reload(): void - { - $this->holder = new Config([]); - $this->loadFiles(); - } } diff --git a/tests/ZM/Config/RefactoredConfigTest.php b/tests/ZM/Config/RefactoredConfigTest.php index 6f395a90..b195bcc0 100644 --- a/tests/ZM/Config/RefactoredConfigTest.php +++ b/tests/ZM/Config/RefactoredConfigTest.php @@ -1,10 +1,15 @@ "environment", "env" => "development"];'); - file_put_contents($mock_dir . '/test.production.php', - ' "environment", "env" => "production"];'); + file_put_contents( + $mock_dir . '/test.development.php', + ' "environment", "env" => "development"];' + ); + file_put_contents( + $mock_dir . '/test.production.php', + ' "environment", "env" => "production"];' + ); file_put_contents($mock_dir . '/test.invalid.php', ' "invalid"];'); $config = new RefactoredConfig([