mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-22 08:05:34 +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);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace ZM\Config;
|
||||
use OneBot\V12\Config\Config;
|
||||
use ZM\Exception\ConfigException;
|
||||
|
||||
class RefactoredConfig
|
||||
class ZMConfig
|
||||
{
|
||||
/**
|
||||
* @var array 支持的文件扩展名
|
||||
@@ -29,7 +29,7 @@ class ContainerServicesProvider
|
||||
* connection: open, close, message
|
||||
* ```
|
||||
*
|
||||
* @param string $scope 作用域
|
||||
* @param string $scope 作用域
|
||||
* @throws ConfigException
|
||||
*/
|
||||
public function registerServices(string $scope, ...$params): void
|
||||
@@ -81,6 +81,12 @@ class ContainerServicesProvider
|
||||
|
||||
// 注册logger
|
||||
$container->instance(LoggerInterface::class, logger());
|
||||
|
||||
// 注册config
|
||||
$container->instance(ZMConfig::class, new ZMConfig([
|
||||
SOURCE_ROOT_DIR . '/config',
|
||||
]));
|
||||
$container->alias(ZMConfig::class, 'config');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user