feat : Proxy Subject and Database

This commit is contained in:
2025-09-07 11:37:13 +08:00
parent 7d489eecc4
commit 14ba4674ee
11 changed files with 367 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
* @web_site https://ctexthuang.com
*/
declare(strict_types=1);
namespace App\Service\Test\Proxy;
use App\Interface\Test\Decorator\LoggerInterface;
use App\Service\Test\Proxy\Dynamic\DatabaseQueryProxyHandler;
use App\Service\Test\Proxy\Dynamic\RealDatabaseQueryService;
use App\Service\Test\TestBaseService;
use Hyperf\Context\ApplicationContext;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class DynamicProxyService extends TestBaseService
{
/**
* @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function handle(): array
{
$container = ApplicationContext::getContainer();
// 获取真实服务
$realService = $container->get(RealDatabaseQueryService::class);
$proxy = new DatabaseQueryProxyHandler(
$realService,
$container->get(LoggerInterface::class),
);
return $this->return->success('数据查询成功',$proxy->execute('SELECT * FROM user'));
}
}