feat : Proxy Subject and Database
This commit is contained in:
67
app/Service/Test/Proxy/Subject/ProxyService.php
Normal file
67
app/Service/Test/Proxy/Subject/ProxyService.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\Subject;
|
||||
|
||||
use App\Interface\Test\Decorator\LoggerInterface;
|
||||
use App\Interface\Test\Proxy\SubjectInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class ProxyService implements SubjectInterface
|
||||
{
|
||||
/**
|
||||
* @var RealSubjectService
|
||||
*/
|
||||
protected RealSubjectService $realSubjectService;
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* 注入真实类
|
||||
* @param RealSubjectService $realSubjectService
|
||||
*/
|
||||
public function __construct(RealSubjectService $realSubjectService)
|
||||
{
|
||||
$this->realSubjectService = $realSubjectService;
|
||||
}
|
||||
|
||||
public function request(): void
|
||||
{
|
||||
if (!$this->checkAccess()) return;
|
||||
|
||||
$this->realSubjectService->request();
|
||||
$this->logAcces();
|
||||
|
||||
if ($this->checkAccess()) return;
|
||||
$this->logAcces();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true
|
||||
*/
|
||||
private function checkAccess()
|
||||
{
|
||||
$this->logger->log('Proxy: Checking access prior to firing a real request'.PHP_EOL);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function logAcces()
|
||||
{
|
||||
$this->logger->log('Proxy: Logging the time of request'.PHP_EOL);
|
||||
}
|
||||
}
|
||||
34
app/Service/Test/Proxy/Subject/RealSubjectService.php
Normal file
34
app/Service/Test/Proxy/Subject/RealSubjectService.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?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\Subject;
|
||||
|
||||
use App\Interface\Test\Decorator\LoggerInterface;
|
||||
use App\Interface\Test\Proxy\SubjectInterface;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class RealSubjectService implements SubjectInterface
|
||||
{
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function request(): void
|
||||
{
|
||||
$res = 'RealSubjectService: Handling request...'.PHP_EOL;
|
||||
$this->logger->log($res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user