mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-03-17 20:54:52 +08:00
advance bootstraper call order
This commit is contained in:
parent
effecb09e5
commit
cf72893421
@ -25,4 +25,5 @@ return [
|
||||
// 可以添加多个配置文件目录
|
||||
],
|
||||
],
|
||||
'trace' => false, // 是否开启配置跟踪器
|
||||
];
|
||||
|
||||
@ -12,7 +12,8 @@ class RegisterLogger
|
||||
{
|
||||
// 初始化 Logger
|
||||
if (!ob_logger_registered()) {
|
||||
$debug = $config['verbose'] ? 'debug' : null;
|
||||
$debug = $config['verbose'] ?? false;
|
||||
$debug = $debug ? 'debug' : null;
|
||||
// 如果没有注册过 Logger,那么就初始化一个,在启动框架前注册的话,就不会初始化了,可替换为其他 Logger
|
||||
$logger = new ConsoleLogger($config['log-level'] ?? $debug ?? 'info');
|
||||
ob_logger_register($logger);
|
||||
|
||||
@ -8,7 +8,6 @@ use OneBot\Config\Config;
|
||||
use OneBot\Config\Loader\LoaderInterface;
|
||||
use OneBot\Util\Singleton;
|
||||
use ZM\Exception\ConfigException;
|
||||
use ZM\Framework;
|
||||
|
||||
class ZMConfig
|
||||
{
|
||||
@ -87,8 +86,8 @@ class ZMConfig
|
||||
// 初始化配置加载器
|
||||
$this->loader = new ($conf['loader'][0])(...$conf['loader'][1]);
|
||||
|
||||
// 调试模式下启用配置跟踪器
|
||||
if (Framework::getInstance()->getArgv()['debug'] ?? false) {
|
||||
// 启用配置跟踪器
|
||||
if ($conf['trace'] ?? false) {
|
||||
$this->tracer = new ConfigTracer();
|
||||
} else {
|
||||
$this->tracer = null;
|
||||
|
||||
@ -9,6 +9,7 @@ use Symfony\Component\Console\Attribute\AsCommand;
|
||||
use Symfony\Component\Console\CommandLoader\FactoryCommandLoader;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use ZM\Command\Server\ServerStartCommand;
|
||||
use ZM\Exception\SingletonViolationException;
|
||||
use ZM\Store\FileSystem;
|
||||
|
||||
@ -19,6 +20,15 @@ use ZM\Store\FileSystem;
|
||||
*/
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
protected array $bootstrappers = [
|
||||
Bootstrap\LoadConfiguration::class, // 加载配置文件
|
||||
Bootstrap\LoadGlobalDefines::class, // 加载框架级别的全局常量声明
|
||||
Bootstrap\RegisterLogger::class, // 加载 Logger
|
||||
Bootstrap\HandleExceptions::class, // 注册异常处理器
|
||||
Bootstrap\RegisterEventProvider::class, // 绑定框架的 EventProvider 到 libob 的 Driver 上
|
||||
Bootstrap\SetInternalTimezone::class, // 设置时区
|
||||
];
|
||||
|
||||
private static ?ConsoleApplication $obj = null;
|
||||
|
||||
public function __construct(string $name = 'zhamao-framework')
|
||||
@ -78,6 +88,11 @@ final class ConsoleApplication extends Application
|
||||
*/
|
||||
public function run(InputInterface $input = null, OutputInterface $output = null): int
|
||||
{
|
||||
$options = $input?->getOptions() ?? ServerStartCommand::exportOptionArray();
|
||||
foreach ($this->bootstrappers as $bootstrapper) {
|
||||
resolve($bootstrapper)->bootstrap($options);
|
||||
}
|
||||
|
||||
try {
|
||||
return parent::run($input, $output);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@ -93,11 +93,6 @@ class Framework
|
||||
*/
|
||||
public function init(): Framework
|
||||
{
|
||||
// 顺序执行引导器
|
||||
foreach ($this->bootstrappers as $bootstrapper) {
|
||||
resolve($bootstrapper)->bootstrap($this->argv);
|
||||
}
|
||||
|
||||
// 初始化 @OnSetup 事件
|
||||
$this->initSetupAnnotations();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user