feat : Proxy Subject and Database
This commit is contained in:
60
app/Service/Test/Proxy/Dynamic/DatabaseQueryProxyHandler.php
Normal file
60
app/Service/Test/Proxy/Dynamic/DatabaseQueryProxyHandler.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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\Dynamic;
|
||||
|
||||
use App\Interface\Test\Decorator\LoggerInterface;
|
||||
use App\Interface\Test\Proxy\DatabaseQueryInterface;
|
||||
|
||||
class DatabaseQueryProxyHandler
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @var DatabaseQueryInterface
|
||||
*/
|
||||
private DatabaseQueryInterface $realService;
|
||||
|
||||
/**
|
||||
* @param DatabaseQueryInterface $realService
|
||||
* @param LoggerInterface $logger
|
||||
*/
|
||||
public function __construct(
|
||||
DatabaseQueryInterface $realService,
|
||||
LoggerInterface $logger
|
||||
)
|
||||
{
|
||||
$this->realService = $realService;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DatabaseQueryInterface $target
|
||||
* @param string $method
|
||||
* @param array $parameters
|
||||
* @param LoggerInterface $logger
|
||||
* @return array
|
||||
*/
|
||||
public function execute(string $query): array
|
||||
{
|
||||
$this->logger->log('Before executing query'.PHP_EOL);
|
||||
|
||||
// 调用原始方法
|
||||
$result = $this->realService->execute($query);
|
||||
|
||||
$this->logger->log('After executing query'.PHP_EOL);
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user