Compare commits

...

20 Commits

Author SHA1 Message Date
李东云
02655228ae chore(release): 1.0.0-alpha.8 2023-10-08 07:44:10 +00:00
李东云
9f7d4effb7 feat(email): 增加了对邮件优先级的兼容
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-10-08 15:43:47 +08:00
李东云
5980ea773b chore(release): 1.0.0-alpha.7 2023-09-28 08:06:29 +00:00
李东云
110679448f fix(rest): 修复不存在的具名参数
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-28 15:50:47 +08:00
李东云
64f936ab36 chore(release): 1.0.0-alpha.6 2023-09-28 06:59:13 +00:00
李东云
2afc3ad45b fix(rest): 修复没有返回值的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-28 14:59:01 +08:00
李东云
cff919a21e fix(i18n): 修复了无法正确无视大小写导致无法识别的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 16:23:52 +08:00
李东云
2d6d12e1c3 chore(release): 1.0.0-alpha.5 2023-09-26 08:23:29 +00:00
李东云
73420153d3 fix(i18n): 修复了无法正确无视大小写导致无法识别的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 16:23:16 +08:00
李东云
fcb0cd8852 chore(release): 1.0.0-alpha.4 2023-09-26 02:55:03 +00:00
李东云
7a209e876f test(http): 完成并通过了 http 请求的测试
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:54:44 +08:00
李东云
4032d67f1e feat(i18n): 增加枚举值,更新中间件调用方式
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:44:00 +08:00
李东云
dbbe278aa6 build(composer): 引入 pest 并升级到 php8.1
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-09-26 10:43:20 +08:00
李东云
d84855f038 chore(release): 1.0.0-alpha.3 2023-08-30 03:42:37 +00:00
李东云
2d95fbae9e refactor(http): 整理了 Http 请求服务
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-08-30 11:41:59 +08:00
李东云
3042ce0054 chore(release): 1.0.0-alpha.2 2023-07-21 08:22:48 +00:00
李东云
b30c84488b fix(controller): 修复方法访问级别不足以继承的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 16:22:36 +08:00
李东云
c262d38ad0 chore(release): 1.0.0-alpha.1 2023-07-21 03:39:01 +00:00
李东云
a8ec7d8255 build(composer): 更新依赖
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 11:38:31 +08:00
李东云
f1948ab0fe build(release): 增加 alpha 标识,准备正式版
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-07-21 11:04:39 +08:00
26 changed files with 10390 additions and 9706 deletions

3
.gitignore vendored
View File

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

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

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

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

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

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

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

7
.idea/php.xml generated
View File

@@ -46,7 +46,6 @@
<path value="$PROJECT_DIR$/vendor/composer" />
<path value="$PROJECT_DIR$/vendor/fig/http-message-util" />
<path value="$PROJECT_DIR$/vendor/lmc/http-constants" />
<path value="$PROJECT_DIR$/vendor/psr/cache" />
<path value="$PROJECT_DIR$/vendor/psr/http-server-handler" />
<path value="$PROJECT_DIR$/vendor/psr/event-dispatcher" />
<path value="$PROJECT_DIR$/vendor/psr/http-server-middleware" />
@@ -130,7 +129,6 @@
<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" />
@@ -175,9 +173,12 @@
<path value="$PROJECT_DIR$/vendor/hyperf/stringable" />
<path value="$PROJECT_DIR$/vendor/hyperf/support" />
<path value="$PROJECT_DIR$/vendor/ralouphie/getallheaders" />
<path value="$PROJECT_DIR$/vendor/cooper/hyperf-pest" />
<path value="$PROJECT_DIR$/vendor/psr/clock" />
<path value="$PROJECT_DIR$/vendor/symfony/polyfill-php83" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.0" />
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />
<component name="PhpStan">
<PhpStan_settings>
<PhpStanConfiguration tool_path="$PROJECT_DIR$/vendor/bin/phpstan" />

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

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

View File

@@ -1,4 +1,72 @@
# 版本更新日志
## [1.0.0-alpha.8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.7...v1.0.0-alpha.8) (2023-10-08)
### ✨ Features | 新功能
* **email:** 增加了对邮件优先级的兼容 ([9f7d4ef](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/9f7d4effb7e39500d0f65d35788551cc4e7a91f1))
## [1.0.0-alpha.7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.6...v1.0.0-alpha.7) (2023-09-28)
### 🐛 Bug Fixes | Bug 修复
* **rest:** 修复不存在的具名参数 ([1106794](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/110679448f310e1d4e25f370b74f2901ca9425d0))
## [1.0.0-alpha.6](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2023-09-28)
### 🐛 Bug Fixes | Bug 修复
* **i18n:** 修复了无法正确无视大小写导致无法识别的问题 ([cff919a](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/cff919a21e6d50e396a0d5ceaeefbe3b7c0e3095))
* **rest:** 修复没有返回值的问题 ([2afc3ad](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2afc3ad45b97e3df97827efdd9d16d6dedb3238a))
## [1.0.0-alpha.5](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2023-09-26)
### 🐛 Bug Fixes | Bug 修复
* **i18n:** 修复了无法正确无视大小写导致无法识别的问题 ([7342015](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/73420153d3791bff38ddd57b5a17120a4ed3cd08))
## [1.0.0-alpha.4](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.3...v1.0.0-alpha.4) (2023-09-26)
### 📦‍ Build System | 打包构建
* **composer:** 引入 pest 并升级到 php8.1 ([dbbe278](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/dbbe278aa6c96634ed5792b5782825770c5cabe8))
### ✨ Features | 新功能
* **i18n:** 增加枚举值,更新中间件调用方式 ([4032d67](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/4032d67f1e56b8ce29fbfa5bd77ead2636a6ffd3))
### ✅ Tests | 测试
* **http:** 完成并通过了 http 请求的测试 ([7a209e8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7a209e876f8b4301b7bc78f05b68798eb65e77f7))
## [1.0.0-alpha.3](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.2...v1.0.0-alpha.3) (2023-08-30)
### ♻️ Code Refactoring | 代码重构
* **http:** 整理了 Http 请求服务 ([2d95fba](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/2d95fbae9e926788402c24266ab0d232732a7754))
## [1.0.0-alpha.2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.1...v1.0.0-alpha.2) (2023-07-21)
### 🐛 Bug Fixes | Bug 修复
* **controller:** 修复方法访问级别不足以继承的问题 ([b30c844](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b30c84488b7f85447bd802df77c9decbf315ed85))
## [1.0.0-alpha.1](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.0...v1.0.0-alpha.1) (2023-07-21)
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖 ([a8ec7d8](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/a8ec7d82556c2fb8fbe1e356eb6d1936401c810a))
* **release:** 增加 alpha 标识,准备正式版 ([f1948ab](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/f1948ab0fe4594140eede8e52f113963d98a8338))
## [1.0.0-alpha.0](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v0.2.23...v1.0.0-alpha.0) (2023-07-21)

View File

@@ -1 +1 @@
1.0.0-alpha.0
1.0.0-alpha.8

View File

@@ -15,7 +15,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"ext-redis": "^5.3",
"ext-swoole": "*",
"composer/composer": ">=2.0",
@@ -41,6 +41,7 @@
},
"require-dev": {
"alibabacloud/dysmsapi-20170525": "^2.0",
"cooper/hyperf-pest": "^1.1",
"firebase/php-jwt": "^6.1",
"friendsofphp/php-cs-fixer": "^3.13",
"guzzlehttp/guzzle": "^7.5",
@@ -91,7 +92,11 @@
"prefer-stable": true,
"scripts": {
"post-root-package-install": [],
"test": "vendor/bin/pest $1",
"test": [
"rm -rf runtime",
"Composer\\Config::disableProcessTimeout",
"co-pest --prepend tests/bootstrap.php -c phpunit.xml --colors=always $1"
],
"cs-fix": "vendor/bin/php-cs-fixer fix $1 --rules=@PSR12 --allow-risky=yes",
"analyse": "vendor/bin/phpstan analyse $1",
"ci": [
@@ -111,5 +116,5 @@
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.0.0-alpha.0"
"version": "1.0.0-alpha.8"
}

19498
composer.lock generated

File diff suppressed because it is too large Load Diff

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

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

View File

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

View File

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

View File

@@ -9,6 +9,8 @@
namespace Singularity\HDK\Core\Events;
use Symfony\Component\Mime\Email;
/**
* Singularity\HDK\Core\Events\EmailWillSent@HDK-Core
*
@@ -44,7 +46,13 @@ class EmailWillSent
/**
* @var 'text'|'html' $type
*/
public string $type = 'text'
public string $type = 'text',
/**
* @var int
* @see Email::priority()
*/
public int $priority = Email::PRIORITY_NORMAL
) {
}
}

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

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

View File

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

View File

@@ -0,0 +1,28 @@
<?php
/**
* Languages.php@Core
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/9/26
*/
namespace Singularity\HDK\Core\I18n\Enum;
use function Hyperf\Config\config;
enum Languages: string
{
case ZH_CN = 'zh_CN';
case EN = 'en';
public static function getLanguage(string $language): Languages
{
return match (mb_strtolower($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

@@ -62,18 +62,21 @@ class EmailWillSentListener implements ListenerInterface
target: $event->target,
subject: $event->subject,
html: $event->content,
cc: $event->cc
cc: $event->cc,
priority: $event->priority
)
: $emailService->sendText(
target: $event->target,
subject: $event->subject,
text: $event->content,
cc: $event->cc
cc: $event->cc,
priority: $event->priority
);
$stdoutLogger->info('邮件发送成功!');
$stdoutLogger->info("To: $event->target");
$stdoutLogger->info("Subject: $event->subject");
$stdoutLogger->info("Priority: $event->priority");
$stdoutLogger->debug('Content: ');
$stdoutLogger->debug($event->content);
} catch (TransportExceptionInterface $e) {

View File

@@ -12,10 +12,9 @@ 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;
use function Hyperf\Config\config;
/**
* Singularity\HDK\Utils\Middleware\InternationalizationMiddleware@HDK
*
@@ -41,12 +40,8 @@ class InternationalizationMiddleware implements MiddlewareInterface
$language = $req->getPreferredLanguage();
if (!empty($language)) {
$language = match (strtolower($language)) {
'en', 'en_us', 'en-us', 'en-uk', 'en_uk' => 'en',
'zh', 'zh_cn', 'zh-cn' => 'zh_CN',
default => config('translation.locale'),
};
$this->translator->setLocale($language);
$language = Languages::getLanguage($language);
$this->translator->setLocale($language->value);
}
$response = Context::get(ResponseInterface::class);
$response = $response->withAddedHeader(

View File

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

View File

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

View File

@@ -79,12 +79,14 @@ class EmailService
string|array $target,
string $subject,
string $text,
array $cc = []
array $cc = [],
int $priority = Email::PRIORITY_NORMAL
): bool {
$email = (new Email())
->from(Address::create($this->from))
->to(...(is_array($target) ? $target : [$target]))
->cc(...$cc)
->priority($priority)
->subject($subject)
->text($text);
@@ -100,7 +102,7 @@ class EmailService
* @param string $subject
* @param string $html
* @param array<string> $cc
*
* @param int $priority
* @return bool
* @throws TransportExceptionInterface
*/
@@ -108,12 +110,14 @@ class EmailService
string|array $target,
string $subject,
string $html,
array $cc = []
array $cc = [],
int $priority = Email::PRIORITY_NORMAL
): bool {
$email = (new Email())
->from(Address::create($this->from))
->to(...(is_array($target) ? $target : [$target]))
->cc(...$cc)
->priority($priority)
->subject($subject)
->html($html);

View File

@@ -16,6 +16,7 @@ use Psr\Http\Message\ResponseInterface;
/**
* 发起 Http 请求的类
* @deprecated since version 1.0-alpha.3, to be removed in 1.0
*/
class HttpRequestService
{

View File

@@ -20,21 +20,23 @@ use Singularity\HDK\Core\Service\ExtendService;
trait RestfulList
{
#[Inject]
private ExtendService $extend;
protected ExtendService $extend;
#[Inject]
private RequestInterface $request;
protected RequestInterface $request;
public function restSelect(Closure $callback, ?Closure $filter = null)
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);
$parsed_options = [];
$result = $this->parseParameters(
callback: function ($query, $options) use ($callback, &$parsed_options) {
$parsed_options = $options;
return $callback($query, $options);
}
);
return $this->responseFormatter($parsed_options, $result, $filter);
}
public function parseParameters(Closure $callback): mixed
protected function parseParameters(Closure $callback): mixed
{
$query = $this->request->getQueryParams();
$options = [
@@ -49,7 +51,7 @@ trait RestfulList
return $callback(query: $query, options: $options);
}
public function responseFormatter(
protected function responseFormatter(
array $options,
Builder $builder,
?Closure $filter = null

View File

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

View File

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