feat : Proxy Subject and Database
This commit is contained in:
44
app/Service/Test/Proxy/DynamicProxyService.php
Normal file
44
app/Service/Test/Proxy/DynamicProxyService.php
Normal 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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user