60 lines
1.3 KiB
PHP
60 lines
1.3 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\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;
|
|
}
|
|
} |