w7/rangine-aspect
Composer 安装命令:
composer require w7/rangine-aspect
包简介
README 文档
README
composer require w7/rangine-aspect
在rangine中使用
直接安装即可
在laravel中使用
直接安装即可。
编写Aspect
首先让我们编写待切入类
<?php namespace W7\App\Services; class TestAspectService { public function test($arg) { return $arg; } public function test1() { return 1; } public function test2() { return 2; } }
其次新增对应的 TestAspect
<?php namespace W7\App\Aspect; use W7\App\Services\TestAspectService; use W7\Aspect\Aop\AspectAbstract; use W7\Aspect\Aop\AspectJoinPoint; class TestAspect extends AspectAbstract { //表示切入到TestAspectService类的test和test1方法 public static $classMethodMap = [ TestAspectService::class => [ 'test', 'test1' ] ]; public function process(AspectJoinPoint $aspectJoinPoint, \Closure $next) { var_dump('aspect before ' . $aspectJoinPoint->class . ':' . $aspectJoinPoint->method); $result = $next($aspectJoinPoint); var_dump('aspect after ' . $aspectJoinPoint->class . ':' . $aspectJoinPoint->method); return $result; } }
生成代理类配置
rangine
bin/gerent aspect:build
laravel
php artisan aspect:build
使用
(new TestAspectService())->test('woshishui'); var_dump((new TestAspectService())->test1()); var_dump((new TestAspectService())->test2());
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2021-09-15