feat : Decorator Aop
This commit is contained in:
@@ -2,11 +2,13 @@
|
||||
|
||||
namespace App\Aspect;
|
||||
|
||||
use App\Interface\Test\Decorator\LoggerInterface;
|
||||
use App\Lib\Return\AdminReturn;
|
||||
use App\Lib\Return\CommonReturn;
|
||||
use App\Lib\Return\TestReturn;
|
||||
use Hyperf\Context\Context;
|
||||
use Hyperf\Di\Annotation\Aspect;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Di\Aop\AbstractAspect;
|
||||
use Hyperf\Di\Aop\ProceedingJoinPoint;
|
||||
use Hyperf\Di\Exception\Exception;
|
||||
@@ -31,6 +33,12 @@ class CommonReturnAspect extends AbstractAspect
|
||||
*/
|
||||
public array $annotations = [];
|
||||
|
||||
/**
|
||||
* @var LoggerInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
/**
|
||||
* 依赖注入容器
|
||||
* @param RequestInterface $request
|
||||
@@ -49,8 +57,6 @@ class CommonReturnAspect extends AbstractAspect
|
||||
*/
|
||||
public function process(ProceedingJoinPoint $proceedingJoinPoint): mixed
|
||||
{
|
||||
echo 1;
|
||||
var_dump(1);
|
||||
// 在调用前进行处理
|
||||
$result = $proceedingJoinPoint->process();
|
||||
// 在调用后进行处理
|
||||
@@ -70,8 +76,8 @@ class CommonReturnAspect extends AbstractAspect
|
||||
*/
|
||||
private function writeResponseLog(string $content): void
|
||||
{
|
||||
echo json_encode($this->request->all());
|
||||
echo $this->userId;
|
||||
echo json_encode($content);
|
||||
$this->logger->log('返回切入请求体:'.json_encode($this->request->all()));
|
||||
$this->logger->log('返回切入用户id:'.$this->userId);
|
||||
$this->logger->log('返回切入返回体:'.$content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user