diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index 006a6fc..6a059b1 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -1,6 +1,6 @@ _process[] = $class; - } - - - /** - * @return array - */ - public function getProcess(): array - { - return $this->_process; - } - - - /** - * @param array $ports - * @return array - */ - public function sortService(array $ports): array - { - $array = []; - foreach ($ports as $port) { - if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { - array_unshift($array, $port); - } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { - if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { - $array[] = $port; - } else { - array_unshift($array, $port); - } - } else { - $array[] = $port; - } - } - return $array; - } - - - /** - * @param array $ports - * @return array - */ - public function genConfigService(array $ports): array - { - $array = []; - foreach ($ports as $port) { - $config = \Kiri::getDi()->create(Config::class, [], $port); - if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { - array_unshift($array, $config); - } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { - if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { - $array[] = $config; - } else { - array_unshift($array, $config); - } - } else { - $array[] = $config; - } - } - return $array; - } - - - /** - * @param $type - * @return string|null - */ - public function getServerClass($type): ?string - { - return match ($type) { - Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, - Constant::SERVER_TYPE_UDP => Server::class, - Constant::SERVER_TYPE_HTTP => HServer::class, - Constant::SERVER_TYPE_WEBSOCKET => WServer::class, - default => null - }; - } - - - /** - * @param $type - * @return string|null - */ - public function getCoroutineServerClass($type): ?string - { - return match ($type) { - Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, Constant::SERVER_TYPE_UDP => Server::class, - Constant::SERVER_TYPE_HTTP, Constant::SERVER_TYPE_WEBSOCKET => \Swoole\Coroutine\Http\Server::class, - default => null - }; - } - - -} +_process[] = $class; + } + + + /** + * @return array + */ + public function getProcess(): array + { + return $this->_process; + } + + + /** + * @param array $ports + * @return array + */ + public function sortService(array $ports): array + { + $array = []; + foreach ($ports as $port) { + if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { + array_unshift($array, $port); + } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { + if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { + $array[] = $port; + } else { + array_unshift($array, $port); + } + } else { + $array[] = $port; + } + } + return $array; + } + + + /** + * @param array $ports + * @return array + */ + public function genConfigService(array $ports): array + { + $array = []; + foreach ($ports as $port) { + $config = \Kiri::getDi()->create(Config::class, [], $port); + if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { + array_unshift($array, $config); + } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { + if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { + $array[] = $config; + } else { + array_unshift($array, $config); + } + } else { + $array[] = $config; + } + } + return $array; + } + + + /** + * @param $type + * @return string|null + */ + public function getServerClass($type): ?string + { + return match ($type) { + Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, + Constant::SERVER_TYPE_UDP => Server::class, + Constant::SERVER_TYPE_HTTP => HServer::class, + Constant::SERVER_TYPE_WEBSOCKET => WServer::class, + default => null + }; + } + + + /** + * @param $type + * @return string|null + */ + public function getCoroutineServerClass($type): ?string + { + return match ($type) { + Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, Constant::SERVER_TYPE_UDP => Server::class, + Constant::SERVER_TYPE_HTTP, Constant::SERVER_TYPE_WEBSOCKET => \Swoole\Coroutine\Http\Server::class, + default => null + }; + } + + +} diff --git a/Broadcast/Broadcast.php b/Broadcast/Broadcast.php index d477517..adc4570 100644 --- a/Broadcast/Broadcast.php +++ b/Broadcast/Broadcast.php @@ -3,8 +3,8 @@ namespace Kiri\Server\Broadcast; use Kiri; -use Kiri\Server\ProcessManager; use Kiri\Server\ServerInterface; +use Kiri\Server\Abstracts\ProcessManager; class Broadcast { diff --git a/Server.php b/Server.php index d44d208..9c2e884 100644 --- a/Server.php +++ b/Server.php @@ -10,10 +10,6 @@ use Kiri\Abstracts\Config; use Kiri\Events\EventDispatch; use Kiri\Events\EventProvider; use Kiri\Exception\ConfigException; -use Kiri\Message\Constrict\Request; -use Kiri\Message\Constrict\RequestInterface; -use Kiri\Message\Constrict\Response; -use Kiri\Message\Constrict\ResponseInterface; use Kiri\Message\Handler\Abstracts\HttpService; use Kiri\Message\Handler\Router; use Kiri\Server\Events\OnBeforeShutdown; @@ -31,6 +27,8 @@ use Swoole\WebSocket\Server as WsServer; use Swoole\Server as SServer; use Swoole\Http\Server as HServer; use Swoole\Coroutine; +use Kiri\Server\Abstracts\ProcessManager; +use Kiri\Server\Abstracts\AsyncServer; defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid'); diff --git a/State.php b/State.php index 8dfa51b..61c9fd5 100644 --- a/State.php +++ b/State.php @@ -5,6 +5,7 @@ namespace Kiri\Server; use Exception; use Kiri\Abstracts\Component; use Kiri\Abstracts\Config; +use Kiri\Server\Abstracts\TraitServer; use Swoole\Process; class State extends Component