From 7d3e8109925e6e4cf1801e4f2618e077ad5bac57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 29 Oct 2021 14:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RpcJsonp.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/RpcJsonp.php b/src/RpcJsonp.php index 0a0c8e3..e5222c8 100644 --- a/src/RpcJsonp.php +++ b/src/RpcJsonp.php @@ -9,8 +9,11 @@ use Kiri\Abstracts\Component; use Kiri\Abstracts\Config; use Kiri\Consul\Agent; use Kiri\Di\NoteManager; +use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; use Kiri\Kiri; +use Server\Events\OnStart; +use Server\ServerManager; use Server\SInterface\OnCloseInterface; use Server\SInterface\OnConnectInterface; use Server\SInterface\OnReceiveInterface; @@ -33,12 +36,18 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa #[Inject(Annotation::class)] public Annotation $annotation; + + #[Inject(EventProvider::class)] + public EventProvider $eventProvider; + /** * * @throws \Exception */ public function init(): void { + $this->eventProvider->on(OnStart::class, [$this, 'register']); + $this->annotation->read(APP_PATH . 'rpc', 'Rpc'); $data = $this->annotation->runtime(APP_PATH . 'rpc'); @@ -58,21 +67,20 @@ class RpcJsonp extends Component implements OnConnectInterface, OnReceiveInterfa } } } - $this->register(); } /** * @throws ConfigException */ - public function register() + public function register(Server $server) { $config = Config::get('rpc'); $agent = Kiri::getDi()->get(Agent::class); $data = $agent->service->register($config['registry']['config']); if ($data->getStatusCode() != 200) { - exit($data->getBody()->getContents()); + $server->shutdown(); } }