add environment variables support (#255)

This commit is contained in:
sunxyw
2023-01-15 21:30:44 +08:00
committed by GitHub
parent a420c3ab23
commit ca1d2a1ed8
7 changed files with 147 additions and 5 deletions

View File

@@ -7,6 +7,7 @@ use OneBot\Driver\Coroutine\CoroutineInterface;
use OneBot\Driver\Process\ExecutionResult;
use OneBot\V12\Object\MessageSegment;
use Psr\Log\LoggerInterface;
use ZM\Config\Environment;
use ZM\Config\ZMConfig;
use ZM\Container\ContainerHolder;
use ZM\Logger\ConsoleLogger;
@@ -268,3 +269,12 @@ function kv(string $name = ''): Psr\SimpleCache\CacheInterface
/* @phpstan-ignore-next-line */
return is_a($kv_class, KVInterface::class, true) ? $kv_class::open($name) : new $kv_class($name);
}
/**
* 获取环境变量
*/
function env(string $key, mixed $default = null): mixed
{
// TODO: 重新思考容器绑定的加载方式,从而在此处使用 interface
return resolve(Environment::class)->get($key, $default);
}