diff --git a/src/http-server/src/HttpContext.php b/src/http-server/src/HttpContext.php index d47e693e1..d354d7f67 100644 --- a/src/http-server/src/HttpContext.php +++ b/src/http-server/src/HttpContext.php @@ -13,9 +13,9 @@ /** * Class HttpContext * - * @Bean(scope=Bean::PROTOTYPE) - * * @since 2.0 + * + * @Bean(scope=Bean::PROTOTYPE) */ class HttpContext extends AbstractContext { @@ -43,7 +43,7 @@ class HttpContext extends AbstractContext */ public static function new(Request $request, Response $response): self { - $instance = self::__instance(); + $instance = self::__instance(); $instance->request = $request; $instance->response = $response; diff --git a/src/http-server/src/Swoole/RequestListener.php b/src/http-server/src/Swoole/RequestListener.php index 9af1b16a6..f8b5e72ae 100644 --- a/src/http-server/src/Swoole/RequestListener.php +++ b/src/http-server/src/Swoole/RequestListener.php @@ -9,7 +9,7 @@ use Swoft\Http\Message\Request as ServerRequest; use Swoft\Http\Message\Response as ServerResponse; use Swoft\Http\Server\HttpDispatcher; -use Swoft\Server\Swoole\RequestInterface; +use Swoft\Server\Contract\RequestInterface; use Swoole\Http\Request; use Swoole\Http\Response; diff --git a/src/rpc-server/src/Swoole/CloseListener.php b/src/rpc-server/src/Swoole/CloseListener.php index 062c9f9da..bc6159d7d 100644 --- a/src/rpc-server/src/Swoole/CloseListener.php +++ b/src/rpc-server/src/Swoole/CloseListener.php @@ -8,7 +8,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\Exception\ContainerException; use Swoft\Rpc\Server\ServiceServerEvent; -use Swoft\Server\Swoole\CloseInterface; +use Swoft\Server\Contract\CloseInterface; use Swoole\Server; /** diff --git a/src/rpc-server/src/Swoole/ConnectListener.php b/src/rpc-server/src/Swoole/ConnectListener.php index ed2ccc4d9..04d9a22f3 100644 --- a/src/rpc-server/src/Swoole/ConnectListener.php +++ b/src/rpc-server/src/Swoole/ConnectListener.php @@ -8,7 +8,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\Exception\ContainerException; use Swoft\Rpc\Server\ServiceServerEvent; -use Swoft\Server\Swoole\ConnectInterface; +use Swoft\Server\Contract\ConnectInterface; use Swoole\Server; /** diff --git a/src/rpc-server/src/Swoole/ReceiveListener.php b/src/rpc-server/src/Swoole/ReceiveListener.php index 5f07a6c02..b1da5b203 100644 --- a/src/rpc-server/src/Swoole/ReceiveListener.php +++ b/src/rpc-server/src/Swoole/ReceiveListener.php @@ -12,7 +12,7 @@ use Swoft\Rpc\Server\Request; use Swoft\Rpc\Server\Response; use Swoft\Rpc\Server\ServiceDispatcher; -use Swoft\Server\Swoole\ReceiveInterface; +use Swoft\Server\Contract\ReceiveInterface; use Swoole\Server; /** diff --git a/src/server/src/AutoLoader.php b/src/server/src/AutoLoader.php new file mode 100644 index 000000000..8bce41c84 --- /dev/null +++ b/src/server/src/AutoLoader.php @@ -0,0 +1,33 @@ + __DIR__, + ]; + } + + /** + * @return array + */ + public function metadata(): array + { + return []; + } +} \ No newline at end of file diff --git a/src/server/src/Context/ShutdownContext.php b/src/server/src/Context/ShutdownContext.php new file mode 100644 index 000000000..d8aa9d2b6 --- /dev/null +++ b/src/server/src/Context/ShutdownContext.php @@ -0,0 +1,53 @@ +server = $server; + + return $self; + } + + /** + * @return SwooleServer + */ + public function getSwooleServer(): SwooleServer + { + return $this->server; + } +} \ No newline at end of file diff --git a/src/server/src/Context/StartContext.php b/src/server/src/Context/StartContext.php new file mode 100644 index 000000000..b0c9641f1 --- /dev/null +++ b/src/server/src/Context/StartContext.php @@ -0,0 +1,53 @@ +server = $server; + + return $self; + } + + /** + * @return SwooleServer + */ + public function getSwooleServer(): SwooleServer + { + return $this->server; + } +} \ No newline at end of file diff --git a/src/server/src/Context/WorkerErrorContext.php b/src/server/src/Context/WorkerErrorContext.php new file mode 100644 index 000000000..cbb740e81 --- /dev/null +++ b/src/server/src/Context/WorkerErrorContext.php @@ -0,0 +1,114 @@ +server = $server; + $self->workerId = $workerId; + $self->workerPid = $workerPid; + $self->exitCode = $exitCode; + $self->sigal = $signal; + + return $self; + } + + /** + * @return SwooleServer + */ + public function getSwooleServer(): SwooleServer + { + return $this->server; + } + + /** + * @return int + */ + public function getWorkerId(): int + { + return $this->workerId; + } + + /** + * @return int + */ + public function getWorkerPid(): int + { + return $this->workerPid; + } + + /** + * @return int + */ + public function getExitCode(): int + { + return $this->exitCode; + } + + /** + * @return int + */ + public function getSigal(): int + { + return $this->sigal; + } +} \ No newline at end of file diff --git a/src/server/src/Context/WorkerStartContext.php b/src/server/src/Context/WorkerStartContext.php new file mode 100644 index 000000000..81e7acdf0 --- /dev/null +++ b/src/server/src/Context/WorkerStartContext.php @@ -0,0 +1,68 @@ +server = $server; + $self->workerId = $workerId; + + return $self; + } + + /** + * @return SwooleServer + */ + public function getSwooleServer(): SwooleServer + { + return $this->server; + } + + /** + * @return int + */ + public function getWorkerId(): int + { + return $this->workerId; + } +} \ No newline at end of file diff --git a/src/server/src/Context/WorkerStopContext.php b/src/server/src/Context/WorkerStopContext.php new file mode 100644 index 000000000..d94f71089 --- /dev/null +++ b/src/server/src/Context/WorkerStopContext.php @@ -0,0 +1,68 @@ +server = $server; + $self->workerId = $workerId; + + return $self; + } + + /** + * @return SwooleServer + */ + public function getSwooleServer(): SwooleServer + { + return $this->server; + } + + /** + * @return int + */ + public function getWorkerId(): int + { + return $this->workerId; + } +} \ No newline at end of file diff --git a/src/server/src/Contract/CloseInterface.php b/src/server/src/Contract/CloseInterface.php new file mode 100644 index 000000000..d4c450b2c --- /dev/null +++ b/src/server/src/Contract/CloseInterface.php @@ -0,0 +1,27 @@ +getParams(); + $context = ShutdownContext::new($server); + + if (Log::getLogger()->isEnable()) { + $data = [ + 'event' => ServerEvent::BEFORE_SHUTDOWN_EVENT, + 'uri' => '', + 'requestTime' => microtime(true), + ]; + $context->setMulti($data); + } + + Context::set($context); + } +} \ No newline at end of file diff --git a/src/server/src/Listener/BeforeStartEventListener.php b/src/server/src/Listener/BeforeStartEventListener.php new file mode 100644 index 000000000..3168f1208 --- /dev/null +++ b/src/server/src/Listener/BeforeStartEventListener.php @@ -0,0 +1,48 @@ +getParams(); + $context = StartContext::new($server); + + if (Log::getLogger()->isEnable()) { + $data = [ + 'event' => ServerEvent::BEFORE_START_EVENT, + 'uri' => '', + 'requestTime' => microtime(true), + ]; + $context->setMulti($data); + } + + Context::set($context); + } +} \ No newline at end of file diff --git a/src/server/src/Listener/BeforeWorkerErrorListener.php b/src/server/src/Listener/BeforeWorkerErrorListener.php new file mode 100644 index 000000000..391af55f1 --- /dev/null +++ b/src/server/src/Listener/BeforeWorkerErrorListener.php @@ -0,0 +1,48 @@ +getParams(); + + $context = WorkerErrorContext::new($server, $workerId, $workerPid, $exitCode, $signal); + if (Log::getLogger()->isEnable()) { + $data = [ + 'event' => ServerEvent::BEFORE_WORKER_ERROR_EVENT, + 'uri' => (string)$workerId, + 'requestTime' => microtime(true), + ]; + $context->setMulti($data); + } + + Context::set($context); + } +} \ No newline at end of file diff --git a/src/server/src/Listener/BeforeWorkerStartListener.php b/src/server/src/Listener/BeforeWorkerStartListener.php new file mode 100644 index 000000000..a3ea930ab --- /dev/null +++ b/src/server/src/Listener/BeforeWorkerStartListener.php @@ -0,0 +1,48 @@ +getParams(); + $context = WorkerStartContext::new($server, $workerId); + + if (Log::getLogger()->isEnable()) { + $data = [ + 'event' => ServerEvent::BEFORE_WORKER_START_EVENT, + 'uri' => (string)$workerId, + 'requestTime' => microtime(true), + ]; + $context->setMulti($data); + } + + Context::set($context); + } +} \ No newline at end of file diff --git a/src/server/src/Listener/BeforeWorkerStopListener.php b/src/server/src/Listener/BeforeWorkerStopListener.php new file mode 100644 index 000000000..cbf4b27f8 --- /dev/null +++ b/src/server/src/Listener/BeforeWorkerStopListener.php @@ -0,0 +1,50 @@ +getParams(); + $context = WorkerStopContext::new($server, $workerId); + + if (Log::getLogger()->isEnable()) { + $data = [ + 'event' => ServerEvent::BEFORE_WORKER_STOP_EVENT, + 'uri' => (string)$workerId, + 'requestTime' => microtime(true), + ]; + $context->setMulti($data); + } + + Context::set($context); + } + +} \ No newline at end of file diff --git a/src/server/src/Server.php b/src/server/src/Server.php index 010fac5e2..fa47d2f4e 100644 --- a/src/server/src/Server.php +++ b/src/server/src/Server.php @@ -9,6 +9,7 @@ use Swoft\Console\Console; use Swoft\Http\Server\HttpServer; use Swoft\Log\Helper\CLog; +use Swoft\Server\Contract\ServerInterface; use Swoft\Server\Event\ServerStartEvent; use Swoft\Server\Event\WorkerEvent; use Swoft\Server\Exception\ServerException; @@ -258,7 +259,14 @@ public function onStart(CoServer $server): void // Use `go` to open coroutine sgo(function () use ($server) { + // Before + Swoft::trigger(ServerEvent::BEFORE_START_EVENT, $this, $server); + + // Trigger Swoft::trigger(new ServerStartEvent(SwooleEvent::START, $server), $this); + + // After event + Swoft::trigger(ServerEvent::AFTER_EVENT, $this); }, false); } @@ -278,7 +286,7 @@ public function onManagerStart(CoServer $server): void Sys::setProcessTitle(sprintf('%s manager process', $this->pidName)); // Swoole no supported to open coroutine - Swoft::trigger(new ServerStartEvent(SwooleEvent::MANAGER_START, $server), $this); + Swoft::trigger(new ServerStartEvent(SwooleEvent::MANAGER_START, $server), $this); } /** @@ -311,9 +319,14 @@ public function onShutdown(CoServer $server): void // Use `Scheduler` to open coroutine srun(function () use ($server) { + // Before + Swoft::trigger(ServerEvent::BEFORE_SHUTDOWN_EVENT, $this, $server); // Trigger event - Swoft::trigger(new ServerStartEvent(SwooleEvent::SHUTDOWN, $server)); + Swoft::trigger(new ServerStartEvent(SwooleEvent::SHUTDOWN, $server), $this); + + // After event + Swoft::trigger(ServerEvent::AFTER_EVENT, $this); }); } @@ -354,8 +367,14 @@ public function onWorkerStart(CoServer $server, int $workerId): void Sys::setProcessTitle(sprintf('%s %s process', $this->pidName, $procRole)); + // Before + Swoft::trigger(ServerEvent::BEFORE_WORKER_START_EVENT, $this, $server, $workerId); + // Already in coroutine - Swoft::trigger($newEvent); + Swoft::trigger($newEvent, $this); + + // After event + Swoft::trigger(ServerEvent::AFTER_EVENT, $this); } /** @@ -374,9 +393,15 @@ public function onWorkerStop(CoServer $server, int $workerId): void $event->taskProcess = $workerId >= $server->setting['worker_num']; // Use `Scheduler` to open coroutine - srun(function () use ($event) { + srun(function () use ($event, $server, $workerId) { + // Before + Swoft::trigger(ServerEvent::BEFORE_WORKER_STOP_EVENT, $this, $server, $workerId); + // Trigger - Swoft::trigger($event); + Swoft::trigger($event, $this); + + // After event + Swoft::trigger(ServerEvent::AFTER_EVENT, $this); }); } @@ -403,8 +428,23 @@ public function onWorkerError(CoServer $server, int $workerId, int $workerPid, i ]); // Use `Scheduler` to open coroutine - srun(function () use ($event) { - Swoft::trigger($event); + srun(function () use ($event, $workerId, $workerPid, $exitCode, $signal) { + $params = [ + $event, + $workerId, + $workerPid, + $exitCode, + $signal + ]; + + // Before + Swoft::trigger(ServerEvent::BEFORE_WORKER_ERROR_EVENT, $this, ...$params); + + // Trigger + Swoft::trigger($event, $this); + + // After event + Swoft::trigger(ServerEvent::AFTER_EVENT, $this); }); } diff --git a/src/server/src/ServerEvent.php b/src/server/src/ServerEvent.php index 95f57bb10..083e59ea6 100644 --- a/src/server/src/ServerEvent.php +++ b/src/server/src/ServerEvent.php @@ -58,4 +58,34 @@ final class ServerEvent * on user process start event */ public const USER_PROCESS_START = 'swoft.process.user.start'; + + /** + * Before after event + */ + public const AFTER_EVENT = 'swoft.server.event.after'; + + /** + * Before shutdown event + */ + public const BEFORE_SHUTDOWN_EVENT = 'swoft.server.event.shutdown.before'; + + /** + * Before start event + */ + public const BEFORE_START_EVENT = 'swoft.server.event.start.before'; + + /** + * Before worker error event + */ + public const BEFORE_WORKER_ERROR_EVENT = 'swoft.server.event.worker.error.before'; + + /** + * Before worker start event + */ + public const BEFORE_WORKER_START_EVENT = 'swoft.server.event.worker.start.before'; + + /** + * Before worker stop event + */ + public const BEFORE_WORKER_STOP_EVENT = 'swoft.server.event.worker.stop.before'; } diff --git a/src/server/src/Swoole/CloseInterface.php b/src/server/src/Swoole/CloseInterface.php index a68f797e5..ed4ce2cf5 100644 --- a/src/server/src/Swoole/CloseInterface.php +++ b/src/server/src/Swoole/CloseInterface.php @@ -2,24 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface CloseInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\CloseInterface' for instead. */ -interface CloseInterface +interface CloseInterface extends \Swoft\Server\Contract\CloseInterface { - /** - * Close event - * - * on connection closed - * - you can do something. eg. record log - * - * @param Server $server - * @param int $fd - * @param int $reactorId - */ - public function onClose(Server $server, int $fd, int $reactorId): void; } diff --git a/src/server/src/Swoole/ConnectInterface.php b/src/server/src/Swoole/ConnectInterface.php index 748b929cb..17bb6f8f0 100644 --- a/src/server/src/Swoole/ConnectInterface.php +++ b/src/server/src/Swoole/ConnectInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface ConnectInterface * * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\ConnectInterface' for instead. */ -interface ConnectInterface +interface ConnectInterface extends \Swoft\Server\Contract\ConnectInterface { - /** - * Connect event - * - * @param Server $server - * @param int $fd - * @param int $reactorId - */ - public function onConnect(Server $server, int $fd, int $reactorId): void; } diff --git a/src/server/src/Swoole/FinishInterface.php b/src/server/src/Swoole/FinishInterface.php index 9a0cc111e..b1af468bc 100644 --- a/src/server/src/Swoole/FinishInterface.php +++ b/src/server/src/Swoole/FinishInterface.php @@ -2,21 +2,13 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface FinishInterface * - * @since 2.0 + * @since 2.0 + * + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\FinishInterface' for instead. */ -interface FinishInterface +interface FinishInterface extends \Swoft\Server\Contract\FinishInterface { - /** - * Finish event - * - * @param Server $server - * @param int $taskId - * @param string $data - */ - public function onFinish(Server $server, int $taskId, string $data): void; } \ No newline at end of file diff --git a/src/server/src/Swoole/HandshakeInterface.php b/src/server/src/Swoole/HandshakeInterface.php index 2de8cc0ed..f85b35b98 100644 --- a/src/server/src/Swoole/HandshakeInterface.php +++ b/src/server/src/Swoole/HandshakeInterface.php @@ -2,22 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Http\Request; -use Swoole\Http\Response; - /** * Interface HandshakeInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\HandshakeInterface' for instead. */ -interface HandshakeInterface +interface HandshakeInterface extends \Swoft\Server\Contract\HandshakeInterface { - /** - * Ws Handshake event - * - * @param Request $request - * @param Response $response - * @return bool - */ - public function onHandshake(Request $request, Response $response): bool; } diff --git a/src/server/src/Swoole/MessageInterface.php b/src/server/src/Swoole/MessageInterface.php index 84727ed13..4ed644048 100644 --- a/src/server/src/Swoole/MessageInterface.php +++ b/src/server/src/Swoole/MessageInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Websocket\Frame; -use Swoole\Websocket\Server; - /** * Interface MessageInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\MessageInterface' for instead. */ -interface MessageInterface +interface MessageInterface extends \Swoft\Server\Contract\MessageInterface { - /** - * Message event - * - * @param Server $server - * @param Frame $frame - */ - public function onMessage(Server $server, Frame $frame): void; } diff --git a/src/server/src/Swoole/OpenInterface.php b/src/server/src/Swoole/OpenInterface.php index 056e90fcb..b0743de1e 100644 --- a/src/server/src/Swoole/OpenInterface.php +++ b/src/server/src/Swoole/OpenInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoft\Http\Message\Request; -use Swoole\Websocket\Server; - /** * Interface OpenInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\OpenInterface' for instead. */ -interface OpenInterface +interface OpenInterface extends \Swoft\Server\Contract\OpenInterface { - /** - * Open event - * - * @param Server $server - * @param Request $request - */ - public function onOpen(Server $server, Request $request): void; } diff --git a/src/server/src/Swoole/PacketInterface.php b/src/server/src/Swoole/PacketInterface.php index 620a68144..ca203955b 100644 --- a/src/server/src/Swoole/PacketInterface.php +++ b/src/server/src/Swoole/PacketInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface PacketInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\PacketInterface' for instead. */ -interface PacketInterface +interface PacketInterface extends \Swoft\Server\Contract\PacketInterface { - /** - * Packet event - * - * @param Server $server - * @param string $data - * @param array $clientInfo - */ - public function onPacket(Server $server, string $data, array $clientInfo): void; } \ No newline at end of file diff --git a/src/server/src/Swoole/PipeMessageInterface.php b/src/server/src/Swoole/PipeMessageInterface.php index 9e4a9e364..cfdca98fe 100644 --- a/src/server/src/Swoole/PipeMessageInterface.php +++ b/src/server/src/Swoole/PipeMessageInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface PipeMessageInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\PipeMessageInterface' for instead. */ -interface PipeMessageInterface +interface PipeMessageInterface extends \Swoft\Server\Contract\PipeMessageInterface { - /** - * Pipe message event - * - * @param Server $server - * @param int $srcWorkerId - * @param mixed $message - */ - public function onPipeMessage(Server $server, int $srcWorkerId, $message): void; } \ No newline at end of file diff --git a/src/server/src/Swoole/ReceiveInterface.php b/src/server/src/Swoole/ReceiveInterface.php index 42a3ba2df..7602993d7 100644 --- a/src/server/src/Swoole/ReceiveInterface.php +++ b/src/server/src/Swoole/ReceiveInterface.php @@ -2,22 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface ReceiveInterface * * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\ReceiveInterface' for instead. */ -interface ReceiveInterface +interface ReceiveInterface extends \Swoft\Server\Contract\ReceiveInterface { - /** - * Receive event - * - * @param Server $server - * @param int $fd - * @param int $reactorId - * @param string $data - */ - public function onReceive(Server $server, int $fd, int $reactorId, string $data): void; } diff --git a/src/server/src/Swoole/RequestInterface.php b/src/server/src/Swoole/RequestInterface.php index bfcd78fcb..4b440957b 100644 --- a/src/server/src/Swoole/RequestInterface.php +++ b/src/server/src/Swoole/RequestInterface.php @@ -2,21 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Http\Request; -use Swoole\Http\Response; - /** * Interface RequestInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\RequestInterface' for instead. */ -interface RequestInterface +interface RequestInterface extends \Swoft\Server\Contract\RequestInterface { - /** - * Request event - * - * @param Request $request - * @param Response $response - */ - public function onRequest(Request $request, Response $response): void; } diff --git a/src/server/src/Swoole/SwooleEvent.php b/src/server/src/Swoole/SwooleEvent.php index e61c53fcb..93209ddfa 100644 --- a/src/server/src/Swoole/SwooleEvent.php +++ b/src/server/src/Swoole/SwooleEvent.php @@ -1,123 +1,16 @@ RequestInterface::class, - // For websocket server - self::HANDSHAKE => HandshakeInterface::class, - self::MESSAGE => MessageInterface::class, - // For tcp server - self::CLOSE => CloseInterface::class, - self::RECEIVE => ReceiveInterface::class, - self::CONNECT => ConnectInterface::class, - // For udp server - self::PACKET => PacketInterface::class, - // For task - self::TASK => TaskInterface::class, - self::FINISH => FinishInterface::class, - // For process - self::PIPE_MESSAGE => PipeMessageInterface::class, - ]; -} +} \ No newline at end of file diff --git a/src/server/src/Swoole/TaskInterface.php b/src/server/src/Swoole/TaskInterface.php index 2ecaa60b4..47f140e65 100644 --- a/src/server/src/Swoole/TaskInterface.php +++ b/src/server/src/Swoole/TaskInterface.php @@ -2,24 +2,12 @@ namespace Swoft\Server\Swoole; -use Swoole\Server; - /** * Interface TaskInterface * - * @since 2.0 + * @since 2.0 + * @deprecated since Swoft 2.0.4, use '\Swoft\Server\Contract\TaskInterface' for instead. */ -interface TaskInterface +interface TaskInterface extends \Swoft\Server\Contract\TaskInterface { - /** - * Task event - * - * @param Server $server - * @param int $taskId - * @param int $srcWorkerId - * @param mixed $data - * - * @return mixed - */ -// public function onTask(Server $server, $taskId, int $srcWorkerId, $data); } diff --git a/src/server/src/SwooleEvent.php b/src/server/src/SwooleEvent.php new file mode 100644 index 000000000..115c287c6 --- /dev/null +++ b/src/server/src/SwooleEvent.php @@ -0,0 +1,135 @@ + RequestInterface::class, + // For websocket server + self::HANDSHAKE => HandshakeInterface::class, + self::MESSAGE => MessageInterface::class, + // For tcp server + self::CLOSE => CloseInterface::class, + self::RECEIVE => ReceiveInterface::class, + self::CONNECT => ConnectInterface::class, + // For udp server + self::PACKET => PacketInterface::class, + // For task + self::TASK => TaskInterface::class, + self::FINISH => FinishInterface::class, + // For process + self::PIPE_MESSAGE => PipeMessageInterface::class, + ]; +} \ No newline at end of file diff --git a/src/task/src/Swoole/FinishListener.php b/src/task/src/Swoole/FinishListener.php index efe524fab..005d8ea31 100644 --- a/src/task/src/Swoole/FinishListener.php +++ b/src/task/src/Swoole/FinishListener.php @@ -7,7 +7,7 @@ use function go; use Swoft; use Swoft\Bean\Annotation\Mapping\Bean; -use Swoft\Server\Swoole\FinishInterface; +use Swoft\Server\Contract\FinishInterface; use Swoft\Task\TaskEvent; use Swoole\Server; diff --git a/src/task/src/Swoole/TaskListener.php b/src/task/src/Swoole/TaskListener.php index a03604889..34fa471fd 100644 --- a/src/task/src/Swoole/TaskListener.php +++ b/src/task/src/Swoole/TaskListener.php @@ -8,7 +8,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\BeanFactory; use Swoft\Bean\Exception\ContainerException; -use Swoft\Server\Swoole\TaskInterface; +use Swoft\Server\Contract\TaskInterface; use Swoft\Task\Exception\TaskException; use Swoft\Task\Request; use Swoft\Task\Response; diff --git a/src/tcp-server/src/Swoole/CloseListener.php b/src/tcp-server/src/Swoole/CloseListener.php index 3d8335c2c..1aa5ed6f4 100644 --- a/src/tcp-server/src/Swoole/CloseListener.php +++ b/src/tcp-server/src/Swoole/CloseListener.php @@ -8,14 +8,13 @@ use Swoft\Bean\BeanFactory; use Swoft\Bean\Exception\ContainerException; use Swoft\Context\Context; -use Swoft\Server\Swoole\CloseInterface; +use Swoft\Server\Contract\CloseInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; -use Swoft\Tcp\Server\TcpDispatcher; -use Swoft\Tcp\Server\TcpErrorDispatcher; -use Swoft\Tcp\Server\TcpServerEvent; use Swoft\Tcp\Server\Connection; use Swoft\Tcp\Server\Context\TcpCloseContext; +use Swoft\Tcp\Server\TcpErrorDispatcher; +use Swoft\Tcp\Server\TcpServerEvent; use Swoole\Server; use Throwable; diff --git a/src/tcp-server/src/Swoole/ConnectListener.php b/src/tcp-server/src/Swoole/ConnectListener.php index f663c3bc4..0e4be51aa 100644 --- a/src/tcp-server/src/Swoole/ConnectListener.php +++ b/src/tcp-server/src/Swoole/ConnectListener.php @@ -7,7 +7,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\Exception\ContainerException; use Swoft\Context\Context; -use Swoft\Server\Swoole\ConnectInterface; +use Swoft\Server\Contract\ConnectInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; use Swoft\Tcp\Server\Connection; diff --git a/src/tcp-server/src/Swoole/ReceiveListener.php b/src/tcp-server/src/Swoole/ReceiveListener.php index 433ea0bfc..cc551e36c 100644 --- a/src/tcp-server/src/Swoole/ReceiveListener.php +++ b/src/tcp-server/src/Swoole/ReceiveListener.php @@ -4,13 +4,12 @@ use ReflectionException; use Swoft; -use Swoft\Bean\BeanFactory; +use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\Exception\ContainerException; use Swoft\Context\Context; +use Swoft\Server\Contract\ReceiveInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; -use Swoft\Tcp\Server\Connection; -use Swoft\Tcp\Server\Context\TcpCloseContext; use Swoft\Tcp\Server\Context\TcpReceiveContext; use Swoft\Tcp\Server\Request; use Swoft\Tcp\Server\Response; @@ -18,8 +17,6 @@ use Swoft\Tcp\Server\TcpErrorDispatcher; use Swoft\Tcp\Server\TcpServerEvent; use Swoole\Server; -use Swoft\Bean\Annotation\Mapping\Bean; -use Swoft\Server\Swoole\ReceiveInterface; use Throwable; /** diff --git a/src/websocket-server/src/Swoole/CloseListener.php b/src/websocket-server/src/Swoole/CloseListener.php index 2bf69ee94..e73627e9f 100644 --- a/src/websocket-server/src/Swoole/CloseListener.php +++ b/src/websocket-server/src/Swoole/CloseListener.php @@ -6,7 +6,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\BeanFactory; use Swoft\Context\Context; -use Swoft\Server\Swoole\CloseInterface; +use Swoft\Server\Contract\CloseInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; use Swoft\WebSocket\Server\Connection; diff --git a/src/websocket-server/src/Swoole/HandshakeListener.php b/src/websocket-server/src/Swoole/HandshakeListener.php index ccda8061a..f4f9ebb96 100644 --- a/src/websocket-server/src/Swoole/HandshakeListener.php +++ b/src/websocket-server/src/Swoole/HandshakeListener.php @@ -11,7 +11,7 @@ use Swoft\Context\Context; use Swoft\Http\Message\Request as Psr7Request; use Swoft\Http\Message\Response as Psr7Response; -use Swoft\Server\Swoole\HandshakeInterface; +use Swoft\Server\Contract\HandshakeInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; use Swoft\WebSocket\Server\Connection; diff --git a/src/websocket-server/src/Swoole/MessageListener.php b/src/websocket-server/src/Swoole/MessageListener.php index b4cba14fb..5701e83d6 100644 --- a/src/websocket-server/src/Swoole/MessageListener.php +++ b/src/websocket-server/src/Swoole/MessageListener.php @@ -6,7 +6,7 @@ use Swoft\Bean\Annotation\Mapping\Bean; use Swoft\Bean\BeanFactory; use Swoft\Context\Context; -use Swoft\Server\Swoole\MessageInterface; +use Swoft\Server\Contract\MessageInterface; use Swoft\Session\Session; use Swoft\SwoftEvent; use Swoft\WebSocket\Server\Context\WsMessageContext;