mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-18 05:04:51 +08:00
add environment aliases
This commit is contained in:
parent
451ce104c5
commit
96ebb770b6
@ -27,6 +27,15 @@ class ZMConfig implements \ArrayAccess
|
||||
*/
|
||||
public const DEFAULT_CONFIG_PATH = SOURCE_ROOT_DIR . '/config';
|
||||
|
||||
/**
|
||||
* @var string[] 环境别名
|
||||
*/
|
||||
public static array $environment_alias = [
|
||||
'dev' => 'development',
|
||||
'test' => 'testing',
|
||||
'prod' => 'production',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var array 已加载的配置文件
|
||||
*/
|
||||
@ -58,7 +67,7 @@ class ZMConfig implements \ArrayAccess
|
||||
public function __construct(array $config_paths = [], string $environment = 'uninitiated')
|
||||
{
|
||||
$this->config_paths = $config_paths ?: [self::DEFAULT_CONFIG_PATH];
|
||||
$this->environment = $environment;
|
||||
$this->environment = self::$environment_alias[$environment] ?? $environment;
|
||||
$this->holder = new Config([]);
|
||||
if ($environment !== 'uninitiated') {
|
||||
$this->loadFiles();
|
||||
@ -77,6 +86,16 @@ class ZMConfig implements \ArrayAccess
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前环境
|
||||
*
|
||||
* @return string 当前环境
|
||||
*/
|
||||
public function getEnvironment(): string
|
||||
{
|
||||
return $this->environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前环境
|
||||
*
|
||||
@ -86,8 +105,9 @@ class ZMConfig implements \ArrayAccess
|
||||
*/
|
||||
public function setEnvironment(string $environment): void
|
||||
{
|
||||
if ($this->environment !== $environment) {
|
||||
$this->environment = $environment;
|
||||
$target = self::$environment_alias[$environment] ?? $environment;
|
||||
if ($this->environment !== $target) {
|
||||
$this->environment = $target;
|
||||
$this->reload();
|
||||
}
|
||||
}
|
||||
@ -248,6 +268,7 @@ class ZMConfig implements \ArrayAccess
|
||||
$env = null;
|
||||
} else {
|
||||
$env = array_pop($parts);
|
||||
$env = self::$environment_alias[$env] ?? $env;
|
||||
}
|
||||
$group = implode('.', $parts);
|
||||
return [$group, $ext, $load_type, $env];
|
||||
|
||||
@ -19,6 +19,7 @@ use OneBot\Driver\Workerman\WorkermanDriver;
|
||||
use OneBot\Util\Singleton;
|
||||
use Phar;
|
||||
use ZM\Command\Server\ServerStartCommand;
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Event\EventProvider;
|
||||
use ZM\Event\Listener\HttpEventListener;
|
||||
use ZM\Event\Listener\ManagerEventListener;
|
||||
@ -324,7 +325,7 @@ class Framework
|
||||
// 打印工作目录
|
||||
$properties['working_dir'] = WORKING_DIR;
|
||||
// 打印环境信息
|
||||
$properties['environment'] = $this->argv['env'];
|
||||
$properties['environment'] = ZMConfig::getInstance()->getEnvironment();
|
||||
// 打印驱动
|
||||
$properties['driver'] = config('global.driver');
|
||||
// 打印logger显示等级
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user