From 0e32a7f4fbbe275e77c6baf77447c94a4d5b5016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Fri, 18 Sep 2020 19:34:10 +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 --- HttpServer/Server.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/HttpServer/Server.php b/HttpServer/Server.php index 61939335..5effa01d 100644 --- a/HttpServer/Server.php +++ b/HttpServer/Server.php @@ -291,13 +291,15 @@ class Server extends Application if ($this->isUse($config['port'])) { return $this->error_stop($config['host'], $config['port']); } + if ($class instanceof Websocket) { + $this->onLoadWebsocketHandler(); + } $this->baseServer = new $class($config['host'], $config['port'], SWOOLE_PROCESS, $config['mode']); $settings['daemonize'] = $this->daemon; if (!isset($settings['pid_file'])) { $settings['pid_file'] = APP_PATH . 'storage/server.pid'; } $this->baseServer->set($settings); - $this->bindAnnotation(); } else { $newListener = $this->baseServer->addlistener($config['host'], $config['port'], $config['mode']); if (isset($config['settings']) && is_array($config['settings'])) { @@ -309,26 +311,13 @@ class Server extends Application } - /** - * @throws Exception - */ - private function bindAnnotation() - { - if ($this->baseServer instanceof Websocket) { - $this->onLoadWebsocketHandler(); - } - if ($this->baseServer instanceof Http) { - $this->onLoadHttpHandler(); - } - } - - /** * @param $config * @param $newListener * @throws NotFindClassException * @throws ReflectionException * @throws Exception + * @return void */ private function onListenerBind($config, $newListener) { @@ -338,6 +327,7 @@ class Server extends Application $this->debug(sprintf('Listener %s::%d', $config['host'], $config['port'])); if ($config['type'] == self::HTTP) { $this->onBind($newListener, 'request', [Snowflake::createObject(OnRequest::class), 'onHandler']); + $this->onLoadHttpHandler(); } else if ($config['type'] == self::TCP || $config['type'] == self::PACKAGE) { $this->onBind($newListener, 'connect', [Snowflake::createObject(OnConnect::class), 'onHandler']); $this->onBind($newListener, 'close', [Snowflake::createObject(OnClose::class), 'onHandler']);