hyperf aop面向切面编程 - 胡勇健 - D1h.Net第一号博客
返回主页

胡勇健

hyperf aop面向切面编程

控制器 app/Controller/IndexController.php

<?php namespace App\Controller; use App\Service\UserService; use Hyperf\Di\Annotation\Inject; use Hyperf\HttpServer\Annotation\AutoController; /** * @AutoController() */ class IndexController { public function aop(){ return 'aop'; } }

定义切面 app/Aspect/IndexAspect.php

<?php namespace App\Aspect; use App\Controller\IndexController; use Hyperf\Di\Annotation\Aspect; use Hyperf\Di\Aop\AbstractAspect; use Hyperf\Di\Aop\ProceedingJoinPoint; /** * @Aspect() */ class IndexAspect extends AbstractAspect { public $classes = [ IndexController::class . '::' . 'aop', ]; public function process(ProceedingJoinPoint $proceedingJoinPoint) { $result = $proceedingJoinPoint->process(); return '结果处理'.PHP_EOL.$result .PHP_EOL. '结果处理'.PHP_EOL; } }

测试

curl 118.195.173.53:9501/index/aop

测试结果

结果处理 aop 结果处理
posted @ 2021-09-15 17:37  胡勇健  阅读(23)  评论(0编辑  收藏  举报
Copyright © 2021 胡勇健
Powered by .NET 6 on Kubernetes

问答 28u iTmz.Net 3q科技 A8团队1 A8团队2 A8团队3 A8备