From 09cf74abdfec85905071f6180d51c76fb93bfd2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 19 Apr 2023 15:23:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Abstracts/AsyncServer.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index 85f513e..5951fb6 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -5,12 +5,11 @@ namespace Kiri\Server\Abstracts; use Exception; use Kiri; use Kiri\Abstracts\Config; -use Psr\Container\ContainerInterface; +use Kiri\Server\Handler\OnServer; use Kiri\Exception\ConfigException; use Kiri\Server\Events\OnShutdown; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; -use Psr\Log\LoggerInterface; use ReflectionException; use Kiri\Server\Config as SConfig; use Kiri\Di\LocalService; @@ -20,7 +19,7 @@ use Kiri\Server\Constant; use Kiri\Events\EventDispatch; use Kiri\Exception\NotFindClassException; use Kiri\Server\Events\OnServerBeforeStart; -use Kiri\Di\Inject\Container; +use Kiri\Abstracts\Logger; /** * @@ -98,9 +97,7 @@ class AsyncServer implements ServerInterface * @param int $daemon * @return void * @throws ConfigException - * @throws ContainerExceptionInterface * @throws NotFindClassException - * @throws NotFoundExceptionInterface * @throws ReflectionException */ private function createBaseServer(SConfig $config, int $daemon = 0): void @@ -110,11 +107,12 @@ class AsyncServer implements ServerInterface throw new NotFindClassException('Unknown server type ' . $config->type); } $this->server = new $match($config->host, $config->port, $config->mode, $config->socket); - $this->server->set($this->systemConfig($config, $daemon)); - \Kiri::getLogger()->alert('Listen ' . $config->type . ' address ' . $config->host . '::' . $config->port); - + Logger::alert('Listen ' . $config->type . ' address ' . $config->host . '::' . $config->port); + if (!isset($config->events[Constant::SHUTDOWN])) { + $config->events[Constant::SHUTDOWN] = [OnServer::class, 'onShutdown']; + } $this->onEventListen($this->server, Config::get('server.events', [])); $this->onEventListen($this->server, $config->events); }