diff --git a/core/Abstracts/BaseApplication.php b/core/Abstracts/BaseApplication.php index 6f5b8cc1..fbdcf069 100644 --- a/core/Abstracts/BaseApplication.php +++ b/core/Abstracts/BaseApplication.php @@ -28,7 +28,7 @@ use Kiri\Jwt\Jwt; use Kiri\Kiri; use ReflectionException; use Server\ServerManager; -use Server\SInterface\TaskExecute; +use Server\SInterface\OnTaskInterface; use Swoole\Table; /** @@ -205,10 +205,10 @@ abstract class BaseApplication extends Component /** - * @param TaskExecute $execute + * @param OnTaskInterface $execute * @throws ReflectionException */ - public function task(TaskExecute $execute): void + public function task(OnTaskInterface $execute): void { di(ServerManager::class)->task($execute); } diff --git a/core/Error/LoggerProcess.php b/core/Error/LoggerProcess.php index 7ef8356a..09cfea79 100644 --- a/core/Error/LoggerProcess.php +++ b/core/Error/LoggerProcess.php @@ -11,13 +11,13 @@ use Kiri\Exception\ComponentException; use Kiri\Kiri; use Swoole\Coroutine; use Swoole\Process; -use Server\Abstracts\CustomProcess; +use Server\Abstracts\OnProcessInterface; /** * Class LoggerProcess * @package Kiri\Error */ -class LoggerProcess extends CustomProcess +class LoggerProcess extends OnProcessInterface { /** diff --git a/core/Event.php b/core/Event.php index e6d736b3..067b00f7 100644 --- a/core/Event.php +++ b/core/Event.php @@ -71,7 +71,7 @@ class Event extends BaseObject const SERVER_ON_CLOSE = 'Close'; const SERVER_ON_TASK = 'Task'; const SERVER_ON_FINISH = 'Finish'; - const SERVER_ON_PIPE_MESSAGE = 'PipeMessage'; + const SERVER_ON_PIPE_MESSAGE = 'OnPipeMessageInterface'; const SERVER_ON_WORKER_ERROR = 'WorkerError'; const SERVER_ON_MANAGER_START = 'ManagerStart'; const SERVER_ON_MANAGER_STOP = 'ManagerStop'; diff --git a/core/FileListen/FileChangeCustomProcess.php b/core/FileListen/FileChangeCustomProcess.php index 1aa47593..aea0fd32 100644 --- a/core/FileListen/FileChangeCustomProcess.php +++ b/core/FileListen/FileChangeCustomProcess.php @@ -6,14 +6,14 @@ use Exception; use Kiri\Abstracts\Config; use Kiri\Kiri; use ReflectionException; -use Server\Abstracts\CustomProcess; +use Server\Abstracts\OnProcessInterface; use Swoole\Process; /** * */ -class FileChangeCustomProcess extends CustomProcess +class FileChangeCustomProcess extends OnProcessInterface { diff --git a/http-message/Download.php b/http-message/OnDownload.php similarity index 93% rename from http-message/Download.php rename to http-message/OnDownload.php index 360c8f44..5a447a9b 100644 --- a/http-message/Download.php +++ b/http-message/OnDownload.php @@ -2,10 +2,10 @@ namespace Http\Message; -use Server\SInterface\DownloadInterface; +use Server\SInterface\OnDownloadInterface; -class Download extends Response implements DownloadInterface +class OnDownload extends Response implements OnDownloadInterface { use Message; @@ -34,7 +34,7 @@ class Download extends Response implements DownloadInterface * @param int $offset * @return $this */ - public function path(string $path, bool $isChunk = false, int $size = -1, int $offset = 0): Download + public function path(string $path, bool $isChunk = false, int $size = -1, int $offset = 0): OnDownload { $this->path = $path; $this->isChunk = $isChunk; diff --git a/http-message/Response.php b/http-message/Response.php index 8d85b386..78bce7f1 100644 --- a/http-message/Response.php +++ b/http-message/Response.php @@ -6,7 +6,7 @@ use Exception; use JetBrains\PhpStorm\Pure; use Kiri\Core\Help; use Server\Constrict\ResponseInterface; -use Server\SInterface\DownloadInterface; +use Server\SInterface\OnDownloadInterface; /** @@ -208,15 +208,15 @@ class Response implements ResponseInterface * @param bool $isChunk * @param int $size * @param int $offset - * @return DownloadInterface + * @return OnDownloadInterface * @throws Exception */ - public function file($path, bool $isChunk = false, int $size = -1, int $offset = 0): DownloadInterface + public function file($path, bool $isChunk = false, int $size = -1, int $offset = 0): OnDownloadInterface { $path = realpath($path); if (!file_exists($path) || !is_readable($path)) { throw new Exception('Cannot read file "' . $path . '", no permission'); } - return (new Download())->path($path, $isChunk, $size, $offset); + return (new OnDownload())->path($path, $isChunk, $size, $offset); } } diff --git a/http-server/Abstracts/CustomProcess.php b/http-server/Abstracts/OnProcessInterface.php similarity index 96% rename from http-server/Abstracts/CustomProcess.php rename to http-server/Abstracts/OnProcessInterface.php index 9c741eff..a4c91b30 100644 --- a/http-server/Abstracts/CustomProcess.php +++ b/http-server/Abstracts/OnProcessInterface.php @@ -11,7 +11,7 @@ use Swoole\Process; /** * */ -abstract class CustomProcess implements \Server\SInterface\CustomProcess +abstract class OnProcessInterface implements \Server\SInterface\OnProcessInterface { /** @var bool */ diff --git a/http-server/Constant.php b/http-server/Constant.php index 92802d4e..f02fa02d 100644 --- a/http-server/Constant.php +++ b/http-server/Constant.php @@ -26,7 +26,7 @@ class Constant const CLOSE = 'Close'; const TASK = 'Task'; const FINISH = 'Finish'; - const PIPE_MESSAGE = 'PipeMessage'; + const PIPE_MESSAGE = 'OnPipeMessageInterface'; const WORKER_ERROR = 'WorkerError'; const MANAGER_START = 'ManagerStart'; const MANAGER_STOP = 'ManagerStop'; diff --git a/http-server/Constrict/Response.php b/http-server/Constrict/Response.php index 808c8728..4b92f0d1 100644 --- a/http-server/Constrict/Response.php +++ b/http-server/Constrict/Response.php @@ -14,7 +14,7 @@ use Psr\Http\Message\StreamInterface; use Http\Message\ServerRequest as RequestMessage; use Http\Message\Response as Psr7Response; use Server\ServerManager; -use Server\SInterface\DownloadInterface; +use Server\SInterface\OnDownloadInterface; /** @@ -201,9 +201,9 @@ class Response implements ResponseInterface /** * @param string $path - * @return DownloadInterface + * @return OnDownloadInterface */ - public function file(string $path): DownloadInterface + public function file(string $path): OnDownloadInterface { return $this->__call__()->{__FUNCTION__}($path); } diff --git a/http-server/Constrict/ResponseEmitter.php b/http-server/Constrict/ResponseEmitter.php index 76c41143..e0930306 100644 --- a/http-server/Constrict/ResponseEmitter.php +++ b/http-server/Constrict/ResponseEmitter.php @@ -3,7 +3,7 @@ namespace Server\Constrict; use Annotation\Inject; -use Server\SInterface\DownloadInterface; +use Server\SInterface\OnDownloadInterface; use Swoole\Server; @@ -42,7 +42,7 @@ class ResponseEmitter implements Emitter $response->header('Server', 'swoole'); $response->header('Swoole-Version', swoole_version()); - if (!($emitter instanceof DownloadInterface)) { + if (!($emitter instanceof OnDownloadInterface)) { $response->end($emitter->getBody()->getContents()); } else { $emitter->dispatch($response); diff --git a/http-server/Constrict/ResponseInterface.php b/http-server/Constrict/ResponseInterface.php index 053b97c3..9e4ff784 100644 --- a/http-server/Constrict/ResponseInterface.php +++ b/http-server/Constrict/ResponseInterface.php @@ -5,7 +5,7 @@ namespace Server\Constrict; use JetBrains\PhpStorm\Pure; use Http\Message\Response; -use Server\SInterface\DownloadInterface; +use Server\SInterface\OnDownloadInterface; /** * @mixin Response @@ -16,9 +16,9 @@ interface ResponseInterface extends \Psr\Http\Message\ResponseInterface /** * @param string $path - * @return DownloadInterface + * @return OnDownloadInterface */ - public function file(string $path): DownloadInterface; + public function file(string $path): OnDownloadInterface; /** diff --git a/http-server/Manager/OnPipeMessage.php b/http-server/Manager/OnPipeMessage.php index 853c2b0c..3489656d 100644 --- a/http-server/Manager/OnPipeMessage.php +++ b/http-server/Manager/OnPipeMessage.php @@ -6,7 +6,7 @@ use Annotation\Inject; use Server\Abstracts\Server; use Exception; use Server\Events\OnAfterRequest; -use Server\SInterface\PipeMessage; +use Server\SInterface\OnPipeMessageInterface; use Kiri\Events\EventDispatch; /** @@ -29,7 +29,7 @@ class OnPipeMessage extends Server */ public function onPipeMessage(\Swoole\Server $server, int $src_worker_id, mixed $message) { - if (!is_object($message) || !($message instanceof PipeMessage)) { + if (!is_object($message) || !($message instanceof OnPipeMessageInterface)) { return; } diff --git a/http-server/SInterface/OnClose.php b/http-server/SInterface/OnCloseInterface.php similarity index 57% rename from http-server/SInterface/OnClose.php rename to http-server/SInterface/OnCloseInterface.php index 751bf17a..f60ee7aa 100644 --- a/http-server/SInterface/OnClose.php +++ b/http-server/SInterface/OnCloseInterface.php @@ -8,7 +8,7 @@ use Swoole\Server; /** * */ -interface OnClose +interface OnCloseInterface { @@ -19,11 +19,4 @@ interface OnClose public function onClose(Server $server, int $fd): void; - /** - * @param Server $server - * @param int $fd - */ - public function onDisconnect(Server $server, int $fd): void; - - } diff --git a/http-server/SInterface/OnConnect.php b/http-server/SInterface/OnConnectInterface.php similarity index 87% rename from http-server/SInterface/OnConnect.php rename to http-server/SInterface/OnConnectInterface.php index 951acbbb..8e15c06e 100644 --- a/http-server/SInterface/OnConnect.php +++ b/http-server/SInterface/OnConnectInterface.php @@ -4,7 +4,7 @@ namespace Server\SInterface; use Swoole\Server; -interface OnConnect +interface OnConnectInterface { diff --git a/http-server/SInterface/OnDisconnectInterface.php b/http-server/SInterface/OnDisconnectInterface.php new file mode 100644 index 00000000..8ea0ad08 --- /dev/null +++ b/http-server/SInterface/OnDisconnectInterface.php @@ -0,0 +1,19 @@ + 'receive', + OnPacketInterface::class =>'packet', + OnHandshakeInterface::class => 'handshake', + OnMessageInterface::class =>'message', + OnConnectInterface::class =>'connect', + OnCloseInterface::class =>'close', + OnDisconnectInterface::class =>'disconnect' + ]; + + + /** * @return Server|WServer|HServer|null */ @@ -134,17 +154,17 @@ class ServerManager /** - * @param string|CustomProcess $customProcess + * @param string|OnProcessInterface $customProcess * @param null $redirect_stdin_and_stdout * @param int|null $pipe_type * @param bool $enable_coroutine * @throws Exception */ - public function addProcess(string|CustomProcess $customProcess, $redirect_stdin_and_stdout = null, ?int $pipe_type = SOCK_DGRAM, bool $enable_coroutine = true) + public function addProcess(string|OnProcessInterface $customProcess, $redirect_stdin_and_stdout = null, ?int $pipe_type = SOCK_DGRAM, bool $enable_coroutine = true) { $process = $this->initProcess($customProcess, $redirect_stdin_and_stdout, $pipe_type, $enable_coroutine); $this->server->addProcess($process); - if ($customProcess instanceof CustomProcess) { + if ($customProcess instanceof OnProcessInterface) { Kiri::app()->addProcess($customProcess::class, $process); } else { Kiri::app()->addProcess($customProcess, $process); @@ -445,13 +465,13 @@ class ServerManager /** - * @param TaskExecute|string $handler + * @param OnTaskInterface|string $handler * @param array $params * @param int|null $workerId * @throws ReflectionException * @throws Exception */ - public function task(TaskExecute|string $handler, array $params = [], int $workerId = null) + public function task(OnTaskInterface|string $handler, array $params = [], int $workerId = null) { if ($workerId === null || $workerId <= $this->server->setting['worker_num']) { $workerId = random_int($this->server->setting['worker_num'] + 1, @@ -459,8 +479,8 @@ class ServerManager } if (is_string($handler)) { $implements = $this->container->getReflect($handler); - if (!in_array(TaskExecute::class, $implements->getInterfaceNames())) { - throw new Exception('Task must instance ' . TaskExecute::class); + if (!in_array(OnTaskInterface::class, $implements->getInterfaceNames())) { + throw new Exception('Task must instance ' . OnTaskInterface::class); } $handler = $implements->newInstanceArgs($params); } diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php index 0018d3d9..e58f010d 100644 --- a/http-server/Service/Http.php +++ b/http-server/Service/Http.php @@ -26,9 +26,9 @@ use Server\Constrict\ResponseInterface; use Server\Events\OnAfterRequest; use Server\ExceptionHandlerDispatcher; use Server\ExceptionHandlerInterface; -use Server\SInterface\OnClose; -use Server\SInterface\OnConnect; -use Server\SInterface\OnRequest; +use Server\SInterface\OnCloseInterface; +use Server\SInterface\OnConnectInterface; +use Server\SInterface\OnRequestInterface; use Swoole\Http\Request; use Swoole\Http\Response; use Swoole\Server; @@ -36,7 +36,7 @@ use Swoole\Server; /** * */ -class Http implements OnClose, OnConnect, OnRequest +class Http implements OnCloseInterface, OnConnectInterface, OnRequestInterface { use EventDispatchHelper; diff --git a/http-server/Service/Tcp.php b/http-server/Service/Tcp.php index 76d691b5..b258e7db 100644 --- a/http-server/Service/Tcp.php +++ b/http-server/Service/Tcp.php @@ -10,16 +10,16 @@ use Server\Abstracts\Utility\ResponseHelper; use Server\Constrict\TcpEmitter; use Server\ExceptionHandlerDispatcher; use Server\ExceptionHandlerInterface; -use Server\SInterface\OnClose; -use Server\SInterface\OnConnect; -use Server\SInterface\OnReceive; +use Server\SInterface\OnCloseInterface; +use Server\SInterface\OnConnectInterface; +use Server\SInterface\OnReceiveInterface; use Swoole\Server; /** * */ -class Tcp implements OnConnect, OnClose, OnReceive +class Tcp implements OnConnectInterface, OnCloseInterface, OnReceiveInterface { use EventDispatchHelper; diff --git a/http-server/Service/Udp.php b/http-server/Service/Udp.php index 81c4e81f..be85f41c 100644 --- a/http-server/Service/Udp.php +++ b/http-server/Service/Udp.php @@ -13,13 +13,13 @@ use Server\Abstracts\Utility\ResponseHelper; use Server\Constrict\UdpEmitter; use Server\ExceptionHandlerDispatcher; use Server\ExceptionHandlerInterface; -use Server\SInterface\OnPacket; +use Server\SInterface\OnPacketInterface; /** * */ -class Udp implements OnPacket +class Udp implements OnPacketInterface { use EventDispatchHelper; diff --git a/http-server/Service/WebSocket.php b/http-server/Service/WebSocket.php index 75110398..93297337 100644 --- a/http-server/Service/WebSocket.php +++ b/http-server/Service/WebSocket.php @@ -12,10 +12,10 @@ use Server\Abstracts\Utility\ResponseHelper; use Server\Constrict\WebSocketEmitter; use Server\ExceptionHandlerDispatcher; use Server\ExceptionHandlerInterface; -use Server\SInterface\OnClose; -use Server\SInterface\OnHandshake; -use Server\SInterface\OnMessage; -use Server\SInterface\OnRequest; +use Server\SInterface\OnCloseInterface; +use Server\SInterface\OnHandshakeInterface; +use Server\SInterface\OnMessageInterface; +use Server\SInterface\OnRequestInterface; use Swoole\Http\Request; use Swoole\Http\Response; use Swoole\Server; @@ -24,7 +24,7 @@ use Swoole\WebSocket\Frame; /** * */ -class WebSocket implements OnHandshake, OnMessage, OnClose +class WebSocket implements OnHandshakeInterface, OnMessageInterface, OnCloseInterface { @@ -60,7 +60,7 @@ class WebSocket implements OnHandshake, OnMessage, OnClose */ public function onHandshake(Request $request, Response $response): void { - // TODO: Implement OnHandshake() method. + // TODO: Implement OnHandshakeInterface() method. $secWebSocketKey = $request->header['sec-websocket-key']; $patten = '#^[+/0-9A-Za-z]{21}[AQgw]==$#'; if (0 === preg_match($patten, $secWebSocketKey) || 16 !== strlen(base64_decode($secWebSocketKey))) { @@ -91,7 +91,7 @@ class WebSocket implements OnHandshake, OnMessage, OnClose */ public function onMessage(Server $server, Frame $frame): void { - // TODO: Implement OnMessage() method. + // TODO: Implement OnMessageInterface() method. } @@ -101,7 +101,7 @@ class WebSocket implements OnHandshake, OnMessage, OnClose */ public function onClose(Server $server, int $fd): void { - // TODO: Implement OnClose() method. + // TODO: Implement OnCloseInterface() method. } @@ -111,6 +111,6 @@ class WebSocket implements OnHandshake, OnMessage, OnClose */ public function onDisconnect(Server $server, int $fd): void { - // TODO: Implement OnDisconnect() method. + // TODO: Implement OnDisconnectInterface() method. } } diff --git a/http-server/Task/OnServerTask.php b/http-server/Task/OnServerTask.php index f3d56dba..e8b0ac60 100644 --- a/http-server/Task/OnServerTask.php +++ b/http-server/Task/OnServerTask.php @@ -12,7 +12,7 @@ use Server\Constrict\Response; use Server\Constrict\ResponseInterface; use Server\ExceptionHandlerDispatcher; use Server\ExceptionHandlerInterface; -use Server\SInterface\TaskExecute; +use Server\SInterface\OnTaskInterface; use Swoole\Server; @@ -108,7 +108,7 @@ class OnServerTask */ public function onFinish(Server $server, int $task_id, mixed $data) { - if (!($data instanceof TaskExecute)) { + if (!($data instanceof OnTaskInterface)) { return; } $data->finish($server, $task_id); diff --git a/kiri-gii/GiiTask.php b/kiri-gii/GiiTask.php index 2d9f5e24..092718b6 100644 --- a/kiri-gii/GiiTask.php +++ b/kiri-gii/GiiTask.php @@ -31,7 +31,7 @@ class GiiTask extends GiiBase namespace App\Async; -use Server\SInterface\TaskExecute; +use Server\SInterface\OnTaskInterface; ';