改名
This commit is contained in:
+15
-24
@@ -19,6 +19,7 @@ use ReflectionException;
|
|||||||
use Snowflake\Abstracts\Config;
|
use Snowflake\Abstracts\Config;
|
||||||
use Snowflake\Core\Json;
|
use Snowflake\Core\Json;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
|
use Snowflake\Exception\ComponentException;
|
||||||
use Snowflake\Exception\ConfigException;
|
use Snowflake\Exception\ConfigException;
|
||||||
use Snowflake\Exception\NotFindClassException;
|
use Snowflake\Exception\NotFindClassException;
|
||||||
use Snowflake\Process\Biomonitoring;
|
use Snowflake\Process\Biomonitoring;
|
||||||
@@ -338,6 +339,9 @@ class Server extends HttpService
|
|||||||
*/
|
*/
|
||||||
private function dispatchCreate($config, $settings): \Swoole\Server|Packet|Receive|Http|Websocket|null
|
private function dispatchCreate($config, $settings): \Swoole\Server|Packet|Receive|Http|Websocket|null
|
||||||
{
|
{
|
||||||
|
if ($this->isUse($config['port'])) {
|
||||||
|
return $this->error_stop($config['host'], $config['port']);
|
||||||
|
}
|
||||||
if (!($this->baseServer instanceof \Swoole\Server)) {
|
if (!($this->baseServer instanceof \Swoole\Server)) {
|
||||||
return $this->parseServer($config, $settings);
|
return $this->parseServer($config, $settings);
|
||||||
}
|
}
|
||||||
@@ -354,10 +358,6 @@ class Server extends HttpService
|
|||||||
*/
|
*/
|
||||||
private function addListener($config): Packet|Websocket|Receive|Http|null
|
private function addListener($config): Packet|Websocket|Receive|Http|null
|
||||||
{
|
{
|
||||||
if ($this->isUse($config['port'])) {
|
|
||||||
return $this->error_stop($config['host'], $config['port']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$newListener = $this->baseServer->addlistener($config['host'], $config['port'], $config['mode']);
|
$newListener = $this->baseServer->addlistener($config['host'], $config['port'], $config['mode']);
|
||||||
if (!$newListener) {
|
if (!$newListener) {
|
||||||
exit($this->addError(sprintf('Listen %s::%d fail.', $config['host'], $config['port'])));
|
exit($this->addError(sprintf('Listen %s::%d fail.', $config['host'], $config['port'])));
|
||||||
@@ -381,9 +381,6 @@ class Server extends HttpService
|
|||||||
private function parseServer($config, $settings): Packet|Websocket|Receive|Http|null
|
private function parseServer($config, $settings): Packet|Websocket|Receive|Http|null
|
||||||
{
|
{
|
||||||
$class = $this->dispatch($config['type']);
|
$class = $this->dispatch($config['type']);
|
||||||
if ($this->isUse($config['port'])) {
|
|
||||||
return $this->error_stop($config['host'], $config['port']);
|
|
||||||
}
|
|
||||||
if (isset($config['settings']) && !empty($config['settings'])) {
|
if (isset($config['settings']) && !empty($config['settings'])) {
|
||||||
$settings = array_merge($settings, $config['settings']);
|
$settings = array_merge($settings, $config['settings']);
|
||||||
}
|
}
|
||||||
@@ -406,17 +403,14 @@ class Server extends HttpService
|
|||||||
/**
|
/**
|
||||||
* @param $config
|
* @param $config
|
||||||
* @param $newListener
|
* @param $newListener
|
||||||
* @return mixed
|
* @return Packet|Websocket|Receive|Http|null
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws Exception
|
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
|
* @throws ComponentException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function onListenerBind($config, $newListener): mixed
|
private function onListenerBind($config, $newListener): Packet|Websocket|Receive|Http|null
|
||||||
{
|
{
|
||||||
$this->debug(sprintf('Listener %s::%d -> %s', $config['host'], $config['port'], $config['mode']));
|
|
||||||
if ($config['type'] == self::WEBSOCKET) {
|
|
||||||
throw new Exception('Base server must instanceof \Swoole\Websocket\Server::class.');
|
|
||||||
}
|
|
||||||
if (!in_array($config['type'], [self::HTTP, self::TCP, self::PACKAGE])) {
|
if (!in_array($config['type'], [self::HTTP, self::TCP, self::PACKAGE])) {
|
||||||
throw new Exception('Unknown server type(' . $config['type'] . ').');
|
throw new Exception('Unknown server type(' . $config['type'] . ').');
|
||||||
}
|
}
|
||||||
@@ -424,13 +418,11 @@ class Server extends HttpService
|
|||||||
return $this->baseServer;
|
return $this->baseServer;
|
||||||
}
|
}
|
||||||
if ($config['type'] == self::HTTP) {
|
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']);
|
$this->onBind($newListener, 'request', [Snowflake::createObject(OnRequest::class), 'onHandler']);
|
||||||
} else {
|
} else {
|
||||||
$this->noHttp($newListener, $config);
|
$this->noHttp($newListener, $config);
|
||||||
}
|
}
|
||||||
|
$this->debug(sprintf('Listen %s::%d -> ok', $config['host'], $config['port']));
|
||||||
$this->listenTypes[] = $config['type'];
|
$this->listenTypes[] = $config['type'];
|
||||||
return $this->baseServer;
|
return $this->baseServer;
|
||||||
}
|
}
|
||||||
@@ -468,10 +460,10 @@ class Server extends HttpService
|
|||||||
if (in_array($name, $this->listening)) {
|
if (in_array($name, $this->listening)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
array_push($this->listening, $name);
|
||||||
if ($name === 'request') {
|
if ($name === 'request') {
|
||||||
$this->onLoadHttpHandler();
|
$this->onLoadHttpHandler();
|
||||||
}
|
}
|
||||||
array_push($this->listening, $name);
|
|
||||||
$server->on($name, $callback);
|
$server->on($name, $callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -512,13 +504,12 @@ class Server extends HttpService
|
|||||||
*/
|
*/
|
||||||
private function dispatch($type): string
|
private function dispatch($type): string
|
||||||
{
|
{
|
||||||
$default = [
|
return match ($type) {
|
||||||
self::HTTP => Http::class,
|
self::HTTP => Http::class,
|
||||||
self::WEBSOCKET => Websocket::class,
|
self::WEBSOCKET => Websocket::class,
|
||||||
self::TCP => Receive::class,
|
self::PACKAGE => Packet::class,
|
||||||
self::PACKAGE => Packet::class
|
default => Receive::class
|
||||||
];
|
};
|
||||||
return $default[$type] ?? Receive::class;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user