https://github.com/hyperf/aop-integration
AOP Integration
https://github.com/hyperf/aop-integration
Last synced: 7 months ago
JSON representation
AOP Integration
- Host: GitHub
- URL: https://github.com/hyperf/aop-integration
- Owner: hyperf
- Created: 2020-12-20T05:08:28.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-02-09T14:49:52.000Z (almost 3 years ago)
- Last Synced: 2025-06-30T02:49:00.084Z (7 months ago)
- Language: PHP
- Size: 14.6 KB
- Stars: 9
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Aop Integration

## 安装
```
composer require hyperf/aop-integration
```
## 配置 AOP 到 ThinkPHP 框架
1. 添加配置到 `config/config.php` 中
```php
[
'scan' => [
'paths' => [
BASE_PATH . '/app',
],
'ignore_annotations' => [
'mixin',
],
'class_map' => [
],
],
],
'aspects' => [
// 在此配置可用的 Aspect
],
];
```
2. 修改入口文件
```php
[
'scan' => [
'paths' => [
BASE_PATH . '/app',
],
'ignore_annotations' => [
'mixin',
],
'class_map' => [
],
'collectors' => [
AspectCollector::class
],
],
],
'aspects' => [
// 这里写入对应的 Aspect
app\aspect\DebugAspect::class,
]
];
```
### 配置入口文件 start.php
> 我们将初始化方法,放到 timezone 下方,以下省略其他代码
```php
use Hyperf\AopIntegration\ClassLoader;
if ($timezone = config('app.default_timezone')) {
date_default_timezone_set($timezone);
}
// 初始化
ClassLoader::init();
```
### 测试
首先让我们编写待切入类
```php
1];
}
}
```
其次新增对应的 `DebugAspect`
```php
process();
}
}
```
接下来编辑控制器 `app\controller\Index`
```php
0, 'msg' => 'ok', 'data' => (new UserService())->first()]);
}
}
```
最后启动服务,并测试。
```shell
php start.php start
curl http://127.0.0.1:8787/index/json
```