This commit is contained in:
xl
2024-09-04 11:43:24 +08:00
parent 53bcb44b0e
commit e1841d908b
+10 -16
View File
@@ -28,10 +28,7 @@ class ServerCommand extends Command
{ {
public AsyncServer $manager;
public State $state; public State $state;
public EventDispatch $dispatch;
public Router $router;
/** /**
@@ -42,10 +39,7 @@ class ServerCommand extends Command
{ {
parent::__construct($name); parent::__construct($name);
$container = Kiri::getDi(); $container = Kiri::getDi();
$this->manager = $container->get(AsyncServer::class);
$this->state = $container->get(State::class); $this->state = $container->get(State::class);
$this->dispatch = $container->get(EventDispatch::class);
$this->router = $container->get(Router::class);
} }
@@ -99,11 +93,12 @@ class ServerCommand extends Command
protected function stop(): int protected function stop(): int
{ {
$configs = config('server', []); $configs = config('server', []);
$instances = $this->manager->sortService($configs['ports'] ?? []); $instances = Kiri::getDi()->get(AsyncServer::class)->sortService($configs['ports'] ?? []);
foreach ($instances as $config) { foreach ($instances as $config) {
$this->state->exit($config->port); $this->state->exit($config->port);
} }
$this->dispatch->dispatch(new OnShutdown()); $dispatch = Kiri::getDi()->get(EventDispatch::class);
$dispatch->dispatch(new OnShutdown());
return 1; return 1;
} }
@@ -116,14 +111,13 @@ class ServerCommand extends Command
protected function start(InputInterface $input): int protected function start(InputInterface $input): int
{ {
$daemon = (int)$input->getOption('daemon'); $daemon = (int)$input->getOption('daemon');
if (config('reload.hot', false) === true) { $manager = Kiri::getDi()->get(AsyncServer::class);
$this->manager->addProcess(HotReload::class); $router = Kiri::getDi()->get(Router::class);
} else {
$this->router->scan_build_route(); $router->scan_build_route();
} $manager->addProcess(config('processes', []));
$this->manager->addProcess(config('processes', [])); $manager->initCoreServers(config('server', []), $daemon);
$this->manager->initCoreServers(config('server', []), $daemon); $manager->start();
$this->manager->start();
return 1; return 1;
} }