replace legacy config

This commit is contained in:
sunxyw
2022-08-23 18:02:00 +08:00
parent 18892a14c2
commit eb7e700e7c
12 changed files with 94 additions and 56 deletions

View File

@@ -7,7 +7,7 @@ namespace ZM\Config;
use OneBot\V12\Config\Config;
use ZM\Exception\ConfigException;
class ZMConfig
class ZMConfig implements \ArrayAccess
{
/**
* @var array 支持的文件扩展名
@@ -55,6 +55,33 @@ class ZMConfig
$this->loadFiles();
}
/**
* 添加配置文件路径
*
* @param string $path 路径
*/
public function addConfigPath(string $path): void
{
if (!in_array($path, $this->config_paths, true)) {
$this->config_paths[] = $path;
}
}
/**
* 设置当前环境
*
* 变更环境后,将会自动调用 `reload` 方法重载配置
*
* @param string $environment 目标环境
*/
public function setEnvironment(string $environment): void
{
if ($this->environment !== $environment) {
$this->environment = $environment;
$this->reload();
}
}
/**
* 加载配置文件
*
@@ -167,6 +194,26 @@ class ZMConfig
$this->loadFiles();
}
public function offsetExists($offset): bool
{
return $this->get($offset) !== null;
}
public function offsetGet($offset)
{
return $this->get($offset);
}
public function offsetSet($offset, $value): void
{
$this->set($offset, $value);
}
public function offsetUnset($offset): void
{
$this->set($offset, null);
}
/**
* 获取文件元信息
*