diff --git a/app/Aspect/Test/Proxy/LoggingAspect.php b/app/Aspect/Test/Proxy/LoggingAspect.php new file mode 100644 index 0000000..f639fa7 --- /dev/null +++ b/app/Aspect/Test/Proxy/LoggingAspect.php @@ -0,0 +1,54 @@ +arguments['keys']['amount']; + + $this->logger->log('Attempting payment of '.$amount.' for '.$proceedingJoinPoint->methodName); + + try { + $result = $proceedingJoinPoint->process(); + + $this->logger->log('Payment of '.$amount.'succeeded'); + + return $result; + } catch (Throwable $e) { + $this->logger->error('Payment of '.$amount.' failed: '.$e->getMessage()); + return false; + } + } +} \ No newline at end of file diff --git a/app/Aspect/Test/Proxy/SecurityAspect.php b/app/Aspect/Test/Proxy/SecurityAspect.php new file mode 100644 index 0000000..2595db1 --- /dev/null +++ b/app/Aspect/Test/Proxy/SecurityAspect.php @@ -0,0 +1,53 @@ +request->header('Authorization'); + + if (!$this->validateToken($token)) throw new RuntimeException('Unauthorized'); + + return $proceedingJoinPoint->process(); + } + + /** + * @param string|null $token + * @return bool + */ + private function validateToken(?string $token): bool + { + return $token !== 'valid-token'; + } +} \ No newline at end of file diff --git a/app/Controller/Test/ProxyController.php b/app/Controller/Test/ProxyController.php index 2e5a72b..2653168 100644 --- a/app/Controller/Test/ProxyController.php +++ b/app/Controller/Test/ProxyController.php @@ -4,8 +4,10 @@ declare(strict_types=1); namespace App\Controller\Test; +use App\Service\Test\Proxy\AopService; use App\Service\Test\Proxy\BasicSubjectService; use App\Service\Test\Proxy\DynamicProxyService; +use App\Service\Test\Proxy\Payment\PaymentService; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; use Psr\Container\ContainerExceptionInterface; @@ -33,4 +35,13 @@ class ProxyController { return (new DynamicProxyService)->handle(); } + + /** + * @return array + */ + #[RequestMapping(path: 'payment', methods: 'GET')] + public function payment(): array + { + return (new AopService)->handle(); + } } diff --git a/app/Interface/Test/Proxy/PaymentInterface.php b/app/Interface/Test/Proxy/PaymentInterface.php new file mode 100644 index 0000000..76a67bb --- /dev/null +++ b/app/Interface/Test/Proxy/PaymentInterface.php @@ -0,0 +1,13 @@ +