mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
ready to replace legacy config
This commit is contained in:
@@ -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\ZMConfig;
|
||||
use ZM\Container\Container;
|
||||
use ZM\Container\ContainerInterface;
|
||||
use ZM\Context\Context;
|
||||
@@ -141,8 +142,8 @@ function container(): ContainerInterface
|
||||
/**
|
||||
* 解析类实例(使用容器)
|
||||
*
|
||||
* @template T
|
||||
* @param class-string<T> $abstract
|
||||
* @template T
|
||||
* @param class-string<T> $abstract
|
||||
* @return Closure|mixed|T
|
||||
* @noinspection PhpDocMissingThrowsInspection
|
||||
*/
|
||||
@@ -156,7 +157,7 @@ function resolve(string $abstract, array $parameters = [])
|
||||
* 获取容器实例
|
||||
*
|
||||
* @template T
|
||||
* @param null|class-string<T> $abstract
|
||||
* @param null|class-string<T> $abstract
|
||||
* @return Closure|ContainerInterface|mixed|T
|
||||
*/
|
||||
function app(string $abstract = null, array $parameters = [])
|
||||
@@ -187,3 +188,25 @@ function mysql_builder(string $name = '')
|
||||
{
|
||||
return (new MySQLWrapper($name))->createQueryBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 / 设置配置项
|
||||
*
|
||||
* 传入键名和(或)默认值,获取配置项
|
||||
* 传入数组,设置配置项
|
||||
* 不传参数,返回配置容器
|
||||
*
|
||||
* @param null|string|array $key 键名
|
||||
* @param mixed $default 默认值
|
||||
* @return mixed|ZMConfig
|
||||
*/
|
||||
function config($key = null, $default = null)
|
||||
{
|
||||
if (is_null($key)) {
|
||||
return resolve('config');
|
||||
}
|
||||
if (is_array($key)) {
|
||||
return resolve('config')->set(...$key);
|
||||
}
|
||||
return resolve('config')->get($key, $default);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user