From 3110e69350d0f071f89c730660e429db41705bb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Fri, 19 Nov 2021 17:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kiri-engine/Error/LoggerAspect.php | 37 +++++++++++------------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/kiri-engine/Error/LoggerAspect.php b/kiri-engine/Error/LoggerAspect.php index ea616de2..0f217f0f 100644 --- a/kiri-engine/Error/LoggerAspect.php +++ b/kiri-engine/Error/LoggerAspect.php @@ -5,8 +5,9 @@ namespace Kiri\Error; use Exception; +use Http\Aspect\OnAspectInterface; +use Http\Aspect\OnJoinPointInterface; use Http\Constrict\RequestInterface; -use Kiri\IAspect; use Kiri\Kiri; @@ -14,20 +15,24 @@ use Kiri\Kiri; * Class LoggerAspect * @package Kiri\Error */ -class LoggerAspect implements IAspect +class LoggerAspect implements OnAspectInterface { - private float $time; - /** - * @param mixed $handler - * @param array $params + * @param OnJoinPointInterface $joinPoint * @return mixed + * @throws Exception */ - public function invoke(mixed $handler, array $params = []): mixed + public function process(OnJoinPointInterface $joinPoint): mixed { - return call_user_func($handler, ...$params); + $time = microtime(true); + + $response = $joinPoint->process(); + + $this->print_runtime($time); + + return $response; } @@ -44,20 +49,4 @@ class LoggerAspect implements IAspect echo PHP_EOL; } - - public function before(): void - { - // TODO: Implement before() method. - $this->time = microtime(true); - } - - - /** - * @throws Exception - */ - public function after(mixed $response): void - { - // TODO: Implement after() method. - $this->print_runtime($this->time); - } }