chore(deps): 升级 hyperf 框架依赖至 3.0 版本

- 将所有 hyperf 组件版本从 2.2.x 升级到 3.0.x
- 更新 singularity/hdk-core 依赖从0.1.6 到 1.0.0
- 移除 minimum-stability 配置项
- 添加 runtime 目录到 .gitignore
- 更新 RedisArray 类型提示和返回值
- 为监听器方法添加 void 返回类型
- 更新 ColorLineFormatter 的 LogRecord 类型提示
- 添加 hyperf.php 入口文件
This commit is contained in:
李东云
2025-09-28 09:41:31 +08:00
parent 606672b1d6
commit 4484fb1eea
9 changed files with 1880 additions and 580 deletions

1
.gitignore vendored
View File

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

32
bin/hyperf.php Normal file
View File

@@ -0,0 +1,32 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
use Hyperf\Di\ClassLoader;
use Hyperf\Di\Container;
use Hyperf\Di\Definition\DefinitionSource;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Swoole\Runtime;
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);
Runtime::enableCoroutine();
require BASE_PATH . '/vendor/autoload.php';
ClassLoader::init();
$container = new Container(new DefinitionSource([]));
if (!$container instanceof ContainerInterface) {
throw new RuntimeException('The dependency injection container is invalid.');
}
$container = ApplicationContext::setContainer($container);

View File

@@ -18,29 +18,30 @@
"ext-swoole": ">=4.4", "ext-swoole": ">=4.4",
"aliyuncs/oss-sdk-php": "^2.3", "aliyuncs/oss-sdk-php": "^2.3",
"box/spout": "^3.1", "box/spout": "^3.1",
"hyperf/amqp": "~2.2.0", "hyperf/amqp": "3.0.*",
"hyperf/async-queue": "~2.2.0", "hyperf/async-queue": "3.0.*",
"hyperf/cache": "~2.2.0", "hyperf/cache": "3.0.*",
"hyperf/command": "~2.2.0", "hyperf/code-generator": "^0.3.3",
"hyperf/config": "~2.2.0", "hyperf/command": "3.0.*",
"hyperf/constants": "~2.2.0", "hyperf/config": "3.0.*",
"hyperf/crontab": "~2.2.0", "hyperf/constants": "3.0.*",
"hyperf/database": "~2.2.0", "hyperf/crontab": "3.0.*",
"hyperf/db-connection": "~2.2.0", "hyperf/database": "3.0.*",
"hyperf/filesystem": "^2.0", "hyperf/db-connection": "3.0.*",
"hyperf/framework": "~2.2.0", "hyperf/filesystem": "3.0.*",
"hyperf/guzzle": "~2.2.0", "hyperf/framework": "3.0.*",
"hyperf/http-server": "~2.2.0", "hyperf/guzzle": "3.0.*",
"hyperf/logger": "~2.2.0", "hyperf/http-server": "3.0.*",
"hyperf/memory": "~2.2.0", "hyperf/logger": "3.0.*",
"hyperf/metric": "~2.2.0", "hyperf/memory": "3.0.*",
"hyperf/nsq": "~2.2.0", "hyperf/metric": "3.0.*",
"hyperf/process": "~2.2.0", "hyperf/nsq": "3.0.*",
"hyperf/redis": "~2.2.0", "hyperf/process": "3.0.*",
"hyperf/snowflake": "~2.2.0", "hyperf/redis": "3.0.*",
"hyperf/validation": "~2.2.0", "hyperf/snowflake": "3.0.*",
"hyperf/validation": "3.0.*",
"nette/php-generator": "^3.4", "nette/php-generator": "^3.4",
"singularity/hdk-core": "^0.1.6", "singularity/hdk-core": "^1.0.0",
"xxtime/flysystem-aliyun-oss": "~1.5.0", "xxtime/flysystem-aliyun-oss": "~1.5.0",
"yadakhov/insert-on-duplicate-key": "^1.2", "yadakhov/insert-on-duplicate-key": "^1.2",
"zoujingli/ip2region": "^1.0" "zoujingli/ip2region": "^1.0"
@@ -101,7 +102,6 @@
] ]
} }
}, },
"minimum-stability": "dev",
"prefer-stable": true, "prefer-stable": true,
"config": { "config": {
"sort-packages": true, "sort-packages": true,

2360
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,7 @@
namespace HyperfAdmin\BaseUtils; namespace HyperfAdmin\BaseUtils;
use Monolog\Formatter\LineFormatter; use Monolog\Formatter\LineFormatter;
use Monolog\LogRecord;
class ColorLineFormatter extends LineFormatter class ColorLineFormatter extends LineFormatter
{ {
@@ -11,7 +12,7 @@ class ColorLineFormatter extends LineFormatter
'WARNING' => "\e[0;33m{log_str}\e[0m", 'WARNING' => "\e[0;33m{log_str}\e[0m",
]; ];
public function format(array $record): string public function format(LogRecord $record): string
{ {
$log = parent::format($record); $log = parent::format($record);

View File

@@ -15,7 +15,7 @@ class BootAppConfListener implements ListenerInterface
]; ];
} }
public function process(object $event) public function process(object $event): void
{ {
Builder::macro('getAsArray', function () { Builder::macro('getAsArray', function () {
/** @var \Hyperf\Database\Query\Builder $this */ /** @var \Hyperf\Database\Query\Builder $this */

View File

@@ -15,7 +15,7 @@ class DbQueryExecutedListener implements ListenerInterface
]; ];
} }
public function process(object $event) public function process(object $event): void
{ {
if($event instanceof QueryExecuted) { if($event instanceof QueryExecuted) {
if(is_production()) { if(is_production()) {

View File

@@ -15,7 +15,7 @@ class FetchModeListener implements ListenerInterface
]; ];
} }
public function process(object $event) public function process(object $event): void
{ {
if($event instanceof StatementPrepared) { if($event instanceof StatementPrepared) {
$event->statement->setFetchMode(PDO::FETCH_ASSOC); $event->statement->setFetchMode(PDO::FETCH_ASSOC);

View File

@@ -16,12 +16,12 @@ class RedisArray implements \ArrayAccess
$this->redis = container(RedisFactory::class)->get($cluster); $this->redis = container(RedisFactory::class)->get($cluster);
} }
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return $this->redis->hExists($this->name, (string)$offset); return $this->redis->hExists($this->name, (string)$offset);
} }
public function offsetGet($offset) public function offsetGet($offset): mixed
{ {
$val = $this->redis->hGet($this->name, (string)$offset); $val = $this->redis->hGet($this->name, (string)$offset);
if(is_json_str($val)) { if(is_json_str($val)) {
@@ -31,14 +31,14 @@ class RedisArray implements \ArrayAccess
return $val; return $val;
} }
public function offsetSet($offset, $value) public function offsetSet($offset, $value): void
{ {
return $this->redis->hSet($this->name, (string)$offset, is_array($value) ? json_encode($value) : $value); $this->redis->hSet($this->name, (string)$offset, is_array($value) ? json_encode($value) : $value);
} }
public function offsetUnset($offset) public function offsetUnset($offset): void
{ {
return $this->redis->hDel($this->name, (string)$offset); $this->redis->hDel($this->name, (string)$offset);
} }
public function __destruct() public function __destruct()