From 6c378d4b712730faaf818b9691264e4b835b0bde Mon Sep 17 00:00:00 2001 From: bingcool <2437667702@qq.com> Date: Thu, 13 Apr 2023 19:41:50 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86af?= =?UTF-8?q?terHandle=E8=B0=83=E7=94=A8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Core/Crontab/AbstractCronController.php | 1 + src/Core/EventController.php | 16 +++++++++++----- src/Core/ServiceDispatch.php | 3 +++ src/Core/Swoole.php | 6 ++---- src/Core/Timer/Tick.php | 4 ++++ src/Http/HttpAppServer.php | 5 ++++- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/Core/Crontab/AbstractCronController.php b/src/Core/Crontab/AbstractCronController.php index bf6af885..d2afe65e 100644 --- a/src/Core/Crontab/AbstractCronController.php +++ b/src/Core/Crontab/AbstractCronController.php @@ -64,6 +64,7 @@ public function runCron(string $cronName, string $expression, ?callable $func = call_user_func($func, $cronName, $expression); } else { $this->doCronTask($cron, $cronName); + $this->afterHandle(); } if (!$this->isDefer()) { diff --git a/src/Core/EventController.php b/src/Core/EventController.php index 00288116..768d3fa2 100644 --- a/src/Core/EventController.php +++ b/src/Core/EventController.php @@ -12,7 +12,6 @@ namespace Swoolefy\Core; use Swoolefy\Core\Coroutine\CoroutineManager; -use Swoolefy\Exception\SystemException; /** * Class EventController @@ -188,6 +187,17 @@ public function isDefer() return $this->isDefer; } + /** + * afterHandle + */ + public function afterHandle() + { + // call after action + $this->_afterAction(); + // callHooks + $this->callAfterEventHook(); + } + /** * end unset var * @return bool|void @@ -199,10 +209,6 @@ public function end() } // set End $this->setEnd(); - // call hook callable - static::_afterAction(); - // callHooks - $this->callAfterEventHook(); // handle log $this->handleLog(); // remove diff --git a/src/Core/ServiceDispatch.php b/src/Core/ServiceDispatch.php index 9864bd6d..8991f496 100644 --- a/src/Core/ServiceDispatch.php +++ b/src/Core/ServiceDispatch.php @@ -85,6 +85,9 @@ public function dispatch() $serviceInstance->{$action}($this->params); // after Call $serviceInstance->_afterAction($action); + // call hook callable + Hook::callHook(Hook::HOOK_AFTER_REQUEST); + } else { $this->errorHandle($class, $action, 'error500'); return false; diff --git a/src/Core/Swoole.php b/src/Core/Swoole.php index 6e2d73cb..8c078dc3 100644 --- a/src/Core/Swoole.php +++ b/src/Core/Swoole.php @@ -102,8 +102,8 @@ public function bootstrap(mixed $payload) /** * run instance - * @param int $fd - * @param mixed $input + * @param int|null $fd + * @param mixed $payload * @param array $extendData * @return void */ @@ -283,8 +283,6 @@ protected function defer() */ public function end() { - // call hook callable - Hook::callHook(Hook::HOOK_AFTER_REQUEST); // log handle $this->handleLog(); // remove diff --git a/src/Core/Timer/Tick.php b/src/Core/Timer/Tick.php index a0e97880..cc6cdfc0 100644 --- a/src/Core/Timer/Tick.php +++ b/src/Core/Timer/Tick.php @@ -74,6 +74,8 @@ protected static function tick(int $timeIntervalMs, \Closure|array $func, array $tickTaskInstance = new TickController(); call_user_func($func, $params, $timerId); } + // call after action + $tickTaskInstance->afterHandle(); } catch (\Throwable $throwable) { BaseServer::catchException($throwable); } finally { @@ -181,6 +183,8 @@ protected static function after(int $timeIntervalMs, \Closure|array $func, array $tickTaskInstance = new TickController; call_user_func($func, $params, $timer_id); } + // call after action + $tickTaskInstance->afterHandle(); } catch (\Throwable $throwable) { BaseServer::catchException($throwable); } finally { diff --git a/src/Http/HttpAppServer.php b/src/Http/HttpAppServer.php index ef7969b6..531e409b 100644 --- a/src/Http/HttpAppServer.php +++ b/src/Http/HttpAppServer.php @@ -87,11 +87,14 @@ public function onTask($server, $task_id, $from_worker_id, $data, $task = null) $taskInstance->setFromWorkerId((int)$from_worker_id); $task && $taskInstance->setTask($task); $taskInstance->$action($taskData); + $taskInstance->afterHandle(); unset($callable, $extendData, $fd); } catch (\Throwable $throwable) { - $taskInstance->end(); + if(!$taskInstance->isDefer()) { + $taskInstance->end(); + } throw $throwable; } }