From b0b7906135f9dd7cf96fa91005ea84973b8de135 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 20 Jun 2022 17:31:04 +0800 Subject: [PATCH] modify plugin name --- Abstracts/CoroutineServer.php | 12 ++++++++---- Abstracts/TraitServer.php | 8 +++++--- Server.php | 7 ++++--- ServerInterface.php | 2 +- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Abstracts/CoroutineServer.php b/Abstracts/CoroutineServer.php index ab64d4a..9ae354f 100644 --- a/Abstracts/CoroutineServer.php +++ b/Abstracts/CoroutineServer.php @@ -5,9 +5,7 @@ namespace Kiri\Server\Abstracts; use Kiri\Abstracts\Config; use Kiri\Di\ContainerInterface; use Kiri\Events\EventDispatch; -use Kiri\Exception\ConfigException; use Kiri\Server\Constant; -use Kiri\Server\Events\OnShutdown; use Kiri\Server\Events\OnWorkerStart; use Kiri\Server\Events\OnWorkerStop; use Kiri\Server\ServerInterface; @@ -55,10 +53,16 @@ class CoroutineServer implements ServerInterface /** * @param string $name - * @return Server|\Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server|null + * @return Server|Coroutine\Server|Coroutine\Http\Server|null */ - public function getServer(string $name): Server|\Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server|null + public function getServer(string $name = ''): Server|Coroutine\Server|Coroutine\Http\Server|null { + if (empty($this->servers)) { + return null; + } + if (empty($name)) { + return current($this->servers); + } return $this->servers[$name] ?? null; } diff --git a/Abstracts/TraitServer.php b/Abstracts/TraitServer.php index 596cf5a..2bac9f5 100644 --- a/Abstracts/TraitServer.php +++ b/Abstracts/TraitServer.php @@ -16,12 +16,14 @@ trait TraitServer /** - * @param $class + * @param array $class * @return void */ - public function addProcess($class): void + public function addProcess(array $class): void { - $this->_process[] = $class; + foreach ($class as $key => $item) { + $this->_process[] = $item; + } } diff --git a/Server.php b/Server.php index 78f0ae7..5da11ac 100644 --- a/Server.php +++ b/Server.php @@ -35,6 +35,7 @@ use Kiri\Message\Constrict\Response; use Kiri\Message\Constrict\Request; use Kiri\Server\Abstracts\ProcessManager; use Kiri\Server\Abstracts\AsyncServer; +use Kiri\Server\Abstracts\CoroutineServer; defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid'); @@ -54,7 +55,7 @@ class Server extends HttpService /** * @param State $state - * @param AsyncServer $manager + * @param Abstracts\CoroutineServer $manager * @param ContainerInterface $container * @param ProcessManager $processManager * @param EventDispatch $dispatch @@ -64,7 +65,7 @@ class Server extends HttpService * @throws Exception */ public function __construct(public State $state, - public AsyncServer $manager, + public CoroutineServer $manager, public ContainerInterface $container, public ProcessManager $processManager, public EventDispatch $dispatch, @@ -129,7 +130,7 @@ class Server extends HttpService $this->onHotReload(); - $this->processManager->batch($this->process, $this->manager->getServer()); + $this->manager->addProcess($this->process); $this->dispatch->dispatch(new OnServerBeforeStart()); $this->manager->start(); } diff --git a/ServerInterface.php b/ServerInterface.php index d94d313..e371bbb 100644 --- a/ServerInterface.php +++ b/ServerInterface.php @@ -16,7 +16,7 @@ interface ServerInterface * @param string $name * @return Server|\Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server|null */ - public function getServer(string $name): Server|\Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server|null; + public function getServer(string $name = ''): Server|\Swoole\Coroutine\Server|\Swoole\Coroutine\Http\Server|null; /**