改名
This commit is contained in:
+27
-11
@@ -353,20 +353,41 @@ class Server extends Application
|
|||||||
private function onListenerBind($config, $newListener)
|
private function onListenerBind($config, $newListener)
|
||||||
{
|
{
|
||||||
$this->debug(sprintf('Listener %s::%d -> %s', $config['host'], $config['port'], $config['mode']));
|
$this->debug(sprintf('Listener %s::%d -> %s', $config['host'], $config['port'], $config['mode']));
|
||||||
if ($config['type'] == self::HTTP) {
|
if ($config['type'] == self::WEBSOCKET) {
|
||||||
$this->onBind($newListener, 'request', [Snowflake::createObject(OnRequest::class), 'onHandler']);
|
throw new Exception('Base server must instanceof \Swoole\Websocket\Server::class.');
|
||||||
} else if ($config['type'] == self::TCP || $config['type'] == self::PACKAGE) {
|
} else if (!in_array($config['type'], [self::HTTP, self::TCP, self::PACKAGE])) {
|
||||||
|
throw new Exception('Unknown server type(' . $config['type'] . ').');
|
||||||
|
}
|
||||||
if (in_array($config['type'], $this->listenTypes)) {
|
if (in_array($config['type'], $this->listenTypes)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->listenTypes[] = $config['type'];
|
if ($config['type'] == self::HTTP) {
|
||||||
|
if (in_array($config['type'], $this->listenTypes)) {
|
||||||
|
throw new Exception('Base server must instanceof \Swoole\Websocket\Server::class.');
|
||||||
|
}
|
||||||
|
$this->onBind($newListener, 'request', [Snowflake::createObject(OnRequest::class), 'onHandler']);
|
||||||
|
} else {
|
||||||
|
$this->noHttp($newListener, $config);
|
||||||
|
}
|
||||||
|
array_push($this->listenTypes, $config['type']);
|
||||||
|
}
|
||||||
|
|
||||||
$this->onBind($newListener, 'connect', [Snowflake::createObject(OnConnect::class), 'onHandler']);
|
|
||||||
$this->onBind($newListener, 'close', [Snowflake::createObject(OnClose::class), 'onHandler']);
|
/**
|
||||||
|
* @param $newListener
|
||||||
|
* @param $config
|
||||||
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function noHttp($newListener, $config)
|
||||||
|
{
|
||||||
$class = [
|
$class = [
|
||||||
'pack' => $config['resolve']['pack'] ?? null,
|
'pack' => $config['resolve']['pack'] ?? null,
|
||||||
'unpack' => $config['resolve']['unpack'] ?? null
|
'unpack' => $config['resolve']['unpack'] ?? null
|
||||||
];
|
];
|
||||||
|
$this->onBind($newListener, 'connect', [Snowflake::createObject(OnConnect::class), 'onHandler']);
|
||||||
|
$this->onBind($newListener, 'close', [Snowflake::createObject(OnClose::class), 'onHandler']);
|
||||||
if ($config['type'] == self::TCP) {
|
if ($config['type'] == self::TCP) {
|
||||||
$class['class'] = OnReceive::class;
|
$class['class'] = OnReceive::class;
|
||||||
$callback = Snowflake::createObject($class);
|
$callback = Snowflake::createObject($class);
|
||||||
@@ -376,11 +397,6 @@ class Server extends Application
|
|||||||
$callback = Snowflake::createObject($class);
|
$callback = Snowflake::createObject($class);
|
||||||
$this->onBind($newListener, 'packet', [$callback, 'onHandler']);
|
$this->onBind($newListener, 'packet', [$callback, 'onHandler']);
|
||||||
}
|
}
|
||||||
} else if ($config['type'] == self::WEBSOCKET) {
|
|
||||||
throw new Exception('Base server must instanceof \Swoole\Websocket\Server::class.');
|
|
||||||
} else {
|
|
||||||
throw new Exception('Unknown server type(' . $config['type'] . ').');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user