mirror of
https://gitee.com/technical-laohu/mpay_v2_webman.git
synced 2026-04-22 10:04:27 +08:00
重构初始化
This commit is contained in:
1558
support/Setup.php
Normal file
1558
support/Setup.php
Normal file
File diff suppressed because it is too large
Load Diff
52
support/functions.php
Normal file
52
support/functions.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
use app\service\system\config\SystemConfigRuntimeService;
|
||||
use support\Container;
|
||||
|
||||
if (!function_exists('container_get')) {
|
||||
/**
|
||||
* 从容器中获取实例。
|
||||
*
|
||||
* @param string $name 类名或接口名
|
||||
* @return mixed
|
||||
*/
|
||||
function container_get(string $name): mixed
|
||||
{
|
||||
return Container::get($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('container_make')) {
|
||||
/**
|
||||
* 从容器中创建新实例。
|
||||
*
|
||||
* @param string $name 类名或接口名
|
||||
* @param array $parameters 构造参数
|
||||
* @return mixed
|
||||
*/
|
||||
function container_make(string $name, array $parameters = []): mixed
|
||||
{
|
||||
return Container::make($name, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sys_config')) {
|
||||
/**
|
||||
* 获取系统配置项。
|
||||
*
|
||||
* 值来源于 ma_system_config,并通过 SystemConfigRuntimeService 读取缓存。
|
||||
* 系统配置值统一按字符串存储,业务侧按需转换类型。
|
||||
*
|
||||
* @param string $key 配置键名(config_key)
|
||||
* @param mixed $default 默认值
|
||||
* @param bool $refresh 是否强制刷新缓存后再读取
|
||||
* @return mixed
|
||||
*/
|
||||
function sys_config(string $key, mixed $default = null, bool $refresh = false): mixed
|
||||
{
|
||||
/** @var SystemConfigRuntimeService $service */
|
||||
$service = Container::get(SystemConfigRuntimeService::class);
|
||||
|
||||
return $service->get($key, $default, $refresh);
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
// This file is generated by Webman, please don't modify it.
|
||||
|
||||
use support\Container;
|
||||
|
||||
if (!function_exists('container_get')) {
|
||||
/**
|
||||
* 从容器中获取实例(单例)
|
||||
*
|
||||
* @param string $name 类名或接口名
|
||||
* @return mixed
|
||||
*
|
||||
* @example
|
||||
* $foo = container_get(Foo::class);
|
||||
* $user_service = container_get(UserService::class);
|
||||
*/
|
||||
function container_get(string $name)
|
||||
{
|
||||
return Container::get($name);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('container_make')) {
|
||||
/**
|
||||
* 从容器中创建新实例(每次创建新实例)
|
||||
*
|
||||
* @param string $name 类名或接口名
|
||||
* @param array $parameters 构造函数参数
|
||||
* @return mixed
|
||||
*
|
||||
* @example
|
||||
* $log_service = container_make(LogService::class, [$path, $name]);
|
||||
*/
|
||||
function container_make(string $name, array $parameters = [])
|
||||
{
|
||||
return Container::make($name, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('sys_config')) {
|
||||
/**
|
||||
* 获取系统配置项(带默认值)
|
||||
*
|
||||
* 读取来源:ma_system_config 表,通过 SystemConfigService + 缓存。
|
||||
*
|
||||
* @param string $key 配置键名(config_key)
|
||||
* @param mixed $default 默认值(未配置或为 null 时返回)
|
||||
* @return mixed
|
||||
*
|
||||
* @example
|
||||
* $siteName = sys_config('site_name', 'MyPay');
|
||||
*/
|
||||
function sys_config(string $key, mixed $default = null): mixed
|
||||
{
|
||||
/** @var \app\services\SystemConfigService $service */
|
||||
$service = Container::get(\app\services\SystemConfigService::class);
|
||||
return $service->getValue($key, $default);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user