Compare commits

...

38 Commits

Author SHA1 Message Date
李东云
fcb0cd8852 chore(release): 1.0.0-alpha.4 2023-09-26 02:55:03 +00:00
李东云
7a209e876f test(http): 完成并通过了 http 请求的测试
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:54:44 +08:00
李东云
4032d67f1e feat(i18n): 增加枚举值,更新中间件调用方式
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:44:00 +08:00
李东云
dbbe278aa6 build(composer): 引入 pest 并升级到 php8.1
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:43:20 +08:00
李东云
d84855f038 chore(release): 1.0.0-alpha.3 2023-08-30 03:42:37 +00:00
李东云
2d95fbae9e refactor(http): 整理了 Http 请求服务
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-08-30 11:41:59 +08:00
李东云
3042ce0054 chore(release): 1.0.0-alpha.2 2023-07-21 08:22:48 +00:00
李东云
b30c84488b fix(controller): 修复方法访问级别不足以继承的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 16:22:36 +08:00
李东云
c262d38ad0 chore(release): 1.0.0-alpha.1 2023-07-21 03:39:01 +00:00
李东云
a8ec7d8255 build(composer): 更新依赖
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 11:38:31 +08:00
李东云
f1948ab0fe build(release): 增加 alpha 标识,准备正式版
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 11:04:39 +08:00
李东云
ae8001a595 chore(release): 1.0.0-alpha.0 2023-07-21 03:01:22 +00:00
李东云
68844a6132 feat(controller): 增加了一个 Rest 风格的 trait
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 10:55:10 +08:00
李东云
fd788a7eb8 feat(trait): 增加了分页响应的统一处理方法
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-19 15:52:35 +08:00
李东云
7ccf36b398 docs(utils): 移除了导致编辑器出错的注解
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-07 10:31:31 +08:00
李东云
3d86b05fff chore(release): 0.2.23 2023-07-07 02:13:01 +00:00
李东云
722d124e1e fix(i18n): 修复获取偏好语言失败的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-07 10:12:35 +08:00
李东云
5702e7f913 chore(release): 0.2.22 2023-07-06 09:54:58 +00:00
李东云
a6ec6951a9 fix(service): 修复 http 请求类中无效的 query
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-06 17:54:46 +08:00
李东云
a52fc28901 chore(release): 0.2.21 2023-07-05 08:41:23 +00:00
李东云
2b0374bcc8 chore(deprecated): 声明弃用了 SessionMiddleware
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-05 16:40:38 +08:00
李东云
8616c5f61c perf: 适配已弃用的命名空间
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-06-19 18:22:42 +08:00
李东云
aee67d78fc chore(release): 0.2.20 2023-06-19 10:15:18 +00:00
李东云
8974ee595b feat(handler): 增加了 restful 的支持
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-06-19 18:15:00 +08:00
李东云
205554068d chore(release): 0.2.19 2023-06-02 02:20:48 +00:00
李东云
648fe6c8f3 build(composer): 更新依赖
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-06-02 10:19:01 +08:00
李东云
c0aa128dd0 chore(release): 0.2.18 2023-06-02 02:12:27 +00:00
李东云
c748cbd3e3 build: 更新被弃用的写法
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-06-02 10:11:49 +08:00
李东云
43ebd0546a fix: 修复 http 请求失效的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-06-02 10:05:09 +08:00
李东云
200a98293a chore(release): 0.2.17 2023-05-06 09:46:51 +00:00
李东云
be818b7080 feat(xml): 实现了解析xml的方法
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-05-06 17:46:32 +08:00
李东云
d22bd3ee58 build(composer): 更新依赖 2023-05-06 17:16:22 +08:00
李东云
0f9cae0288 chore(release): 0.2.16 2023-04-25 09:18:42 +00:00
李东云
0247dd415c feat(handler): 补全了各种错误的状态码 2023-04-25 17:18:10 +08:00
李东云
77f3141c56 fix(extend): 修复未传入 extends 不存在缺省值的问题 2023-04-25 17:04:57 +08:00
李东云
2a59a51f8b chore(release): 0.2.15 2023-04-13 15:38:50 +00:00
李东云
5e5792b28c feat: 默认绑定 CoreMiddleware 的映射关系 2023-04-13 23:38:38 +08:00
李东云
a6b71dbb03 fix(coreMiddleware): 修复restful 无法分页的问题 2023-04-13 23:37:18 +08:00
43 changed files with 6060 additions and 1140 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,4 @@
vendor/
.phpunit.result.cache
.php-cs-fixer.cache
.php-cs-fixer.cache
runtime/

13
.idea/HDK-Core.iml generated
View File

@@ -2,7 +2,6 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Singularity\HDK\Core\" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Singularity\HDK\Test\Core\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/sebastian/recursion-context" />
@@ -31,7 +30,6 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/fig/http-message-util" />
<excludeFolder url="file://$MODULE_DIR$/vendor/lmc/http-constants" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/cache" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-server-handler" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/event-dispatcher" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/http-server-middleware" />
@@ -111,7 +109,6 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/theseer/tokenizer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/lexer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/inflector" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/annotations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/instantiator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ergebnis/http-method" />
<excludeFolder url="file://$MODULE_DIR$/vendor/firebase/php-jwt" />
@@ -151,6 +148,16 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/pipeline" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/tappable" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/serializer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/code-parser" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/codec" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/conditionable" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/coroutine" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/serializer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/stringable" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/support" />
<excludeFolder url="file://$MODULE_DIR$/vendor/cooper/hyperf-pest" />
<excludeFolder url="file://$MODULE_DIR$/vendor/psr/clock" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php83" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

12
.idea/codeception.xml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Codeception">
<option name="configurations">
<list>
<Configuration>
<option name="path" value="$PROJECT_DIR$/tests" />
</Configuration>
</list>
</option>
</component>
</project>

View File

@@ -1,9 +1,7 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpCSFixerValidationInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="PhpDocSignatureInspection" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="PhpPropertyOnlyWrittenInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PhpStanGlobal" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
</profile>
</component>

6
.idea/pest.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PestSettings">
<option name="preferredTestFlavor" value="TEST" />
</component>
</project>

17
.idea/php.xml generated
View File

@@ -46,7 +46,6 @@
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/fig/http-message-util" />
<path value="$PROJECT_DIR$/vendor/lmc/http-constants" />
<path value="$PROJECT_DIR$/vendor/psr/cache" />
<path value="$PROJECT_DIR$/vendor/psr/http-server-handler" />
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
<path value="$PROJECT_DIR$/vendor/psr/http-server-middleware" />
@@ -130,14 +129,12 @@
<path value="$PROJECT_DIR$/vendor/theseer/tokenizer" />
<path value="$PROJECT_DIR$/vendor/doctrine/lexer" />
<path value="$PROJECT_DIR$/vendor/doctrine/inflector" />
<path value="$PROJECT_DIR$/vendor/doctrine/annotations" />
<path value="$PROJECT_DIR$/vendor/doctrine/instantiator" />
<path value="$PROJECT_DIR$/vendor/ergebnis/http-method" />
<path value="$PROJECT_DIR$/vendor/firebase/php-jwt" />
<path value="$PROJECT_DIR$/vendor/jetbrains/phpstorm-attributes" />
<path value="$PROJECT_DIR$/vendor/lizhichao/one-sm" />
<path value="$PROJECT_DIR$/vendor/phpoption/phpoption" />
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
<path value="$PROJECT_DIR$/vendor/sebastian/comparator" />
<path value="$PROJECT_DIR$/vendor/sebastian/global-state" />
<path value="$PROJECT_DIR$/vendor/sebastian/object-enumerator" />
@@ -167,9 +164,21 @@
<path value="$PROJECT_DIR$/vendor/hyperf/tappable" />
<path value="$PROJECT_DIR$/vendor/hyperf/db" />
<path value="$PROJECT_DIR$/vendor/symfony/serializer" />
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" />
<path value="$PROJECT_DIR$/vendor/hyperf/serializer" />
<path value="$PROJECT_DIR$/vendor/hyperf/code-parser" />
<path value="$PROJECT_DIR$/vendor/hyperf/coroutine" />
<path value="$PROJECT_DIR$/vendor/hyperf/conditionable" />
<path value="$PROJECT_DIR$/vendor/hyperf/codec" />
<path value="$PROJECT_DIR$/vendor/hyperf/stringable" />
<path value="$PROJECT_DIR$/vendor/hyperf/support" />
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
<path value="$PROJECT_DIR$/vendor/cooper/hyperf-pest" />
<path value="$PROJECT_DIR$/vendor/psr/clock" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php83" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0" />
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
<component name="PhpStan">
<PhpStan_settings>
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />

31
.idea/phpspec.xml generated Normal file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PHPSpec">
<suites>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
</suites>
</component>
</project>

View File

@@ -1,4 +1,144 @@
# 版本更新日志
## [1.0.0-alpha.4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2023-09-26)
### 📦‍ Build System | 打包构建
* **composer:** 引入 pest 并升级到 php8.1 ([dbbe278](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/dbbe278aa6c96634ed5792b5782825770c5cabe8))
### ✨ Features | 新功能
* **i18n:** 增加枚举值,更新中间件调用方式 ([4032d67](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4032d67f1e56b8ce29fbfa5bd77ead2636a6ffd3))
### ✅ Tests | 测试
* **http:** 完成并通过了 http 请求的测试 ([7a209e8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7a209e876f8b4301b7bc78f05b68798eb65e77f7))
## [1.0.0-alpha.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2023-08-30)
### ♻️ Code Refactoring | 代码重构
* **http:** 整理了 Http 请求服务 ([2d95fba](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2d95fbae9e926788402c24266ab0d232732a7754))
## [1.0.0-alpha.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2023-07-21)
### 🐛 Bug Fixes | Bug 修复
* **controller:** 修复方法访问级别不足以继承的问题 ([b30c844](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b30c84488b7f85447bd802df77c9decbf315ed85))
## [1.0.0-alpha.1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2023-07-21)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([a8ec7d8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a8ec7d82556c2fb8fbe1e356eb6d1936401c810a))
* **release:** 增加 alpha 标识,准备正式版 ([f1948ab](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/f1948ab0fe4594140eede8e52f113963d98a8338))
## [1.0.0-alpha.0](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.23...v1.0.0-alpha.0) (2023-07-21)
### ✏️ Documentation | 文档
* **utils:** 移除了导致编辑器出错的注解 ([7ccf36b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7ccf36b398f86a31c7d8dde6ff24f0d9828cfb80))
### ✨ Features | 新功能
* **controller:** 增加了一个 Rest 风格的 trait ([68844a6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/68844a6132059da89f69a34ba59229c40e5bcace))
* **trait:** 增加了分页响应的统一处理方法 ([fd788a7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/fd788a7eb804b7fe085346d817123c04c8bd0d01))
### [0.2.23](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.22...v0.2.23) (2023-07-07)
### 🐛 Bug Fixes | Bug 修复
* **i18n:** 修复获取偏好语言失败的问题 ([722d124](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/722d124e1ed87c493dfb8841212b408717444d98))
### [0.2.22](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.21...v0.2.22) (2023-07-06)
### 🐛 Bug Fixes | Bug 修复
* **service:** 修复 http 请求类中无效的 query ([a6ec695](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a6ec6951a9a68a4c5144aee97638486826d6af84))
### [0.2.21](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.20...v0.2.21) (2023-07-05)
### ⚡ Performance Improvements | 性能优化
* 适配已弃用的命名空间 ([8616c5f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/8616c5f61cc8e69c9d61f42f5dc5d18e7c79fd7b))
### 🚀 Chore | 构建/工程依赖/工具
* **deprecated:** 声明弃用了 SessionMiddleware ([2b0374b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2b0374bcc83a5534358a7fce34b723e3bd38dceb))
### [0.2.20](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.19...v0.2.20) (2023-06-19)
### ✨ Features | 新功能
* **handler:** 增加了 restful 的支持 ([8974ee5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/8974ee595b3411bac086c3046eb24ba44087ecc7))
### [0.2.19](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.18...v0.2.19) (2023-06-02)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([648fe6c](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/648fe6c8f32e2511f0c1a79dbafff8e889c1da7b))
### [0.2.18](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.17...v0.2.18) (2023-06-02)
### 🐛 Bug Fixes | Bug 修复
* 修复 http 请求失效的问题 ([43ebd05](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/43ebd0546abb25446e83522fd0c069dd0e6880c7))
### 📦‍ Build System | 打包构建
* 更新被弃用的写法 ([c748cbd](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c748cbd3e322b5a926996fc2ee958b2e2a911d7c))
### [0.2.17](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.16...v0.2.17) (2023-05-06)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([d22bd3e](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/d22bd3ee587f7799b33a28015c148e50afe79107))
### ✨ Features | 新功能
* **xml:** 实现了解析xml的方法 ([be818b7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/be818b708011bb05a65752380248c8307938d110))
### [0.2.16](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.15...v0.2.16) (2023-04-25)
### 🐛 Bug Fixes | Bug 修复
* **extend:** 修复未传入 extends 不存在缺省值的问题 ([77f3141](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/77f3141c56a09905e0c357c1b183c1c8831c9acd))
### ✨ Features | 新功能
* **handler:** 补全了各种错误的状态码 ([0247dd4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/0247dd415c2a62c21b5a6fbb15ab1e6ce3d1a316))
### [0.2.15](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.14...v0.2.15) (2023-04-13)
### 🐛 Bug Fixes | Bug 修复
* **coreMiddleware:** 修复restful 无法分页的问题 ([a6b71db](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a6b71dbb037624ac69eddc1e5b1d671ab45b06ae))
### ✨ Features | 新功能
* 默认绑定 CoreMiddleware 的映射关系 ([5e5792b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/5e5792b28ca13cc8833280ba3d26ec588c445350))
### [0.2.14](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.13...v0.2.14) (2023-04-12)

View File

@@ -1 +1 @@
0.2.14
1.0.0-alpha.4

View File

@@ -15,41 +15,42 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-redis": "^5.3",
"ext-swoole": "*",
"composer/composer": ">=2.0",
"ergebnis/http-method": "^2.2",
"hyperf/config": "^3.0.0",
"hyperf/constants": "^3.0.0",
"hyperf/context": "^3.0.0",
"hyperf/di": "^3.0.0",
"hyperf/framework": "^3.0.0",
"hyperf/logger": "^3.0.0",
"hyperf/redis": "^3.0.0",
"hyperf/resource": "^3.0.0",
"hyperf/translation": "^3.0.0",
"hyperf/config": "^3.0.18",
"hyperf/constants": "^3.0.18",
"hyperf/context": "^3.0.18",
"hyperf/di": "^3.0.18",
"hyperf/framework": "^3.0.18",
"hyperf/logger": "^3.0.18",
"hyperf/redis": "^3.0.18",
"hyperf/resource": "^3.0.18",
"hyperf/translation": "^3.0.18",
"jetbrains/phpstorm-attributes": "^1.0",
"lmc/http-constants": "^1.2",
"myclabs/php-enum": "^1.8",
"roave/dont": "^1.5",
"symfony/http-foundation": "^6.0",
"symfony/polyfill-php81": "^1.26",
"teapot/status-code": "^1.1"
"teapot/status-code": "^1.1",
"ext-libxml": "*",
"ext-dom": "*"
},
"require-dev": {
"ext-dom": "*",
"ext-libxml": "*",
"alibabacloud/dysmsapi-20170525": "^2.0",
"cooper/hyperf-pest": "^1.1",
"firebase/php-jwt": "^6.1",
"friendsofphp/php-cs-fixer": "^3.13",
"guzzlehttp/guzzle": "^7.5",
"hyperf/crontab": "^3.0.0",
"hyperf/database": "^3.0.0",
"hyperf/db": "^3.0.0",
"hyperf/guzzle": "^3.0.0",
"hyperf/session": "^3.0.0",
"hyperf/validation": "^3.0.0",
"hyperf/crontab": "^3.0.18",
"hyperf/database": "^3.0.18",
"hyperf/db": "^3.0.18",
"hyperf/guzzle": "^3.0.18",
"hyperf/session": "^3.0.18",
"hyperf/validation": "^3.0.18",
"pestphp/pest": "^1.22",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
@@ -61,12 +62,12 @@
},
"suggest": {
"firebase/php-jwt": "JWT 鉴权必需",
"hyperf/session": "^3.0.0",
"hyperf/session": "^3.0.18",
"symfony/mailer": "用于发送电子邮件",
"symfony/serializer": "处理 XML 必需",
"ext-dom": "处理 XML 必需",
"ext-libxml": "处理 XML 必需",
"hyperf/guzzle": "^3.0.0",
"hyperf/guzzle": "^3.0.18",
"alibabacloud/dysmsapi-20170525": "阿里云短信服务必需"
},
"config": {
@@ -91,7 +92,11 @@
"prefer-stable": true,
"scripts": {
"post-root-package-install": [],
"test": "vendor/bin/pest $1",
"test": [
"rm -rf runtime",
"Composer\\Config::disableProcessTimeout",
"co-pest --prepend tests/bootstrap.php -c phpunit.xml --colors=always $1"
],
"cs-fix": "vendor/bin/php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse $1",
"ci": [
@@ -108,8 +113,8 @@
},
"packagist": {
"type": "composer",
"url": "https://mirrors.cloud.tencent.com/composer/"
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "0.2.14"
"version": "1.0.0-alpha.4"
}

6007
composer.lock generated

File diff suppressed because it is too large Load Diff

26
docs/Http 请求.md Normal file
View File

@@ -0,0 +1,26 @@
# Http 请求
## 1 组成
* 单例类
* \Singularity\HDK\Core\Http\RequestService
* 工厂类
* \Singularity\HDK\Core\Http\RequestServiceFactory
## 2 初始化服务
创建一个请求服务的方法有两种,效果是一致的:
* 工厂模式
* `\Singularity\HDK\Core\Http\RequestServiceFactory::make($options)`
* `\Singularity\HDK\Core\Http\RequestServiceFactory::make()->setOptions($options)`
* 单例模式
* `new \Singularity\HDK\Core\Http\RequestService($options)`
* `(new \Singularity\HDK\Core\Http\RequestService())->setOptions($options)`
这两个方法都回返回一个 `\Singularity\HDK\Core\Http\RequestService` 实例
## 3 规范
每个通过本包提供的 Http 请求服务创建的服务,都应该在构建方法中实例化一个 RequestService 服务,
之后该服务中使用的所有请求都基于该服务,这样可以避免共用单例模式导致的 options 污染

12
docs/REST 控制器.md Normal file
View File

@@ -0,0 +1,12 @@
# REST 资源控制器支持
## 列表的筛选、排序
* [**RestfulList**](../src/Traits/RestfulList.php)
### RestfulList
在 AbstractController 中已经默认进行了集成
- parseParameters 用来解析请求
- responseFormatter 用来将 builder 转化成响应
- restSelect 额外的语法糖,调用了上面的两个方法

View File

@@ -9,6 +9,8 @@
declare(strict_types=1);
use function Hyperf\Support\env;
return [
// 响应
'response' => [

View File

@@ -7,4 +7,4 @@ docker run \
-v "$(pwd)":/srv/www \
-v ~/.ssh:/root/.ssh \
-v ~/.gitconfig:/root/.gitconfig \
harbor.luxcreo.cn/library/hyperf:8.0-swoole /bin/ash
harbor.luxcreo.cn/library/hyperf:8.1-swoole /bin/ash

View File

@@ -2,4 +2,4 @@
docker run --rm -it \
-v $(pwd):/app -e "GIT_AUTHOR_NAME=$(git config user.name)" -e "EMAIL=$(git config user.email)" \
detouched/standard-version:latest $1
detouched/standard-version:latest -p=alpha $1

View File

@@ -14,8 +14,10 @@ namespace Singularity\HDK\Core;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Framework\Logger\StdoutLogger;
use Hyperf\HttpServer\Contract\CoreMiddlewareInterface;
use Singularity\HDK\Core\Listener\EmailWillSentListener;
use Singularity\HDK\Core\Listener\SmsWillSentListener;
use Singularity\HDK\Core\Middleware\CommonCoreMiddleware;
class ConfigProvider
{
@@ -27,6 +29,7 @@ class ConfigProvider
// 合并到 config/autoload/dependencies.php 文件
'dependencies' => [
StdoutLoggerInterface::class => StdoutLogger::class,
CoreMiddlewareInterface::class => CommonCoreMiddleware::class
],
// 合并到 config/autoload/annotations.php 文件
'annotations' => [

View File

@@ -21,8 +21,8 @@ use Dont\DontToString;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Singularity\HDK\Core\Traits\RestfulList;
/**
* 抽象控制器基类
@@ -42,13 +42,11 @@ abstract class AbstractController
use DontSerialise;
use DontDeserialise;
use DontToString;
use RestfulList;
#[Inject]
protected ContainerInterface $container;
#[Inject]
protected RequestInterface $request;
#[Inject]
protected ResponseInterface $response;

View File

@@ -7,6 +7,8 @@ use Singularity\HDK\Core\Constants\CommonErrorCode;
use Teapot\StatusCode\RFC\RFC7231;
use Throwable;
use function Hyperf\Config\config;
/**
* 用户无权访问
*/

View File

@@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Singularity\HDK\Core\Exceptions\Handler;
use Carbon\Carbon;
use Hyperf\Codec\Json;
use Hyperf\Database\Exception\QueryException;
use Hyperf\Database\Model\ModelNotFoundException;
use Hyperf\Di\Annotation\Inject;
@@ -23,19 +25,21 @@ use Hyperf\HttpMessage\Exception\MethodNotAllowedHttpException;
use Hyperf\HttpMessage\Exception\NotFoundHttpException;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Utils\Codec\Json;
use Hyperf\Validation\ValidationException;
use Lmc\HttpConstants\Header;
use Psr\Http\Message\ResponseInterface;
use RedisException;
use Singularity\HDK\Core\Constants\CommonErrorCode;
use Singularity\HDK\Core\Exceptions\ValidateException;
use Singularity\HDK\Core\Service\ApiStyleService;
use Symfony\Component\Mailer\Exception\TransportException;
use Teapot\StatusCode\All;
use Teapot\StatusCode\RFC\RFC4918;
use Teapot\StatusCode\RFC\RFC7231;
use Throwable;
use function Hyperf\Config\config;
use function Hyperf\Translation\__;
/**
* 通用异常处理
* Singularity\HDK\Utils\Exceptions\Handler\CommonHandler@hyperf-development-kit
@@ -46,17 +50,15 @@ use Throwable;
*/
class CommonHandler extends ExceptionHandler
{
/**
*
* @var RequestInterface|null
*/
#[Inject(required: false)]
private ?RequestInterface $request;
/**
* @var StdoutLogger
*/
#[Inject]
private StdoutLogger $logger;
#[Inject]
private ApiStyleService $apiStyleService;
/**
* {@inheritDoc}
*/
@@ -64,14 +66,18 @@ class CommonHandler extends ExceptionHandler
{
// 阻止异常冒泡
$this->stopPropagation();
$restful = config('common.response.restful');
$restful = $this->apiStyleService->get();
// $restful = config('common.response.restful');
$code_name = config('common.response.code_name');
$message_name = config('common.response.message_name');
$is_testing = config('app_status') === true;
$this->request?->url();
$is_debug = $this->request?->hasHeader('Postman-Token') || str_starts_with($this->request?->header('User-Agent', ''), 'apifox');
$is_debug = $this->request?->hasHeader('Postman-Token') || str_starts_with(
$this->request?->header('User-Agent', ''),
'apifox'
);
$error_type = $throwable::class;
$request_time = date('Y-m-d H:i:s');
$request_time = Carbon::now()->toDateTimeString();
$request_data = Json::encode($this->request?->getParsedBody());
$request_headers = Json::encode($this->request?->getHeaders());
// 901 程序语法错误
@@ -81,7 +87,10 @@ class CommonHandler extends ExceptionHandler
'42S22' => CommonErrorCode::PROGRAM_SQL_COLUMN_NOT_FOUND,
default => CommonErrorCode::PROGRAM_SQL_ERROR,
};
$data = [$code_name => $code, $message_name => CommonErrorCode::getMessage($is_testing ? $code : CommonErrorCode::PROGRAM_SQL_ERROR)];
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage($is_testing ? $code : CommonErrorCode::PROGRAM_SQL_ERROR),
];
if ($is_testing) {
$data['details'] = ['sql' => $throwable->getSql(), 'error' => $throwable->getMessage()];
}
@@ -91,27 +100,48 @@ class CommonHandler extends ExceptionHandler
$message = explode(': ', $throwable->getMessage());
$allow_method = explode(', ', $message[1]);
$code = CommonErrorCode::REQUEST_METHOD_ERROR;
$data = [$code_name => $code, $message_name => CommonErrorCode::getMessage($code, ['methods' => join(', ', $allow_method)]), 'currentMethod' => $this->request?->getMethod(), 'allowedMethod' => $allow_method];
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage($code, ['methods' => join(', ', $allow_method)]),
'currentMethod' => $this->request?->getMethod(),
'allowedMethod' => $allow_method,
];
$status_code = RFC7231::METHOD_NOT_ALLOWED;
}
// 验证失败
if ($throwable instanceof BadRequestHttpException) {
$data = [
$code_name => CommonErrorCode::REQUEST_PARAMS_ERROR,
$message_name => $is_testing ? $throwable->getMessage() : CommonErrorCode::getMessage(
CommonErrorCode::SERVER_ERROR
),
];
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
$data = [$code_name => CommonErrorCode::REQUEST_PARAMS_ERROR, $message_name => $is_testing ? $throwable->getMessage() : CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR)];
}
if ($throwable instanceof ValidationException) {
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
$data = $throwable->validator->errors()->first();
if (is_numeric($data)) {
$code = (int) $data;
$code = (int)$data;
$data = CommonErrorCode::getMessage($code);
}
$data = [$code_name => $code ?? CommonErrorCode::REQUEST_PARAMS_ERROR, $message_name => $data];
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
}
if ($throwable instanceof ValidateException) {
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
$code = $throwable->getCode();
$message = $throwable->getMessage();
$data = [$code_name => $code, $message_name => empty($message) ? CommonErrorCode::getMessage($code, ['param' => $throwable->getFieldName()]) : $message];
$data = [
$code_name => $code,
$message_name => empty($message)
? CommonErrorCode::getMessage(
$code,
[
'param' => $throwable->getFieldName(),
]
)
: $message,
];
if ($is_debug) {
$data['currentValue'] = $throwable->getCurrentValue();
$data['availableValue'] = $throwable->getAvailableValue();
@@ -126,7 +156,8 @@ class CommonHandler extends ExceptionHandler
// 模型不存在
if ($throwable instanceof ModelNotFoundException) {
$code = empty($throwable->getCode()) ? CommonErrorCode::MODEL_NOT_FOUND : $throwable->getCode();
$message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, ['resource' => '资源']) : $throwable->getMessage();
$message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, ['resource' => '资源']
) : $throwable->getMessage();
$data = [$code_name => $code, $message_name => $message];
$status_code = RFC7231::NOT_FOUND;
}
@@ -137,7 +168,12 @@ class CommonHandler extends ExceptionHandler
if ($throwable->getMessage() === 'Connection refused') {
$code = CommonErrorCode::SERVER_CACHE_REDIS_REFUSED_ERROR;
}
$data = [$code_name => $code, $message_name => CommonErrorCode::getMessage($is_testing ? $code : CommonErrorCode::SERVER_CACHE_REDIS_ERROR)];
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage(
$is_testing ? $code : CommonErrorCode::SERVER_CACHE_REDIS_ERROR
),
];
}
// 306 消息异常
// 30601 邮箱发件异常
@@ -146,14 +182,29 @@ class CommonHandler extends ExceptionHandler
if (strpos($throwable->getMessage(), '500 Error: bad syntax')) {
$code = CommonErrorCode::SERVER_MESSAGE_EMAIL_NOT_FOUND;
}
$data = [$code_name => $code, $message_name => CommonErrorCode::getMessage($is_testing ? $code : CommonErrorCode::SERVER_MESSAGE_EMAIL_ERROR)];
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage(
$is_testing ? $code : CommonErrorCode::SERVER_MESSAGE_EMAIL_ERROR
),
];
}
if (empty($data)) {
// 其他情况
$data = [$code_name => $is_testing ? $throwable->getCode() == 0 ? CommonErrorCode::SERVER_ERROR : $throwable->getCode() : CommonErrorCode::SERVER_ERROR, $message_name => $is_testing ? $throwable->getMessage() : __(CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR))];
$data = [
$code_name => $is_testing ? $throwable->getCode(
) == 0 ? CommonErrorCode::SERVER_ERROR : $throwable->getCode() : CommonErrorCode::SERVER_ERROR,
$message_name => $is_testing ? $throwable->getMessage() : __(
CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR)
),
];
// 其他错误
if ($throwable instanceof HttpException) {
$data = [$code_name => $throwable->getCode() ?: $throwable->getStatusCode(), $message_name => $throwable->getMessage()];
$data = [
$code_name => $throwable->getCode() ?: $throwable->getStatusCode(),
$message_name => $throwable->getMessage(),
];
$status_code = $throwable->getStatusCode();
}
}
$response = $response->withHeader(Header::CONTENT_TYPE, 'application/json; charset=utf-8');
@@ -164,7 +215,7 @@ class CommonHandler extends ExceptionHandler
$this->logger->error(
<<<ERROR_LOG
TYPE: {$error_type}
[{$data[$code_name]}] {$data[$message_name]}
[$data[$code_name]] $data[$message_name]
{$throwable->getMessage()}
-------------------------------
REQUEST_TIME: {$request_time}
@@ -194,11 +245,14 @@ TRACE:
ERROR_LOG
);
$data = Json::encode($data);
if ($restful) {
$response = $response->withStatus($status_code ?? $throwable->status ?? $throwable->statusCode ?? RFC7231::INTERNAL_SERVER_ERROR);
if ($restful === ApiStyleService::RESTFUL) {
$response = $response->withStatus(
$status_code ?? $throwable->status ?? $throwable->statusCode ?? RFC7231::INTERNAL_SERVER_ERROR
);
}
return $response->withBody(new SwooleStream($data));
}
/**
* 判断该异常处理器是否要对该异常进行处理.
*/

191
src/Http/RequestService.php Normal file
View File

@@ -0,0 +1,191 @@
<?php
declare(strict_types=1);
namespace Singularity\HDK\Core\Http;
use Ergebnis\Http\Method;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Hyperf\Codec\Json;
use Hyperf\Guzzle\ClientFactory;
use Psr\Http\Message\ResponseInterface;
use Singularity\HDK\Core\Service\AbstractSingleton;
/**
* Singularity\HDK\Core\Service\Http\RequestService@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*
* @template Options of array<literal-string, mixed>
*/
final class RequestService extends AbstractSingleton
{
// public const TIMEOUT = 20;
private ClientFactory $client;
/**
* @var Options
*/
private array $options = [];
/**
* @param Options $options
*/
public function __construct(array $options = [])
{
$this->setOptions($options);
/** @var ClientFactory $client */
$client = \Hyperf\Support\make(ClientFactory::class);
$this->client = $client;
}
/**
* 定制 options
* @param Options $options
* @return $this
*/
public function setOptions(array $options): self
{
$this->options = array_replace_recursive($this->options, $options);
return $this;
}
/**
* @param string $url
* @param array<string, string|int> $params
* @param array $data
* @param Options $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestGet(
string $url,
array $params = [],
array $data = [],
array $options = []
): ResponseInterface {
$request = new Request(
method: Method\Rfc\Rfc7231::GET, uri: $url
);
return $this->getClient($options)->send($request, ['query' => $params, 'json' => $data,]);
}
/**
* 工厂模式初始化请求
* @param Options $options
* @return Client
*/
private function getClient(array $options): Client
{
$options = array_replace_recursive($this->options, $options);
return $this->client->create($options);
}
/**
* @param string $url
* @param array<string, string|int> $params
* @param array<string, mixed> $data
* @param Options $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestPost(
string $url,
array $params = [],
array $data = [],
array $options = []
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::POST,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data),
);
return $this->getClient($options)->send($request, ['query' => $params,]);
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestPut(
string $url,
array $params = [],
array $data = [],
array $options = []
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::PUT,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)
);
return $this->getClient($options)->send(
$request, ['query' => $params,]
);
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestPatch(
string $url,
array $params = [],
array $data = [],
array $options = []
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc5789::PATCH,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)
);
return $this->getClient($options)->send(
$request, ['query' => $params,]
);
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestDelete(
string $url,
array $params = [],
array $data = [],
array $options = []
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::DELETE,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)
);
return $this->getClient($options)->send(
$request, ['query' => $params,]
);
}
}

View File

@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
/**
* RequestFactory.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*/
namespace Singularity\HDK\Core\Http;
use Singularity\HDK\Core\Service\AbstractFactory;
final class RequestServiceFactory extends AbstractFactory
{
public static function make(array $options = []): RequestService
{
return new RequestService($options);
}
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* Languages.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/26
*/
namespace Singularity\HDK\Core\I18n\Enum;
use function Hyperf\Config\config;
enum Languages: string
{
case ZH_CN = 'zh_CN';
case EN = 'en';
public static function getLanguage(string $language): Languages
{
return match ($language) {
'en', 'en_us', 'en-us', 'en-uk', 'en_uk' => self::EN,
'zh', 'zh_cn', 'zh-cn' => self::ZH_CN,
default => self::from(config('translation.locale')),
};
}
}

View File

@@ -10,18 +10,20 @@
namespace Singularity\HDK\Core\Middleware;
use Hyperf\Codec\Json;
use Hyperf\Contract\Arrayable;
use Hyperf\Contract\Jsonable;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\CoreMiddleware;
use Hyperf\Utils\Codec\Json;
use Lmc\HttpConstants\Header;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Singularity\HDK\Core\Service\UtilsService;
use function Hyperf\Config\config;
/**
* Singularity\HDK\Utils\Middleware\ClassicCoreMiddleware@hyperf-development-kit
*

View File

@@ -10,19 +10,21 @@
namespace Singularity\HDK\Core\Middleware;
use Hyperf\Codec\Json;
use Hyperf\Contract\Arrayable;
use Hyperf\Contract\Jsonable;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Stream\SwooleStream;
use Hyperf\HttpServer\CoreMiddleware;
use Hyperf\Utils\Codec\Json;
use Lmc\HttpConstants\Header;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Singularity\HDK\Core\Service\ApiStyleService;
use Singularity\HDK\Core\Service\UtilsService;
use function Hyperf\Config\config;
/**
* Singularity\HDK\Core\Middleware\CommonCoreMiddleware@HDK-Core
*
@@ -73,11 +75,12 @@ class CommonCoreMiddleware extends CoreMiddleware
'last'
);
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->url(1), 'first');
return $this->utilsService->extendLinkToHeader(
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
$response->previousPageUrl(),
'prev'
);
return $fact_response->withBody(new SwooleStream(Json::encode($response->items())));
}
return parent::transferToResponse($response, $request);

View File

@@ -12,6 +12,7 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Singularity\HDK\Core\I18n\Enum\Languages;
use Symfony\Component\HttpFoundation\Request;
/**
@@ -37,14 +38,10 @@ class InternationalizationMiddleware implements MiddlewareInterface
$req = (new Request());
$req->headers->set(Header::ACCEPT_LANGUAGE, $request->getHeaderLine(Header::ACCEPT_LANGUAGE));
$language = $req->getPreferredLanguage([config('translation.locale')]);
$language = $req->getPreferredLanguage();
if (!empty($language)) {
$language = match (strtolower($language)) {
'en', 'en_us', 'en-us', 'en-uk', 'en_uk' => 'en',
'zh', 'zh_cn', 'zh-cn' => 'zh_CN',
default => config('translation.locale'),
};
$this->translator->setLocale($language);
$language = Languages::getLanguage($language);
$this->translator->setLocale($language->value);
}
$response = Context::get(ResponseInterface::class);
$response = $response->withAddedHeader(

View File

@@ -15,8 +15,11 @@ use Hyperf\Contract\SessionInterface;
use Hyperf\HttpMessage\Cookie\Cookie;
use Hyperf\HttpMessage\Server\Response;
use Hyperf\Session\SessionManager;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
/**
* Singularity\HDK\Core\Middleware\SessionMiddleware@HDK-Core
@@ -24,12 +27,70 @@ use Psr\Http\Message\ServerRequestInterface;
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/3/8
*
* @deprecated since 0.2.21, use \Singularity\HDK\Auth\Middleware\SessionMiddleware instead.
*/
class SessionMiddleware extends \Hyperf\Session\Middleware\SessionMiddleware
class SessionMiddleware implements MiddlewareInterface
{
public function __construct(private SessionManager $sessionManager, private ConfigInterface $config)
{
parent::__construct($this->sessionManager, $this->config);
}
/**
* Process an incoming server request.
* Processes an incoming server request in order to produce a response.
* If unable to produce the response itself, it may delegate to the provided
* request handler to do so.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (!$this->isSessionAvailable()) {
return $handler->handle($request);
}
$session = $this->sessionManager->start($request);
try {
$response = $handler->handle($request);
} finally {
$this->storeCurrentUrl($request, $session);
$session = $this->sessionManager->getSession();
/*
* 现在的机制,但凡写入 Redis 的数据,
* 过期时间就是固定的 gc_maxlifetime
*
* 而 RedisHandler 只会被依赖注入时加载一次,
* 后续无法临时修改 gc_maxlifetime
*
* 又因为现在没有其他情况用到 session
* 只有登录之后才会记下用户信息
*
* 所以一个妥协的方案,就是只有登录了再写入 Redis
*
* (除非重写整套 RedisHandler/RedisHandlerFactory/...
*/
if (!$this->auth($session)) {
$this->sessionManager->end($session);
}
}
return $this->addCookieToResponse($request, $response, $session);
}
private function isSessionAvailable(): bool
{
return $this->config->has('session.handler');
}
/**
* Store the current URL for the request if necessary.
*/
private function storeCurrentUrl(RequestInterface $request, SessionInterface $session)
{
if ($request->getMethod() === 'GET') {
$session->setPreviousUrl($this->fullUrl($request));
}
}
/**
@@ -43,10 +104,13 @@ class SessionMiddleware extends \Hyperf\Session\Middleware\SessionMiddleware
$cookie = new Cookie(
name: $session->getName(),
value: $session->getId(),
expire: $this->getCookieExpirationDate(),
expire: $this->getCookieExpirationDate($session),
path: $this->config->get('session.options.path', '/'),
domain: $this->config->get('session.options.domain', $request->getUri()->getHost()),
secure: $this->config->get('session.options.secure', strtolower($request->getUri()->getScheme()) === 'https'),
secure: $this->config->get(
'session.options.secure',
strtolower($request->getUri()->getScheme()) === 'https'
),
httpOnly: true,
sameSite: $this->config->get('session.options.samesite', Cookie::SAMESITE_LAX)
);
@@ -57,12 +121,24 @@ class SessionMiddleware extends \Hyperf\Session\Middleware\SessionMiddleware
return $response->withCookie($cookie);
}
/**
* Get the full URL for the request.
*/
private function fullUrl(RequestInterface $request): string
{
$uri = $request->getUri();
$query = $uri->getQuery();
$question = $uri->getHost() . $uri->getPath() == '/' ? '/?' : '?';
return $query ? $this->url($request) . $question . $query : $this->url($request);
}
/**
* Get the session lifetime in seconds.
*/
private function getCookieExpirationDate(): int
private function getCookieExpirationDate(SessionInterface $session): int
{
if ($this->config->get('session.options.expire_on_close')) {
// if ($this->config->get('session.options.expire_on_close')) {
if (!$this->auth($session)) {
$expirationDate = 0;
} else {
$expireSeconds = $this->config->get('session.options.cookie_lifetime', 5 * 60 * 60);
@@ -70,4 +146,17 @@ class SessionMiddleware extends \Hyperf\Session\Middleware\SessionMiddleware
}
return $expirationDate;
}
/**
* Get the URL (no query string) for the request.
*/
private function url(RequestInterface $request): string
{
return rtrim(preg_replace('/\?.*/', '', (string)$request->getUri()));
}
private function auth(SessionInterface $session)
{
return $session->has('userInfo');
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
/**
* AbstractFactory.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*/
namespace Singularity\HDK\Core\Service;
use Dont\DontCall;
use Dont\DontInstantiate;
/**
* Singularity\HDK\Core\Service\AbstractFactory@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*/
abstract class AbstractFactory
{
use DontInstantiate;
use DontCall;
abstract static function make();
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* SingletonInterface.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*/
namespace Singularity\HDK\Core\Service;
use Dont\DontCallStatic;
use Dont\DontClone;
/**
* Singularity\HDK\Core\Service\SingletonInterface@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/8/30
*/
abstract class AbstractSingleton
{
use DontCallStatic;
use DontClone;
}

View File

@@ -11,6 +11,8 @@ namespace Singularity\HDK\Core\Service;
use Hyperf\Context\Context;
use function Hyperf\Config\config;
class ApiStyleService
{
public const RESTFUL = 'restful';

View File

@@ -18,6 +18,8 @@ use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use function Hyperf\Config\config;
/**
* 邮箱验证码
*/

View File

@@ -24,13 +24,10 @@ class ExtendService
array|string|null $params = null
): array {
$params ??= $request?->getQueryParams();
$extends = $params['extends'] ?? null;
if (!empty($extends)) {
$extends = explode(',', $extends);
return Context::set(self::class, array_map('trim', $extends));
}
$extends = explode(',', $params['extends'] ?? '');
$extends = array_map('trim', $extends);
return [];
return Context::set(self::class, array_filter($extends));
}
@@ -57,6 +54,6 @@ class ExtendService
*/
public function hasExtend(string $field): bool
{
return $this->utils->inArray($field, Context::get(self::class));
return $this->utils->inArray($field, Context::get(self::class) ?? []);
}
}

View File

@@ -6,29 +6,23 @@ namespace Singularity\HDK\Core\Service;
use Ergebnis\Http\Method;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\BadResponseException;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Utils;
use Hyperf\Codec\Json;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
use Hyperf\Utils\Codec\Json;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
/**
* 发起 Http 请求的类
* @deprecated since version 1.0-alpha.3, to be removed in 1.0
*/
class HttpRequestService
{
public const TIMEOUT = 20;
// public const TIMEOUT = 20;
/**
* @Inject()
* @var ClientFactory
*/
#[Inject]
private ClientFactory $client;
/**
@@ -39,14 +33,16 @@ class HttpRequestService
/**
* @param string $url
* @param array<string, string|int> $params
* @param array $data
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestGet(string $url, array $params = []): ResponseInterface
public function requestGet(string $url, array $params = [], array $data = []): ResponseInterface
{
$request = new Request(Method\Rfc\Rfc7231::GET, $url);
return $this->getClient()->send($request, [
'params' => $params,
'query' => $params,
'json' => $data,
]);
}
@@ -62,12 +58,17 @@ class HttpRequestService
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestPost(string $url, array $data = [], array $params = []): ResponseInterface
public function requestPost(string $url, array $params = [], array $data = []): ResponseInterface
{
$data = Json::encode($data);
$request = new Request('post', $url, ['Content-Type' => 'application/json'], Utils::streamFor($data));
$request = new Request(
'post',
$url,
['Content-Type' => 'application/json'],
Utils::streamFor($data),
);
return $this->getClient()->send($request, [
'params' => $params,
'query' => $params,
]);
}
@@ -79,18 +80,13 @@ class HttpRequestService
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestPut(string $url, array $data = [], array $params = []): ResponseInterface
public function requestPut(string $url, array $params = [], array $data = []): ResponseInterface
{
$data = Json::encode($data);
$request = new Request('put', $url, ['Content-Type' => 'application/json'], Utils::streamFor($data));
$result = $this->getClient()->send($request, [
'params' => $params,
return $this->getClient()->send($request, [
'query' => $params,
]);
$json = Json::decode($result->getBody()->getContents());
if ($json['code'] !== 200) {
throw new ServerException($json['message'], $request, $result);
}
return $result;
}
/**
@@ -103,20 +99,4 @@ class HttpRequestService
$this->options = array_replace_recursive($this->options, $options);
return $this;
}
/**
* @param ResponseInterface $response
* @param RequestInterface $request
* @return ResponseInterface
*/
private function parseResponse(
ResponseInterface $response,
RequestInterface $request
): ResponseInterface {
if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
return $response;
} else {
throw new BadResponseException($response->getReasonPhrase(), $request, $response);
}
}
}

View File

@@ -9,7 +9,9 @@
namespace Singularity\HDK\Core\Service;
use Hyperf\Utils\Codec\Json;
use Hyperf\Codec\Json;
use function Hyperf\Config\config;
class OssService
{

View File

@@ -6,12 +6,14 @@ use AlibabaCloud\SDK\Dysmsapi\V20170525\Dysmsapi;
use AlibabaCloud\SDK\Dysmsapi\V20170525\Models\SendSmsRequest;
use AlibabaCloud\Tea\Exception\TeaError;
use Darabonba\OpenApi\Models\Config;
use Hyperf\Codec\Json;
use Hyperf\HttpMessage\Exception\ServerErrorHttpException;
use Hyperf\Utils\Codec\Json;
use Singularity\HDK\Core\Constants\CommonErrorCode;
use Singularity\HDK\Core\Exceptions\ValidateException;
use UnexpectedValueException;
use function Hyperf\Config\config;
/**
* 短信服务
*/

View File

@@ -8,7 +8,6 @@ use Closure;
use Exception;
use Generator;
use Hyperf\HttpServer\Contract\RequestInterface;
use JetBrains\PhpStorm\NoReturn;
use JetBrains\PhpStorm\Pure;
use Psr\Http\Message\ResponseInterface;
@@ -236,7 +235,6 @@ class UtilsService
*
* @return void
*/
#[NoReturn]
public function unlimitedSubCategoriesQuicklyWithLevel(
array &$list,
int $level = 1,

View File

@@ -27,13 +27,8 @@ class XmlService
* @param string $xmlVersion
* @param string $xmlEncoding
* @param bool $xmlStandalone 是否添加声明规范的标签到xml
* @param bool $xmlTypeCastAttributes
* @param bool $asCollection
* @param int[] $decoderIgnoredNodeTypes
* @param int[] $encoderIgnoredNodeTypes
* @param int $loadOptions
* @param bool $removeEmptyTags
*
* @return false|string
* @see https://symfony.com/doc/current/components/serializer.html#the-xmlencoder
*/
@@ -44,29 +39,48 @@ class XmlService
string $xmlVersion = '1.0',
string $xmlEncoding = 'utf-8',
bool $xmlStandalone = false,
bool $xmlTypeCastAttributes = true,
bool $asCollection = true,
array $decoderIgnoredNodeTypes = [XML_PI_NODE, XML_COMMENT_NODE],
array $encoderIgnoredNodeTypes = [],
int $loadOptions = LIBXML_NONET | LIBXML_NOBLANKS,
bool $removeEmptyTags = false
bool $removeEmptyTags = false,
): false|string {
return $this->service->encode(
$data,
XmlEncoder::FORMAT,
[
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => $encoderIgnoredNodeTypes,
XmlEncoder::ROOT_NODE_NAME => $xmlRootNodeName,
XmlEncoder::FORMAT_OUTPUT => $xmlFormatOutput,
XmlEncoder::VERSION => $xmlVersion,
XmlEncoder::ENCODING => $xmlEncoding,
XmlEncoder::STANDALONE => $xmlStandalone,
XmlEncoder::TYPE_CAST_ATTRIBUTES => $xmlTypeCastAttributes,
XmlEncoder::ROOT_NODE_NAME => $xmlRootNodeName,
XmlEncoder::AS_COLLECTION => $asCollection,
XmlEncoder::DECODER_IGNORED_NODE_TYPES => $decoderIgnoredNodeTypes,
XmlEncoder::ENCODER_IGNORED_NODE_TYPES => $encoderIgnoredNodeTypes,
XmlEncoder::LOAD_OPTIONS => $loadOptions,
XmlEncoder::REMOVE_EMPTY_TAGS => $removeEmptyTags,
]
);
}
/**
* @param string $xml
* @param bool $xmlTypeCastAttributes 是否自动转换类型
* @param bool $asCollection 是否全部使用数组
* @param int[] $decoderIgnoredNodeTypes
* @param int $loadOptions
* @return array<string, mixed>
*/
public function decode(
string $xml,
bool $xmlTypeCastAttributes = true,
bool $asCollection = false,
array $decoderIgnoredNodeTypes = [XML_PI_NODE, XML_COMMENT_NODE],
int $loadOptions = LIBXML_NONET | LIBXML_NOBLANKS,
): array {
return $this->service->decode(
$xml,
XmlEncoder::FORMAT,
[
XmlEncoder::LOAD_OPTIONS => $loadOptions,
XmlEncoder::DECODER_IGNORED_NODE_TYPES => $decoderIgnoredNodeTypes,
XmlEncoder::TYPE_CAST_ATTRIBUTES => $xmlTypeCastAttributes,
XmlEncoder::AS_COLLECTION => $asCollection,
]
);
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* Paginatable.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/7/18
*/
namespace Singularity\HDK\Core\Traits;
use Closure;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Database\Model\Builder;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Stringable\Str;
use Singularity\HDK\Core\Service\ExtendService;
trait RestfulList
{
#[Inject]
protected ExtendService $extend;
#[Inject]
protected RequestInterface $request;
protected function restSelect(Closure $callback, ?Closure $filter = null)
{
$options = [];
$result = $this->parseParameters(function ($query, $parsedOptions) use ($callback, &$options) {
$options = $parsedOptions;
$callback($query, $parsedOptions);
});
return $this->responseFormatter($options, $result, $filter);
}
protected function parseParameters(Closure $callback): mixed
{
$query = $this->request->getQueryParams();
$options = [
'size' => $this->request->query('size'),
'page' => $this->request->query('page'),
'order' => $this->request->query('order', 'created_at'),
'sort' => $this->request->query('sort', 'desc'),
'group' => $this->request->query('group'),
'extends' => $this->extend->getExtends(),
];
unset($query['sort'], $query['page'], $query['size'], $query['order'], $query['group'], $query['extends']);
return $callback(query: $query, options: $options);
}
protected function responseFormatter(
array $options,
Builder $builder,
?Closure $filter = null
) {
$perPage = $options['size'] ?? null;
$order = $options['order'] ?? 'created_at';
$sort = $options['sort'] ?? 'desc';
$pagination = !!($options['page'] ?? $perPage ?? false);
// $group = $options['group'] ?? null;
$builder = $builder->orderBy(Str::snake($order), $sort);
$result = $pagination ? $builder->paginate($perPage) : $builder->get();
if (is_null($filter)) {
return $result;
}
if ($result instanceof LengthAwarePaginatorInterface) {
$collection = $result->getCollection();
$collection = $filter($collection);
return $result->setCollection($collection);
}
return $filter($result);
}
}

View File

@@ -9,12 +9,10 @@
namespace Singularity\HDK\Test\Core\Unit;
use Hyperf\Context\Context;
use Singularity\HDK\Core\Service\ExtendService;
use Singularity\HDK\Core\Service\UtilsService;
$service = new ExtendService(new UtilsService());
/** @var ExtendService $service */
$service = make(ExtendService::class, ['utils' => new UtilsService()]);
it('asserts no parameters can be parsed.', function (ExtendService $service, $params) {
@@ -23,7 +21,7 @@ it('asserts no parameters can be parsed.', function (ExtendService $service, $pa
$params
);
$result = $service->getExtends();
expect($result)->toBeArray()->toHaveCount(0)->toBe([]);
expect($result)->toBeArray()->toBe([])->toHaveCount(0)->toBe([]);
})->with([
[$service, null],
[$service, ''],
@@ -32,6 +30,11 @@ it('asserts no parameters can be parsed.', function (ExtendService $service, $pa
[$service, ['extends' => null]],
]);
it('asserts has no specify extend', function () use ($service) {
Context::destroy(ExtendService::class);
expect($service->hasExtend('a'))->toBeFalse();
})->depends('it asserts query parameters can be parsed.');
it('asserts query parameters can be parsed.', function () use ($service) {
$result = $service->parse(
null,
@@ -44,19 +47,21 @@ it('asserts query parameters can be parsed.', function () use ($service) {
});
it('asserts has extends', function () use ($service) {
Context::set(ExtendService::class, ['a', 'b']);
expect($service->hasExtends())->toBeTrue();
});
it('asserts has specify extend', function () use ($service) {
Context::set(ExtendService::class, ['a', 'b']);
expect($service->hasExtend('a'))->toBeTrue()
->and($service->hasExtend('b'))->toBeTrue()
->and($service->hasExtend('c'))->toBeFalse();
})->depends('it asserts query parameters can be parsed.');
it('asserts parsed extends', function () use ($service) {
$extends = $service->getExtends();
expect($extends)->toBeArray()->toMatchArray([
'a',
'b',
]);
})->depends('it asserts query parameters can be parsed.');
// it('asserts parsed extends', function () use ($service) {
// $extends = $service->getExtends();
// expect($extends)->toBeArray()->toMatchArray([
// 'a',
// 'b',
// ]);
// })->depends('it asserts query parameters can be parsed.');

View File

@@ -7,7 +7,7 @@
* Created on 2023/1/9
*/
use Hyperf\Utils\Codec\Json;
use Hyperf\Codec\Json;
use Singularity\HDK\Core\Service\OssService;
use function Spatie\PestPluginTestTime\testTime;

View File

@@ -0,0 +1,41 @@
<?php
/**
* RequestServiceTest.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/20
*/
namespace Singularity\HDK\Test\Core\Unit;
use Singularity\HDK\Core\Http\RequestService;
use Singularity\HDK\Core\Http\RequestServiceFactory;
class RequestServiceTest
{
private RequestService $service;
public function __construct()
{
$this->service = RequestServiceFactory::make();
}
public function getInstance(): RequestService
{
return $this->service;
}
}
test('Http 请求服务可以正常使用', function () {
/** @var RequestServiceTest $class */
$class = \Hyperf\Support\make(RequestServiceTest::class);
$response = $class->getInstance()->requestGet('http://baidu.com/');
$content = $response->getBody()->getContents();
expect($content)->toBe(<<<HTML
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>
HTML);
});

View File

@@ -12,7 +12,13 @@ namespace HyperfTest\Unit\Common;
use Singularity\HDK\Core\Service\XmlService;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
$service = new XmlService(new XmlEncoder());
use function Hyperf\Support\make;
/** @var XmlService $service */
$service = make(
XmlService::class,
['encoder' => make(XmlEncoder::class)]
);
test(
'assert Xml can be encoded',
@@ -40,8 +46,7 @@ test(
<validTime>2099/03/27</validTime>
</ClientInfo>
XML
,
XML,
'xmlRootNodeName' => 'ClientInfo',
],
'normal attribute' => [
@@ -99,3 +104,27 @@ XML
'ClientInfo',
],
]);
test('assert Xml can be parsed', function (string $xml, array $expected) use ($service) {
$data = $service->decode($xml);
expect($data)->toBe($expected);
})->with([
'normal' => [
'xml' => <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<ClientInfo version="1.0" descripe="LuxAlignAuthentication">
<UserName>zhm</UserName>
<Email>haimei.zheng@luxcreo.ai</Email>
<BiosId>420036H32020120279</BiosId>
</ClientInfo>
XML,
'expected' => [
'@version' => 1.0,
'@descripe' => 'LuxAlignAuthentication',
'UserName' => 'zhm',
'Email' => 'haimei.zheng@luxcreo.ai',
'BiosId' => '420036H32020120279',
],
],
]);

View File

@@ -9,8 +9,29 @@ declare(strict_types=1);
* @contact group@hyperf.io
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSource;
use Psr\Container\ContainerInterface;
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
error_reporting(E_ALL);
date_default_timezone_set('Asia/Shanghai');
!defined('BASE_PATH') && define('BASE_PATH', dirname(__DIR__, 1));
!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);
Swoole\Runtime::enableCoroutine(true);
require BASE_PATH . '/vendor/autoload.php';
Hyperf\Di\ClassLoader::init();
$container = new Container(new DefinitionSource([]));
if (!$container instanceof ContainerInterface) {
throw new RuntimeException('The dependency injection container is invalid.');
}
$container = ApplicationContext::setContainer($container);