Compare commits

..

31 Commits

Author SHA1 Message Date
李东云
76387a45b4 chore(release): 0.1.10 2025-09-26 17:30:11 +08:00
李东云
0009619d9c ci: 添加发布到注册表的CI工作流
- 创建了基于标签推送触发的发布工作流
- 实现了仓库代码检出和文件列表展示
- 添加了使用阿里云镜像源的依赖安装和打包步骤
- 集成了将构建产物上传到私有注册表的功能
- 配置了完整的CI运行状态输出和调试信息

Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2025-09-26 17:29:56 +08:00
ch4o5
c060e84476 chore(release): 0.1.9 2024-09-12 11:06:35 +00:00
李东云
bebac5992a feat(email): 增加了单独定制发件人的方法
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2024-09-12 19:06:23 +08:00
ch4o5
7d15d85515 chore(release): 0.1.8 2024-09-12 10:31:25 +00:00
李东云
04719839ad build(composer): 更新依赖
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2024-09-12 18:31:00 +08:00
李东云
1c057722bc feat(email): 增加了密送参数
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2024-09-12 18:28:29 +08:00
ch4o5
52f4867c72 chore(release): 0.1.7 2023-07-05 08:49:21 +00:00
李东云
b51699b0d9 feat(session): 增加了定制的 session 中间件
只有已登录的 Session 才保存

Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-05 16:49:04 +08:00
李东云
a570e1964e build(composer): 更新依赖
限定了 hyperf/crontab 的版本,避开有问题的版本
2023-03-30 18:00:00 +08:00
ch4o5
def9f0469d chore(release): 0.1.6 2023-03-21 03:02:49 +00:00
李东云
5ed5070f32 build(composer): 更新依赖 2023-03-21 11:02:17 +08:00
李东云
8dcf586baf test(email): 更新了邮件发送的测试账号 2023-02-27 11:05:13 +08:00
李东云
a7a8087509 fix(middleware.i18n): 尝试修复了多语言无法正确获取的问题 2023-02-18 15:50:46 +08:00
ch4o5
e50a2e08df chore(release): 0.1.5 2023-02-03 02:28:18 +00:00
李东云
fca8f9d013 fix(commonHandler): 修复了一处兼容问题 2023-02-03 10:28:00 +08:00
ch4o5
113e7fca57 chore(release): 0.1.4 2023-02-02 08:03:53 +00:00
李东云
24161f0841 style(cs-fixer): prettier 2023-02-02 16:03:44 +08:00
ch4o5
fe3181c7d1 chore(release): 0.1.3 2023-02-02 07:33:26 +00:00
李东云
6c27804856 fix(extend): 修复了解析不到为空不为数组的问题 2023-02-02 15:32:11 +08:00
李东云
c3eb95d300 fix(extend): 修复了解析不到为null不为数组的问题 2023-02-01 21:11:46 +08:00
李东云
a7a61bd674 fix(extend): 修复了解析不到为null不为数组的问题 2023-02-01 21:05:51 +08:00
李东云
7fd7d23051 feat(email/sms): 添加了发送邮件和短信的事件 2023-01-29 16:41:30 +08:00
李东云
0b4fb23779 build(composer): 修复 php 版本限制 2023-01-28 18:43:57 +08:00
李东云
eb20bc9fdb build(composer): 修复 php 版本限制 2023-01-28 18:42:49 +08:00
ch4o5
01350cbb6c chore(release): 0.1.2 2023-01-28 10:37:19 +00:00
李东云
1f0ef04c7a build(composer): 修复 ConfigProvider 命名空间 2023-01-28 18:37:11 +08:00
ch4o5
4b2c03f8ec chore(release): 0.1.1 2023-01-28 10:33:27 +00:00
李东云
0fa3c23a3e refactor: 向后兼容到7.4 2023-01-28 18:25:44 +08:00
李东云
c83728cad2 feat: 增加了inArray、hasExtends方法 2023-01-19 17:43:57 +08:00
李东云
3e2d3400b4 docs(README): 提示版本过期,需要更新 2023-01-16 22:33:56 +08:00
62 changed files with 3304 additions and 8323 deletions

View File

@@ -0,0 +1,30 @@
name: Release development version to registry
on:
push:
tags:
- '**.**'
jobs:
Publish on Tagged:
runs-on: ubuntu-latest
steps:
- run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}."
- name: Check out repository code
uses: actions/checkout@v4
- run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner."
- name: List files in the repository
run: |
ls ${{ gitea.workspace }}
- name: Zip files in the repository
run: |
sed -i 's|deb.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list
sed -i 's|security.debian.org|mirrors.aliyun.com|g' /etc/apt/sources.list
apt-get update
apt-get install zip
zip -r dist.zip *
- name: Publish to registry
run: |
curl --user ch4o5:4fd300672472e666014314c1c94c604c634165a9 \
--upload-file ./dist.zip \
https://nest.doylee.cn/api/packages/HDK/composer?version=${{ gitea.ref_name }}
- run: echo "🍏 This job's status is ${{ job.status }}."

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

@@ -30,6 +30,7 @@
<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" />
@@ -62,6 +63,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/http-message" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/exception-handler" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/macroable" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/engine" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/pool" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/event" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/validation" />
@@ -80,6 +82,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/manifest" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phar-io/version" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-timer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-text-template" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-code-coverage" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/php-invoker" />
@@ -88,7 +91,6 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php81" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/translation-contracts" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/event-dispatcher" />
@@ -109,6 +111,7 @@
<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" />
@@ -133,31 +136,7 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/friendsofphp/php-cs-fixer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/filp/whoops" />
<excludeFolder url="file://$MODULE_DIR$/vendor/doctrine/deprecations" />
<excludeFolder url="file://$MODULE_DIR$/vendor/phpunit/phpunit" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/engine" />
<excludeFolder url="file://$MODULE_DIR$/vendor/spatie/pest-plugin-test-time" />
<excludeFolder url="file://$MODULE_DIR$/vendor/spatie/test-time" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/coordinator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/engine-contract" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/resource" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/paginator" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/guzzle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/http-foundation" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/collection" />
<excludeFolder url="file://$MODULE_DIR$/vendor/hyperf/db" />
<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" />
<excludeFolder url="file://$MODULE_DIR$/vendor/facade/ignition-contracts" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

12
.idea/codeception.xml generated
View File

@@ -1,12 +0,0 @@
<?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,7 +1,8 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PhpDocSignatureInspection" enabled="true" level="INFORMATION" enabled_by_default="true" />
<inspection_tool class="PhpCSFixerValidationInspection" enabled="true" level="WEAK WARNING" 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
View File

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

24
.idea/php-docker-settings.xml generated Normal file
View File

@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpDockerContainerSettings">
<list>
<map>
<entry key="9fb85f67-19fd-423f-9358-1b155a12eb7d">
<value>
<DockerContainerSettings>
<option name="version" value="1" />
<option name="volumeBindings">
<list>
<DockerVolumeBindingImpl>
<option name="containerPath" value="/opt/project" />
<option name="hostPath" value="$PROJECT_DIR$" />
</DockerVolumeBindingImpl>
</list>
</option>
</DockerContainerSettings>
</value>
</entry>
</map>
</list>
</component>
</project>

44
.idea/php.xml generated
View File

@@ -46,6 +46,7 @@
<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" />
@@ -78,8 +79,6 @@
<path value="$PROJECT_DIR$/vendor/hyperf/http-message" />
<path value="$PROJECT_DIR$/vendor/hyperf/exception-handler" />
<path value="$PROJECT_DIR$/vendor/hyperf/macroable" />
<path value="$PROJECT_DIR$/vendor/hyperf/resource" />
<path value="$PROJECT_DIR$/vendor/hyperf/paginator" />
<path value="$PROJECT_DIR$/vendor/hyperf/engine" />
<path value="$PROJECT_DIR$/vendor/hyperf/pool" />
<path value="$PROJECT_DIR$/vendor/hyperf/event" />
@@ -108,7 +107,6 @@
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php80" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-ctype" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
<path value="$PROJECT_DIR$/vendor/symfony/translation" />
<path value="$PROJECT_DIR$/vendor/symfony/translation-contracts" />
<path value="$PROJECT_DIR$/vendor/symfony/event-dispatcher" />
@@ -129,12 +127,14 @@
<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" />
@@ -147,38 +147,28 @@
<path value="$PROJECT_DIR$/vendor/pestphp/pest-plugin" />
<path value="$PROJECT_DIR$/vendor/filp/whoops" />
<path value="$PROJECT_DIR$/vendor/nunomaduro/collision" />
<path value="$PROJECT_DIR$/vendor/spatie/test-time" />
<path value="$PROJECT_DIR$/vendor/spatie/pest-plugin-test-time" />
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" />
<path value="$PROJECT_DIR$/vendor/friendsofphp/php-cs-fixer" />
<path value="$PROJECT_DIR$/vendor/symfony/options-resolver" />
<path value="$PROJECT_DIR$/vendor/symfony/stopwatch" />
<path value="$PROJECT_DIR$/vendor/phpstan/phpstan" />
<path value="$PROJECT_DIR$/vendor/doctrine/deprecations" />
<path value="$PROJECT_DIR$/vendor/hyperf/coordinator" />
<path value="$PROJECT_DIR$/vendor/hyperf/guzzle" />
<path value="$PROJECT_DIR$/vendor/hyperf/engine-contract" />
<path value="$PROJECT_DIR$/vendor/hyperf/crontab" />
<path value="$PROJECT_DIR$/vendor/symfony/http-foundation" />
<path value="$PROJECT_DIR$/vendor/hyperf/pipeline" />
<path value="$PROJECT_DIR$/vendor/hyperf/collection" />
<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" />
<path value="$PROJECT_DIR$/vendor/hyperf/crontab" />
<path value="$PROJECT_DIR$/vendor/fidry/cpu-core-counter" />
<path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
<path value="$PROJECT_DIR$/vendor/cooper/hyperf-pest" />
<path value="$PROJECT_DIR$/vendor/clue/ndjson-react" />
<path value="$PROJECT_DIR$/vendor/evenement/evenement" />
<path value="$PROJECT_DIR$/vendor/react/child-process" />
<path value="$PROJECT_DIR$/vendor/react/cache" />
<path value="$PROJECT_DIR$/vendor/react/dns" />
<path value="$PROJECT_DIR$/vendor/react/stream" />
<path value="$PROJECT_DIR$/vendor/react/event-loop" />
<path value="$PROJECT_DIR$/vendor/react/socket" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
<component name="PhpProjectSharedConfiguration" php_language_level="7.4" />
<component name="PhpStan">
<PhpStan_settings>
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />

31
.idea/phpspec.xml generated
View File

@@ -1,31 +0,0 @@
<?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

@@ -30,10 +30,6 @@
"type": "perf",
"section": "⚡ Performance Improvements | 性能优化"
},
{
"type": "tests",
"section": "✅ Tests | 测试"
},
{
"type": "test",
"section": "✅ Tests | 测试"
@@ -57,7 +53,7 @@
],
"bumpFiles": [
{
"filename": "VERSION_TRACKER.txt",
"filename": "MY_VERSION_TRACKER.txt",
"type": "plain-text"
},
{

View File

@@ -1,299 +1,101 @@
# 版本更新日志
## [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)
### [0.1.10](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.9...v0.1.10) (2025-09-26)
### 📦‍ Build System | 打包构建
### 👷 Continuous Integration | CI 配置
* **composer:** 引入 pest 并升级到 php8.1 ([dbbe278](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/dbbe278aa6c96634ed5792b5782825770c5cabe8))
* 添加发布到注册表的CI工作流 ([0009619](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/0009619d9c74472dd2477d29896fa8e1e64fee36))
### [0.1.9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.8...v0.1.9) (2024-09-12)
### ✨ Features | 新功能
* **i18n:** 增加枚举值,更新中间件调用方式 ([4032d67](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4032d67f1e56b8ce29fbfa5bd77ead2636a6ffd3))
* **email:** 增加了单独定制发件人的方法 ([bebac59](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/bebac5992a89ebe41eb20ea926938f4b3fde2cc1))
### [0.1.8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.7...v0.1.8) (2024-09-12)
### ✨ Features | 新功能
* **email:** 增加了密送参数 ([1c05772](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/1c057722bcf407ab1faf6b5feb285e1e472fc627))
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([0471983](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/04719839ad518ef3c00ffb67b8b563561de36858))
### [0.1.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.6...v0.1.7) (2023-07-05)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([a570e19](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a570e1964e01b9e29de05f4a7607a4ed567beffa))
### ✨ Features | 新功能
* **session:** 增加了定制的 session 中间件 ([b51699b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b51699b0d98322df33fb3a0bccebe5f4034e2a71))
### [0.1.6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.5...v0.1.6) (2023-03-21)
### 🐛 Bug Fixes | Bug 修复
* **middleware.i18n:** 尝试修复了多语言无法正确获取的问题 ([a7a8087](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a7a80875092653e56d8dc9351743a08933d59282))
### ✅ 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)
* **email:** 更新了邮件发送的测试账号 ([8dcf586](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/8dcf586baf1960f906d63c15f3d659b16b456048))
### 📦‍ 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))
* **composer:** 更新依赖 ([5ed5070](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/5ed5070f323d0ea34b8c99b5ac826dc6c24431df))
## [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)
### [0.1.5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.4...v0.1.5) (2023-02-03)
### 🐛 Bug Fixes | Bug 修复
* **i18n:** 修复获取偏好语言失败的问题 ([722d124](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/722d124e1ed87c493dfb8841212b408717444d98))
* **commonHandler:** 修复了一处兼容问题 ([fca8f9d](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/fca8f9d013e1d121bf8bc997710d77ff038fdae0))
### [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)
### ✨ Features | 新功能
* **handler:** 补充 restful 响应的状态码 ([e69c149](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/e69c1494c3ec0a8d26341f1891d7d067511e8baf))
### [0.2.13](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.12...v0.2.13) (2023-04-11)
### ✨ Features | 新功能
* **xml:** 增加了 xml 生成的方法及测试用例 ([90a521f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/90a521f90acee7fd6efe6f0a554e749c16fadc1c))
### [0.2.12](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.11...v0.2.12) (2023-04-10)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖以兼容 nano ([7e5cb89](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7e5cb89dfe1c09390e78cdd527c60151f2cd0418))
* **phpstan:** fix ([c25e6ee](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c25e6eed52e83d2ca62fc3d0cf83f508a1045c5a))
* **scripts:** 更新脚本 ([4ba0cb8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4ba0cb83f5dc88817260cb2b2dfde491c6b5ba75))
### [0.2.11](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.10...v0.2.11) (2023-04-03)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([78b56a6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/78b56a6aa9038743be7df9a17787b94771e226c3))
* **composer:** 更新依赖 ([c991c31](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c991c312609e7501c7adad28ec8229efad717db0))
### ✨ Features | 新功能
* **i18n:** 引入了 symfony 的 Accept-Language 机制 ([859a1a1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/859a1a1f2aa683f9f026652952d1a03ba5d7be02))
### [0.2.10](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.9...v0.2.10) (2023-03-21)
### 📦‍ Build System | 打包构建
* **composer:** 只留下了腾讯源,更新依赖 ([afec642](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/afec6424545daa3b3f2a4b91e97e359b4a840a19))
* **composer:** 只留下了腾讯源,更新依赖 ([b2debf9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b2debf9c135554a15639c299f183c43f3682545b))
* **composer:** 更新依赖 ([70ad307](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/70ad3078b1ddeeeb0179dd44770e959ecf072fed))
### [0.2.9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.8...v0.2.9) (2023-03-15)
### 🐛 Bug Fixes | Bug 修复
* 修复了一处大小写错误 ([2d2a535](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2d2a535fd2c1ae13195f13498864540b503edd1e))
### ✨ Features | 新功能
* 增加了inArray、hasExtends方法 ([de96e28](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/de96e288c3429c58deed15ea667a5e15a34fb81f))
* 增加了对 session 中间件配置 cookie 方式的补充 ([a618af5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a618af5ab353f478dd4bcce18a7b84f611fd0c7a))
* 增加默认api风格参数 ([e33c115](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/e33c1159388efa3590e81f484c01a66d21f8b574))
* 实现了通过中间件设置是否 restful 的逻辑 ([2d2148f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2d2148f3ecabef09801a225632430bf103dbf218))
* 添加了 http 请求服务 ([7c1efe1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7c1efe1a1f18f082ed7b7b6383112034982e2893))
* **api:** 增加了可以使用中间件定制是否 restful 的逻辑 ([b8c3d6d](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b8c3d6d06810fb920df200a4d75746b49e2fbd07))
### [0.2.8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.7...v0.2.8) (2023-02-03)
### 🐛 Bug Fixes | Bug 修复
* **commonHandler:** 修复了一处兼容问题 ([c8f9b79](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c8f9b793ee7c2ba4d77a2779b6825211dcf52636))
### [0.2.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.6...v0.2.7) (2023-02-02)
### ⚡ Performance Improvements | 性能优化
* **Sms:** 修改抛出的异常类型,追加方法注释 ([5a1a2a8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/5a1a2a89bd7d706a6e8d1ef567c59969d8d63554))
### ✨ Features | 新功能
* **Email:** 实现了邮件发送的事件机制 ([8757908](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/8757908f3f8a6dff5516bd6e449c8dd3952ec2cd))
* **Listener:** 添加了一个抽象监听器类,预先注入了一些属性 ([1dbad8e](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/1dbad8e5a65d299b9a56b6a5c4759be5c3736707))
* **Sms:** 实现了短信发送的事件机制 ([5151787](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/51517879820de832395efc40bb308a736f33f131))
### ✏️ Documentation | 文档
* **README:** 修复一直报错的文件名 ([135db1b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/135db1bf6aeeedbb0d59405567bb4837f3221e49))
* **Sms:** 补充所抛出异常的注释 ([b65818b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b65818bfb6d8368514d517c31dd6b6696b2d08be))
### ✅ Tests | 测试
* **extend:** 补充测试用例 ([e41847a](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/e41847a2340916de24726f8266dca8b514b4edd3))
### 🐛 Bug Fixes | Bug 修复
* **extend:** 修复了解析不到为空不为数组的问题 ([099ab60](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/099ab601030caef52806f5b9ec4d62fb27b08e72))
### [0.1.4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.3...v0.1.4) (2023-02-02)
### 💄 Styles | 风格
* **cs-fixer:** prettier ([a729270](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a729270fac57cd617e8f166bb59f9ccffe33358b))
* **cs-fixer:** prettier ([24161f0](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/24161f084127602a32d9a7ca3af122eb26169fec))
### [0.2.6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.5...v0.2.6) (2023-01-16)
### [0.1.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.2...v0.1.3) (2023-02-02)
### 💄 Styles | 风格
### 📦‍ Build System | 打包构建
* 移除冗余的注释 ([3d09207](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3d092074b3784b120cabb1561a9d6b9af5c3c428))
### 🐛 Bug Fixes | Bug 修复
* **configure:** 修复配置文件和实际应用的字段名不统一 ([d1bae3e](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/d1bae3e623dde3839acb44d4a7905c7dab78e8ce))
### [0.2.5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.4...v0.2.5) (2023-01-13)
* **composer:** 修复 php 版本限制 ([0b4fb23](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/0b4fb2377985dc70a2cfa5a603f73e2ced14dc8c))
* **composer:** 修复 php 版本限制 ([eb20bc9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/eb20bc9fdbc887d0e478a3ceaa4396001fbbbdfd))
### ✨ Features | 新功能
* **CoreMiddleware:** 增加restful场景下的分页响应处理 ([aeddb55](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/aeddb55988e714e53b7458ead8668dee6ebec63e))
### [0.2.4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.3...v0.2.4) (2023-01-13)
### ⏪ Revert | 回退
* **constant:** 移除冗余的http头authentication的枚举类型 ([cdb1937](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/cdb193778fb888851682bb1671bc55dd8f0e3423))
* **email/sms:** 添加了发送邮件和短信的事件 ([7fd7d23](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7fd7d2305120f60b70390b49c6256b01fbec6485))
### 🐛 Bug Fixes | Bug 修复
* **oss:** 修复了oss的配置缺失和错误 ([922c780](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/922c780c49edc2cddbce3e66e6b9dfde7be364f8))
* **extend:** 修复了解析不到为null不为数组的问题 ([c3eb95d](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c3eb95d300f312b14204edd6b97d80b76c273ff3))
* **extend:** 修复了解析不到为null不为数组的问题 ([a7a61bd](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a7a61bd6748ca432e95c396738ebdd7dcfe96463))
* **extend:** 修复了解析不到为空不为数组的问题 ([6c27804](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/6c278048568c6b070192b290f54562f05c1803e6))
### [0.2.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.2...v0.2.3) (2023-01-13)
### [0.1.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.1.1...v0.1.2) (2023-01-28)
### ✏️ Documentation | 文档
### 📦‍ Build System | 打包构建
* **link:** 增加错误码对应的语雀文档 ([3a1f269](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3a1f2695fef03840d9afe3578f3e7ed33da45926))
* **composer:** 修复 ConfigProvider 命名空间 ([1f0ef04](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/1f0ef04c7a092e2d7df1cafb94b3a50a04ee66cd))
### ✨ Features | 新功能
* **constant:** 增加http头authentication的枚举类型 ([08c1f66](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/08c1f6609c3035dd7d7f39e8389b66a8ba2e34a5))
### [0.2.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.1...v0.2.2) (2023-01-13)
### ⚡ Performance Improvements | 性能优化
* **exceptions.handler:** 优化trace显示格式 ([9f9ff31](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9f9ff31a83ea5662500c688471b78f02ff67eb15))
### 0.2.1 (2023-01-13)
### 0.1.1 (2023-01-28)
### 🎉 Init | 初始化
@@ -302,35 +104,15 @@
* 初始化项目 ([a13779a](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a13779ab3fb617189227b9d2c0462588be8ceee5))
### ✅ Tests | 测试
* **oss:** 增加 oss 票据生成的测试文件 ([b5970d5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b5970d543435495706502c5b67897ff1cfd5fb85))
* **service:** 添加了base64Wrapper的测试 ([69ce665](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/69ce66561f19e44d35b134c6d032ff69f48201a3))
* **service:** 添加了发送邮件的测试 ([65e3485](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/65e34857e2978a9952ee89df71b1e0c9101ec69c))
* **service:** 添加了解析 extends 的测试 ([da1d6c6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/da1d6c68d21b2739c8bb1701243e6419eae14975))
### ✨ Features | 新功能
* **utils:** 重写了构造URL的方法增加对应的单元测试 ([9f79d14](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9f79d1465ba6ed4b4c0d0c30e23ffa34bbeece65))
* 迁移到了 Core 命名空间下 ([a8a582f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a8a582f3aa0948c982e31bf8938b6f3331d8dc6d))
### ✏️ Documentation | 文档
* **core:** 添加作者信息 ([096d4e5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/096d4e56ed30c23de1338bb6f057a91e629c6ea5))
* **README:** 增加说明文件 ([4cf16ae](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4cf16ae0cdcf6f7a1eb99fde95a6c3ef01bd7b2b))
### ⚡ Performance Improvements | 性能优化
* **utils:** 获取真实IP方法增加apache的处理 ([47e522c](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/47e522c67bf595282df7671f1d045e44593022bf))
### ♻️ Code Refactoring | 代码重构
### 🚀 Chore | 构建/工程依赖/工具
* **migrate:** 迁移注解以支持hyperf3 ([480f406](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/480f406cccde21f5fb39ba431b6f633c562e5f96))
* **migrate:** 迁移注解以支持hyperf3 ([91db3c7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/91db3c731f651e178f830953bf97958c5ddc973d))
* 移除调试用的打印语句 ([37ed1ce](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/37ed1cef77d094f6cd78dd1c97f5d2e3cf6376a3))
* **tests:** 移除了示例测试文件 ([e705bed](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/e705bedd5d3e72887e9e5fac35926237db844116))
### 📦‍ Build System | 打包构建
@@ -341,17 +123,23 @@
* **composer:** 更新依赖 ([1e4fbe5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/1e4fbe59276ed2913aa21973f9502505115d2628))
* **composer:** 添加依赖到开发环境 ([9f5699f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9f5699f39cd7a89c37e9365322c6082a97a973f4))
* **version:** 添加changelog配置 ([4deffe0](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4deffe055ebe8586a183103d84dcd5b97969ca7d))
* **version:** 添加changelog配置及脚本 ([3bc4e27](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3bc4e275a761bf71bb0ca227770b82c3d5ec76bb))
* 迁移到hyperf3 ([9fedbb4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9fedbb40f4c9f3221a97986dc7063d049c914728))
### 🚀 Chore | 构建/工程依赖/工具
### ✏️ Documentation | 文档
* **release:** 0.2.1-0 ([ab44630](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/ab44630db8c2d05c21bccdf0899569f911b01473))
* 移除调试用的打印语句 ([37ed1ce](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/37ed1cef77d094f6cd78dd1c97f5d2e3cf6376a3))
* **tests:** 移除了示例测试文件 ([e705bed](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/e705bedd5d3e72887e9e5fac35926237db844116))
* **core:** 添加作者信息 ([096d4e5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/096d4e56ed30c23de1338bb6f057a91e629c6ea5))
* **README:** 修复一直报错的文件名 ([135db1b](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/135db1bf6aeeedbb0d59405567bb4837f3221e49))
* **README:** 增加说明文件 ([4cf16ae](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4cf16ae0cdcf6f7a1eb99fde95a6c3ef01bd7b2b))
* **README:** 提示版本过期,需要更新 ([3e2d340](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3e2d3400b45edf4b503a91c078aaa3ef0fff553e))
### 🐛 Bug Fixes | Bug 修复
### ✨ Features | 新功能
* **composer:** 修复ConfigProvider命名空间 ([3989f59](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3989f5913ea56cba8751afc225c19b8f6730d2c3))
* 增加了inArray、hasExtends方法 ([c83728c](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c83728cad28438c3bcef9d946680fe1637a6814f))
* **utils:** 重写了构造URL的方法增加对应的单元测试 ([9f79d14](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9f79d1465ba6ed4b4c0d0c30e23ffa34bbeece65))
* 迁移到了 Core 命名空间下 ([a8a582f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a8a582f3aa0948c982e31bf8938b6f3331d8dc6d))
### ♻️ Code Refactoring | 代码重构
* 向后兼容到7.4 ([0fa3c23](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/0fa3c23a3e249cd2473a468ee64d7efc8b6eafe3))

View File

@@ -2,6 +2,15 @@
The Common HDK for Any project by Hyperf.
> DEPRECATED!!!
>
> This Branch is outdated,
> only used for support old versions.
> Such as Hyperf 2.2 or less.
>
> Please UPGRADE your version to Hyperf 3.0
> and HDK-Core 0.2.*
## PHP Versions
This version will work on Hyperf version 2.2 and above.

View File

@@ -1 +0,0 @@
1.0.0-alpha.4

View File

@@ -15,60 +15,54 @@
}
],
"require": {
"php": "^8.1",
"php": "^7.4|^8.0",
"ext-redis": "^5.3",
"ext-swoole": "*",
"composer/composer": ">=2.0",
"ergebnis/http-method": "^2.2",
"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",
"hyperf/config": "^2.2",
"hyperf/constants": "^2.2",
"hyperf/context": "^2.2",
"hyperf/database": "^2.2",
"hyperf/di": "^2.2",
"hyperf/framework": "^2.2",
"hyperf/http-server": "^2.2",
"hyperf/logger": "^2.2",
"hyperf/redis": "^2.2",
"hyperf/translation": "^2.2",
"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",
"ext-libxml": "*",
"ext-dom": "*"
"myclabs/php-enum": "^1.8.4",
"roave/dont": "^1.1",
"symfony/polyfill-php81": "^1.27",
"teapot/status-code": "^1.1"
},
"require-dev": {
"alibabacloud/dysmsapi-20170525": "^2.0",
"cooper/hyperf-pest": "^1.1",
"firebase/php-jwt": "^6.1",
"firebase/php-jwt": "^6.3",
"friendsofphp/php-cs-fixer": "^3.13",
"guzzlehttp/guzzle": "^7.5",
"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",
"hyperf/crontab": "<=3.0.9 || >3.0.13 <3.1",
"hyperf/session": "^2.2",
"hyperf/validation": "^2.2",
"pestphp/pest": "^1.22",
"phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest",
"spatie/pest-plugin-test-time": "^1.1",
"swoole/ide-helper": "*",
"symfony/mailer": "^6.0",
"symfony/serializer": "^6.0"
"symfony/mailer": "^5.4"
},
"suggest": {
"hyperf/resource": "If you need",
"firebase/php-jwt": "JWT 鉴权必需",
"hyperf/session": "^3.0.18",
"hyperf/session": "Session 鉴权必需",
"symfony/mailer": "用于发送电子邮件",
"symfony/serializer": "处理 XML 必需",
"ext-dom": "处理 XML 必需",
"ext-libxml": "处理 XML 必需",
"hyperf/guzzle": "^3.0.18",
"alibabacloud/dysmsapi-20170525": "阿里云短信服务必需"
"guzzlehttp/guzzle": "需要发起 http 请求时必需",
"alibabacloud/dysmsapi-20170525": "阿里云短信服务必需",
"laminas/laminas-text": "用于cli展示表格和大字",
"gevman/interactive-cli": "用于提供漂亮的交互式命令行",
"clue/stdio-react": "一个基于 reactphp 的交互式命令行",
"brainmaestro/composer-git-hooks": "用于 php 项目的 git-hooks"
},
"config": {
"optimize-autoloader": true,
@@ -92,11 +86,7 @@
"prefer-stable": true,
"scripts": {
"post-root-package-install": [],
"test": [
"rm -rf runtime",
"Composer\\Config::disableProcessTimeout",
"co-pest --prepend tests/bootstrap.php -c phpunit.xml --colors=always $1"
],
"test": "vendor/bin/pest $1",
"cs-fix": "vendor/bin/php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse $1",
"ci": [
@@ -114,7 +104,15 @@
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
},
"packagist-tx": {
"type": "composer",
"url": "https://mirrors.cloud.tencent.com/composer/"
},
"packagist-hw": {
"type": "composer",
"url": "https://repo.huaweicloud.com/repository/php/"
}
},
"version": "1.0.0-alpha.4"
"version": "0.1.10"
}

8914
composer.lock generated Executable file → Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,26 +0,0 @@
# 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 污染

View File

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

View File

@@ -1,13 +1,11 @@
parameters:
level: 6
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
paths:
- publish
- src
- tests
ignoreErrors:
- '#Constant BASE_PATH not found#'
- '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read\.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) is unused\.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) has parameter \$response with no value type specified in iterable type array\.#'
- '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) has parameter \$[a-zA-Z0-9_]+ with no value type specified in iterable type array.#'
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9_]+\(\) has parameter \$[a-zA-Z0-9_]+ with no type specified.#'

View File

@@ -9,8 +9,6 @@
declare(strict_types=1);
use function Hyperf\Support\env;
return [
// 响应
'response' => [
@@ -70,7 +68,7 @@ return [
'aliyun' => [
'access_key_id' => env('ACCESS_KEY_ID', ''),
'access_key_secret' => env('ACCESS_KEY_SECRET', ''),
'sign_name' => '', // 短信签名名称
'sign' => '', // 短信签名名称
'template_code' => '', // 短信模板CODE
],
],
@@ -78,8 +76,6 @@ return [
'oss' => [
'access_key_id' => env('ACCESS_KEY_ID', ''),
'access_key_secret' => env('ACCESS_KEY_SECRET', ''),
'oss_host' => env('OSS_HOST', ''),
'oss_callback' => env('OSS_CALLBACK'), // 可选
],
],
],

View File

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

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env sh
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 -p=alpha $1
-v $(pwd):/app -e "GIT_AUTHOR_NAME=ch4o5" -e "EMAIL=dongyun.li@luxcreo.ai" \
detouched/standard-version:latest $1

View File

@@ -14,10 +14,8 @@ 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
{
@@ -29,7 +27,6 @@ class ConfigProvider
// 合并到 config/autoload/dependencies.php 文件
'dependencies' => [
StdoutLoggerInterface::class => StdoutLogger::class,
CoreMiddlewareInterface::class => CommonCoreMiddleware::class
],
// 合并到 config/autoload/annotations.php 文件
'annotations' => [

View File

@@ -1,5 +1,4 @@
<?php
/**
* CommonErrorCode.php@hyperf-development-kit
*
@@ -14,307 +13,382 @@ use Hyperf\Constants\AbstractConstants;
use Hyperf\Constants\Annotation\Constants;
/**
* @Constants
* Singularity\HyperfDevelopmentKit\Utils\Constants\CommonErrorCode@hyperf-development-kit
*
* @author 李东云<dongyun.li@luxcreo.cn>
* Powered by PhpStorm
* Created on 2022/4/25
*
* @see https://lux-software.yuque.com/htnx76/vcm2oc/pkzgpv
*/
#[Constants]
class CommonErrorCode extends AbstractConstants
{
// =============== 9 服务器异常 =================
/**
* @Message("common_error.server_common_error")
*/
public const SERVER_ERROR = 9000000;
/**
* @Message("common_error.program.default")
*/
public const PROGRAM_ERROR = 9000000;
// 901 逻辑错误
/**
* @Message("common_error.program.syntax.default")
*/
public const PROGRAM_SYNTAX_ERROR = 9010001;
// 902 SQL 错误
/**
* @Message("common_error.program.sql.default")
*/
public const PROGRAM_SQL_ERROR = 9020001;
/**
* @Message("common_error.program.sql.update")
*/
public const PROGRAM_SQL_UPDATE_ERROR = 9020101;
// 90201 字段不存在
/**
* @Message("common_error.program.sql.column_not_found")
*/
public const PROGRAM_SQL_COLUMN_NOT_FOUND = 9020101;
/**
* @Message("common_error.program.sql.insert")
*/
public const PROGRAM_SQL_INSERT_ERROR = 9020201;
// =============== 1 请求错误 =================
// 101 请求方式有误
/**
* @Message("common_error.params.method.default")
*/
public const REQUEST_METHOD_ERROR = 1010001;
// 102 参数非法
/**
* 参数非法.
* @Message("common_error.params.format_error")
*/
public const FORMATTER_ERROR = 1020001;
/**
* 缺少参数.
* @Message("common_error.params.error.default")
*/
public const REQUEST_PARAMS_MISS = 1020002;
/**
* 签名非法.
* @Message("common_error.params.error.default")
*/
public const REQUEST_SIGN_ERROR = 1020003;
// 103 参数错误
/**
* @Message("common_error.params.error.default")
*/
public const REQUEST_PARAMS_ERROR = 1030001;
// 10301 用户信息错误
/**
* @Message("common_error.params.error.user.default")
*/
public const REQUEST_PARAMS_ERROR_USER = 1030101;
/**
* @Message("common_error.params.error.user.sign_up.default")
*/
public const REQUEST_PARAMS_ERROR_USER_REGISTERED = 1030102;
/**
* @Message("common_error.params.error.user.username.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_USERNAME_UNIQUE = 1030111;
/**
* @Message("common_error.params.error.user.sec_phone.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_UNIQUE = 1030121;
/**
* @Message("common_error.params.error.user.sec_phone.required")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_REQUIRED = 1030122;
/**
* @Message("common_error.params.error.user.sec_phone.undefined")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_PHONE_UNDEFINED = 1030123;
/**
* @Message("common_error.params.error.user.sec_email.unique")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_UNIQUE = 1030131;
/**
* @Message("common_error.params.error.user.sec_email.required")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_REQUIRED = 1030132;
/**
* @Message("common_error.params.error.user.sec_email.undefined")
*/
public const REQUEST_PARAMS_ERROR_USER_SEC_EMAIL_UNDEFINED = 1030133;
/**
* @Message("common_error.params.error.user.action.error")
*/
public const REQUEST_PARAMS_ERROR_USER_ACTION_ERROR = 1030141;
// 10302 验证码错误
/**
* @Message("common_error.params.error.code.error")
*/
public const REQUEST_PARAMS_ERROR_CODE_ERROR = 1030201;
/**
* @Message("common_error.params.error.code.timeout")
*/
public const REQUEST_PARAMS_ERROR_CODE_TIMEOUT = 1030202;
/**
* @Message("common_error.params.error.code.limit.minute")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_MINUTE = 1030301;
/**
* @Message("common_error.params.error.code.limit.hour")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_HOUR = 1030302;
/**
* @Message("common_error.params.error.code.limit.day")
*/
public const REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_DAY = 1030303;
/**
* @Message("common_error.params.error.target.format")
*/
public const REQUEST_PARAMS_ERROR_TARGET_FORMAT = 1030401;
/**
* @Message("common_error.params.error.target.missing")
*/
public const REQUEST_PARAMS_ERROR_TARGET_MISSING = 1030402;
// =============== 2 鉴权问题 =================
// 201 JWT 鉴权失败
/**
* @Message("common_error.auth.default")
*/
public const UNAUTHORIZED = 200000;
/**
* @Message("common_error.auth.jwt.default")
*/
public const AUTH_JWT_ERROR = 201000;
// 20101 验证
/**
* @Message("common_error.auth.jwt.iat")
*/
public const AUTH_JWT_IAT_ERROR = 2010101;
/**
* @Message("common_error.auth.jwt.nbf")
*/
public const AUTH_JWT_NBF_ERROR = 2010102;
/**
* @Message("common_error.auth.jwt.exp")
*/
public const AUTH_JWT_EXP_TIMEOUT = 2010103;
/**
* @Message("common_error.auth.jwt.iss")
*/
public const AUTH_JWT_ISS_ERROR = 2010104;
/**
* @Message("common_error.auth.jwt.uid")
*/
public const AUTH_JWT_UID_ERROR = 2010105;
// 202 Session 鉴权
/**
* @Message("common_error.auth.session.default")
*/
public const AUTH_SESSION_ERROR = 202000;
// 20201 验证
/**
* @Message("common_error.auth.session.uid")
*/
public const AUTH_SESSION_UID_ERROR = 2020101;
/**
* @Message("common_error.auth.session.created_at")
*/
public const AUTH_SESSION_CREATED_AT_ERROR = 2020102;
// 203 SAML 鉴权
/**
* @Message("common_error.auth.saml.default")
*/
public const AUTH_SAML_ERROR = 203000;
// 20301 验证
/**
* @Message("common_error.auth.saml.params.default")
*/
public const AUTH_SAML_REQUEST_PARAMS_ERROR = 2030100;
/**
* @Message("common_error.auth.saml.params.saml_request")
*/
public const AUTH_SAML_REQUEST_PARAMS_SAML_REQUEST = 2030101;
// 204 无权访问
/**
* @Message("common_error.auth.forbidden.default")
*/
public const FORBIDDEN = 204000;
// 20401 无权访问
/**
* @Message("common_error.auth.forbidden.read.default")
*/
public const FORBIDDEN_READ_ERROR = 2040101;
// 20402 无权修改
/**
* @Message("common_error.auth.forbidden.update.default")
*/
public const FORBIDDEN_UPDATE_ERROR = 2040201;
/**
* @Message("common_error.auth.forbidden.update.address.unique")
*/
public const FORBIDDEN_UPDATE_ADDRESS_DEFAULT_UNIQUE_ERROR = 2040211;
// 20403 无权创建
/**
* @Message("common_error.auth.forbidden.create.default")
*/
public const FORBIDDEN_CREATE_ERROR = 2040301;
/**
* @Message("common_error.auth.forbidden.create.wechat.redundant")
*/
public const FORBIDDEN_CREATE_WECHAT_REDUNDANT_ERROR = 2040311;
// 20404 无权删除
/**
* @Message("common_error.auth.forbidden.delete.default")
*/
public const FORBIDDEN_DELETE_ERROR = 2040401;
/**
* @Message("common_error.auth.forbidden.delete.wechat.only")
*/
public const FORBIDDEN_DELETE_ONLY_USERNAME_WITH_WECHAT = 2040411;
// 205 App 鉴权
/**
* @Message("common_error.auth.app.default")
*/
public const AUTH_APP_ERROR = 205000;
// ============== 3 依赖服务出错 ===============
// 303 缓存异常
// 30301 Redis 异常
/**
* @Message("common_error.server.cache.redis.default")
*/
public const SERVER_CACHE_REDIS_ERROR = 3030101;
/**
* @Message("common_error.server.cache.redis.refused")
*/
public const SERVER_CACHE_REDIS_REFUSED_ERROR = 3030110;
// 30302 SMS 异常
/**
* @Message("common_error.server.dependency_sms_common_error")
*/
public const SERVER_DEPENDENCY_SMS_ERROR = 3030201;
// 30303 微信错误
/**
* @Message("common_error.server.dependency.wechat.default")
*/
public const SERVER_DEPENDENCY_WECHAT_ERROR = 3030301;
/**
* @Message("common_error.server.dependency.wechat.code")
*/
public const SERVER_DEPENDENCY_WECHAT_CODE_ERROR = 3030302;
/**
* @Message("common_error.server.dependency.wechat.timeout")
*/
public const SERVER_DEPENDENCY_WECHAT_CODE_TIMEOUT_ERROR = 3030311;
// 306 消息异常
// 30601 自建邮箱发件服务异常
/**
* @Message("common_error.server.message.email.default")
*/
public const SERVER_MESSAGE_EMAIL_ERROR = 3060101;
/**
* @Message("common_error.server.message.email.not_found")
*/
public const SERVER_MESSAGE_EMAIL_NOT_FOUND = 3060102;
// =============== 4 资源不存在 ================
// 401 路由不存在
/**
* @Message("common_error.not_found.route.default")
*/
public const ROUTE_NOT_FOUND = 4010001;
// 402 模型不存在
/**
* @Message("common_error.model.not_found")
*/
public const MODEL_NOT_FOUND = 4020001;
// 40201 用户不存在
/**
* @Message("common_error.model.user.default")
* @note !!!这个码一定不要改,前端根据这个做判断了!!!!
*/
public const USER_NOT_FOUND = 4020101;
/**
* @Message("common_error.model.user.not_valid")
*/
public const USER_NOT_VALID = 4020102;
/**
* @Message("common_error.model.document.default")
*/

View File

@@ -1,5 +1,4 @@
<?php
/**
* AbstractController.php@hyperf-development-kit
*
@@ -17,12 +16,11 @@ use Dont\DontDeserialise;
use Dont\DontGet;
use Dont\DontSerialise;
use Dont\DontSet;
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;
/**
* 抽象控制器基类
@@ -41,15 +39,28 @@ abstract class AbstractController
use DontClone;
use DontSerialise;
use DontDeserialise;
use DontToString;
use RestfulList;
#[Inject]
/**
* @Inject
* @var ContainerInterface
*/
protected ContainerInterface $container;
#[Inject]
/**
* @Inject
* @var RequestInterface
*/
protected RequestInterface $request;
/**
* @Inject
* @var ResponseInterface
*/
protected ResponseInterface $response;
#[Inject]
/**
* @Inject
* @var \Hyperf\Contract\StdoutLoggerInterface
*/
protected StdoutLoggerInterface $stdoutLogger;
}

View File

@@ -9,6 +9,8 @@
namespace Singularity\HDK\Core\Events;
use Singularity\HDK\Core\Service\EmailService;
/**
* Singularity\HDK\Core\Events\EmailWillSent@HDK-Core
*
@@ -20,31 +22,64 @@ namespace Singularity\HDK\Core\Events;
*/
class EmailWillSent
{
/**
* @var string|string[] $target
*/
public $target;
/**
* @var non-empty-string $subject
*/
public string $subject;
/**
* @var non-empty-string $content
*/
public string $content;
/**
* @var string[] $cc
*/
public array $cc = [];
/**
* @var string[] $bcc
*/
public array $bcc = [];
/**
* @var string 'text'|'html' $type
*/
public string $type = 'text';
/**
* @var EmailService|null
*/
public ?EmailService $sender;
public function __construct(
/**
* @var string|string[] $target
* @phpstan-param string|string[] $target
*/
public string|array $target,
$target,
string $subject,
string $content,
/**
* @var non-empty-string $subject
* @var non-empty-string[] $cc
*/
public string $subject,
/**
* @var non-empty-string $content
*/
public string $content,
/**
* @var string[] $cc
*/
public array $cc = [],
/**
* @var 'text'|'html' $type
*/
public string $type = 'text'
array $cc = [],
string $type = 'text',
array $bcc = [],
?EmailService $sender = null
) {
$this->type = $type;
$this->cc = $cc;
$this->content = $content;
$this->subject = $subject;
$this->target = $target;
$this->bcc = $bcc;
$this->sender = $sender;
}
}

View File

@@ -20,6 +20,29 @@ namespace Singularity\HDK\Core\Events;
*/
class SmsWillSent
{
/**
* @var non-empty-string $phone 目标手机号
* @example +8613700000001
* @example 8613700000001
* @example 13700000001
*/
public string $phone;
/**
* @var array<literal-string, literal-string|int>|null $templateParam 模板变量
*/
public ?array $templateParam = null;
/**
* @var literal-string|null $templateCode 模板代码
*/
public ?string $templateCode = null;
/**
* @var literal-string|null $signName 模板签名
*/
public ?string $signName = null;
public function __construct(
/**
* @var non-empty-string $phone 目标手机号
@@ -27,22 +50,26 @@ class SmsWillSent
* @example 8613700000001
* @example 13700000001
*/
public string $phone,
string $phone,
/**
* @var array<literal-string, literal-string|int>|null $templateParam 模板变量
*/
public ?array $templateParam = null,
?array $templateParam = null,
/**
* @var literal-string|null $templateCode 模板代码
*/
public ?string $templateCode = null,
?string $templateCode = null,
/**
* @var literal-string|null $signName 模板签名
*/
public ?string $signName = null,
?string $signName = null
) {
$this->signName = $signName;
$this->templateCode = $templateCode;
$this->templateParam = $templateParam;
$this->phone = $phone;
}
}

View File

@@ -12,14 +12,17 @@ use Throwable;
*/
class DbException extends HttpException
{
public string $sql;
public function __construct(
int $code = CommonErrorCode::PROGRAM_SQL_ERROR,
?string $message = null,
public string $sql = '',
string $sql = '',
Throwable $previous = null
) {
$this->sql = $sql;
if ($code == CommonErrorCode::FORBIDDEN) {
$previous_code = $previous?->getCode();
$previous_code = empty($previous) ? null : $previous->getCode();
$code = empty($previous_code) ? $code : $previous_code;
}
parent::__construct(

View File

@@ -7,8 +7,6 @@ use Singularity\HDK\Core\Constants\CommonErrorCode;
use Teapot\StatusCode\RFC\RFC7231;
use Throwable;
use function Hyperf\Config\config;
/**
* 用户无权访问
*/
@@ -20,7 +18,7 @@ class Forbidden extends HttpException
Throwable $previous = null
) {
if ($code == CommonErrorCode::FORBIDDEN) {
$previous_code = $previous?->getCode();
$previous_code = empty($previous) ? null : $previous->getCode();
$code = empty($previous_code) ? $code : $previous_code;
}
parent::__construct(

View File

@@ -12,8 +12,6 @@ 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;
@@ -25,21 +23,17 @@ 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\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
@@ -50,51 +44,81 @@ use function Hyperf\Translation\__;
*/
class CommonHandler extends ExceptionHandler
{
#[Inject(required: false)]
/**
* @Inject(required=false)
*
* @var RequestInterface|null
*/
private ?RequestInterface $request;
#[Inject]
/**
* @Inject
* @var StdoutLogger
*/
private StdoutLogger $logger;
#[Inject]
private ApiStyleService $apiStyleService;
/**
* {@inheritDoc}
*/
public function handle(Throwable $throwable, ResponseInterface $response): ResponseInterface
{
public function handle(
Throwable $throwable,
ResponseInterface $response
): ResponseInterface {
// 阻止异常冒泡
$this->stopPropagation();
$restful = $this->apiStyleService->get();
// $restful = config('common.response.restful');
$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'
);
$error_type = $throwable::class;
$request_time = Carbon::now()->toDateTimeString();
$request_data = Json::encode($this->request?->getParsedBody());
$request_headers = Json::encode($this->request?->getHeaders());
$error_type = get_class($throwable);
$request_time = date('Y-m-d H:i:s');
if (!empty($this->request)) {
$this->request->url();
$is_debug = $this->request->hasHeader('Postman-Token')
|| str_starts_with($this->request->header('User-Agent', ''), 'apifox');
$request_data = Json::encode($this->request->getParsedBody());
$request_headers = Json::encode($this->request->getHeaders());
} else {
$is_debug = false;
$request_data = null;
$request_headers = null;
}
// 901 程序语法错误
// 902 SQL 语法错误
if ($throwable instanceof QueryException) {
$code = match ($throwable->getCode()) {
'42S22' => CommonErrorCode::PROGRAM_SQL_COLUMN_NOT_FOUND,
default => CommonErrorCode::PROGRAM_SQL_ERROR,
};
if ($throwable->getCode() === '42S22') {
$code = CommonErrorCode::PROGRAM_SQL_COLUMN_NOT_FOUND;
} else {
$code = CommonErrorCode::PROGRAM_SQL_ERROR;
}
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage($is_testing ? $code : CommonErrorCode::PROGRAM_SQL_ERROR),
$message_name => CommonErrorCode::getMessage(
$is_testing
? $code
: CommonErrorCode::PROGRAM_SQL_ERROR
),
];
if ($is_testing) {
$data['details'] = ['sql' => $throwable->getSql(), 'error' => $throwable->getMessage()];
$data['details'] = [
'sql' => $throwable->getSql(),
'error' => $throwable->getMessage(),
];
}
}
// 101 请求方式错误
if ($throwable instanceof MethodNotAllowedHttpException) {
$message = explode(': ', $throwable->getMessage());
@@ -102,65 +126,73 @@ class CommonHandler extends ExceptionHandler
$code = CommonErrorCode::REQUEST_METHOD_ERROR;
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage($code, ['methods' => join(', ', $allow_method)]),
'currentMethod' => $this->request?->getMethod(),
$message_name => CommonErrorCode::getMessage($code, [
'methods' => join(', ', $allow_method),
]),
'currentMethod' => empty($this->request) ? null : $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
),
$message_name => $is_testing
? $throwable->getMessage()
: CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR),
];
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
}
if ($throwable instanceof ValidationException) {
$data = $throwable->validator->errors()->first();
if (is_numeric($data)) {
$code = (int)$data;
$data = CommonErrorCode::getMessage($code);
}
$data = [$code_name => $code ?? CommonErrorCode::REQUEST_PARAMS_ERROR, $message_name => $data];
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
$data = [
$code_name => $code ?? CommonErrorCode::REQUEST_PARAMS_ERROR,
$message_name => $data,
];
}
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,
$message_name => empty($message) ? CommonErrorCode::getMessage($code, [
'param' => $throwable->getFieldName(),
]) : $message,
];
if ($is_debug) {
$data['currentValue'] = $throwable->getCurrentValue();
$data['availableValue'] = $throwable->getAvailableValue();
}
}
// 路由不存在
if ($throwable instanceof NotFoundHttpException) {
$code = CommonErrorCode::ROUTE_NOT_FOUND;
$data = [$code_name => $code, $message_name => CommonErrorCode::getMessage($code)];
$status_code = RFC7231::NOT_FOUND;
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage($code),
];
$status_code = 404;
}
// 模型不存在
if ($throwable instanceof ModelNotFoundException) {
$code = empty($throwable->getCode()) ? CommonErrorCode::MODEL_NOT_FOUND : $throwable->getCode();
$message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, ['resource' => '资源']
) : $throwable->getMessage();
$data = [$code_name => $code, $message_name => $message];
$status_code = RFC7231::NOT_FOUND;
$message = empty($throwable->getCode()) ? CommonErrorCode::getMessage($code, [
'resource' => '资源',
]) : $throwable->getMessage();
$data = [
$code_name => $code,
$message_name => $message,
];
$status_code = 404;
}
// 300 服务出错
// 303 缓存异常
if ($throwable instanceof RedisException) {
@@ -171,10 +203,13 @@ class CommonHandler extends ExceptionHandler
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage(
$is_testing ? $code : CommonErrorCode::SERVER_CACHE_REDIS_ERROR
$is_testing
? $code
: CommonErrorCode::SERVER_CACHE_REDIS_ERROR
),
];
}
// 306 消息异常
// 30601 邮箱发件异常
if ($throwable instanceof TransportException) {
@@ -185,58 +220,72 @@ class CommonHandler extends ExceptionHandler
$data = [
$code_name => $code,
$message_name => CommonErrorCode::getMessage(
$is_testing ? $code : CommonErrorCode::SERVER_MESSAGE_EMAIL_ERROR
$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,
$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(),
];
$status_code = $throwable->getStatusCode();
}
}
$response = $response->withHeader(Header::CONTENT_TYPE, 'application/json; charset=utf-8');
$response = $response->withHeader(
Header::CONTENT_TYPE,
'application/json; charset=utf-8'
);
if ($is_debug && $is_testing) {
$data += ['errorType' => $error_type, 'errorTrack' => $throwable->getTrace()];
$data['trace'] = [
'errorType' => $error_type,
'errorTrack' => $throwable->getTrace(),
];
}
$cookies = json_encode($this->request->getCookieParams(), JSON_UNESCAPED_UNICODE);
$cookies = Json::encode($this->request->getCookieParams());
$this->logger->error(
<<<ERROR_LOG
TYPE: {$error_type}
TYPE: $error_type
[$data[$code_name]] $data[$message_name]
{$throwable->getMessage()}
-------------------------------
REQUEST_TIME: {$request_time}
REQUEST_TIME: $request_time
-------------------------------
REQUEST_HEADERS:
{$request_headers}
$request_headers
-------------------------------
REQUEST_COOKIES:
{$cookies}
$cookies
-------------------------------
REQUEST_METHOD:
{$this->request?->getMethod()}
{$this->request->getMethod()}
-------------------------------
REQUEST_URL:
{$this->request?->getUri()}
{$this->request->getUri()}
-------------------------------
REQUEST_QUERY:
{$this->request?->getQueryString()}
{$this->request->getQueryString()}
-------------------------------
REQUEST_DATA:
{$request_data}
$request_data
-------------------------------
TRACE:
{$throwable->getTraceAsString()}
@@ -245,12 +294,19 @@ TRACE:
ERROR_LOG
);
$data = Json::encode($data);
if ($restful === ApiStyleService::RESTFUL) {
if ($restful) {
$response = $response->withStatus(
$status_code ?? $throwable->status ?? $throwable->statusCode ?? RFC7231::INTERNAL_SERVER_ERROR
$status_code ??
$throwable->status ??
$throwable->statusCode ??
RFC7231::INTERNAL_SERVER_ERROR
);
}
return $response->withBody(new SwooleStream($data));
return $response
->withBody(
new SwooleStream($data)
);
}
/**

View File

@@ -13,13 +13,17 @@ use Throwable;
*/
class Unauthorized extends HttpException
{
/** @var string $authenticationType */
private string $authenticationType;
public function __construct(
int $code = CommonErrorCode::UNAUTHORIZED,
Throwable $previous = null,
private string $authenticationType = RFC7616::DIGEST
string $authenticationType = RFC7616::DIGEST
) {
$this->authenticationType = $authenticationType;
if ($code == CommonErrorCode::UNAUTHORIZED) {
$previous_code = $previous?->getCode();
$previous_code = empty($previous) ? null : $previous->getCode();
$code = empty($previous_code) ? $code : $previous_code;
}

View File

@@ -12,6 +12,15 @@ use Throwable;
*/
class ValidateException extends HttpException
{
/** @var string $field */
private $field;
/** @var mixed $currentValue */
private $currentValue;
/** @var array<int, mixed> $availableValue */
private $availableValue;
/**
* @param int $code
* @param string|null $message
@@ -23,13 +32,16 @@ class ValidateException extends HttpException
public function __construct(
int $code = CommonErrorCode::FORMATTER_ERROR,
?string $message = null,
private string $field = '',
private mixed $currentValue = null,
private array $availableValue = [],
string $field = '',
$currentValue = null,
array $availableValue = [],
Throwable $previous = null
) {
$this->availableValue = $availableValue;
$this->currentValue = $currentValue;
$this->field = $field;
if ($code == CommonErrorCode::FORMATTER_ERROR) {
$previous_code = $previous?->getCode();
$previous_code = empty($previous) ? null : $previous->getCode();
$code = empty($previous_code) ? $code : $previous_code;
}
parent::__construct(
@@ -54,7 +66,7 @@ class ValidateException extends HttpException
/**
* @return mixed
*/
public function getCurrentValue(): mixed
public function getCurrentValue()
{
return $this->currentValue;
}

View File

@@ -1,191 +0,0 @@
<?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

@@ -1,22 +0,0 @@
<?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

@@ -1,28 +0,0 @@
<?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

@@ -13,22 +13,18 @@ use Hyperf\Contract\ContainerInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Event\Contract\ListenerInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
abstract class AbstractListener implements ListenerInterface
{
#[Inject]
/**
* @var ContainerInterface
* @Inject()
*/
protected ContainerInterface $container;
protected StdoutLoggerInterface $stdoutLogger;
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @var StdoutLoggerInterface
* @Inject()
*/
public function __construct()
{
$this->stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
}
protected StdoutLoggerInterface $stdoutLogger;
}

View File

@@ -9,11 +9,7 @@
namespace Singularity\HDK\Core\Listener;
use Hyperf\Contract\ContainerInterface;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\Event\Contract\ListenerInterface;
use JetBrains\PhpStorm\NoReturn;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Singularity\HDK\Core\Constants\CommonErrorCode;
@@ -30,11 +26,8 @@ use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
*
* @link ../../docs/Email.md
*/
class EmailWillSentListener implements ListenerInterface
class EmailWillSentListener extends AbstractListener
{
#[Inject]
private ContainerInterface $container;
/**
* @inheritDoc
*/
@@ -46,29 +39,33 @@ class EmailWillSentListener implements ListenerInterface
}
/**
* @param EmailWillSent $event
* @param object $event
*
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
#[NoReturn]
public function process(object $event): void
{
$stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
$emailService = $this->container->get(EmailService::class);
/** @var $event EmailWillSent */
$emailService = $event->sender ?? EmailService::make();
try {
$event->type === 'html'
? $emailService->sendHtml(
target: $event->target,
subject: $event->subject,
html: $event->content,
cc: $event->cc
$event->target,
$event->subject,
$event->content,
$event->cc,
$event->bcc,
)
: $emailService->sendText(
target: $event->target,
subject: $event->subject,
text: $event->content,
cc: $event->cc
$event->target,
$event->subject,
$event->content,
$event->cc,
$event->bcc,
);
$stdoutLogger->info('邮件发送成功!');

View File

@@ -45,10 +45,10 @@ class SmsWillSentListener extends AbstractListener
$smsService = $this->container->get(SmsService::class);
try {
$smsService->sendSmsCountryside(
phone: $event->phone,
templateCode: $event->templateCode,
templateParam: $event->templateParam,
signName: $event->signName
$event->phone,
$event->templateCode,
$event->templateParam,
$event->signName
);
} catch (Throwable $throwable) {
$code = $throwable->getCode();

View File

@@ -1,5 +1,4 @@
<?php
/**
* ClassicCoreMiddleware.php@hyperf-development-kit
*
@@ -10,56 +9,52 @@
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 Hyperf\Utils\Contracts\Arrayable;
use Hyperf\Utils\Contracts\Jsonable;
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
*
* @author 李东云<dongyun.li@luxcreo.cn>
* Powered by PhpStorm
* Created on 2022/4/29
*
* @deprecated
* @see CommonCoreMiddleware
*/
class ClassicCoreMiddleware extends CoreMiddleware
{
#[Inject]
/**
* @Inject()
* @var \Singularity\HDK\Core\Service\UtilsService
*/
private UtilsService $utilsService;
/**
* Transfer the non-standard response content to a standard response object.
* @template TKey of array-key
* @template TValue
* @param null|array<TKey, TValue>|Arrayable<TKey, TValue>|Jsonable|string $response
*
* @param null|array<string, mixed>|Arrayable<string, mixed>|Jsonable|string $response
*/
protected function transferToResponse($response, ServerRequestInterface $request): ResponseInterface
{
$code_name = config('common.response.code_name');
$message_name = config('common.response.message_name');
$data_name = config('common.response.data_name');
// 分页数据
if ($response instanceof LengthAwarePaginatorInterface) {
$paginator = $response;
$fact_response = $this->response()->withHeader('Per-Page', (string)$paginator->perPage())->withHeader(
'Total',
(string)$paginator->total()
)->withHeader('Current-Page', (string)$paginator->currentPage())->withHeader(
'Total-Pages',
(string)$paginator->hasPages()
);
$fact_response = $this->response()->withHeader('Per-Page', (string)$paginator->perPage())
->withHeader('Total', (string)$paginator->total())
->withHeader('Current-Page', (string)$paginator->currentPage())
->withHeader('Total-Pages', (string)$paginator->hasPages());
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $paginator->nextPageUrl(), 'next');
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
@@ -72,10 +67,11 @@ class ClassicCoreMiddleware extends CoreMiddleware
$paginator->previousPageUrl(),
'prev'
);
return $fact_response->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(
Json::encode(
[
return $fact_response
->withAddedHeader(Header::CONTENT_TYPE, 'application/json')
->withBody(
new SwooleStream(
Json::encode([
$code_name => 200,
$message_name => 'ok',
$data_name => $response->items(),
@@ -85,28 +81,39 @@ class ClassicCoreMiddleware extends CoreMiddleware
'perPage' => $paginator->perPage(),
'total' => $paginator->total(),
],
]
])
)
)
);
}
// 普通数组
if (is_array($response) || $response instanceof Arrayable) {
$response = [$code_name => 200, $message_name => 'ok', $data_name => $response];
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(Json::encode($response))
);
);
}
// 可 Json 化的数据结构
if ($response instanceof Jsonable) {
$response = [$code_name => 200, $message_name => 'ok', $data_name => Json::decode((string)$response)];
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(Json::encode($response))
);
if ($response instanceof Jsonable && $response instanceof Arrayable) {
$response = [
$code_name => 200,
$message_name => 'ok',
$data_name => $response->toArray(),
];
return $this->response()
->withAddedHeader(Header::CONTENT_TYPE, 'application/json')
->withBody(new SwooleStream(Json::encode($response)));
}
// 普通数组
if (is_array($response) || $response instanceof Arrayable) {
$response = [
$code_name => 200,
$message_name => 'ok',
$data_name => $response,
];
return $this->response()
->withAddedHeader(Header::CONTENT_TYPE, 'application/json')
->withBody(new SwooleStream(Json::encode($response)));
}
// 其他默认按字符串处理
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'text/plain')->withBody(
new SwooleStream((string)$response)
);
return $this->response()
->withAddedHeader(Header::CONTENT_TYPE, 'text/plain')
->withBody(
new SwooleStream((string)$response)
);
}
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* ClassicStyleMiddleware.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/3/10
*/
namespace Singularity\HDK\Core\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Singularity\HDK\Core\Service\ApiStyleService;
class ClassicStyleMiddleware implements MiddlewareInterface
{
public function __construct(protected ApiStyleService $apiStyleService)
{
}
/**
* @inheritDoc
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->apiStyleService->set(ApiStyleService::CLASSIC);
return $handler->handle($request);
}
}

View File

@@ -1,160 +0,0 @@
<?php
/**
* ClassicCoreMiddleware.php@hyperf-development-kit
*
* @author 李东云<dongyun.li@luxcreo.cn>
* Powered by PhpStorm
* Created on 2022/4/29
*/
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 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
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/3/10
*/
class CommonCoreMiddleware extends CoreMiddleware
{
#[Inject]
private UtilsService $utilsService;
#[Inject]
private ApiStyleService $apiStyleService;
/**
* @inheritDoc
*/
protected function transferToResponse($response, ServerRequestInterface $request): ResponseInterface
{
$style = $this->apiStyleService->get();
if ($style === ApiStyleService::RESTFUL) {
return $this->transferToRestfulResponse($response, $request);
} else {
return $this->transferToClassicResponse($response, $request);
}
}
/**
* @param array|string|Arrayable|Jsonable|null $response
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
protected function transferToRestfulResponse(Arrayable|Jsonable|array|string|null $response, ServerRequestInterface $request): ResponseInterface
{
// 分页数据
if ($response instanceof LengthAwarePaginatorInterface) {
$fact_response = $this->response()
->withHeader('Per-Page', (string)$response->perPage())
->withHeader('Total', (string)$response->total())
->withHeader('Current-Page', (string)$response->currentPage())
->withHeader('Total-Pages', (string)$response->hasPages());
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->nextPageUrl(), 'next');
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
$response->url($response->lastPage()),
'last'
);
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->url(1), 'first');
$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);
}
/**
* @param array|string|Arrayable|Jsonable|null $response
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
protected function transferToClassicResponse(
Arrayable|Jsonable|array|string|null $response,
ServerRequestInterface $request
): ResponseInterface {
$code_name = config('common.response.code_name');
$message_name = config('common.response.message_name');
$data_name = config('common.response.data_name');
// 分页数据
if ($response instanceof LengthAwarePaginatorInterface) {
$paginator = $response;
$fact_response = $this->response()->withHeader('Per-Page', (string)$paginator->perPage())->withHeader(
'Total',
(string)$paginator->total()
)->withHeader('Current-Page', (string)$paginator->currentPage())->withHeader(
'Total-Pages',
(string)$paginator->hasPages()
);
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $paginator->nextPageUrl(), 'next');
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
$paginator->url($paginator->lastPage()),
'last'
);
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $paginator->url(1), 'first');
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
$paginator->previousPageUrl(),
'prev'
);
return $fact_response->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(
Json::encode(
[
$code_name => 200,
$message_name => 'ok',
$data_name => $response->items(),
'meta' => [
'currentPage' => $paginator->currentPage(),
'lastPage' => $paginator->lastPage(),
'perPage' => $paginator->perPage(),
'total' => $paginator->total(),
],
]
)
)
);
}
// 普通数组
if (is_array($response) || $response instanceof Arrayable) {
$response = [$code_name => 200, $message_name => 'ok', $data_name => $response];
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(Json::encode($response))
);
}
// 可 Json 化的数据结构
if ($response instanceof Jsonable) {
$response = [$code_name => 200, $message_name => 'ok', $data_name => Json::decode((string)$response)];
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'application/json')->withBody(
new SwooleStream(Json::encode($response))
);
}
// 其他默认按字符串处理
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'text/plain')->withBody(
new SwooleStream((string)$response)
);
}
}

View File

@@ -15,16 +15,20 @@ use Singularity\HDK\Core\Service\ExtendService;
class ExtendsMiddleware implements MiddlewareInterface
{
/**
* @Inject
* @var \Singularity\HDK\Core\Service\ExtendService
*/
#[Inject]
private ExtendService $service;
/**
* @inheritDoc
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$this->service->parse($request);
return $handler->handle($request);
}
}

View File

@@ -7,13 +7,10 @@ namespace Singularity\HDK\Core\Middleware;
use Hyperf\Context\Context;
use Hyperf\Contract\TranslatorInterface;
use Hyperf\Di\Annotation\Inject;
use Lmc\HttpConstants\Header;
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;
/**
* Singularity\HDK\Utils\Middleware\InternationalizationMiddleware@HDK
@@ -25,9 +22,9 @@ use Symfony\Component\HttpFoundation\Request;
class InternationalizationMiddleware implements MiddlewareInterface
{
/**
* @Inject
* @var TranslatorInterface
*/
#[Inject]
private TranslatorInterface $translator;
/**
@@ -35,20 +32,25 @@ class InternationalizationMiddleware implements MiddlewareInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$req = (new Request());
$req->headers->set(Header::ACCEPT_LANGUAGE, $request->getHeaderLine(Header::ACCEPT_LANGUAGE));
$language = $req->getPreferredLanguage();
if (!empty($language)) {
$language = Languages::getLanguage($language);
$this->translator->setLocale($language->value);
}
$response = Context::get(ResponseInterface::class);
$response = $response->withAddedHeader(
Header::CONTENT_LANGUAGE,
strtr($this->translator->getLocale(), '_', '-')
);
Context::set(ResponseInterface::class, $response);
$language = $request->getHeaderLine('Accept-Language');
if (!empty($language)) {
switch (true) {
case in_array(strtolower($language), ['en', 'en_us', 'en-us', 'en-uk', 'en_uk']):
$language = 'en';
break;
case in_array(strtolower($language), ['zh', 'zh_cn', 'zh-cn']):
$language = 'zh_CN';
break;
default:
$language = config('translation.locale') ;
break;
}
$this->translator->setLocale($language);
$response = $response->withAddedHeader('Content-Language', strtr($this->translator->getLocale(), '_', '-'));
Context::set(ResponseInterface::class, $response);
}
return $handler->handle($request);
}

View File

@@ -1,32 +0,0 @@
<?php
/**
* ClassicStyleMiddleware.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/3/10
*/
namespace Singularity\HDK\Core\Middleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Singularity\HDK\Core\Service\ApiStyleService;
class RestStyleMiddleware implements MiddlewareInterface
{
public function __construct(protected ApiStyleService $apiStyleService)
{
}
/**
* @inheritDoc
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$this->apiStyleService->set(ApiStyleService::RESTFUL);
return $handler->handle($request);
}
}

View File

@@ -1,68 +0,0 @@
<?php
/**
* RestfulCoreMiddleware.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/1/14
*/
namespace Singularity\HDK\Core\Middleware;
use Hyperf\Contract\Arrayable;
use Hyperf\Contract\Jsonable;
use Hyperf\Contract\LengthAwarePaginatorInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\CoreMiddleware;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Singularity\HDK\Core\Service\UtilsService;
/**
* Singularity\HDK\Core\Middleware\RestfulCoreMiddleware@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/1/14
*
* @deprecated
* @see CommonCoreMiddleware
*/
class RestfulCoreMiddleware extends CoreMiddleware
{
#[Inject]
private UtilsService $utilsService;
/**
* @template TKey of array-key
* @template TValue
* @param null|array<TKey, TValue>|Arrayable<TKey, TValue>|Jsonable|string $response
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
protected function transferToResponse($response, ServerRequestInterface $request): ResponseInterface
{
// 分页数据
if ($response instanceof LengthAwarePaginatorInterface) {
$fact_response = $this->response()
->withHeader('Per-Page', (string)$response->perPage())
->withHeader('Total', (string)$response->total())
->withHeader('Current-Page', (string)$response->currentPage())
->withHeader('Total-Pages', (string)$response->hasPages());
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->nextPageUrl(), 'next');
$fact_response = $this->utilsService->extendLinkToHeader(
$fact_response,
$response->url($response->lastPage()),
'last'
);
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->url(1), 'first');
return $this->utilsService->extendLinkToHeader(
$fact_response,
$response->previousPageUrl(),
'prev'
);
}
return parent::transferToResponse($response, $request);
}
}

View File

@@ -22,18 +22,21 @@ use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
/**
* Singularity\HDK\Core\Middleware\SessionMiddleware@HDK-Core
* Singularity\HDK\Auth\Middleware\SessionMiddleware@HDK-Core
*
* @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 implements MiddlewareInterface
{
public function __construct(private SessionManager $sessionManager, private ConfigInterface $config)
private SessionManager $sessionManager;
private ConfigInterface $config;
public function __construct(SessionManager $sessionManager, ConfigInterface $config)
{
$this->config = $config;
$this->sessionManager = $sessionManager;
}
/**
@@ -93,6 +96,11 @@ class SessionMiddleware implements MiddlewareInterface
}
}
private function auth(SessionInterface $session): bool
{
return $session->has('userInfo');
}
/**
* Add the session cookie to the response·.
*/
@@ -102,17 +110,17 @@ class SessionMiddleware implements MiddlewareInterface
SessionInterface $session
): ResponseInterface {
$cookie = new Cookie(
name: $session->getName(),
value: $session->getId(),
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->getName(),
$session->getId(),
$this->getCookieExpirationDate($session),
$this->config->get('session.options.path', '/'),
$this->config->get('session.options.domain', $request->getUri()->getHost()),
$this->config->get(
'session.options.secure',
strtolower($request->getUri()->getScheme()) === 'https'
),
httpOnly: true,
sameSite: $this->config->get('session.options.samesite', Cookie::SAMESITE_LAX)
true,
$this->config->get('session.options.samesite', Cookie::SAMESITE_LAX)
);
if (!method_exists($response, 'withCookie')) {
return $response->withHeader('Set-Cookie', (string)$cookie);
@@ -154,9 +162,4 @@ class SessionMiddleware implements MiddlewareInterface
{
return rtrim(preg_replace('/\?.*/', '', (string)$request->getUri()));
}
private function auth(SessionInterface $session)
{
return $session->has('userInfo');
}
}

View File

@@ -1,30 +0,0 @@
<?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

@@ -1,26 +0,0 @@
<?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

@@ -1,42 +0,0 @@
<?php
/**
* ApiStyleService.php@HDK-Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/3/10
*/
namespace Singularity\HDK\Core\Service;
use Hyperf\Context\Context;
use function Hyperf\Config\config;
class ApiStyleService
{
public const RESTFUL = 'restful';
public const CLASSIC = 'classic';
public function __construct()
{
Context::set(self::class, config('common.response.restful') ? self::RESTFUL : self::CLASSIC);
}
/**
* @param literal-string $style
* @return $this
*/
public function set(string $style): static
{
Context::set(self::class, $style === self::RESTFUL ? self::RESTFUL : self::CLASSIC);
return $this;
}
public function get(): string
{
return Context::get(self::class) ?? (config('common.response.restful')
? ApiStyleService::RESTFUL
: ApiStyleService::CLASSIC);
}
}

View File

@@ -11,15 +11,12 @@ declare(strict_types=1);
namespace Singularity\HDK\Core\Service;
use JetBrains\PhpStorm\Deprecated;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use function Hyperf\Config\config;
/**
* 邮箱验证码
*/
@@ -45,6 +42,18 @@ class EmailService
);
}
public static function make(
?string $dsn = null,
?string $mailSenderName = null,
?string $mailSender = null
): EmailService {
return new static(
$dsn,
$mailSenderName,
$mailSender,
);
}
/**
* 发送邮件
*
@@ -56,8 +65,9 @@ class EmailService
* @throws TransportExceptionInterface
* @see EmailService::sendText
* @see EmailService::sendHtml
* @deprecated
* @noinspection PhpUnused
*/
#[Deprecated]
public function sendCode(
string $target,
string $subject,
@@ -68,23 +78,26 @@ class EmailService
/**
* @param string|array<string> $target
* @param string $subject
* @param string $text
* @param string $subject
* @param string $text
* @param array<string> $cc
* @param array $bcc
*
* @return bool
* @throws TransportExceptionInterface
*/
public function sendText(
string|array $target,
$target,
string $subject,
string $text,
array $cc = []
array $cc = [],
array $bcc = []
): bool {
$email = (new Email())
->from(Address::create($this->from))
->to(...(is_array($target) ? $target : [$target]))
->cc(...$cc)
->bcc(...$bcc)
->subject($subject)
->text($text);
@@ -97,23 +110,26 @@ class EmailService
* 以 HTML 格式发送邮件
*
* @param string|array<string> $target
* @param string $subject
* @param string $html
* @param string $subject
* @param string $html
* @param array<string> $cc
* @param array $bcc
*
* @return bool
* @throws TransportExceptionInterface
*/
public function sendHtml(
string|array $target,
$target,
string $subject,
string $html,
array $cc = []
array $cc = [],
array $bcc = []
): bool {
$email = (new Email())
->from(Address::create($this->from))
->to(...(is_array($target) ? $target : [$target]))
->cc(...$cc)
->bcc(...$bcc)
->subject($subject)
->html($html);

View File

@@ -10,27 +10,33 @@ use Psr\Http\Message\ServerRequestInterface;
*/
class ExtendService
{
public function __construct(private UtilsService $utils)
/** @var UtilsService $utils */
private UtilsService $utils;
public function __construct(UtilsService $utils)
{
$this->utils = $utils;
}
/**
* @param ServerRequestInterface|null $request
* @param array<string, string>|null $params
* @param array<string, string>|string|null $params
* @return string[]
*/
public function parse(
?ServerRequestInterface $request,
array|string|null $params = null
$params = null
): array {
$params ??= $request?->getQueryParams();
$extends = explode(',', $params['extends'] ?? '');
$extends = array_map('trim', $extends);
return Context::set(self::class, array_filter($extends));
$params = $params ?? (isset($request) ? $request->getQueryParams() : null);
$extends = empty($params['extends']) ? [] : $params['extends'];
if (!empty($extends)) {
$extends = explode(',', $extends);
$extends = array_map('trim', $extends);
}
Context::set(self::class, $extends);
return $extends;
}
/**
* @return array<string, string>
*/
@@ -54,6 +60,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

@@ -1,102 +0,0 @@
<?php
declare(strict_types=1);
namespace Singularity\HDK\Core\Service;
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\Di\Annotation\Inject;
use Hyperf\Guzzle\ClientFactory;
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;
#[Inject]
private ClientFactory $client;
/**
* @var array<literal-string, mixed>
*/
private array $options = [];
/**
* @param string $url
* @param array<string, string|int> $params
* @param array $data
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestGet(string $url, array $params = [], array $data = []): ResponseInterface
{
$request = new Request(Method\Rfc\Rfc7231::GET, $url);
return $this->getClient()->send($request, [
'query' => $params,
'json' => $data,
]);
}
private function getClient(): Client
{
return $this->client->create($this->options);
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @return ResponseInterface
* @throws GuzzleException
*/
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),
);
return $this->getClient()->send($request, [
'query' => $params,
]);
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @return ResponseInterface
* @throws GuzzleException
*/
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));
return $this->getClient()->send($request, [
'query' => $params,
]);
}
/**
* 定制 options
* @param array<string, mixed> $options
* @return $this
*/
public function setOptions(array $options): HttpRequestService
{
$this->options = array_replace_recursive($this->options, $options);
return $this;
}
}

View File

@@ -9,12 +9,16 @@
namespace Singularity\HDK\Core\Service;
use Hyperf\Codec\Json;
use function Hyperf\Config\config;
use Hyperf\Utils\Codec\Json;
class OssService
{
public ?string $accessKeyId = null;
public ?string $accessKeySecret = null;
public ?string $host = null;
public ?string $callbackUrl = null;
public ?int $expiration = 30;
/**
* @param string|null $accessKeyId 不传则取配置文件
* @param string|null $accessKeySecret 不传则取配置文件
@@ -22,16 +26,17 @@ class OssService
* @param int|null $expiration 过期时间默认30s
*/
public function __construct(
public ?string $accessKeyId = null,
public ?string $accessKeySecret = null,
public ?string $host = null,
public ?string $callbackUrl = null,
public ?int $expiration = 30
?string $accessKeyId = null,
?string $accessKeySecret = null,
?string $host = null,
?string $callbackUrl = null,
?int $expiration = 30
) {
$this->accessKeyId ??= config('common.third_party.storage.oss.access_key_id');
$this->accessKeySecret ??= config('common.third_party.storage.oss.access_key_secret');
$this->host ??= config('common.third_party.storage.oss.oss_host');
$this->callbackUrl ??= config('common.third_party.storage.oss.oss_callback') ?? null;
$this->expiration = $expiration;
$this->callbackUrl = $callbackUrl?? config('oss_callback');
$this->host = $host?? config('common.third_party.storage.oss.oss_host');
$this->accessKeySecret = $accessKeySecret ?? config('common.third_party.storage.oss.access_key_secret');
$this->accessKeyId = $accessKeyId ?? config('common.third_party.storage.oss.access_key_id');
}
/**
@@ -86,7 +91,7 @@ class OssService
$string_to_sign = $base64_policy;
$signature = base64_encode(hash_hmac('sha1', $string_to_sign, $this->accessKeySecret, true));
$callback = isset($this->callbackUrl) ? Json::encode([
$callback = Json::encode([
'callbackUrl' => $this->callbackUrl,
'callbackBody' => $isImage ? <<<'callbackBody'
{
@@ -117,20 +122,17 @@ callbackBody : <<<'callbackBody'
}
callbackBody,
'callbackBodyType' => 'application/json',
]) : null;
]);
$result = [
return [
'accessid' => $this->accessKeyId,
'host' => $this->host,
'policy' => $base64_policy,
'signature' => $signature,
'expire' => $expire_time,
'dir' => $dir,
'callback' => base64_encode($callback),
];
if (isset($callback)) {
$result += ['callback' => base64_encode($callback),];
}
return $result;
}
/**

View File

@@ -6,14 +6,12 @@ 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\HttpMessage\Exception\HttpException;
use Hyperf\Utils\Codec\Json;
use Singularity\HDK\Core\Constants\CommonErrorCode;
use Singularity\HDK\Core\Exceptions\ValidateException;
use UnexpectedValueException;
use function Hyperf\Config\config;
/**
* 短信服务
*/
@@ -22,7 +20,7 @@ class SmsService
/**
* @var Dysmsapi
*/
private Dysmsapi $client;
private $client;
public function __construct()
{
@@ -53,17 +51,14 @@ class SmsService
* @param string|null $signName 短信签名名称
*
* @return bool
* @throws UnexpectedValueException 参数校验
* @throws ValidateException 频率太高
* @throws ServerErrorHttpException 阿里云短信服务报错
* @link https://help.aliyun.com/document_detail/419273.htm
*
* @noinspection PhpUnused
*/
public function sendSmsCountryside(
string $phone,
?string $templateCode = null,
?array $templateParam = null,
?string $signName = null,
?string $signName = null
): bool {
if (is_array($templateParam) && count($templateParam) <= 0) {
throw new UnexpectedValueException('不支持空数组,请用 null 代替或不传', CommonErrorCode::FORMATTER_ERROR);
@@ -96,22 +91,31 @@ class SmsService
// 频率太高
if ($code === 'isv.BUSINESS_LIMIT_CONTROL') {
$error_code = match (mb_substr($message, 2, 2)) {
'天级' => CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_DAY,
'小时' => CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_HOUR,
'分钟' => CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_MINUTE,
default => null
};
switch (mb_substr($message, 2, 2)) {
case '天级':
$error_code = CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_DAY;
break;
case '小时':
$error_code = CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_HOUR;
break;
case '分钟':
$error_code = CommonErrorCode::REQUEST_PARAMS_ERROR_CODE_MAX_TIMES_MINUTE;
break;
default:
$error_code = null;
break;
}
if (isset($error_code)) {
throw new ValidateException($error_code);
}
}
throw new ServerErrorHttpException(
message: $message,
code: CommonErrorCode::SERVER_DEPENDENCY_SMS_ERROR,
previous: $error
throw new HttpException(
500,
$message,
CommonErrorCode::SERVER_DEPENDENCY_SMS_ERROR,
$error
);
}

View File

@@ -8,7 +8,6 @@ use Closure;
use Exception;
use Generator;
use Hyperf\HttpServer\Contract\RequestInterface;
use JetBrains\PhpStorm\Pure;
use Psr\Http\Message\ResponseInterface;
/**
@@ -100,7 +99,6 @@ class UtilsService
* @param bool $anchorQuery 开启后query 参数将被尽量组合到锚点中,以支持 spa 路由
* @return string
*/
#[Pure]
public function buildUrl(string $url, array $moreQueries = [], bool $anchorQuery = false): string
{
if (count($moreQueries) === 0) {
@@ -273,9 +271,8 @@ class UtilsService
*
* @return array{'size': float, 'unit': string}
*/
#[Pure]
public function convertStorageSize(
float|int|string $size,
$size,
bool $unitToUpper = false,
int $precision = 2
): array {
@@ -303,9 +300,8 @@ class UtilsService
*
* @return array{'duration': float, 'unit': string}
*/
#[Pure]
public function convertDuration(
int|float $duration,
$duration,
bool $unitToUpper = false,
bool $format = true,
int $precision = 3
@@ -327,14 +323,13 @@ class UtilsService
];
}
/**
* 更快的判断数组元素方法
* @param float|int|string $needle
* @param string|int|float $needle
* @param array<int, mixed> $haystack
* @return bool
*/
public function inArray(float|int|string $needle, array $haystack): bool
public function inArray($needle, array $haystack): bool
{
$list = array_flip($haystack);
return isset($list[$needle]);

View File

@@ -1,86 +0,0 @@
<?php
/**
* XmlService.php@LuxOP
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/4/10
*/
namespace Singularity\HDK\Core\Service;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
class XmlService
{
private XmlEncoder $service;
public function __construct(XmlEncoder $encoder)
{
$this->service = $encoder;
}
/**
* @param object|array<string, mixed> $data
* @param string $xmlRootNodeName
* @param bool $xmlFormatOutput 是否格式化
* @param string $xmlVersion
* @param string $xmlEncoding
* @param bool $xmlStandalone 是否添加声明规范的标签到xml
* @param int[] $encoderIgnoredNodeTypes
* @param bool $removeEmptyTags
* @return false|string
* @see https://symfony.com/doc/current/components/serializer.html#the-xmlencoder
*/
public function encode(
object|array $data,
string $xmlRootNodeName = 'root',
bool $xmlFormatOutput = true,
string $xmlVersion = '1.0',
string $xmlEncoding = 'utf-8',
bool $xmlStandalone = false,
array $encoderIgnoredNodeTypes = [],
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::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

@@ -1,78 +0,0 @@
<?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

@@ -12,25 +12,27 @@ namespace Singularity\HDK\Test\Core\Service;
use Singularity\HDK\Core\Service\EmailService;
use Symfony\Component\Mailer\Exception\TransportException;
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
$dsn = 'smtp://account@luxcreo.com:Qfsd8866@smtp-mail.outlook.com:587';
$mail_sender_name = 'LuxCreo';
$mail_sender = 'account@luxcreo.ai';
$mail_sender = 'account@luxcreo.com';
$email = new EmailService($dsn, $mail_sender_name, $mail_sender);
it('assertions that send HTML is available', function () use ($email) {
$result = $email->sendHtml(
'dongyun.li@luxcreo.ai',
'HDK Unit Test HTML',
<<<HTML
$target = 'dongyun.li@luxcreo.ai';
it('assertions that send HTML is available', function () use ($email, $target) {
$result = $email->sendHtml(
$target,
'HDK Unit Test HTML',
<<<HTML
<h1>Hello, World!</h1>
HTML
);
expect($result)->toBeTrue();
);
expect($result)->toBeTrue();
});
it('assertions that send Text is available', function () use ($email) {
it('assertions that send Text is available', function () use ($email, $target) {
$result = $email->sendText(
'dongyun.li@luxcreo.ai',
$target,
'HDK Unit Test Text',
<<<Text
<h1>Hello, World!</h1>
@@ -41,24 +43,26 @@ Text
it('assertions Error Receiver can be catch', function () use ($email) {
try {
$email->sendHtml(
$result = $email->sendHtml(
'unknown@luxcreo.ai',
'HDK Unit Test',
<<<HTML
<h1>Hello, World!</h1>
HTML
);
expect($result)->toBeTrue();
} catch (TransportException $t) {
expect($t->getCode())->toBe(554);
}
try {
$email->sendText(
$result = $email->sendText(
'unknown@luxcreo.ai',
'HDK Unit Test',
<<<Text
<h1>Hello, World!</h1>
Text
);
expect($result)->toBeTrue();
} catch (TransportException $t) {
expect($t->getCode())->toBe(554);
}

View File

@@ -9,7 +9,6 @@
namespace Singularity\HDK\Test\Core\Unit;
use Hyperf\Context\Context;
use Singularity\HDK\Core\Service\ExtendService;
use Singularity\HDK\Core\Service\UtilsService;
@@ -21,7 +20,7 @@ it('asserts no parameters can be parsed.', function (ExtendService $service, $pa
$params
);
$result = $service->getExtends();
expect($result)->toBeArray()->toBe([])->toHaveCount(0)->toBe([]);
expect($result)->toBeArray()->toHaveCount(0)->toBe([]);
})->with([
[$service, null],
[$service, ''],
@@ -30,11 +29,6 @@ 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,
@@ -47,21 +41,19 @@ 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,13 +7,14 @@
* Created on 2023/1/9
*/
use Hyperf\Codec\Json;
use Hyperf\Utils\Codec\Json;
use Singularity\HDK\Core\Service\OssService;
use function Spatie\PestPluginTestTime\testTime;
// use function Spatie\PestPluginTestTime\testTime;
it('asserts oss policy can be generated', function ($setDir, $isImage, $maxSize) {
testTime()->freeze();
$time = time();
// testTime()->freeze();
$oss = new OssService(
'{MOCK_ACCESS_KEY_ID}',
'{MOCK_ACCESS_KEY_SECRET}',
@@ -40,8 +41,8 @@ it('asserts oss policy can be generated', function ($setDir, $isImage, $maxSize)
->and($host)->toBe('{MOCK_HOST}')
->and($dir)->toBe($setDir)
->and($setDir)->toBe($policy['conditions'][1][2])
->and($expire)->toBe(testTime()->addSeconds(30)->unix())
->and($policy['expiration'])->toBe(testTime()->setMilli(0)->toIso8601ZuluString('m'))
->and($expire)->toBe($time + 30)
// ->and($policy['expiration'])->toBe(testTime()->setMilli(0)->toIso8601ZuluString('m'))
->and($maxSize)->toBe($policy['conditions'][0][2])
->and($callback['callbackUrl'])->toBe('{MOCK_CALLBACK_URL}')
->and($signature)->toBe($sign);

View File

@@ -1,41 +0,0 @@
<?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

@@ -29,7 +29,7 @@ test('断言验证码可以正常生成指定长度', function (int $length) use
})->with($length_data)->group('pure', 'utils');
test('断言可以根据参数构建 URL', function (string $url, array $params, bool $anchorQuery, string $expect) use ($utils) {
$url = $utils->buildUrl(url: $url, moreQueries: $params, anchorQuery: $anchorQuery);
$url = $utils->buildUrl($url, $params, $anchorQuery);
expect($url)->toBe($expect);
})->with([
['baidu.com/list', ['a' => 'b'], false, 'baidu.com/list?a=b'],
@@ -58,7 +58,7 @@ test('断言可以根据参数构建 URL', function (string $url, array $params,
['c' => 'd'],
true,
'http://username:password@127.0.0.1/git/resp?id=1#/page?a=b&c=d',
]
],
])->group('pure', 'utils');
test('断言可以判断是否是数组中的元素', function (

View File

@@ -1,130 +0,0 @@
<?php
/**
* XmlServiceTest.php@LuxOP
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/4/10
*/
namespace HyperfTest\Unit\Common;
use Singularity\HDK\Core\Service\XmlService;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use function Hyperf\Support\make;
/** @var XmlService $service */
$service = make(
XmlService::class,
['encoder' => make(XmlEncoder::class)]
);
test(
'assert Xml can be encoded',
function (array $data, string $expect, string $rootNodeName) use ($service) {
$result = $service->encode($data, $rootNodeName);
expect($result)->toBe($expect);
}
)->with([
'normal' => [
'data' => [
'@version' => '1.0',
'@descripe' => 'Luxcreo',
'UserName' => 'zhm',
'Email' => 'haimei.zheng@luxcreo.ai',
'BiosId' => '420036H32020120279',
'validTime' => '2099/03/27',
],
'expect' => <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<ClientInfo version="1.0" descripe="Luxcreo">
<UserName>zhm</UserName>
<Email>haimei.zheng@luxcreo.ai</Email>
<BiosId>420036H32020120279</BiosId>
<validTime>2099/03/27</validTime>
</ClientInfo>
XML,
'xmlRootNodeName' => 'ClientInfo',
],
'normal attribute' => [
'data' => [
'@version' => '1.0',
'@descripe' => 'Luxcreo',
'UserName' => 'zhm',
'Email' => [
'@type' => 'Business',
'#' => 'haimei.zheng@luxcreo.ai',
],
'BiosId' => '420036H32020120279',
'validTime' => '2099/03/27',
],
'expect' => <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<ClientInfo version="1.0" descripe="Luxcreo">
<UserName>zhm</UserName>
<Email type="Business">haimei.zheng@luxcreo.ai</Email>
<BiosId>420036H32020120279</BiosId>
<validTime>2099/03/27</validTime>
</ClientInfo>
XML
,
'ClientInfo',
],
'normal comment' => [
'data' => [
'@version' => '1.0',
'@descripe' => 'Luxcreo',
'UserName' => 'zhm',
'Email' => [
'@type' => 'Business',
'#' => 'haimei.zheng@luxcreo.ai',
],
'BiosId' => '420036H32020120279',
'validTime' => [
'#comment' => '到期时间',
],
],
'expect' => <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<ClientInfo version="1.0" descripe="Luxcreo">
<UserName>zhm</UserName>
<Email type="Business">haimei.zheng@luxcreo.ai</Email>
<BiosId>420036H32020120279</BiosId>
<validTime>
<!--到期时间-->
</validTime>
</ClientInfo>
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,29 +9,8 @@ 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);