split runtime info into runtime preferences

This commit is contained in:
sunxyw
2023-03-09 22:36:20 +08:00
parent 772288b517
commit 510bb8dc30
17 changed files with 126 additions and 134 deletions

View File

@@ -4,9 +4,9 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\HasRuntimeInfo;
use ZM\Config\RuntimePreferences;
interface Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void;
public function bootstrap(RuntimePreferences $preferences): void;
}

View File

@@ -5,12 +5,12 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use OneBot\Exception\ExceptionHandler;
use ZM\Config\RuntimePreferences;
use ZM\Exception\Handler;
use ZM\HasRuntimeInfo;
class HandleExceptions implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
// 注册全局错误处理器
set_error_handler(function ($error_no, $error_msg, $error_file, $error_line) {

View File

@@ -7,12 +7,12 @@ namespace ZM\Bootstrap;
use Dotenv\Dotenv;
use ZM\Config\Environment;
use ZM\Config\EnvironmentInterface;
use ZM\Config\RuntimePreferences;
use ZM\Config\ZMConfig;
use ZM\HasRuntimeInfo;
class LoadConfiguration implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
// TODO: 重新思考容器绑定的加载方式,从而在此处使用 interface
$env = resolve(Environment::class);
@@ -20,7 +20,7 @@ class LoadConfiguration implements Bootstrapper
new ZMConfig([
'source' => [
'paths' => [$runtime_info->getConfigDir()],
'paths' => [$preferences->getConfigDir()],
],
]);
}

View File

@@ -4,11 +4,11 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\HasRuntimeInfo;
use ZM\Config\RuntimePreferences;
class LoadGlobalDefines implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
require FRAMEWORK_ROOT_DIR . '/src/Globals/global_defines_framework.php';
}

View File

@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\HasRuntimeInfo;
use ZM\Config\RuntimePreferences;
use ZM\Plugin\PluginManager;
class LoadPlugins implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
// 先遍历下插件目录下是否有这个插件,没有这个插件则不能打包
$plugin_dir = config('global.plugin.load_dir', SOURCE_ROOT_DIR . '/plugins');

View File

@@ -4,12 +4,12 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\Config\RuntimePreferences;
use ZM\Event\EventProvider;
use ZM\HasRuntimeInfo;
class RegisterEventProvider implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
global $ob_event_provider;
$ob_event_provider = EventProvider::getInstance();

View File

@@ -4,17 +4,17 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\HasRuntimeInfo;
use ZM\Config\RuntimePreferences;
use ZM\Logger\ConsoleLogger;
class RegisterLogger implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
// 初始化 Logger
if (!ob_logger_registered()) {
// 如果没有注册过 Logger那么就初始化一个在启动框架前注册的话就不会初始化了可替换为其他 Logger
$logger = new ConsoleLogger($runtime_info->getLogLevel());
$logger = new ConsoleLogger($preferences->getLogLevel());
ob_logger_register($logger);
}
}

View File

@@ -4,11 +4,11 @@ declare(strict_types=1);
namespace ZM\Bootstrap;
use ZM\HasRuntimeInfo;
use ZM\Config\RuntimePreferences;
class SetInternalTimezone implements Bootstrapper
{
public function bootstrap(HasRuntimeInfo $runtime_info): void
public function bootstrap(RuntimePreferences $preferences): void
{
date_default_timezone_set(config('global.runtime.timezone', 'UTC'));
}