diff --git a/Server/Events/OnShutdown.php b/Server/Events/OnShutdown.php index 11f67136..75a432c5 100644 --- a/Server/Events/OnShutdown.php +++ b/Server/Events/OnShutdown.php @@ -9,9 +9,9 @@ class OnShutdown /** - * @param Server $server + * @param Server|null $server */ - public function __construct(Server $server) + public function __construct(?Server $server = null) { } diff --git a/http-helper/Server.php b/http-helper/Server.php index ba366f6e..819e68a2 100644 --- a/http-helper/Server.php +++ b/http-helper/Server.php @@ -3,17 +3,20 @@ namespace Http; +use Annotation\Inject; use Exception; use Http\Abstracts\HttpService; use JetBrains\PhpStorm\Pure; use Kiri\Abstracts\Config; use Kiri\Error\LoggerProcess; +use Kiri\Events\EventDispatch; use Kiri\Exception\ConfigException; use Kiri\Exception\NotFindClassException; use Kiri\Process\Biomonitoring; use ReflectionException; use Rpc\Service; use Server\Constant; +use Server\Events\OnShutdown; use Server\ServerManager; use Swoole\Runtime; @@ -37,6 +40,11 @@ class Server extends HttpService private mixed $daemon = 0; + /** @var EventDispatch */ + #[Inject(EventDispatch::class)] + public EventDispatch $eventDispatch; + + /** * */ @@ -126,6 +134,7 @@ class Server extends HttpService foreach ($configs['ports'] ?? [] as $config) { $this->manager->stopServer($config['port']); } + $this->eventDispatch->dispatch(new OnShutdown()); }