mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKit.git
synced 2026-01-15 00:35:08 +08:00
50 lines
1.6 KiB
Markdown
50 lines
1.6 KiB
Markdown
# HDK 最佳实践
|
||
|
||
通用 Hyperf 开发工具集。
|
||
|
||
A General Development Kit for Hyperf.
|
||
|
||
> 如果你想参与贡献,请移步 [CONTRIBUTING.md](./CONTRIBUTING.md)
|
||
|
||
## 概述
|
||
|
||
HDK 主要包含了以下几部分内容,这也是这个库的边界:
|
||
|
||
* 开始一个新的 *Hyperf* 项目所需的脚本
|
||
* 通用类、函数
|
||
* 通用异常、错误码及错误捕获
|
||
|
||
* 项目相关 *RPC* 连接器
|
||
|
||
## 安装
|
||
|
||
```bash
|
||
composer config secure-http false \
|
||
&& composer config repo.lux-map composer https://satis.luxcreo.cn/ \
|
||
&& composer require singularity/hyperf-development-kit \
|
||
&& php bin/hyperf vendor:publish singularity/hyperf-development-kit
|
||
```
|
||
|
||
## 配置
|
||
|
||
配置,是 HDK 保证灵活性的重要一环。
|
||
|
||
当你使用上面的命令进行安装之后,即已经发布了 HDK 的配置文件,*config/autoload/common.php*。
|
||
|
||
主要分为以下几块:
|
||
|
||
* 响应相关
|
||
* 鉴权相关
|
||
* redis 补充配置
|
||
* 领域所需的特定配置
|
||
|
||
## 异常处理
|
||
|
||
建议遵循以下原则:
|
||
|
||
1. 项目内的 *ErrorCode.php* **应当** 继承 `Singularity\HDK\Utils\Constants\CommonErrorCode` 类,以避免重复定义错误码
|
||
2. 在 *config/autoload/exceptions.php* 中添加 `Singularity\HDK\Utils\Exceptions\Handler\CommonHandler::class` 行,并放置在所有捕获器的最后
|
||
1. 如有增加,**应当** 增加在 HDK 中(参考[CONTRIBUTING.md](./CONTRIBUTING.md))
|
||
2. 在项目中自行维护的情况下,**建议** 继承 `Singularity\HDK\Utils\Exceptions\Handler\CommonHandler::class` ,并在重写 `handle()`
|
||
方法时,处理完新增异常后,调用父类的 `handle()` 方法
|