diff --git a/app/Controller/Test/AdapterTestController.php b/app/Controller/Test/AdapterTestController.php index 7ba2925..eae229c 100644 --- a/app/Controller/Test/AdapterTestController.php +++ b/app/Controller/Test/AdapterTestController.php @@ -4,13 +4,14 @@ declare(strict_types=1); namespace App\Controller\Test; +use App\Controller\AbstractController; use App\Service\Test\Adapter\CacheService; use App\Service\Test\Adapter\PayService; use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\RequestMapping; #[Controller(prefix: 'adapter/test')] -class AdapterTestController +class AdapterTestController extends AbstractController { /** * pay 适配器 diff --git a/app/Controller/Test/DecoratorController.php b/app/Controller/Test/DecoratorController.php new file mode 100644 index 0000000..24a7383 --- /dev/null +++ b/app/Controller/Test/DecoratorController.php @@ -0,0 +1,42 @@ +handle(); + } + + public function container() + { + return (new ContainerService)->handle(); + } + + public function aop() + { + return (new AopService)->handle(); + } + + public function http() + { + return (new HttpService)->handle(); + } +} diff --git a/app/Interface/Test/Adapter/PaymentGateway.php b/app/Interface/Test/Adapter/PaymentGatewayInterface.php similarity index 73% rename from app/Interface/Test/Adapter/PaymentGateway.php rename to app/Interface/Test/Adapter/PaymentGatewayInterface.php index 1237322..ea498af 100644 --- a/app/Interface/Test/Adapter/PaymentGateway.php +++ b/app/Interface/Test/Adapter/PaymentGatewayInterface.php @@ -2,7 +2,7 @@ namespace App\Interface\Test\Adapter; -interface PaymentGateway +interface PaymentGatewayInterface { public function pay(float $amount): array; } \ No newline at end of file diff --git a/app/Interface/Test/Decorator/ComponentInterface.php b/app/Interface/Test/Decorator/ComponentInterface.php new file mode 100644 index 0000000..d11dcda --- /dev/null +++ b/app/Interface/Test/Decorator/ComponentInterface.php @@ -0,0 +1,12 @@ +return->success(); } diff --git a/app/Service/Test/Decorator/Basic/BasicDecorator.php b/app/Service/Test/Decorator/Basic/BasicDecorator.php new file mode 100644 index 0000000..e3815e9 --- /dev/null +++ b/app/Service/Test/Decorator/Basic/BasicDecorator.php @@ -0,0 +1,40 @@ +component = $component; + } + + /** + * 装饰器基类 + * @return string + */ + public function operation(): string + { + return $this->component->operation(); + } +} \ No newline at end of file diff --git a/app/Service/Test/Decorator/Basic/ConcreteComponentService.php b/app/Service/Test/Decorator/Basic/ConcreteComponentService.php new file mode 100644 index 0000000..1cabb36 --- /dev/null +++ b/app/Service/Test/Decorator/Basic/ConcreteComponentService.php @@ -0,0 +1,26 @@ +return->success('success',[ + 'simple' => $simple->operation(), + 'decorator1' => $decorator1->operation(), + 'decorator2' => $decorator2->operation() + ]); + } +} \ No newline at end of file diff --git a/app/Service/Test/Decorator/ContainerService.php b/app/Service/Test/Decorator/ContainerService.php new file mode 100644 index 0000000..d823430 --- /dev/null +++ b/app/Service/Test/Decorator/ContainerService.php @@ -0,0 +1,22 @@ +return->success(); + } +} \ No newline at end of file diff --git a/app/Service/Test/Decorator/HttpService.php b/app/Service/Test/Decorator/HttpService.php new file mode 100644 index 0000000..055f86d --- /dev/null +++ b/app/Service/Test/Decorator/HttpService.php @@ -0,0 +1,22 @@ +return->success(); + } +} \ No newline at end of file diff --git a/request/test.http b/request/test.http index daa9d50..de9029f 100644 --- a/request/test.http +++ b/request/test.http @@ -10,4 +10,9 @@ account=13632877014&password=123456 ### Adapter cache test GET {{host}}/adapter/test/cache +Content-Type: application/x-www-form-urlencoded + + +### Decorator basic test +GET {{host}}/decorator/test/basic Content-Type: application/x-www-form-urlencoded \ No newline at end of file