modify plugin name

This commit is contained in:
2022-06-16 17:49:06 +08:00
parent 0051f1f15c
commit 35ce71a8cc
6 changed files with 120 additions and 125 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
<?php <?php
namespace Kiri\Server; namespace Kiri\Server\Abstracts;
use Exception; use Exception;
use Kiri; use Kiri;
+1 -5
View File
@@ -1,24 +1,20 @@
<?php <?php
namespace Kiri\Server; namespace Kiri\Server\Abstracts;
use Closure; use Closure;
use Kiri; use Kiri;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Annotation\Inject;
use Kiri\Context; use Kiri\Context;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Exception\ConfigException; use Kiri\Exception\ConfigException;
use Kiri\Server\Abstracts\BaseProcess;
use Kiri\Server\Broadcast\Message; use Kiri\Server\Broadcast\Message;
use Kiri\Server\Contract\OnProcessInterface; use Kiri\Server\Contract\OnProcessInterface;
use Kiri\Server\Events\OnProcessStart; use Kiri\Server\Events\OnProcessStart;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Swoole\Coroutine;
use Swoole\Process; use Swoole\Process;
use Kiri\Server\Events\OnProcessStop; use Kiri\Server\Events\OnProcessStop;
use Kiri\Di\ContainerInterface; use Kiri\Di\ContainerInterface;
use Swoole\Timer;
class ProcessManager class ProcessManager
{ {
+114 -114
View File
@@ -1,114 +1,114 @@
<?php <?php
namespace Kiri\Server; namespace Kiri\Server\Abstracts;
use Swoole\Http\Server as HServer; use Swoole\Http\Server as HServer;
use Swoole\Server; use Swoole\Server;
use Swoole\WebSocket\Server as WServer; use Swoole\WebSocket\Server as WServer;
trait TraitServer trait TraitServer
{ {
private array $_process = []; private array $_process = [];
/** /**
* @param $class * @param $class
* @return void * @return void
*/ */
public function addProcess($class): void public function addProcess($class): void
{ {
$this->_process[] = $class; $this->_process[] = $class;
} }
/** /**
* @return array * @return array
*/ */
public function getProcess(): array public function getProcess(): array
{ {
return $this->_process; return $this->_process;
} }
/** /**
* @param array $ports * @param array $ports
* @return array * @return array
*/ */
public function sortService(array $ports): array public function sortService(array $ports): array
{ {
$array = []; $array = [];
foreach ($ports as $port) { foreach ($ports as $port) {
if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) {
array_unshift($array, $port); array_unshift($array, $port);
} else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) {
if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) {
$array[] = $port; $array[] = $port;
} else { } else {
array_unshift($array, $port); array_unshift($array, $port);
} }
} else { } else {
$array[] = $port; $array[] = $port;
} }
} }
return $array; return $array;
} }
/** /**
* @param array $ports * @param array $ports
* @return array<Config> * @return array<Config>
*/ */
public function genConfigService(array $ports): array public function genConfigService(array $ports): array
{ {
$array = []; $array = [];
foreach ($ports as $port) { foreach ($ports as $port) {
$config = \Kiri::getDi()->create(Config::class, [], $port); $config = \Kiri::getDi()->create(Config::class, [], $port);
if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) { if ($port['type'] == Constant::SERVER_TYPE_WEBSOCKET) {
array_unshift($array, $config); array_unshift($array, $config);
} else if ($port['type'] == Constant::SERVER_TYPE_HTTP) { } else if ($port['type'] == Constant::SERVER_TYPE_HTTP) {
if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) { if (!empty($array) && $array[0]['type'] == Constant::SERVER_TYPE_WEBSOCKET) {
$array[] = $config; $array[] = $config;
} else { } else {
array_unshift($array, $config); array_unshift($array, $config);
} }
} else { } else {
$array[] = $config; $array[] = $config;
} }
} }
return $array; return $array;
} }
/** /**
* @param $type * @param $type
* @return string|null * @return string|null
*/ */
public function getServerClass($type): ?string public function getServerClass($type): ?string
{ {
return match ($type) { return match ($type) {
Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP,
Constant::SERVER_TYPE_UDP => Server::class, Constant::SERVER_TYPE_UDP => Server::class,
Constant::SERVER_TYPE_HTTP => HServer::class, Constant::SERVER_TYPE_HTTP => HServer::class,
Constant::SERVER_TYPE_WEBSOCKET => WServer::class, Constant::SERVER_TYPE_WEBSOCKET => WServer::class,
default => null default => null
}; };
} }
/** /**
* @param $type * @param $type
* @return string|null * @return string|null
*/ */
public function getCoroutineServerClass($type): ?string public function getCoroutineServerClass($type): ?string
{ {
return match ($type) { return match ($type) {
Constant::SERVER_TYPE_BASE, Constant::SERVER_TYPE_TCP, Constant::SERVER_TYPE_UDP => Server::class, 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, Constant::SERVER_TYPE_HTTP, Constant::SERVER_TYPE_WEBSOCKET => \Swoole\Coroutine\Http\Server::class,
default => null default => null
}; };
} }
} }
+1 -1
View File
@@ -3,8 +3,8 @@
namespace Kiri\Server\Broadcast; namespace Kiri\Server\Broadcast;
use Kiri; use Kiri;
use Kiri\Server\ProcessManager;
use Kiri\Server\ServerInterface; use Kiri\Server\ServerInterface;
use Kiri\Server\Abstracts\ProcessManager;
class Broadcast class Broadcast
{ {
+2 -4
View File
@@ -10,10 +10,6 @@ use Kiri\Abstracts\Config;
use Kiri\Events\EventDispatch; use Kiri\Events\EventDispatch;
use Kiri\Events\EventProvider; use Kiri\Events\EventProvider;
use Kiri\Exception\ConfigException; 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\Abstracts\HttpService;
use Kiri\Message\Handler\Router; use Kiri\Message\Handler\Router;
use Kiri\Server\Events\OnBeforeShutdown; use Kiri\Server\Events\OnBeforeShutdown;
@@ -31,6 +27,8 @@ use Swoole\WebSocket\Server as WsServer;
use Swoole\Server as SServer; use Swoole\Server as SServer;
use Swoole\Http\Server as HServer; use Swoole\Http\Server as HServer;
use Swoole\Coroutine; 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'); defined('PID_PATH') or define('PID_PATH', APP_PATH . 'storage/server.pid');
+1
View File
@@ -5,6 +5,7 @@ namespace Kiri\Server;
use Exception; use Exception;
use Kiri\Abstracts\Component; use Kiri\Abstracts\Component;
use Kiri\Abstracts\Config; use Kiri\Abstracts\Config;
use Kiri\Server\Abstracts\TraitServer;
use Swoole\Process; use Swoole\Process;
class State extends Component class State extends Component