变更
This commit is contained in:
+13
-24
@@ -37,24 +37,9 @@ class AsyncServer implements ServerInterface
|
|||||||
private Server|null $server = null;
|
private Server|null $server = null;
|
||||||
|
|
||||||
|
|
||||||
#[Container(Config::class)]
|
|
||||||
public Config $config;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var Kiri\Di\Container
|
|
||||||
*/
|
|
||||||
#[Container(ContainerInterface::class)]
|
|
||||||
public ContainerInterface $container;
|
|
||||||
|
|
||||||
#[Container(EventDispatch::class)]
|
|
||||||
public EventDispatch $dispatch;
|
|
||||||
|
|
||||||
#[Container(LoggerInterface::class)]
|
#[Container(LoggerInterface::class)]
|
||||||
public LoggerInterface $logger;
|
public LoggerInterface $logger;
|
||||||
|
|
||||||
#[Container(ProcessManager::class)]
|
|
||||||
public ProcessManager $processManager;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -78,7 +63,9 @@ class AsyncServer implements ServerInterface
|
|||||||
if (!empty($rpcService)) {
|
if (!empty($rpcService)) {
|
||||||
$this->addListener(instance(SConfig::class, [], $rpcService));
|
$this->addListener(instance(SConfig::class, [], $rpcService));
|
||||||
}
|
}
|
||||||
$this->processManager->batch(Config::get('processes', []));
|
|
||||||
|
$processManager = Kiri::getDi()->get(ProcessManager::class);
|
||||||
|
$processManager->batch(Config::get('processes', []));
|
||||||
|
|
||||||
$this->onSignal(Config::get('signal', []));
|
$this->onSignal(Config::get('signal', []));
|
||||||
}
|
}
|
||||||
@@ -103,7 +90,8 @@ class AsyncServer implements ServerInterface
|
|||||||
{
|
{
|
||||||
$this->server->shutdown();
|
$this->server->shutdown();
|
||||||
|
|
||||||
$this->dispatch->dispatch(new OnShutdown());
|
$processManager = Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
$processManager->dispatch(new OnShutdown());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -117,6 +105,7 @@ class AsyncServer implements ServerInterface
|
|||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
private function createBaseServer(SConfig $config, int $daemon = 0): void
|
private function createBaseServer(SConfig $config, int $daemon = 0): void
|
||||||
{
|
{
|
||||||
@@ -132,8 +121,6 @@ class AsyncServer implements ServerInterface
|
|||||||
|
|
||||||
$this->onEventListen($this->server, Config::get('server.events', []));
|
$this->onEventListen($this->server, Config::get('server.events', []));
|
||||||
$this->onEventListen($this->server, $config->events);
|
$this->onEventListen($this->server, $config->events);
|
||||||
|
|
||||||
// $this->container->set(ServerInterface::class, $this->server);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -176,13 +163,14 @@ class AsyncServer implements ServerInterface
|
|||||||
$port->set($this->resetSettings($config->type, $config->settings));
|
$port->set($this->resetSettings($config->type, $config->settings));
|
||||||
|
|
||||||
$this->onEventListen($port, $config->getEvents());
|
$this->onEventListen($port, $config->getEvents());
|
||||||
$this->container->get(LocalService::class)->set($config->getName(), $port);
|
Kiri::getDi()->get(LocalService::class)->set($config->getName(), $port);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $no
|
* @param $no
|
||||||
* @param array $signInfo
|
* @param array $signInfo
|
||||||
* @return void
|
* @return void
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function onSigint($no, array $signInfo): void
|
public function onSigint($no, array $signInfo): void
|
||||||
{
|
{
|
||||||
@@ -219,14 +207,13 @@ class AsyncServer implements ServerInterface
|
|||||||
* @param Server\Port|Server $base
|
* @param Server\Port|Server $base
|
||||||
* @param array $events
|
* @param array $events
|
||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ReflectionException
|
||||||
* @throws NotFoundExceptionInterface
|
|
||||||
*/
|
*/
|
||||||
private function onEventListen(Server\Port|Server $base, array $events): void
|
private function onEventListen(Server\Port|Server $base, array $events): void
|
||||||
{
|
{
|
||||||
foreach ($events as $name => $event) {
|
foreach ($events as $name => $event) {
|
||||||
if (is_array($event) && is_string($event[0])) {
|
if (is_array($event) && is_string($event[0])) {
|
||||||
$event[0] = $this->container->get($event[0]);
|
$event[0] = Kiri::getDi()->get($event[0]);
|
||||||
}
|
}
|
||||||
$base->on($name, $event);
|
$base->on($name, $event);
|
||||||
}
|
}
|
||||||
@@ -237,10 +224,12 @@ class AsyncServer implements ServerInterface
|
|||||||
* @return void
|
* @return void
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function start(): void
|
public function start(): void
|
||||||
{
|
{
|
||||||
$this->dispatch->dispatch(new OnServerBeforeStart());
|
$processManager = Kiri::getDi()->get(EventDispatch::class);
|
||||||
|
$processManager->dispatch(new OnServerBeforeStart());
|
||||||
$this->server->start();
|
$this->server->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user