Files
hyperf_test/app/Service/Test/Proxy/DynamicProxyService.php

44 lines
1.1 KiB
PHP

<?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'));
}
}