mirror of
http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore.git
synced 2026-01-15 07:35:08 +08:00
Compare commits
14 Commits
v1.0.0-bet
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a296c56e9 | ||
|
|
2dace65933 | ||
|
|
e8596c9d30 | ||
|
|
b6dd7dd4ac | ||
|
|
0283c7286a | ||
|
|
e4105a285f | ||
|
|
d20718db32 | ||
|
|
d524fb4e89 | ||
|
|
eeab8a258d | ||
|
|
bac22a8ea6 | ||
|
|
44c26b6491 | ||
|
|
f422fb6b31 | ||
|
|
762acbb368 | ||
|
|
2167fd209a |
9
.idea/HDK-Core.iml
generated
9
.idea/HDK-Core.iml
generated
@@ -143,7 +143,6 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-intl-idn" />
|
<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-intl-normalizer" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />
|
<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-php73" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php80" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php81" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php81" />
|
||||||
@@ -177,6 +176,14 @@
|
|||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
||||||
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php82" />
|
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php82" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/clue/ndjson-react" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/evenement/evenement" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/react/cache" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/react/child-process" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/vendor/react/dns" />
|
||||||
|
<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" />
|
||||||
</content>
|
</content>
|
||||||
<orderEntry type="inheritedJdk" />
|
<orderEntry type="inheritedJdk" />
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
<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>
|
|
||||||
10
.idea/php.xml
generated
10
.idea/php.xml
generated
@@ -84,7 +84,6 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/tea-utils" />
|
<path value="$PROJECT_DIR$/vendor/alibabacloud/tea-utils" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" />
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php81" />
|
||||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/gateway-spi" />
|
<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/alibabacloud/endpoint-util" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/translation" />
|
<path value="$PROJECT_DIR$/vendor/symfony/translation" />
|
||||||
<path value="$PROJECT_DIR$/vendor/alibabacloud/dysmsapi-20170525" />
|
<path value="$PROJECT_DIR$/vendor/alibabacloud/dysmsapi-20170525" />
|
||||||
@@ -192,6 +191,15 @@
|
|||||||
<path value="$PROJECT_DIR$/vendor/spatie/pest-plugin-test-time" />
|
<path value="$PROJECT_DIR$/vendor/spatie/pest-plugin-test-time" />
|
||||||
<path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
<path value="$PROJECT_DIR$/vendor/carbonphp/carbon-doctrine-types" />
|
||||||
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php82" />
|
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php82" />
|
||||||
|
<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>
|
</include_path>
|
||||||
</component>
|
</component>
|
||||||
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
|
||||||
|
|||||||
42
.idea/phpspec.xml
generated
42
.idea/phpspec.xml
generated
@@ -5,48 +5,6 @@
|
|||||||
<PhpSpecSuiteConfiguration>
|
<PhpSpecSuiteConfiguration>
|
||||||
<option name="myPath" value="$PROJECT_DIR$" />
|
<option name="myPath" value="$PROJECT_DIR$" />
|
||||||
</PhpSpecSuiteConfiguration>
|
</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>
|
|
||||||
<PhpSpecSuiteConfiguration>
|
|
||||||
<option name="myPath" value="$PROJECT_DIR$" />
|
|
||||||
</PhpSpecSuiteConfiguration>
|
|
||||||
</suites>
|
</suites>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
55
CHANGELOG.md
55
CHANGELOG.md
@@ -1,4 +1,59 @@
|
|||||||
# 版本更新日志
|
# 版本更新日志
|
||||||
|
## [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)
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes | Bug 修复
|
||||||
|
|
||||||
|
* **core-middleware:** 修复 JsonResource 不走响应格式化的问题 ([d524fb4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/d524fb4e890dd06da8c4fe2f0853e34944cd0e28))
|
||||||
|
|
||||||
|
|
||||||
|
### 📦 Build System | 打包构建
|
||||||
|
|
||||||
|
* **composer:** 更新依赖 ([d20718d](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/d20718db32a9dc05535ff66598475186e8016167))
|
||||||
|
|
||||||
|
## [1.0.0-beta.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.2...v1.0.0-beta.3) (2024-05-17)
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes | Bug 修复
|
||||||
|
|
||||||
|
* **i18n:** 在没有配置项目默认语言,且传入意料之外的语言时,默认为英文 ([44c26b6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/44c26b64918702062f28499d566eaa54d8aff491))
|
||||||
|
|
||||||
|
|
||||||
|
### 📦 Build System | 打包构建
|
||||||
|
|
||||||
|
* **composer:** 更新依赖 ([bac22a8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/bac22a8ea683c42f597e070e1395881b46b2bd83))
|
||||||
|
|
||||||
|
## [1.0.0-beta.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.1...v1.0.0-beta.2) (2024-01-18)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚡ Performance Improvements | 性能优化
|
||||||
|
|
||||||
|
* **exception:** 取消了必须是 apifox/postman 的设计 ([2167fd2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2167fd209a3cc46ea77fc64909ff8adf71ec6ef0))
|
||||||
|
|
||||||
|
|
||||||
|
### 🐛 Bug Fixes | Bug 修复
|
||||||
|
|
||||||
|
* **CoreMiddleware:** 修复如果直接输出 ResponseInterface 实例会报错的问题 ([762acbb](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/762acbb368d6a901478fe3d6b2a3e30793f2c57c))
|
||||||
|
|
||||||
## [1.0.0-beta.1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.0...v1.0.0-beta.1) (2023-12-15)
|
## [1.0.0-beta.1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-beta.0...v1.0.0-beta.1) (2023-12-15)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.0.0-beta.1
|
1.0.0-beta.6
|
||||||
@@ -130,5 +130,5 @@
|
|||||||
"url": "https://mirrors.aliyun.com/composer/"
|
"url": "https://mirrors.aliyun.com/composer/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"version": "1.0.0-beta.1"
|
"version": "1.0.0-beta.6"
|
||||||
}
|
}
|
||||||
|
|||||||
3528
composer.lock
generated
3528
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
namespace Singularity\HDK\Core\Events;
|
namespace Singularity\HDK\Core\Events;
|
||||||
|
|
||||||
|
use Singularity\HDK\Core\Service\EmailService;
|
||||||
use Symfony\Component\Mime\Email;
|
use Symfony\Component\Mime\Email;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,10 +40,19 @@ class EmailWillSent
|
|||||||
public string $content,
|
public string $content,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* 抄送
|
||||||
|
*
|
||||||
* @var string[] $cc
|
* @var string[] $cc
|
||||||
*/
|
*/
|
||||||
public array $cc = [],
|
public array $cc = [],
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密送
|
||||||
|
*
|
||||||
|
* @var string[] $bcc
|
||||||
|
*/
|
||||||
|
public array $bcc = [],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var 'text'|'html' $type
|
* @var 'text'|'html' $type
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +62,12 @@ class EmailWillSent
|
|||||||
* @var int
|
* @var int
|
||||||
* @see Email::priority()
|
* @see Email::priority()
|
||||||
*/
|
*/
|
||||||
public int $priority = Email::PRIORITY_NORMAL
|
public int $priority = Email::PRIORITY_NORMAL,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var EmailService|null
|
||||||
|
*/
|
||||||
|
public ?EmailService $sender = null,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ declare(strict_types=1);
|
|||||||
namespace Singularity\HDK\Core\Exceptions\Handler;
|
namespace Singularity\HDK\Core\Exceptions\Handler;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use GuzzleHttp\Exception\ClientException;
|
||||||
|
use GuzzleHttp\Exception\ServerException;
|
||||||
use Hyperf\Codec\Json;
|
use Hyperf\Codec\Json;
|
||||||
use Hyperf\Database\Exception\QueryException;
|
use Hyperf\Database\Exception\QueryException;
|
||||||
use Hyperf\Database\Model\ModelNotFoundException;
|
use Hyperf\Database\Model\ModelNotFoundException;
|
||||||
@@ -72,10 +74,8 @@ class CommonHandler extends ExceptionHandler
|
|||||||
$message_name = config('common.response.message_name');
|
$message_name = config('common.response.message_name');
|
||||||
$is_testing = config('app_status') === true;
|
$is_testing = config('app_status') === true;
|
||||||
$this->request?->url();
|
$this->request?->url();
|
||||||
$is_debug = $this->request?->hasHeader('Postman-Token') || str_starts_with(
|
|
||||||
$this->request?->header('User-Agent', ''),
|
$is_debug = $is_testing;
|
||||||
'apifox'
|
|
||||||
);
|
|
||||||
$error_type = $throwable::class;
|
$error_type = $throwable::class;
|
||||||
$request_time = Carbon::now()->toDateTimeString();
|
$request_time = Carbon::now()->toDateTimeString();
|
||||||
$request_data = Json::encode($this->request?->getParsedBody());
|
$request_data = Json::encode($this->request?->getParsedBody());
|
||||||
@@ -95,6 +95,26 @@ class CommonHandler extends ExceptionHandler
|
|||||||
$data['details'] = ['sql' => $throwable->getSql(), 'error' => $throwable->getMessage()];
|
$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 请求方式错误
|
// 101 请求方式错误
|
||||||
if ($throwable instanceof MethodNotAllowedHttpException) {
|
if ($throwable instanceof MethodNotAllowedHttpException) {
|
||||||
$message = explode(': ', $throwable->getMessage());
|
$message = explode(': ', $throwable->getMessage());
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ enum Languages: string
|
|||||||
return match (mb_strtolower($language)) {
|
return match (mb_strtolower($language)) {
|
||||||
'en', 'en_us', 'en-us', 'en-uk', 'en_uk' => self::EN,
|
'en', 'en_us', 'en-us', 'en-uk', 'en_uk' => self::EN,
|
||||||
'zh', 'zh_cn', 'zh-cn' => self::ZH_CN,
|
'zh', 'zh_cn', 'zh-cn' => self::ZH_CN,
|
||||||
default => self::from(config('translation.locale')),
|
default => self::from(config('translation.locale') ?? 'en'),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ class EmailWillSentListener implements ListenerInterface
|
|||||||
public function process(object $event): void
|
public function process(object $event): void
|
||||||
{
|
{
|
||||||
$stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
|
$stdoutLogger = $this->container->get(StdoutLoggerInterface::class);
|
||||||
$emailService = $this->container->get(EmailService::class);
|
// $emailService = $this->container->get(EmailService::class);
|
||||||
|
$emailService = $event->sender ?? EmailService::make();
|
||||||
try {
|
try {
|
||||||
$event->type === 'html'
|
$event->type === 'html'
|
||||||
? $emailService->sendHtml(
|
? $emailService->sendHtml(
|
||||||
@@ -63,6 +64,7 @@ class EmailWillSentListener implements ListenerInterface
|
|||||||
subject: $event->subject,
|
subject: $event->subject,
|
||||||
html: $event->content,
|
html: $event->content,
|
||||||
cc: $event->cc,
|
cc: $event->cc,
|
||||||
|
bcc: $event->bcc,
|
||||||
priority: $event->priority
|
priority: $event->priority
|
||||||
)
|
)
|
||||||
: $emailService->sendText(
|
: $emailService->sendText(
|
||||||
@@ -70,6 +72,7 @@ class EmailWillSentListener implements ListenerInterface
|
|||||||
subject: $event->subject,
|
subject: $event->subject,
|
||||||
text: $event->content,
|
text: $event->content,
|
||||||
cc: $event->cc,
|
cc: $event->cc,
|
||||||
|
bcc: $event->bcc,
|
||||||
priority: $event->priority
|
priority: $event->priority
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ use Hyperf\Di\Annotation\Inject;
|
|||||||
use Hyperf\HttpMessage\Server\ResponsePlusProxy;
|
use Hyperf\HttpMessage\Server\ResponsePlusProxy;
|
||||||
use Hyperf\HttpMessage\Stream\SwooleStream;
|
use Hyperf\HttpMessage\Stream\SwooleStream;
|
||||||
use Hyperf\HttpServer\CoreMiddleware;
|
use Hyperf\HttpServer\CoreMiddleware;
|
||||||
|
use Hyperf\Resource\Json\JsonResource;
|
||||||
use Lmc\HttpConstants\Header;
|
use Lmc\HttpConstants\Header;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
@@ -47,14 +48,14 @@ class CommonCoreMiddleware extends CoreMiddleware
|
|||||||
*/
|
*/
|
||||||
protected function transferToResponse(
|
protected function transferToResponse(
|
||||||
$response,
|
$response,
|
||||||
ServerRequestInterface $request
|
ServerRequestInterface $request,
|
||||||
): ResponsePlusInterface {
|
): ResponsePlusInterface {
|
||||||
$style = $this->apiStyleService->get();
|
$style = $this->apiStyleService->get();
|
||||||
|
|
||||||
if ($style === ApiStyleService::RESTFUL) {
|
if (!($response instanceof ResponseInterface) || $response instanceof JsonResource) {
|
||||||
$response = $this->transferToRestfulResponse($response, $request);
|
$response = $style === ApiStyleService::RESTFUL
|
||||||
} else {
|
? $this->transferToRestfulResponse($response, $request)
|
||||||
$response = $this->transferToClassicResponse($response, $request);
|
: $this->transferToClassicResponse($response, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ResponsePlusProxy($response);
|
return new ResponsePlusProxy($response);
|
||||||
@@ -68,7 +69,7 @@ class CommonCoreMiddleware extends CoreMiddleware
|
|||||||
*/
|
*/
|
||||||
protected function transferToRestfulResponse(
|
protected function transferToRestfulResponse(
|
||||||
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
|
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
|
||||||
ServerRequestInterface $request
|
ServerRequestInterface $request,
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
// 分页数据
|
// 分页数据
|
||||||
if ($response instanceof LengthAwarePaginatorInterface) {
|
if ($response instanceof LengthAwarePaginatorInterface) {
|
||||||
@@ -103,7 +104,7 @@ class CommonCoreMiddleware extends CoreMiddleware
|
|||||||
*/
|
*/
|
||||||
protected function transferToClassicResponse(
|
protected function transferToClassicResponse(
|
||||||
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
|
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
|
||||||
ServerRequestInterface $request
|
ServerRequestInterface $request,
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
$code_name = config('common.response.code_name');
|
$code_name = config('common.response.code_name');
|
||||||
$message_name = config('common.response.message_name');
|
$message_name = config('common.response.message_name');
|
||||||
@@ -162,6 +163,9 @@ class CommonCoreMiddleware extends CoreMiddleware
|
|||||||
new SwooleStream(Json::encode($response))
|
new SwooleStream(Json::encode($response))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
if ($response instanceof ResponseInterface) {
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
// 其他默认按字符串处理
|
// 其他默认按字符串处理
|
||||||
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'text/plain')->withBody(
|
return $this->response()->withAddedHeader(Header::CONTENT_TYPE, 'text/plain')->withBody(
|
||||||
new SwooleStream((string)$response)
|
new SwooleStream((string)$response)
|
||||||
|
|||||||
@@ -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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送邮件
|
* 发送邮件
|
||||||
*
|
*
|
||||||
@@ -68,9 +80,11 @@ class EmailService
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string|array<string> $target
|
* @param string|array<string> $target
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param array<string> $cc
|
* @param array<string> $cc
|
||||||
|
* @param array $bcc
|
||||||
|
* @param int $priority
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
@@ -80,12 +94,14 @@ class EmailService
|
|||||||
string $subject,
|
string $subject,
|
||||||
string $text,
|
string $text,
|
||||||
array $cc = [],
|
array $cc = [],
|
||||||
|
array $bcc = [],
|
||||||
int $priority = Email::PRIORITY_NORMAL
|
int $priority = Email::PRIORITY_NORMAL
|
||||||
): bool {
|
): bool {
|
||||||
$email = (new Email())
|
$email = (new Email())
|
||||||
->from(Address::create($this->from))
|
->from(Address::create($this->from))
|
||||||
->to(...(is_array($target) ? $target : [$target]))
|
->to(...(is_array($target) ? $target : [$target]))
|
||||||
->cc(...$cc)
|
->cc(...$cc)
|
||||||
|
->bcc(...$bcc)
|
||||||
->priority($priority)
|
->priority($priority)
|
||||||
->subject($subject)
|
->subject($subject)
|
||||||
->text($text);
|
->text($text);
|
||||||
@@ -99,10 +115,12 @@ class EmailService
|
|||||||
* 以 HTML 格式发送邮件
|
* 以 HTML 格式发送邮件
|
||||||
*
|
*
|
||||||
* @param string|array<string> $target
|
* @param string|array<string> $target
|
||||||
* @param string $subject
|
* @param string $subject
|
||||||
* @param string $html
|
* @param string $html
|
||||||
* @param array<string> $cc
|
* @param array<string> $cc
|
||||||
* @param int $priority
|
* @param array $bcc
|
||||||
|
* @param int $priority
|
||||||
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
* @throws TransportExceptionInterface
|
* @throws TransportExceptionInterface
|
||||||
*/
|
*/
|
||||||
@@ -111,12 +129,14 @@ class EmailService
|
|||||||
string $subject,
|
string $subject,
|
||||||
string $html,
|
string $html,
|
||||||
array $cc = [],
|
array $cc = [],
|
||||||
|
array $bcc = [],
|
||||||
int $priority = Email::PRIORITY_NORMAL
|
int $priority = Email::PRIORITY_NORMAL
|
||||||
): bool {
|
): bool {
|
||||||
$email = (new Email())
|
$email = (new Email())
|
||||||
->from(Address::create($this->from))
|
->from(Address::create($this->from))
|
||||||
->to(...(is_array($target) ? $target : [$target]))
|
->to(...(is_array($target) ? $target : [$target]))
|
||||||
->cc(...$cc)
|
->cc(...$cc)
|
||||||
|
->bcc(...$bcc)
|
||||||
->priority($priority)
|
->priority($priority)
|
||||||
->subject($subject)
|
->subject($subject)
|
||||||
->html($html);
|
->html($html);
|
||||||
|
|||||||
Reference in New Issue
Block a user