From 92dd75b82c5b2e69618ffe270f7fb4b3cdec40e6 Mon Sep 17 00:00:00 2001 From: xl Date: Tue, 3 Sep 2024 14:47:27 +0800 Subject: [PATCH] eee --- Abstracts/AsyncServer.php | 6 - Abstracts/TraitServer.php | 4 +- Events/OnTaskerStart.php | 2 - Handler/OnPipeMessage.php | 1 - Handler/OnRequest.php | 112 -------- Handler/OnServer.php | 1 - Handler/OnServerManager.php | 1 - Handler/OnServerWorker.php | 1 - HotReload.php | 2 +- {Abstracts => Processes}/BaseProcess.php | 269 +++++++++--------- .../OnProcessInterface.php | 50 ++-- ServerCommand.php | 1 - Task/Task.php | 5 - Task/TaskExecute.php | 1 - 14 files changed, 159 insertions(+), 297 deletions(-) delete mode 100644 Handler/OnRequest.php rename {Abstracts => Processes}/BaseProcess.php (85%) rename {Contract => Processes}/OnProcessInterface.php (78%) diff --git a/Abstracts/AsyncServer.php b/Abstracts/AsyncServer.php index 9557f29..ae88192 100644 --- a/Abstracts/AsyncServer.php +++ b/Abstracts/AsyncServer.php @@ -3,7 +3,6 @@ namespace Kiri\Server\Abstracts; use Exception; -use Kiri\Exception\ConfigException; use Kiri\Exception\NotFindClassException; use Kiri\Server\Config as SConfig; use Kiri\Server\Constant; @@ -12,11 +11,6 @@ use Kiri\Server\Events\OnShutdown; use Kiri\Server\Handler\OnServer; use Kiri\Server\ServerInterface; use Kiri\Server\Task\Task; -use Kiri\Di\Inject\Container; -use Psr\Container\ContainerExceptionInterface; -use Psr\Container\ContainerInterface; -use Psr\Container\NotFoundExceptionInterface; -use ReflectionException; use Swoole\Server; use Symfony\Component\Console\Output\OutputInterface; diff --git a/Abstracts/TraitServer.php b/Abstracts/TraitServer.php index 884bd0a..fd4a546 100644 --- a/Abstracts/TraitServer.php +++ b/Abstracts/TraitServer.php @@ -4,14 +4,12 @@ namespace Kiri\Server\Abstracts; use Exception; use Kiri; -use Kiri\Di\Inject\Container; -use Psr\Log\LoggerInterface; use Swoole\Http\Server as HServer; use Swoole\Process; use Swoole\Server; +use Kiri\Server\Processes\BaseProcess; use Kiri\Server\Constant; use Kiri\Server\Config; -use Kiri\Error\StdoutLogger; use Swoole\WebSocket\Server as WServer; trait TraitServer diff --git a/Events/OnTaskerStart.php b/Events/OnTaskerStart.php index c80c6fe..766f8c2 100644 --- a/Events/OnTaskerStart.php +++ b/Events/OnTaskerStart.php @@ -2,9 +2,7 @@ namespace Kiri\Server\Events; -use Kiri\Exception\ConfigException; use Swoole\Server; -use Kiri; /** * diff --git a/Handler/OnPipeMessage.php b/Handler/OnPipeMessage.php index 89126f8..aa606e0 100644 --- a/Handler/OnPipeMessage.php +++ b/Handler/OnPipeMessage.php @@ -2,7 +2,6 @@ namespace Kiri\Server\Handler; -use Exception; use Kiri\Server\Abstracts\Server; use Kiri\Server\Contract\OnPipeMessageInterface; diff --git a/Handler/OnRequest.php b/Handler/OnRequest.php deleted file mode 100644 index 7c24b4c..0000000 --- a/Handler/OnRequest.php +++ /dev/null @@ -1,112 +0,0 @@ -responseEmitter = $this->response->emmit; - $exception = \config('exception.http'); - if (!in_array(ExceptionHandlerInterface::class, class_implements($exception))) { - $exception = ExceptionHandlerDispatcher::class; - } - $this->exception = \Kiri::getDi()->get($exception); - $this->router = $dataGrip->get(ROUTER_TYPE_HTTP); - } - - - /** - * @param Request $request - * @param Response $response - * @throws - */ - public function onRequest(Request $request, Response $response): void - { - /** @var CQ $PsrRequest */ - try { - $PsrRequest = $this->initRequestAndResponse($request); - - $PsrResponse = $this->router->query($request->server['path_info'], $request->getMethod()) - ->run($PsrRequest); - } catch (Throwable $throwable) { - $PsrResponse = $this->exception->emit($throwable, $this->constrictResponse); - } finally { - $this->responseEmitter->response($PsrResponse, $response, $PsrRequest); - } - } - - - /** - * @param Request $request - * @return ServerRequestInterface - */ - public function initRequestAndResponse(Request $request): ServerRequestInterface - { - $response = new ConstrictResponse($this->response->contentType); - - Context::set(ResponseInterface::class, $response); - - return Context::set(RequestInterface::class, CQ::builder($request)); - } - -} diff --git a/Handler/OnServer.php b/Handler/OnServer.php index b3971f1..128e6e6 100644 --- a/Handler/OnServer.php +++ b/Handler/OnServer.php @@ -6,7 +6,6 @@ use Kiri; use Kiri\Di\Inject\Container; use Kiri\Error\StdoutLogger; use Psr\Log\LoggerInterface; -use ReflectionException; use Kiri\Server\Abstracts\Server; use Kiri\Server\Events\OnBeforeShutdown; use Kiri\Server\Events\OnShutdown; diff --git a/Handler/OnServerManager.php b/Handler/OnServerManager.php index 22b3711..9625751 100644 --- a/Handler/OnServerManager.php +++ b/Handler/OnServerManager.php @@ -3,7 +3,6 @@ namespace Kiri\Server\Handler; use Kiri; -use ReflectionException; use Kiri\Server\Abstracts\Server; use Kiri\Server\Events\OnManagerStart; use Kiri\Server\Events\OnManagerStop; diff --git a/Handler/OnServerWorker.php b/Handler/OnServerWorker.php index 001d1ca..6523cfa 100644 --- a/Handler/OnServerWorker.php +++ b/Handler/OnServerWorker.php @@ -13,7 +13,6 @@ use Kiri\Server\Events\OnWorkerExit; use Kiri\Server\Events\OnWorkerStart; use Kiri\Server\Events\OnWorkerStop; use Swoole\Server; -use Kiri\Di\Inject\Container; use Swoole\Timer; use Throwable; use function config; diff --git a/HotReload.php b/HotReload.php index 4c7eff2..4c5133c 100644 --- a/HotReload.php +++ b/HotReload.php @@ -5,8 +5,8 @@ namespace Kiri\Server; use Kiri\Di\Context; use Kiri\Router\Router; -use Kiri\Server\Abstracts\BaseProcess; use Kiri\Server\Events\OnWorkerStart; +use Kiri\Server\Processes\BaseProcess; use Swoole\Coroutine; use Swoole\Event; use Swoole\Process; diff --git a/Abstracts/BaseProcess.php b/Processes/BaseProcess.php similarity index 85% rename from Abstracts/BaseProcess.php rename to Processes/BaseProcess.php index 8c18ed1..0f74da3 100644 --- a/Abstracts/BaseProcess.php +++ b/Processes/BaseProcess.php @@ -1,137 +1,132 @@ -enable_queue; - } - - - /** - * @return string - */ - public function getName(): string - { - if (empty($this->name)) { - $this->name = uniqid('p.'); - } - return $this->name; - } - - - /** - * @return bool - */ - public function isStop(): bool - { - return $this->stop; - } - - /** - * @return bool - */ - public function getRedirectStdinAndStdout(): bool - { - return $this->redirect_stdin_and_stdout; - } - - /** - * @return int - */ - public function getPipeType(): int - { - return $this->pipe_type; - } - - /** - * @return bool - */ - public function isEnableCoroutine(): bool - { - return $this->enable_coroutine; - } - - - /** - * - */ - public function stop(): void - { - $this->stop = true; - } - - - /** - * @return $this - */ - abstract public function onSigterm(): static; - - - /** - * @param $data - * @return void - */ - protected function onShutdown($data): void - { - $this->stop = true; - $value = Context::get('waite:process:message'); - \Kiri::getLogger()->alert('Process ' . $this->getName() . ' stop'); - if (!is_null($value) && Coroutine::exists((int)$value)) { - Coroutine::cancel((int)$value); - } - } - - -} +enable_queue; + } + + + /** + * @return string + */ + public function getName(): string + { + if (empty($this->name)) { + $this->name = uniqid('p.'); + } + return $this->name; + } + + + /** + * @return bool + */ + public function isStop(): bool + { + return $this->stop; + } + + /** + * @return bool + */ + public function getRedirectStdinAndStdout(): bool + { + return $this->redirect_stdin_and_stdout; + } + + /** + * @return int + */ + public function getPipeType(): int + { + return $this->pipe_type; + } + + /** + * @return bool + */ + public function isEnableCoroutine(): bool + { + return $this->enable_coroutine; + } + + + /** + * + */ + public function stop(): void + { + $this->stop = true; + } + + + /** + * @return $this + */ + abstract public function onSigterm(): static; + + + /** + * @param $data + * @return void + */ + protected function onShutdown($data): void + { + $this->stop = true; + $value = Context::get('waite:process:message'); + \Kiri::getLogger()->alert('Process ' . $this->getName() . ' stop'); + if (!is_null($value) && Coroutine::exists((int)$value)) { + Coroutine::cancel((int)$value); + } + } + + +} diff --git a/Contract/OnProcessInterface.php b/Processes/OnProcessInterface.php similarity index 78% rename from Contract/OnProcessInterface.php rename to Processes/OnProcessInterface.php index 264ad1e..6002794 100644 --- a/Contract/OnProcessInterface.php +++ b/Processes/OnProcessInterface.php @@ -1,25 +1,25 @@ -