An open API service indexing awesome lists of open source software.

https://github.com/hyperf/aop-integration

AOP Integration
https://github.com/hyperf/aop-integration

Last synced: 7 months ago
JSON representation

AOP Integration

Awesome Lists containing this project

README

          

# Aop Integration

![PHPUnit](https://github.com/hyperf/aop-integration/workflows/PHPUnit/badge.svg)

## 安装

```
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
```