mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 03:25:05 +08:00
Compare commits
30 Commits
v1.0.0-bet
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6464880c4 | ||
|
|
29ad0ab1c9 | ||
|
|
d1702f7726 | ||
|
|
45824755c6 | ||
|
|
7237cc3d03 | ||
|
|
bc9977a16f | ||
|
|
115a6b154d | ||
|
|
b2cf757bf6 | ||
|
|
3a1f912520 | ||
|
|
3ca9955069 | ||
|
|
15da6e6770 | ||
|
|
68451820b0 | ||
|
|
55da02080e | ||
|
|
0f7b9464c9 | ||
|
|
bf40c6e681 | ||
|
|
9a8575b382 | ||
|
|
c6ab9db698 | ||
|
|
2e0e4feaa5 | ||
|
|
c8b454540d | ||
|
|
bb11a1d8f4 | ||
|
|
b4dcd01e8d | ||
|
|
3b3502f763 | ||
|
|
768f2d79c0 | ||
|
|
225bdedd23 | ||
|
|
aaa4382ff2 | ||
|
|
9a296c56e9 | ||
|
|
2dace65933 | ||
|
|
e8596c9d30 | ||
|
|
b6dd7dd4ac | ||
|
|
0283c7286a |
49
.devcontainer/devcontainer.json
Normal file
49
.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,49 @@
|
||||
{
|
||||
"name": "Hyperf Development Kit Core Dev Container",
|
||||
"image": "harbor.luxcreo.cn/library/hyperf:8.1-swoole",
|
||||
// 基础配置
|
||||
"workspaceFolder": "/srv/www", // 对应 --workdir
|
||||
"workspaceMount": "source=${localWorkspaceFolder},target=/srv/www,type=bind", // 主工作区挂载
|
||||
// 附加挂载
|
||||
"mounts": [
|
||||
"source=${env:HOME}/.ssh,target=/root/.ssh,type=bind", // SSH 密钥挂载
|
||||
"source=${env:HOME}/.gitconfig,target=/root/.gitconfig,type=bind" // SSH 密钥挂载
|
||||
],
|
||||
// 容器生命周期
|
||||
"shutdownAction": "stopContainer", // 类似 --rm 的清理行为
|
||||
"updateRemoteUserUID": true, // 确保用户 ID 同步
|
||||
// 保留的必要 runArgs
|
||||
"runArgs": [
|
||||
"--pull=always", // 强制拉取最新镜像
|
||||
"--name=hdk-core" // 容器命名(需保持唯一性)
|
||||
],
|
||||
// 初始化命令
|
||||
"postCreateCommand": "echo 'Container initialized!'",
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"rid9.datetime",
|
||||
"MS-CEINTL.vscode-language-pack-zh-hans",
|
||||
"ms-azuretools.vscode-docker",
|
||||
"janisdd.vscode-edit-csv",
|
||||
"onecentlin.laravel-blade",
|
||||
"DavidWang.ini-for-vscode",
|
||||
"bmewburn.vscode-intelephense-client",
|
||||
"mechatroner.rainbow-csv",
|
||||
"Alibaba-Cloud.tongyi-lingma",
|
||||
"atommaterial.a-file-icon-vscode",
|
||||
"ParthR2031.colorful-comments",
|
||||
"vincaslt.highlight-matching-tag",
|
||||
"xabikos.JavaScriptSnippets",
|
||||
"shufo.vscode-blade-formatter",
|
||||
"dansysanalyst.pest-snippets",
|
||||
"m1guelpf.better-pest",
|
||||
"xoronic.pestfile",
|
||||
"xdebug.php-debug",
|
||||
"golang.go",
|
||||
"cweijan.vscode-typora",
|
||||
"ciceroisback.loam"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,10 +19,10 @@ jobs:
|
||||
run: |
|
||||
apt-get update
|
||||
apt-get install zip
|
||||
zip -r hdk-core.dist.zip *
|
||||
zip -r dist.zip *
|
||||
- name: Publish to registry
|
||||
run: |
|
||||
curl --user ch4o5:4fd300672472e666014314c1c94c604c634165a9 \
|
||||
--upload-file ./hdk-core.dist.zip \
|
||||
https://nest.doylee.cn/api/packages/HDK/composer?version=${{ gitea.ref_name }}-alpha
|
||||
--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 }}."
|
||||
7
.idea/HDK-Core.iml
generated
7
.idea/HDK-Core.iml
generated
@@ -4,6 +4,7 @@
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="Singularity\HDK\Core\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" packagePrefix="Singularity\HDK\Test\Core\" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/runtime" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/adbario/php-dot-notation" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/alibabacloud/credentials" />
|
||||
@@ -143,7 +144,6 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-idn" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-normalizer" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php72" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php73" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php81" />
|
||||
@@ -185,6 +185,11 @@
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/react/event-loop" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/react/socket" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/react/stream" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/php-diff" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/phpspec" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/phpspec/prophecy" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php84" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/yaml" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
||||
12
.idea/codeception.xml
generated
12
.idea/codeception.xml
generated
@@ -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>
|
||||
25
.idea/jsonSchemas.xml
generated
Normal file
25
.idea/jsonSchemas.xml
generated
Normal file
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="JsonSchemaMappingsProjectConfiguration">
|
||||
<state>
|
||||
<map>
|
||||
<entry key="composer.json">
|
||||
<value>
|
||||
<SchemaInfo>
|
||||
<option name="name" value="composer.json" />
|
||||
<option name="relativePathToSchema" value="https://getcomposer.org/schema.json" />
|
||||
<option name="applicationDefined" value="true" />
|
||||
<option name="patterns">
|
||||
<list>
|
||||
<Item>
|
||||
<option name="path" value="composer.json" />
|
||||
</Item>
|
||||
</list>
|
||||
</option>
|
||||
</SchemaInfo>
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</state>
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/php-test-framework.xml
generated
7
.idea/php-test-framework.xml
generated
@@ -2,6 +2,13 @@
|
||||
<project version="4">
|
||||
<component name="PhpTestFrameworkSettings">
|
||||
<test_tools>
|
||||
<tool tool_name="PHPSpec">
|
||||
<settings>
|
||||
<configurations>
|
||||
<local_configuration executable_path="$PROJECT_DIR$/vendor/phpspec/phpspec/bin/phpspec" />
|
||||
</configurations>
|
||||
</settings>
|
||||
</tool>
|
||||
<tool tool_name="Pest">
|
||||
<settings>
|
||||
<configurations>
|
||||
|
||||
14
.idea/php.xml
generated
14
.idea/php.xml
generated
@@ -15,9 +15,6 @@
|
||||
<PhpCSFixerConfiguration standards="PSR1;PSR2;Symfony;DoctrineAnnotation;PHP70Migration;PHP71Migration" tool_path="$PROJECT_DIR$/vendor/friendsofphp/php-cs-fixer/php-cs-fixer" />
|
||||
</phpcsfixer_settings>
|
||||
</component>
|
||||
<component name="PhpExternalFormatter">
|
||||
<option name="externalFormatter" value="PHP_CBF" />
|
||||
</component>
|
||||
<component name="PhpIncludePathManager">
|
||||
<include_path>
|
||||
<path value="$PROJECT_DIR$/vendor/hyperf/pool" />
|
||||
@@ -84,7 +81,6 @@
|
||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/tea-utils" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" />
|
||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/gateway-spi" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
|
||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/endpoint-util" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/translation" />
|
||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/dysmsapi-20170525" />
|
||||
@@ -192,8 +188,6 @@
|
||||
<path value="$PROJECT_DIR$/vendor/spatie/pest-plugin-test-time" />
|
||||
<path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php82" />
|
||||
<path value="$PROJECT_DIR$/vendor/sebastian/resource-operations" />
|
||||
<path value="$PROJECT_DIR$/vendor/facade/ignition-contracts" />
|
||||
<path value="$PROJECT_DIR$/vendor/cooper/hyperf-pest" />
|
||||
<path value="$PROJECT_DIR$/vendor/clue/ndjson-react" />
|
||||
<path value="$PROJECT_DIR$/vendor/evenement/evenement" />
|
||||
@@ -203,14 +197,18 @@
|
||||
<path value="$PROJECT_DIR$/vendor/react/stream" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/event-loop" />
|
||||
<path value="$PROJECT_DIR$/vendor/react/socket" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php72" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php84" />
|
||||
<path value="$PROJECT_DIR$/vendor/symfony/yaml" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpspec/phpspec" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpspec/php-diff" />
|
||||
<path value="$PROJECT_DIR$/vendor/phpspec/prophecy" />
|
||||
</include_path>
|
||||
</component>
|
||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
||||
<component name="PhpStan">
|
||||
<PhpStan_settings>
|
||||
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />
|
||||
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />
|
||||
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />
|
||||
</PhpStan_settings>
|
||||
</component>
|
||||
<component name="PhpStanOptionsConfiguration">
|
||||
|
||||
39
.idea/phpspec.xml
generated
39
.idea/phpspec.xml
generated
@@ -11,45 +11,6 @@
|
||||
<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>
|
||||
<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>
|
||||
103
CHANGELOG.md
103
CHANGELOG.md
@@ -1,4 +1,107 @@
|
||||
# 版本更新日志
|
||||
### [1.0.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.2...v1.0.3) (2025-11-25)
|
||||
|
||||
|
||||
### 🚀 Chore | 构建/工程依赖/工具
|
||||
|
||||
* **deps:** 更新 roave/dont 依赖版本约束 ([29ad0ab](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/29ad0ab1c9c7bd8a634505a390efda82d954a929))
|
||||
|
||||
### [1.0.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.1...v1.0.2) (2025-09-26)
|
||||
|
||||
### [1.0.1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0...v1.0.1) (2025-08-19)
|
||||
|
||||
|
||||
### 👷 Continuous Integration | CI 配置
|
||||
|
||||
* **gitea:** 更新发布流程并简化版本号 ([bc9977a](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/bc9977a16f0a996aebccda403ceb51b65c28dddd))
|
||||
|
||||
## [1.0.0](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.14...v1.0.0) (2025-08-18)
|
||||
|
||||
## [1.0.0-beta.14](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.13...v1.0.0-beta.14) (2025-08-12)
|
||||
|
||||
|
||||
### ♻️ Code Refactoring | 代码重构
|
||||
|
||||
* **exception:** 重构异常处理逻辑 ([3a1f912](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3a1f912520999ec947295efed564448a85ad1039))
|
||||
|
||||
## [1.0.0-beta.13](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.12...v1.0.0-beta.13) (2025-08-08)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **CoreMiddleware:** 修复分页头部信息设置错误 ([15da6e6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/15da6e67702cdd7d31b55ab58ba9cbbb1a698157))
|
||||
|
||||
## [1.0.0-beta.12](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.11...v1.0.0-beta.12) (2025-08-08)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **exception:** 新增业务错误处理和 API 迁移支持 ([55da020](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/55da02080efa5bd6978b7d0a0e3bbcb1cde41027))
|
||||
|
||||
## [1.0.0-beta.11](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.10...v1.0.0-beta.11) (2025-07-11)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* 新增SP相关配置的枚举 ([bf40c6e](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/bf40c6e681cb1ff37a8fc331a3cd0cdb495e6ff1))
|
||||
|
||||
## [1.0.0-beta.10](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.9...v1.0.0-beta.10) (2025-07-09)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **core:** 添加 X-SP-ID 解析中间件 ([c6ab9db](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c6ab9db69810bcd395c52cc304dffa54978d6e84))
|
||||
|
||||
## [1.0.0-beta.9](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.8...v1.0.0-beta.9) (2025-07-07)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **deps:** 更新依赖并添加 PHPSpec 支持 ([c8b4545](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/c8b454540d2c4371c72f6cb79b5f65b97e7b92f2))
|
||||
|
||||
## [1.0.0-beta.8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.7...v1.0.0-beta.8) (2025-03-04)
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **email:** 添加邮件附件功能 ([3b3502f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/3b3502f7634b48c31c3e7689cdcfe1f4b504b968))
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** Update Dependencies ([b4dcd01](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b4dcd01e8d1fcd2c1fa211ef2a54512593500780))
|
||||
|
||||
## [1.0.0-beta.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.6...v1.0.0-beta.7) (2025-03-03)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **devcontainer:** 添加 Hyperf 开发套件核心配置文件 ([aaa4382](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/aaa4382ff2c5105bc362777f62156b8383b67ed8))
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **EmailService:** 添加邮件附件功能并更新单元测试 ([225bded](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/225bdedd23b1655d5fb7260838fc8c60db5d8f9f))
|
||||
|
||||
## [1.0.0-beta.6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.5...v1.0.0-beta.6) (2024-12-06)
|
||||
|
||||
|
||||
### 🐛 Bug Fixes | Bug 修复
|
||||
|
||||
* **exceptions:** 处理 HTTP 客户端和服务器异常 ([2dace65](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2dace65933d7361c1124f8c5c125a507894584fb))
|
||||
|
||||
## [1.0.0-beta.5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.4...v1.0.0-beta.5) (2024-09-12)
|
||||
|
||||
|
||||
### 📦 Build System | 打包构建
|
||||
|
||||
* **composer:** 更新依赖 ([0283c72](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/0283c7286a58104c0ea649820fdab2dc781053c9))
|
||||
|
||||
|
||||
### ✨ Features | 新功能
|
||||
|
||||
* **email:** 对发送邮件增加密送,增加单独定制发件人的方法 ([b6dd7dd](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b6dd7dd4ace2623a4631d22fc4e6394e9d2ddda7))
|
||||
|
||||
## [1.0.0-beta.4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.3...v1.0.0-beta.4) (2024-06-23)
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
1.0.0-beta.4
|
||||
1.0.3
|
||||
@@ -38,11 +38,12 @@
|
||||
"jetbrains/phpstorm-attributes": "^1.0",
|
||||
"lmc/http-constants": "^1.2.0",
|
||||
"myclabs/php-enum": "^1.8.4",
|
||||
"roave/dont": "^1.6.0",
|
||||
"roave/dont": "*",
|
||||
"symfony/http-foundation": "^6.4",
|
||||
"symfony/polyfill-php81": "^1.28",
|
||||
"symfony/polyfill-php82": "^1.28",
|
||||
"symfony/polyfill-php83": "^1.28",
|
||||
"symfony/polyfill-php84": "^1.28",
|
||||
"teapot/status-code": "^1.1.2"
|
||||
},
|
||||
"require-dev": {
|
||||
@@ -59,8 +60,9 @@
|
||||
"hyperf/testing": "^3.1",
|
||||
"hyperf/validation": "3.1.*",
|
||||
"pestphp/pest": "^2.23",
|
||||
"phpspec/phpspec": "^7.5",
|
||||
"phpstan/phpstan": "^1.10.49",
|
||||
"rector/rector": "^0.15.25",
|
||||
"rector/rector": "*",
|
||||
"roave/security-advisories": "dev-latest",
|
||||
"spatie/pest-plugin-test-time": "^2.0",
|
||||
"swoole/ide-helper": "*",
|
||||
@@ -107,7 +109,7 @@
|
||||
"phpunit.xml"
|
||||
]
|
||||
},
|
||||
"minimum-stability": "dev",
|
||||
"minimum-stability": "beta",
|
||||
"prefer-stable": true,
|
||||
"scripts": {
|
||||
"post-root-package-install": [],
|
||||
@@ -125,10 +127,14 @@
|
||||
]
|
||||
},
|
||||
"repositories": {
|
||||
"nest": {
|
||||
"type": "composer",
|
||||
"url": "https://nest.doylee.cn/api/packages/HDK/composer"
|
||||
},
|
||||
"packagist": {
|
||||
"type": "composer",
|
||||
"url": "https://mirrors.aliyun.com/composer/"
|
||||
}
|
||||
},
|
||||
"version": "1.0.0-beta.4"
|
||||
"version": "1.0.3"
|
||||
}
|
||||
|
||||
5192
composer.lock
generated
5192
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -163,4 +163,11 @@ return [
|
||||
'default' => 'DOC deleted',
|
||||
],
|
||||
],
|
||||
|
||||
// 业务错误
|
||||
'business' => [
|
||||
'default' => 'Business Error',
|
||||
'old_version' => 'This feature is not available in the current version.',
|
||||
'not_implemented' => 'This feature is not implemented yet.',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -172,4 +172,11 @@ return [
|
||||
'default' => '文档已删除',
|
||||
],
|
||||
],
|
||||
|
||||
// 业务错误
|
||||
'business' => [
|
||||
'default' => '业务错误',
|
||||
'old_version' => '当前版本过低,请升级到最新版本',
|
||||
'not_implemented' => '该功能尚未实现',
|
||||
],
|
||||
];
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace Singularity\HDK\Core\Constants;
|
||||
|
||||
use Hyperf\Constants\AbstractConstants;
|
||||
use Hyperf\Constants\Annotation\Constants;
|
||||
use Hyperf\Constants\Annotation\Message;
|
||||
|
||||
/**
|
||||
* Singularity\HyperfDevelopmentKit\Utils\Constants\CommonErrorCode@hyperf-development-kit
|
||||
@@ -319,4 +320,15 @@ class CommonErrorCode extends AbstractConstants
|
||||
* @Message("common_error.model.document.default")
|
||||
*/
|
||||
public const DOCUMENT_NOT_EXISTS = 4020201;
|
||||
|
||||
// 500 业务错误
|
||||
|
||||
#[Message('common_error.business.default')]
|
||||
public const BUSINESS_ERROR = 500001;
|
||||
// 501 版本问题
|
||||
#[Message('common_error.business.old_version')]
|
||||
public const BUSINESS_FLAT_OLD_VERSION = 501001;
|
||||
|
||||
#[Message('common_error.business.not_implemented')]
|
||||
public const BUSINESS_NOT_IMPLEMENTED = 501002;
|
||||
}
|
||||
|
||||
16
src/Enumerations/Sp/EnvConfiguration.php
Normal file
16
src/Enumerations/Sp/EnvConfiguration.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* EnvConfiguration.php@Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/7/11
|
||||
*/
|
||||
|
||||
namespace Singularity\HDK\Core\Enumerations\Sp;
|
||||
|
||||
interface EnvConfiguration
|
||||
{
|
||||
public const DEVELOPMENT = 'development';
|
||||
public const PRODUCTION = 'production';
|
||||
}
|
||||
12
src/Enumerations/Sp/ServiceProviderConfiguration.php
Normal file
12
src/Enumerations/Sp/ServiceProviderConfiguration.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* ServiceProviderConfiguration.php@Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/7/11
|
||||
*/
|
||||
|
||||
namespace Singularity\HDK\Core\Enumerations\Sp;
|
||||
|
||||
interface ServiceProviderConfiguration extends EnvConfiguration, SiteConfiguration {}
|
||||
16
src/Enumerations/Sp/SiteConfiguration.php
Normal file
16
src/Enumerations/Sp/SiteConfiguration.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* SiteConfigration.php@Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/7/11
|
||||
*/
|
||||
|
||||
namespace Singularity\HDK\Core\Enumerations\Sp;
|
||||
|
||||
interface SiteConfiguration
|
||||
{
|
||||
public const CN = 'CN';
|
||||
public const NA = 'NA';
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* EmailWillSent.php@HDK-Core
|
||||
*
|
||||
@@ -9,6 +10,8 @@
|
||||
|
||||
namespace Singularity\HDK\Core\Events;
|
||||
|
||||
use Singularity\HDK\Core\Service\EmailService;
|
||||
use Symfony\Component\Mime\Address;
|
||||
use Symfony\Component\Mime\Email;
|
||||
|
||||
/**
|
||||
@@ -24,9 +27,9 @@ class EmailWillSent
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var string|string[] $target
|
||||
* @var Address|string|string[]|Address[] $target
|
||||
*/
|
||||
public string|array $target,
|
||||
public Address|string|array $target,
|
||||
|
||||
/**
|
||||
* @var non-empty-string $subject
|
||||
@@ -39,10 +42,19 @@ class EmailWillSent
|
||||
public string $content,
|
||||
|
||||
/**
|
||||
* 抄送
|
||||
*
|
||||
* @var string[] $cc
|
||||
*/
|
||||
public array $cc = [],
|
||||
|
||||
/**
|
||||
* 密送
|
||||
*
|
||||
* @var string[] $bcc
|
||||
*/
|
||||
public array $bcc = [],
|
||||
|
||||
/**
|
||||
* @var 'text'|'html' $type
|
||||
*/
|
||||
@@ -52,7 +64,23 @@ class EmailWillSent
|
||||
* @var int
|
||||
* @see Email::priority()
|
||||
*/
|
||||
public int $priority = Email::PRIORITY_NORMAL
|
||||
) {
|
||||
}
|
||||
public int $priority = Email::PRIORITY_NORMAL,
|
||||
|
||||
/**
|
||||
* @var EmailService|null
|
||||
*/
|
||||
public ?EmailService $sender = null,
|
||||
|
||||
/**
|
||||
* 附件路径集合、含附件路径、文件名、文件类型的数组集合
|
||||
* @var string[]|array{'path': string, 'name': string, 'mimeType': string}[] $attachmentPaths
|
||||
*/
|
||||
public array $attachmentPaths = [],
|
||||
|
||||
/**
|
||||
* 附件内容集合、含附件内容、文件名、文件类型的数组集合
|
||||
* @var string[]|array{'content': string, 'name': string, 'mimeType': string}[] $attachments
|
||||
*/
|
||||
public array $attachments = [],
|
||||
) {}
|
||||
}
|
||||
|
||||
34
src/Exceptions/ApiMigrated.php
Normal file
34
src/Exceptions/ApiMigrated.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* DomainOrderNotSupportException.php@LuxDesign
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/8/1
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Core\Exceptions;
|
||||
|
||||
use Hyperf\HttpMessage\Exception\HttpException;
|
||||
use Singularity\HDK\Core\Constants\CommonErrorCode;
|
||||
use Teapot\StatusCode\RFC\RFC7231;
|
||||
use Throwable;
|
||||
|
||||
final class ApiMigrated extends HttpException
|
||||
{
|
||||
public function __construct(
|
||||
public string $apiPath,
|
||||
int $code = CommonErrorCode::BUSINESS_FLAT_OLD_VERSION,
|
||||
?string $message = null,
|
||||
Throwable $previous = null,
|
||||
) {
|
||||
parent::__construct(RFC7231::SEE_OTHER, $message, $code, $previous);
|
||||
}
|
||||
|
||||
public function getNewPath(): string
|
||||
{
|
||||
return $this->apiPath;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,8 @@ declare(strict_types=1);
|
||||
namespace Singularity\HDK\Core\Exceptions\Handler;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use Hyperf\Codec\Json;
|
||||
use Hyperf\Database\Exception\QueryException;
|
||||
use Hyperf\Database\Model\ModelNotFoundException;
|
||||
@@ -30,6 +32,8 @@ use Lmc\HttpConstants\Header;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use RedisException;
|
||||
use Singularity\HDK\Core\Constants\CommonErrorCode;
|
||||
use Singularity\HDK\Core\Exceptions\ApiMigrated;
|
||||
use Singularity\HDK\Core\Exceptions\NotImplementedException;
|
||||
use Singularity\HDK\Core\Exceptions\ValidateException;
|
||||
use Singularity\HDK\Core\Service\ApiStyleService;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
@@ -38,6 +42,7 @@ use Teapot\StatusCode\RFC\RFC7231;
|
||||
use Throwable;
|
||||
|
||||
use function Hyperf\Config\config;
|
||||
use function Hyperf\Support\make;
|
||||
use function Hyperf\Translation\__;
|
||||
|
||||
/**
|
||||
@@ -50,9 +55,6 @@ use function Hyperf\Translation\__;
|
||||
*/
|
||||
class CommonHandler extends ExceptionHandler
|
||||
{
|
||||
#[Inject(required: false)]
|
||||
private ?RequestInterface $request;
|
||||
|
||||
#[Inject]
|
||||
private StdoutLogger $logger;
|
||||
|
||||
@@ -66,18 +68,23 @@ class CommonHandler extends ExceptionHandler
|
||||
{
|
||||
// 阻止异常冒泡
|
||||
$this->stopPropagation();
|
||||
if ($throwable instanceof BadRequestHttpException) {
|
||||
$request = $throwable->getRequest();
|
||||
} else {
|
||||
$request = make(RequestInterface::class);
|
||||
}
|
||||
$restful = $this->apiStyleService->get();
|
||||
// $restful = config('common.response.restful');
|
||||
$code_name = config('common.response.code_name');
|
||||
$message_name = config('common.response.message_name');
|
||||
$is_testing = config('app_status') === true;
|
||||
$this->request?->url();
|
||||
$request?->url();
|
||||
|
||||
$is_debug = $is_testing;
|
||||
$error_type = $throwable::class;
|
||||
$request_time = Carbon::now()->toDateTimeString();
|
||||
$request_data = Json::encode($this->request?->getParsedBody());
|
||||
$request_headers = Json::encode($this->request?->getHeaders());
|
||||
$request_data = $request?->getBody()->getContents();
|
||||
$request_headers = Json::encode($request?->getHeaders());
|
||||
// 901 程序语法错误
|
||||
// 902 SQL 语法错误
|
||||
if ($throwable instanceof QueryException) {
|
||||
@@ -93,6 +100,26 @@ class CommonHandler extends ExceptionHandler
|
||||
$data['details'] = ['sql' => $throwable->getSql(), 'error' => $throwable->getMessage()];
|
||||
}
|
||||
}
|
||||
if ($throwable instanceof ClientException) {
|
||||
$content = $throwable->getResponse()->getBody()->getContents();
|
||||
|
||||
['errorCode' => $code, 'errorMsg' => $msg] = Json::decode($content);
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => $msg,
|
||||
];
|
||||
$status_code = 400;
|
||||
}
|
||||
if ($throwable instanceof ServerException) {
|
||||
$content = $throwable->getResponse()->getBody()->getContents();
|
||||
|
||||
['errorCode' => $code, 'errorMsg' => $msg] = Json::decode($content);
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => $msg,
|
||||
];
|
||||
$status_code = 500;
|
||||
}
|
||||
// 101 请求方式错误
|
||||
if ($throwable instanceof MethodNotAllowedHttpException) {
|
||||
$message = explode(': ', $throwable->getMessage());
|
||||
@@ -101,7 +128,7 @@ class CommonHandler extends ExceptionHandler
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => CommonErrorCode::getMessage($code, ['methods' => join(', ', $allow_method)]),
|
||||
'currentMethod' => $this->request?->getMethod(),
|
||||
'currentMethod' => $request?->getMethod(),
|
||||
'allowedMethod' => $allow_method,
|
||||
];
|
||||
$status_code = RFC7231::METHOD_NOT_ALLOWED;
|
||||
@@ -111,7 +138,7 @@ class CommonHandler extends ExceptionHandler
|
||||
$data = [
|
||||
$code_name => CommonErrorCode::REQUEST_PARAMS_ERROR,
|
||||
$message_name => $is_testing ? $throwable->getMessage() : CommonErrorCode::getMessage(
|
||||
CommonErrorCode::SERVER_ERROR
|
||||
CommonErrorCode::SERVER_ERROR,
|
||||
),
|
||||
];
|
||||
$status_code = RFC4918::UNPROCESSABLE_ENTITY;
|
||||
@@ -136,7 +163,7 @@ class CommonHandler extends ExceptionHandler
|
||||
$code,
|
||||
[
|
||||
'param' => $throwable->getFieldName(),
|
||||
]
|
||||
],
|
||||
)
|
||||
: $message,
|
||||
];
|
||||
@@ -156,7 +183,7 @@ class CommonHandler extends ExceptionHandler
|
||||
$code = empty($throwable->getCode()) ? CommonErrorCode::MODEL_NOT_FOUND : $throwable->getCode();
|
||||
$message = empty($throwable->getCode()) ? CommonErrorCode::getMessage(
|
||||
$code,
|
||||
['resource' => '资源']
|
||||
['resource' => '资源'],
|
||||
) : $throwable->getMessage();
|
||||
$data = [$code_name => $code, $message_name => $message];
|
||||
$status_code = RFC7231::NOT_FOUND;
|
||||
@@ -171,7 +198,7 @@ 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,
|
||||
),
|
||||
];
|
||||
}
|
||||
@@ -185,17 +212,39 @@ 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,
|
||||
),
|
||||
];
|
||||
}
|
||||
// 500 业务错误
|
||||
if ($throwable instanceof ApiMigrated) {
|
||||
$code = $throwable->getCode();
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => $throwable->getMessage(),
|
||||
];
|
||||
$headers = [
|
||||
'Location' => $throwable->getNewPath(),
|
||||
];
|
||||
}
|
||||
if ($throwable instanceof NotImplementedException || $throwable instanceof \Hyperf\Framework\Exception\NotImplementedException) {
|
||||
$code = $throwable->getCode();
|
||||
if ($code === 0) {
|
||||
$code = CommonErrorCode::BUSINESS_NOT_IMPLEMENTED;
|
||||
}
|
||||
$message = $throwable->getMessage() ?? CommonErrorCode::getMessage($code);
|
||||
$data = [
|
||||
$code_name => $code,
|
||||
$message_name => $message,
|
||||
];
|
||||
}
|
||||
if (empty($data)) {
|
||||
// 其他情况
|
||||
$data = [
|
||||
$code_name => $is_testing ? $throwable->getCode(
|
||||
) == 0 ? CommonErrorCode::SERVER_ERROR : $throwable->getCode() : CommonErrorCode::SERVER_ERROR,
|
||||
$message_name => $is_testing ? $throwable->getMessage() : __(
|
||||
CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR)
|
||||
CommonErrorCode::getMessage(CommonErrorCode::SERVER_ERROR),
|
||||
),
|
||||
];
|
||||
// 其他错误
|
||||
@@ -211,45 +260,47 @@ class CommonHandler extends ExceptionHandler
|
||||
if ($is_debug && $is_testing) {
|
||||
$data += ['errorType' => $error_type, 'errorTrack' => $throwable->getTrace()];
|
||||
}
|
||||
$cookies = json_encode($this->request->getCookieParams(), JSON_UNESCAPED_UNICODE);
|
||||
$cookies = json_encode($request->getCookieParams(), JSON_UNESCAPED_UNICODE);
|
||||
$this->logger->error(
|
||||
<<<ERROR_LOG
|
||||
TYPE: {$error_type}
|
||||
[$data[$code_name]] $data[$message_name]
|
||||
{$throwable->getMessage()}
|
||||
-------------------------------
|
||||
REQUEST_TIME: {$request_time}
|
||||
-------------------------------
|
||||
REQUEST_HEADERS:
|
||||
{$request_headers}
|
||||
-------------------------------
|
||||
REQUEST_COOKIES:
|
||||
{$cookies}
|
||||
-------------------------------
|
||||
REQUEST_METHOD:
|
||||
{$this->request?->getMethod()}
|
||||
-------------------------------
|
||||
REQUEST_URL:
|
||||
{$this->request?->getUri()}
|
||||
-------------------------------
|
||||
REQUEST_QUERY:
|
||||
{$this->request?->getQueryString()}
|
||||
-------------------------------
|
||||
REQUEST_DATA:
|
||||
{$request_data}
|
||||
-------------------------------
|
||||
TRACE:
|
||||
{$throwable->getTraceAsString()}
|
||||
===============================
|
||||
|
||||
ERROR_LOG
|
||||
TYPE: {$error_type}
|
||||
[$data[$code_name]] $data[$message_name]
|
||||
{$throwable->getMessage()}
|
||||
-------------------------------
|
||||
REQUEST_TIME: {$request_time}
|
||||
-------------------------------
|
||||
REQUEST_HEADERS:
|
||||
{$request_headers}
|
||||
-------------------------------
|
||||
REQUEST_COOKIES:
|
||||
{$cookies}
|
||||
-------------------------------
|
||||
REQUEST_METHOD:
|
||||
{$request?->getMethod()}
|
||||
-------------------------------
|
||||
REQUEST_URL:
|
||||
{$request?->getUri()}
|
||||
-------------------------------
|
||||
REQUEST_QUERY:
|
||||
{$request?->getUri()->getQuery()}
|
||||
-------------------------------
|
||||
REQUEST_DATA:
|
||||
{$request_data}
|
||||
-------------------------------
|
||||
TRACE:
|
||||
{$throwable->getTraceAsString()}
|
||||
===============================
|
||||
ERROR_LOG,
|
||||
);
|
||||
$data = Json::encode($data);
|
||||
if ($restful === ApiStyleService::RESTFUL) {
|
||||
$response = $response->withStatus(
|
||||
$status_code ?? $throwable->status ?? $throwable->statusCode ?? RFC7231::INTERNAL_SERVER_ERROR
|
||||
$status_code ?? $throwable->status ?? $throwable->statusCode ?? RFC7231::INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
foreach ($headers ?? [] as $header => $value) {
|
||||
$response->withHeader($header, $value);
|
||||
}
|
||||
return $response->withBody(new SwooleStream($data));
|
||||
}
|
||||
|
||||
|
||||
29
src/Exceptions/NotImplementedException.php
Normal file
29
src/Exceptions/NotImplementedException.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* NotImplementedException.php@Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/8/2
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Core\Exceptions;
|
||||
|
||||
use Hyperf\HttpMessage\Exception\HttpException;
|
||||
use Singularity\HDK\Core\Constants\CommonErrorCode;
|
||||
use Teapot\StatusCode\RFC\RFC7231;
|
||||
use Throwable;
|
||||
|
||||
final class NotImplementedException extends HttpException
|
||||
{
|
||||
public function __construct(
|
||||
int $code = CommonErrorCode::BUSINESS_NOT_IMPLEMENTED,
|
||||
?string $message = null,
|
||||
Throwable $previous = null,
|
||||
) {
|
||||
$message ??= CommonErrorCode::getMessage($code);
|
||||
parent::__construct(RFC7231::NOT_IMPLEMENTED, $message, $code, $previous);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* EmailWillSentListener.php@HDK-Core
|
||||
*
|
||||
@@ -55,7 +56,8 @@ class EmailWillSentListener implements ListenerInterface
|
||||
public function process(object $event): void
|
||||
{
|
||||
$stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
|
||||
$emailService = $this->container->get(EmailService::class);
|
||||
// $emailService = $this->container->get(EmailService::class);
|
||||
$emailService = $event->sender ?? EmailService::make();
|
||||
try {
|
||||
$event->type === 'html'
|
||||
? $emailService->sendHtml(
|
||||
@@ -63,6 +65,9 @@ class EmailWillSentListener implements ListenerInterface
|
||||
subject: $event->subject,
|
||||
html: $event->content,
|
||||
cc: $event->cc,
|
||||
bcc: $event->bcc,
|
||||
attachmentPaths: $event->attachmentPaths,
|
||||
attachments: $event->attachments,
|
||||
priority: $event->priority
|
||||
)
|
||||
: $emailService->sendText(
|
||||
@@ -70,6 +75,9 @@ class EmailWillSentListener implements ListenerInterface
|
||||
subject: $event->subject,
|
||||
text: $event->content,
|
||||
cc: $event->cc,
|
||||
bcc: $event->bcc,
|
||||
attachmentPaths: $event->attachmentPaths,
|
||||
attachments: $event->attachments,
|
||||
priority: $event->priority
|
||||
);
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class CommonCoreMiddleware extends CoreMiddleware
|
||||
->withHeader('Per-Page', (string)$response->perPage())
|
||||
->withHeader('Total', (string)$response->total())
|
||||
->withHeader('Current-Page', (string)$response->currentPage())
|
||||
->withHeader('Total-Pages', (string)$response->hasPages());
|
||||
->withHeader('Total-Pages', (string)$response->lastPage());
|
||||
$fact_response = $this->utilsService->extendLinkToHeader($fact_response, $response->nextPageUrl(), 'next');
|
||||
$fact_response = $this->utilsService->extendLinkToHeader(
|
||||
$fact_response,
|
||||
@@ -90,7 +90,10 @@ class CommonCoreMiddleware extends CoreMiddleware
|
||||
$response->previousPageUrl(),
|
||||
'prev'
|
||||
);
|
||||
return $fact_response->withBody(new SwooleStream(Json::encode($response->items())));
|
||||
return $fact_response->withBody(new SwooleStream(Json::encode($response->items())))->withHeader(
|
||||
Header::CONTENT_TYPE,
|
||||
'application/json',
|
||||
);
|
||||
}
|
||||
|
||||
return parent::transferToResponse($response, $request);
|
||||
|
||||
32
src/Middleware/SpParseMiddleware.php
Normal file
32
src/Middleware/SpParseMiddleware.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* SpParseMiddleware.php@Core
|
||||
*
|
||||
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
|
||||
* Powered by PhpStorm
|
||||
* Created on 2025/7/9
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Singularity\HDK\Core\Middleware;
|
||||
|
||||
use Hyperf\Context\Context;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\MiddlewareInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
|
||||
final class SpParseMiddleware implements MiddlewareInterface
|
||||
{
|
||||
|
||||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
|
||||
{
|
||||
$sp = $request->getHeaderLine('X-SP-ID');
|
||||
if (!empty($sp)) {
|
||||
Context::set('sp', $sp);
|
||||
}
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,18 @@ class EmailService
|
||||
);
|
||||
}
|
||||
|
||||
public static function make(
|
||||
?string $dsn = null,
|
||||
?string $mailSenderName = null,
|
||||
?string $mailSender = null,
|
||||
): static {
|
||||
return new static(
|
||||
dsn: $dsn,
|
||||
mailSenderName: $mailSenderName,
|
||||
mailSender: $mailSender,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件
|
||||
*
|
||||
@@ -67,29 +79,51 @@ class EmailService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array<string> $target
|
||||
* @param string $subject
|
||||
* @param string $text
|
||||
* @param Address|string|array<string|Address> $target
|
||||
* @param string $subject
|
||||
* @param string $text
|
||||
* @param array<string> $cc
|
||||
* @param array $bcc
|
||||
* @param int $priority
|
||||
*
|
||||
* @return bool
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendText(
|
||||
string|array $target,
|
||||
Address|string|array $target,
|
||||
string $subject,
|
||||
string $text,
|
||||
array $cc = [],
|
||||
array $bcc = [],
|
||||
array $attachmentPaths = [],
|
||||
array $attachments = [],
|
||||
int $priority = Email::PRIORITY_NORMAL
|
||||
): bool {
|
||||
$email = (new Email())
|
||||
->from(Address::create($this->from))
|
||||
->to(...(is_array($target) ? $target : [$target]))
|
||||
->cc(...$cc)
|
||||
->bcc(...$bcc)
|
||||
->priority($priority)
|
||||
->subject($subject)
|
||||
->text($text);
|
||||
|
||||
foreach ($attachmentPaths as $attachmentPath) {
|
||||
if (is_string($attachmentPath)) {
|
||||
$email = $email->attachFromPath($attachmentPath);
|
||||
} else {
|
||||
$email = $email->attachFromPath($attachmentPath['path'], $attachmentPath['name'] ?? null, $attachmentPath['mimeType'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
if (is_string($attachment)) {
|
||||
$email = $email->attach($attachment);
|
||||
} else {
|
||||
$email = $email->attach($attachment['content'], $attachment['name'] ?? null, $attachment['mimeType'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
return true;
|
||||
@@ -98,29 +132,51 @@ class EmailService
|
||||
/**
|
||||
* 以 HTML 格式发送邮件
|
||||
*
|
||||
* @param string|array<string> $target
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param Address|string|array<string|Address> $target
|
||||
* @param string $subject
|
||||
* @param string $html
|
||||
* @param array<string> $cc
|
||||
* @param int $priority
|
||||
* @param array $bcc
|
||||
* @param int $priority
|
||||
*
|
||||
* @return bool
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function sendHtml(
|
||||
string|array $target,
|
||||
Address|string|array $target,
|
||||
string $subject,
|
||||
string $html,
|
||||
array $cc = [],
|
||||
array $bcc = [],
|
||||
array $attachmentPaths = [],
|
||||
array $attachments = [],
|
||||
int $priority = Email::PRIORITY_NORMAL
|
||||
): bool {
|
||||
$email = (new Email())
|
||||
->from(Address::create($this->from))
|
||||
->to(...(is_array($target) ? $target : [$target]))
|
||||
->cc(...$cc)
|
||||
->bcc(...$bcc)
|
||||
->priority($priority)
|
||||
->subject($subject)
|
||||
->html($html);
|
||||
|
||||
foreach ($attachmentPaths as $attachmentPath) {
|
||||
if (is_string($attachmentPath)) {
|
||||
$email = $email->attachFromPath($attachmentPath);
|
||||
} else {
|
||||
$email = $email->attachFromPath($attachmentPath['path'], $attachmentPath['name'] ?? null, $attachmentPath['mimeType'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($attachments as $attachment) {
|
||||
if (is_string($attachment)) {
|
||||
$email = $email->attach($attachment);
|
||||
} else {
|
||||
$email = $email->attach($attachment['content'], $attachment['name'] ?? null, $attachment['mimeType'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
$this->mailer->send($email);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* EmailServiceTest.php@HDK-Core
|
||||
*
|
||||
@@ -9,15 +10,19 @@
|
||||
|
||||
namespace Singularity\HDK\Test\Core\Service;
|
||||
|
||||
use PharIo\Manifest\Email;
|
||||
use Singularity\HDK\Core\Service\EmailService;
|
||||
use Symfony\Component\Mailer\Exception\TransportException;
|
||||
|
||||
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
||||
$mail_sender_name = 'LuxCreo';
|
||||
$mail_sender = 'account@luxcreo.ai';
|
||||
$email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
||||
use function Hyperf\Support\make;
|
||||
|
||||
it('assertions that send HTML is available', function () use ($email) {
|
||||
|
||||
it('assertions that send HTML is available', function () {
|
||||
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
||||
$mail_sender_name = 'LuxCreo';
|
||||
$mail_sender = 'account@luxcreo.ai';
|
||||
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
||||
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
||||
$result = $email->sendHtml(
|
||||
'dongyun.li@luxcreo.ai',
|
||||
'HDK Unit Test HTML',
|
||||
@@ -26,9 +31,15 @@ it('assertions that send HTML is available', function () use ($email) {
|
||||
HTML
|
||||
);
|
||||
expect($result)->toBeTrue();
|
||||
})->skip();
|
||||
});
|
||||
|
||||
it('assertions that send Text is available', function () {
|
||||
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
||||
$mail_sender_name = 'LuxCreo';
|
||||
$mail_sender = 'account@luxcreo.ai';
|
||||
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
||||
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
||||
|
||||
it('assertions that send Text is available', function () use ($email) {
|
||||
$result = $email->sendText(
|
||||
'dongyun.li@luxcreo.ai',
|
||||
'HDK Unit Test Text',
|
||||
@@ -37,9 +48,15 @@ it('assertions that send Text is available', function () use ($email) {
|
||||
Text
|
||||
);
|
||||
expect($result)->toBeTrue();
|
||||
})->skip();
|
||||
});
|
||||
|
||||
it('assertions Error Receiver can be catch', function () {
|
||||
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
||||
$mail_sender_name = 'LuxCreo';
|
||||
$mail_sender = 'account@luxcreo.ai';
|
||||
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
||||
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
||||
|
||||
it('assertions Error Receiver can be catch', function () use ($email) {
|
||||
try {
|
||||
$email->sendHtml(
|
||||
'unknown@luxcreo.ai',
|
||||
@@ -62,4 +79,30 @@ Text
|
||||
} catch (TransportException $t) {
|
||||
expect($t->getCode())->toBe(554);
|
||||
}
|
||||
})->skip('会报错必须运行在协程环境下');
|
||||
});
|
||||
|
||||
it('should can contain attachment', function () {
|
||||
$dsn = 'smtp://account@luxcreo.ai:Qfsd8866@smtp.qiye.aliyun.com:465';
|
||||
$mail_sender_name = 'LuxCreo';
|
||||
$mail_sender = 'account@luxcreo.ai';
|
||||
// $email = new EmailService($dsn, $mail_sender_name, $mail_sender);
|
||||
$email = make(EmailService::class, ['dsn' => $dsn, 'mailSenderName' => $mail_sender_name, 'mailSender' => $mail_sender]);
|
||||
|
||||
$email->sendHtml(
|
||||
'dongyun.li@luxcreo.ai',
|
||||
'HDK Unit Test HTML',
|
||||
<<<HTML
|
||||
<h1>Hello, World!</h1>
|
||||
HTML,
|
||||
[],
|
||||
[],
|
||||
[
|
||||
[
|
||||
'path' => __DIR__ . '/../../README.md',
|
||||
'name' => 'README.md',
|
||||
'mimeType' => 'text/markdown',
|
||||
],
|
||||
],
|
||||
[]
|
||||
);
|
||||
})->only();
|
||||
|
||||
Reference in New Issue
Block a user