Compare commits

..

8 Commits

Author SHA1 Message Date
李东云
6eacde9970 chore(release): 1.0.0-alpha.18 2023-12-14 08:29:17 +00:00
李东云
7d6dc7fe9f feat(bin): 增加了迁移到最新版本的脚本
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 16:28:59 +08:00
李东云
97131d224c refactor: 迁移到 hyperf3.1 的写法
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 16:03:23 +08:00
李东云
08d00a785f build(composer): 清理 composer 配置
移除了多余的 composer 包仓库

Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 15:48:30 +08:00
李东云
16f69c193c chore(release): 1.0.0-alpha.17 2023-12-14 07:38:35 +00:00
李东云
b89b218eaa build(composer): 更新依赖,增加 php8.2/8.3的 polyfill
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 15:38:14 +08:00
李东云
14d28deee2 fix(CoreMiddleware): 修复参数类型过少的问题
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 15:24:22 +08:00
李东云
cbc59ccf74 build(ide): 增加了docker 映射
Signed-off-by: 李东云 <dongyu.li@luxcreo.ai>
2023-12-14 15:23:46 +08:00
16 changed files with 3185 additions and 2723 deletions

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

@@ -175,6 +175,8 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/swow/psr7-plus" />
<excludeFolder url="file://$MODULE_DIR$/vendor/ta-tikoma/phpunit-architecture-test" />
<excludeFolder url="file://$MODULE_DIR$/vendor/webmozart/assert" />
<excludeFolder url="file://$MODULE_DIR$/vendor/carbonphp/carbon-doctrine-types" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-php82" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />

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

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

2
.idea/php.xml generated
View File

@@ -190,6 +190,8 @@
<path value="$PROJECT_DIR$/vendor/friendsofhyperf/rector" />
<path value="$PROJECT_DIR$/vendor/spatie/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/symfony/polyfill-php82" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="8.1" />

3
.idea/phpspec.xml generated
View File

@@ -44,6 +44,9 @@
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
<PhpSpecSuiteConfiguration>
<option name="myPath" value="$PROJECT_DIR$" />
</PhpSpecSuiteConfiguration>
</suites>
</component>
</project>

View File

@@ -1,4 +1,34 @@
# 版本更新日志
## [1.0.0-alpha.18](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.17...v1.0.0-alpha.18) (2023-12-14)
### 📦‍ Build System | 打包构建
* **composer:** 清理 composer 配置 ([08d00a7](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/08d00a785f3be1846333777edae94e0ae237c8a2))
### ♻️ Code Refactoring | 代码重构
* 迁移到 hyperf3.1 的写法 ([97131d2](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/97131d224cfb601ba075ff1af1c4ca333680b459))
### ✨ Features | 新功能
* **bin:** 增加了迁移到最新版本的脚本 ([7d6dc7f](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/7d6dc7fe9f9bc637755768852518420e98176d56))
## [1.0.0-alpha.17](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.16...v1.0.0-alpha.17) (2023-12-14)
### 🐛 Bug Fixes | Bug 修复
* **CoreMiddleware:** 修复参数类型过少的问题 ([14d28de](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/14d28deee2ec97991b7effe99a37cc03b19a291c))
### 📦‍ Build System | 打包构建
* **composer:** 更新依赖,增加 php8.2/8.3的 polyfill ([b89b218](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/b89b218eaa211d0262e2f1dff4d61f2a79eacda6))
* **ide:** 增加了docker 映射 ([cbc59cc](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/commit/cbc59ccf74dafcedca1e4369e647ba1c003efe39))
## [1.0.0-alpha.16](http://124.126.16.154:8888/singularity/HyperfDevelopmentKitCore/compare/v1.0.0-alpha.15...v1.0.0-alpha.16) (2023-12-04)

View File

@@ -1 +1 @@
1.0.0-alpha.16
1.0.0-alpha.18

19
bin/hdk-migrate-core.sh Normal file
View File

@@ -0,0 +1,19 @@
#!/bin/sh
# shellcheck disable=SC2039
LIB_HOME_DIR="$(pwd)/vendor/singularity/hdk-core"
LATEST_VERSION=$(cat "${LIB_HOME_DIR}/VERSION_TRACKER.txt")
echo -e '\033[44;34;5m=============================\033[0m'
echo ''
$(pwd)/vendor/bin/rector \
process \
--autoload-file=vendor/autoload.php \
--config="${LIB_HOME_DIR}/hyperf31_rector.php"
echo ''
echo -e '\033[44;34;5m=============================\033[0m'
echo -e '\033[;31;1m🎉Congratulations!\033[0m'
echo "Now you have been migrated to HDK-Core v${LATEST_VERSION}!"
echo ''

View File

@@ -16,10 +16,13 @@
],
"require": {
"php": ">=8.1",
"ext-dom": "*",
"ext-libxml": "*",
"ext-redis": "^5.3|^6.0",
"ext-swoole": "*",
"composer/composer": ">=2.0",
"ergebnis/http-method": "^2.2",
"ergebnis/http-method": "^2.5",
"friendsofhyperf/rector": "^0.1.5",
"hyperf/config": "3.1.*",
"hyperf/constants": "3.1.*",
"hyperf/context": "3.1.*",
@@ -30,22 +33,21 @@
"hyperf/resource": "3.1.*",
"hyperf/translation": "3.1.*",
"jetbrains/phpstorm-attributes": "^1.0",
"lmc/http-constants": "^1.2",
"myclabs/php-enum": "^1.8",
"roave/dont": "^1.5",
"symfony/http-foundation": "^6.0",
"symfony/polyfill-php81": "^1.26",
"teapot/status-code": "^1.1",
"ext-libxml": "*",
"ext-dom": "*"
"lmc/http-constants": "^1.2.0",
"myclabs/php-enum": "^1.8.4",
"roave/dont": "^1.6.0",
"symfony/http-foundation": "^6.4",
"symfony/polyfill-php81": "^1.28",
"symfony/polyfill-php82": "^1.28",
"symfony/polyfill-php83": "^1.28",
"teapot/status-code": "^1.1.2"
},
"require-dev": {
"alibabacloud/dysmsapi-20170525": "^2.0",
"firebase/php-jwt": "^6.1",
"firebase/php-jwt": "^6.9",
"friendsofhyperf/pest-plugin-hyperf": "3.1.*",
"friendsofhyperf/rector": "^0.1.5",
"friendsofphp/php-cs-fixer": "^3.13",
"guzzlehttp/guzzle": "^7.5",
"friendsofphp/php-cs-fixer": "^3.41.1",
"guzzlehttp/guzzle": "^7.8",
"hyperf/crontab": "3.1.*",
"hyperf/database": "3.1.*",
"hyperf/db": "3.1.*",
@@ -54,12 +56,13 @@
"hyperf/testing": "^3.1",
"hyperf/validation": "3.1.*",
"pestphp/pest": "^2.23",
"phpstan/phpstan": "^1.9",
"phpstan/phpstan": "^1.10.49",
"rector/rector": "^0.15.25",
"roave/security-advisories": "dev-latest",
"spatie/pest-plugin-test-time": "^2.0",
"swoole/ide-helper": "*",
"symfony/mailer": "^6.0",
"symfony/serializer": "^6.0"
"symfony/mailer": "^6.4.0",
"symfony/serializer": "^6.4.1"
},
"suggest": {
"firebase/php-jwt": "JWT 鉴权必需",
@@ -74,7 +77,6 @@
"config": {
"optimize-autoloader": true,
"sort-packages": true,
"secure-http": false,
"allow-plugins": {
"pestphp/pest-plugin": true
}
@@ -89,7 +91,6 @@
"Singularity\\HDK\\Test\\Core\\": "tests/"
}
},
"minimum-stability": "alpha",
"archive": {
"exclude": [
".idea",
@@ -103,6 +104,7 @@
"phpunit.xml"
]
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-root-package-install": [],
@@ -120,14 +122,10 @@
]
},
"repositories": {
"lux-map": {
"type": "composer",
"url": "https://satis.luxcreo.cn/"
},
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
},
"version": "1.0.0-alpha.16"
"version": "1.0.0-alpha.18"
}

5488
composer.lock generated

File diff suppressed because it is too large Load Diff

197
hyperf31_rector.php Normal file
View File

@@ -0,0 +1,197 @@
<?php
/**
* hyperf31_rector.php@LuxLink
*
* @author 李东云 <Dongyun.Li@LuxCreo.Ai>
* Powered by PhpStorm
* Created on 2023/12/14
*/
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Renaming\ValueObject\MethodCallRename;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->importNames(true, false);
$rectorConfig->paths([
__DIR__ . '/src',
__DIR__ . '/publish',
__DIR__ . '/tests',
]);
$rectorConfig
->ruleWithConfiguration(RenameClassRector::class, [
// AsyncQueue
'Hyperf\AsyncQueue\Message' => 'Hyperf\AsyncQueue\JobMessage',
// DbConnection
'Hyperf\DbConnection\Listener\CreatingListener' => 'Hyperf\DbConnection\Listener\InitUidOnCreatingListener',
// HttpMessage
'Hyperf\HttpMessage\Server\ConnectionInterface' => 'Hyperf\Engine\Contract\Http\Writable',
'Hyperf\HttpMessage\Server\Connection\SwooleConnection' => 'Hyperf\Engine\Http\WritableConnection',
// Redis
'Hyperf\Redis\ScanCaller' => 'Hyperf\Redis\Traits\ScanCaller',
// Channel
'Hyperf\Utils\Channel\Caller' => 'Hyperf\Coroutine\Channel\Caller',
'Hyperf\Utils\Channel\ChannelManager' => 'Hyperf\Coroutine\Channel\Manager',
// Codec
'Hyperf\Utils\Codec\Base62' => 'Hyperf\Codec\Base62',
'Hyperf\Utils\Codec\Json' => 'Hyperf\Codec\Json',
'Hyperf\Utils\Codec\Xml' => 'Hyperf\Codec\Xml',
// CodeGen
'Hyperf\Utils\CodeGen\Package' => 'Hyperf\CodeParser\Package',
'Hyperf\Utils\CodeGen\PhpDocReader' => 'Hyperf\CodeParser\PhpDocReader',
'Hyperf\Utils\CodeGen\PhpDocReaderManager' => 'Hyperf\CodeParser\PhpDocReaderManager',
'Hyperf\Utils\CodeGen\PhpParser' => 'Hyperf\CodeParser\PhpParser',
'Hyperf\Utils\CodeGen\Project' => 'Hyperf\CodeParser\Project',
// Command
'Hyperf\Command\ConfirmableTrait' => 'Hyperf\Command\Concerns\Confirmable',
'Hyperf\Command\DisableEventDispatcher' => 'Hyperf\Command\Concerns\DisableEventDispatcher',
'Hyperf\Command\NullDisableEventDispatcher' => 'Hyperf\Command\Concerns\NullDisableEventDispatcher',
// Contracts
'Hyperf\Utils\Contracts\Arrayable' => 'Hyperf\Contract\Arrayable',
'Hyperf\Utils\Contracts\Jsonable' => 'Hyperf\Contract\Jsonable',
'Hyperf\Utils\Contracts\MessageBag' => 'Hyperf\Contract\MessageBag',
'Hyperf\Utils\Contracts\MessageProvider' => 'Hyperf\Contract\MessageProvider',
'Hyperf\Utils\Contracts\Xmlable' => 'Hyperf\Contract\Xmlable',
// Coordinator
'Hyperf\Utils\Coordinator\Constants' => 'Hyperf\Coordinator\Constants',
'Hyperf\Utils\Coordinator\Coordinator' => 'Hyperf\Coordinator\Coordinator',
'Hyperf\Utils\Coordinator\CoordinatorManager' => 'Hyperf\Coordinator\CoordinatorManager',
// Coroutine
'Hyperf\Utils\Coroutine\Concurrent' => 'Hyperf\Coroutine\Concurrent',
'Hyperf\Utils\Coroutine\Locker' => 'Hyperf\Coroutine\Locker',
// Exception
'Hyperf\Utils\Exception\ChannelClosedException' => 'Hyperf\Coroutine\Exception\ChannelClosedException',
'Hyperf\Utils\Exception\ExceptionThrower' => 'Hyperf\Support\Exception\ExceptionThrower',
'Hyperf\Utils\Exception\InvalidArgumentException' => 'Hyperf\Support\Exception\InvalidArgumentException',
'Hyperf\Utils\Exception\IPReadFailedException' => 'Hyperf\Support\Exception\IPReadFailedException',
'Hyperf\Utils\Exception\ParallelExecutionException' => 'Hyperf\Coroutine\Exception\ParallelExecutionException',
'Hyperf\Utils\Exception\TimeoutException' => 'Hyperf\Coroutine\Exception\TimeoutException',
'Hyperf\Utils\Exception\WaitTimeoutException' => 'Hyperf\Coroutine\Exception\WaitTimeoutException',
// Filesystem
'Hyperf\Utils\Filesystem\FileNotFoundException' => 'Hyperf\Support\Filesystem\FileNotFoundException',
'Hyperf\Utils\Filesystem\Filesystem' => 'Hyperf\Support\Filesystem\Filesystem',
// Packer
'Hyperf\Utils\Packer\JsonPacker' => 'Hyperf\Codec\Packer\JsonPacker',
'Hyperf\Utils\Packer\PhpSerializerPacker' => 'Hyperf\Codec\Packer\PhpSerializerPacker',
// Reflection
'Hyperf\Utils\Reflection\ClassInvoker' => 'Hyperf\Support\Reflection\ClassInvoker',
// Serializer
'Hyperf\Utils\Serializer\ExceptionNormalizer' => 'Hyperf\Serializer\ExceptionNormalizer',
'Hyperf\Utils\Serializer\JsonDeNormalizer' => 'Hyperf\Serializer\JsonDeNormalizer',
'Hyperf\Utils\Serializer\ScalarNormalizer' => 'Hyperf\Serializer\ScalarNormalizer',
'Hyperf\Utils\Serializer\Serializer' => 'Hyperf\Serializer\Serializer',
'Hyperf\Utils\Serializer\SerializerFactory' => 'Hyperf\Serializer\SerializerFactory',
'Hyperf\Utils\Serializer\SimpleNormalizer' => 'Hyperf\Serializer\SimpleNormalizer',
'Hyperf\Utils\Serializer\SymfonyNormalizer' => 'Hyperf\Serializer\SymfonyNormalizer',
// Traits
'Hyperf\Utils\Traits\Conditionable' => 'Hyperf\Conditionable\Conditionable',
'Hyperf\Utils\Traits\Container' => 'Hyperf\Support\Traits\Container',
'Hyperf\Utils\Traits\CoroutineProxy' => 'Hyperf\Context\Traits\CoroutineProxy',
'Hyperf\Utils\Traits\ForwardsCalls' => 'Hyperf\Support\Traits\ForwardsCalls',
'Hyperf\Utils\Traits\StaticInstance' => 'Hyperf\Support\Traits\StaticInstance',
'Hyperf\Utils\Traits\Tappable' => 'Hyperf\Tappable\Tappable',
// Utils
'Hyperf\Utils\ApplicationContext' => 'Hyperf\Context\ApplicationContext',
'Hyperf\Utils\Arr' => 'Hyperf\Collection\Arr',
'Hyperf\Utils\Backoff' => 'Hyperf\Support\Backoff',
'Hyperf\Utils\ChannelPool' => 'Hyperf\Coroutine\Channel\Pool',
'Hyperf\Utils\ClearStatCache' => 'Hyperf\Support\ClearStatCache',
'Hyperf\Utils\Collection' => 'Hyperf\Collection\Collection',
'Hyperf\Utils\Composer' => 'Hyperf\Support\Composer',
'Hyperf\Utils\Coroutine' => 'Hyperf\Coroutine\Coroutine',
'Hyperf\Utils\Fluent' => 'Hyperf\Support\Fluent',
'Hyperf\Utils\HigherOrderCollectionProxy' => 'Hyperf\Collection\HigherOrderCollectionProxy',
'Hyperf\Utils\HigherOrderTapProxy' => 'Hyperf\Tappable\HigherOrderTapProxy',
'Hyperf\Utils\InteractsWithTime' => 'Hyperf\Support\Traits\InteractsWithTime',
'Hyperf\Utils\IPReader' => 'Hyperf\Support\IPReader',
'Hyperf\Utils\MessageBag' => 'Hyperf\Support\MessageBag',
'Hyperf\Utils\MimeTypeExtensionGuesser' => 'Hyperf\Support\MimeTypeExtensionGuesser',
'Hyperf\Utils\Network' => 'Hyperf\Support\Network',
'Hyperf\Utils\Optional' => 'Hyperf\Support\Optional',
'Hyperf\Utils\Parallel' => 'Hyperf\Coroutine\Parallel',
'Hyperf\Utils\Pipeline' => 'Hyperf\Pipeline\Pipeline',
'Hyperf\Utils\Pluralizer' => 'Hyperf\Support\Pluralizer',
'Hyperf\Utils\ResourceGenerator' => 'Hyperf\Support\ResourceGenerator',
'Hyperf\Utils\SafeCaller' => 'Hyperf\Support\SafeCaller',
'Hyperf\Utils\Str' => 'Hyperf\Stringable\Str',
'Hyperf\Utils\Stringable' => 'Hyperf\Stringable\Stringable',
'Hyperf\Utils\System' => 'Hyperf\Support\System',
'Hyperf\Utils\Waiter' => 'Hyperf\Coroutine\Waiter',
'Hyperf\Utils\WaitGroup' => 'Hyperf\Coroutine\WaitGroup',
]);
$rectorConfig
->ruleWithConfiguration(RenameFunctionRector::class, [
// hyperf/config
'config' => 'Hyperf\Config\config',
// hyperf/collection
'collect' => 'Hyperf\Collection\collect',
'data_fill' => 'Hyperf\Collection\data_fill',
'data_get' => 'Hyperf\Collection\data_get',
'data_set' => 'Hyperf\Collection\data_set',
'head' => 'Hyperf\Collection\head',
'last' => 'Hyperf\Collection\last',
// hyperf/continue
'co' => 'Hyperf\Coroutine\co',
'defer' => 'Hyperf\Coroutine\defer',
'go' => 'Hyperf\Coroutine\go',
'parallel' => 'Hyperf\Coroutine\parallel',
'run' => 'Hyperf\Coroutine\run',
'wait' => 'Hyperf\Coroutine\wait',
// hyperf/tappable
'tap' => 'Hyperf\Tappable\tap',
// hyperf/translation
'__' => 'Hyperf\Translation\__',
'trans' => 'Hyperf\Translation\trans',
'trans_choice' => 'Hyperf\Translation\trans_choice',
// hyperf/utils
'value' => 'Hyperf\Support\value',
'env' => 'Hyperf\Support\env',
'retry' => 'Hyperf\Support\retry',
'with' => 'Hyperf\Support\with',
'call' => 'Hyperf\Support\call',
'class_basename' => 'Hyperf\Support\class_basename',
'trait_uses_recursive' => 'Hyperf\Support\trait_uses_recursive',
'class_uses_recursive' => 'Hyperf\Support\class_uses_recursive',
'setter' => 'Hyperf\Support\setter',
'getter' => 'Hyperf\Support\getter',
'make' => 'Hyperf\Support\make',
'swoole_hook_flags' => 'Hyperf\Support\swoole_hook_flags',
'optional' => 'Hyperf\Support\optional',
]);
$rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [
new MethodCallRename('Hyperf\Dag\Dag', 'checkCircularDependences', 'checkCircularDependencies'),
// new MethodCallRename('Hyperf\DbConnection\Connection', 'isTransaction', 'transactionLevel'),
new MethodCallRename('Hyperf\Testing\Client', 'init', 'initRequest'),
new MethodCallRename('Hyperf\Cache\CacheListenerCollector', 'getListner', 'getListener'),
]);
};

View File

@@ -24,7 +24,6 @@ class ConfigProvider
/** @phpstan-ignore-next-line */
public function __invoke(): array
{
/** @noinspection PhpUndefinedConstantInspection */
return [
// 合并到 config/autoload/dependencies.php 文件
'dependencies' => [

View File

@@ -4,7 +4,8 @@ declare(strict_types=1);
namespace Singularity\HDK\Core\Http;
use Ergebnis\Http\Method;
use Ergebnis\Http\Method\Rfc\Rfc5789;
use Ergebnis\Http\Method\Rfc\Rfc7231;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
@@ -49,7 +50,9 @@ final class RequestService extends AbstractSingleton
/**
* 定制 options
*
* @param Options $options
*
* @return $this
*/
public function setOptions(array $options): self
@@ -59,10 +62,11 @@ final class RequestService extends AbstractSingleton
}
/**
* @param string $url
* @param string $url
* @param array<string, string|int> $params
* @param array<string, mixed> $data
* @param Options $options
* @param array<string, mixed> $data
* @param Options $options
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -73,7 +77,7 @@ final class RequestService extends AbstractSingleton
array $options = []
): ResponseInterface {
$request = new Request(
method: Method\Rfc\Rfc7231::GET,
method: Rfc7231::GET,
uri: $url
);
return $this->getClient($options)->send($request, ['query' => $params, 'json' => $data,]);
@@ -81,7 +85,9 @@ final class RequestService extends AbstractSingleton
/**
* 工厂模式初始化请求
*
* @param Options $options
*
* @return Client
*/
private function getClient(array $options): Client
@@ -91,10 +97,11 @@ final class RequestService extends AbstractSingleton
}
/**
* @param string $url
* @param string $url
* @param array<string, string|int> $params
* @param array<string, mixed> $data
* @param Options $options
* @param array<string, mixed> $data
* @param Options $options
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -106,7 +113,7 @@ final class RequestService extends AbstractSingleton
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::POST,
method: Rfc7231::POST,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data),
@@ -115,10 +122,11 @@ final class RequestService extends AbstractSingleton
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @param Options $options
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -130,7 +138,7 @@ final class RequestService extends AbstractSingleton
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::PUT,
method: Rfc7231::PUT,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)
@@ -142,10 +150,11 @@ final class RequestService extends AbstractSingleton
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @param Options $options
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -157,7 +166,7 @@ final class RequestService extends AbstractSingleton
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc5789::PATCH,
method: Rfc5789::PATCH,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)
@@ -169,10 +178,11 @@ final class RequestService extends AbstractSingleton
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
* @param Options $options
* @param Options $options
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -184,7 +194,7 @@ final class RequestService extends AbstractSingleton
): ResponseInterface {
$data = Json::encode($data);
$request = new Request(
method: Method\Rfc\Rfc7231::DELETE,
method: Rfc7231::DELETE,
uri: $url,
headers: ['Content-Type' => 'application/json'],
body: Utils::streamFor($data)

View File

@@ -61,13 +61,13 @@ class CommonCoreMiddleware extends CoreMiddleware
}
/**
* @param array|string|Arrayable|Jsonable|null $response
* @param ServerRequestInterface $request
* @param null|array|Arrayable|Jsonable|ResponseInterface|string $response
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
protected function transferToRestfulResponse(
Arrayable|Jsonable|array|string|null $response,
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
ServerRequestInterface $request
): ResponseInterface {
// 分页数据
@@ -96,13 +96,13 @@ class CommonCoreMiddleware extends CoreMiddleware
}
/**
* @param array|string|Arrayable|Jsonable|null $response
* @param ServerRequestInterface $request
* @param null|array|Arrayable|Jsonable|ResponseInterface|string $response
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
protected function transferToClassicResponse(
Arrayable|Jsonable|array|string|null $response,
null|array|Arrayable|Jsonable|ResponseInterface|string $response,
ServerRequestInterface $request
): ResponseInterface {
$code_name = config('common.response.code_name');

View File

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace Singularity\HDK\Core\Service;
use Ergebnis\Http\Method;
use Ergebnis\Http\Method\Rfc\Rfc7231;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use GuzzleHttp\Psr7\Request;
@@ -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
@@ -31,15 +32,16 @@ class HttpRequestService
private array $options = [];
/**
* @param string $url
* @param string $url
* @param array<string, string|int> $params
* @param array<string, mixed> $data
* @param array<string, mixed> $data
*
* @return ResponseInterface
* @throws GuzzleException
*/
public function requestGet(string $url, array $params = [], array $data = []): ResponseInterface
{
$request = new Request(Method\Rfc\Rfc7231::GET, $url);
$request = new Request(Rfc7231::GET, $url);
return $this->getClient()->send($request, [
'query' => $params,
'json' => $data,
@@ -52,9 +54,10 @@ class HttpRequestService
}
/**
* @param string $url
* @param array<string, mixed> $data
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -74,9 +77,10 @@ class HttpRequestService
/**
* @param string $url
* @param array<string, mixed> $data
* @param string $url
* @param array<string, mixed> $data
* @param array<string, string|int> $params
*
* @return ResponseInterface
* @throws GuzzleException
*/
@@ -91,7 +95,9 @@ class HttpRequestService
/**
* 定制 options
*
* @param array<string, mixed> $options
*
* @return $this
*/
public function setOptions(array $options): HttpRequestService

View File

@@ -14,6 +14,8 @@ use Singularity\HDK\Core\Http\RequestService;
use Singularity\HDK\Core\Http\RequestServiceFactory;
use Teapot\StatusCode\RFC\RFC7231;
use function Hyperf\Support\make;
class RequestServiceTest
{
private RequestService $service;
@@ -31,7 +33,7 @@ class RequestServiceTest
test('Http 请求服务可以正常使用', function () {
/** @var RequestServiceTest $class */
$class = \Hyperf\Support\make(RequestServiceTest::class);
$class = make(RequestServiceTest::class);
$response = $class->getInstance()->setOptions([
'allow_redirects' => false,
])->requestGet('https://www.baidu.com');

View File

@@ -3,9 +3,11 @@
declare(strict_types=1);
use Hyperf\Context\ApplicationContext;
use Hyperf\Di\ClassLoader;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSource;
use Psr\Container\ContainerInterface;
use Swoole\Runtime;
ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');
@@ -17,10 +19,10 @@ 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);
Runtime::enableCoroutine(true);
require BASE_PATH . '/vendor/autoload.php';
Hyperf\Di\ClassLoader::init();
ClassLoader::init();
$container = new Container(new DefinitionSource([]));
if (!$container instanceof ContainerInterface) {