Files
hyperf_test/app/Controller/Test/DecoratorController.php
2025-09-07 10:15:57 +08:00

58 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Controller\Test;
use App\Controller\AbstractController;
use App\Service\Test\Decorator\AopService;
use App\Service\Test\Decorator\BasicService;
use App\Service\Test\Decorator\ContainerService;
use App\Service\Test\Decorator\HttpService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
#[Controller(prefix: 'decorator/test')]
class DecoratorController extends AbstractController
{
/**
* basic 装饰器
* @return array
*/
#[RequestMapping(path: 'basic', methods: 'GET')]
public function basic(): array
{
return (new BasicService)->handle();
}
/**
* container 装饰器(依赖注入)
* @return array
*/
#[RequestMapping(path: 'container', methods: 'GET')]
public function container(): array
{
return (new ContainerService)->handle();
}
/**
* aop 装饰器(切面)
* @return array
*/
#[RequestMapping(path: 'aop', methods: 'GET')]
public function aop(): array
{
return (new AopService)->handle();
}
/**
* http 装饰器
* @return array
*/
#[RequestMapping(path: 'http', methods: 'GET')]
public function http(): array
{
return (new HttpService)->handle();
}
}