Skip to content

Commit

Permalink
Merge branch '3.0' into bean-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft authored Nov 25, 2023
2 parents 47e2829 + 3043be4 commit e10759e
Show file tree
Hide file tree
Showing 132 changed files with 917 additions and 1,960 deletions.
2 changes: 1 addition & 1 deletion .github/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ services:
POSTGRESQL_VERSION: ${POSTGRESQL_VERSION}
volumes:
- "${GITHUB_WORKSPACE}:/imi:rw"
- "/tmp/composer:/root/.composer/cache/files:rw"
- "/tmp/base_cache:/tmp/base_cache:rw"
- shared-volume:/tmp/docker
working_dir: /imi
command: tail -f /dev/null
Expand Down
113 changes: 105 additions & 8 deletions .github/workflows/daily-test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
name: daily-test
name: Daily Test

on:
schedule:
- cron: "0 16 * * *" # 这个值是 UTC 时间,每天北京时间 0 点执行
push:
paths:
- ".github/workflows/daily-test.yml"
pull_request:
paths:
- ".github/workflows/daily-test.yml"

jobs:
ci:
name: Linux PHP-${{ matrix.php }} Swoole-${{ matrix.swoole.version }} RoadRunner-${{ matrix.roadrunner }}
runs-on: ubuntu-20.04
daily-test-3_0:
name: 3.0_Linux PHP-${{ matrix.php }} Swoole-${{ matrix.swoole.version }} RoadRunner-${{ matrix.roadrunner }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [8.2]
swoole:
- version: master
postgresql_version: ""
roadrunner: [2.7.*]
env:
ENV_SERVICE: php
POSTGRESQL_VERSION: ${{ matrix.swoole.postgresql_version }}
PHP_VERSION: ${{ matrix.php }}
SWOOLE_VERSION: ${{ matrix.swoole.version }}
MYSQL_DOCKER_VERSION: "8.0"
Expand All @@ -29,11 +33,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: "3.0"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: /tmp/composer
key: ${{ runner.os }}-composer-${{ matrix.swoole.version }}-${{ hashFiles('/composer.json') }}
path: /tmp/base_cache/composer
key: ${{ runner.os }}-daily-test-3.0-composer-${{ matrix.php }}-${{ hashFiles('*/composer.json', 'src/Components/*/composer.json') }}
restore-keys: |
${{ runner.os }}-daily-test-3.0-composer-${{ matrix.php }}-
${{ runner.os }}-daily-test-3.0-composer-
- name: Prepare
uses: ./.github/actions/ci-prepare
with:
Expand Down Expand Up @@ -89,3 +98,91 @@ jobs:
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php

daily-test-2_1:
name: 2.1_Linux PHP-${{ matrix.php }} Swoole-${{ matrix.swoole.version }} RoadRunner-${{ matrix.roadrunner }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ 8.2 ]
swoole:
- version: master
roadrunner: [ 2.7.* ]
env:
ENV_SERVICE: php
PHP_VERSION: ${{ matrix.php }}
SWOOLE_VERSION: ${{ matrix.swoole.version }}
MYSQL_DOCKER_VERSION: "8.0"
REDIS_SERVER_HOST: redis
ROADRUNNER_DOCKER_VERSION: ${{ matrix.roadrunner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COMPOSER_ENV: --ignore-platform-reqs
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: "2.1"
- name: Cache dependencies
uses: actions/cache@v3
with:
path: /tmp/base_cache/composer
key: ${{ runner.os }}-daily-test-2.1-composer-${{ matrix.php }}-${{ hashFiles('*/composer.json', 'src/Components/*/composer.json') }}
restore-keys: |
${{ runner.os }}-daily-test-2.1-composer-${{ matrix.php }}-
${{ runner.os }}-daily-test-2.1-composer-
- name: Prepare
uses: ./.github/actions/ci-prepare
with:
env: ${{ env.ENV_SERVICE }}
- name: Test
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test
- name: Test swoole
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-swoole
- name: Test workerman
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-workerman
- name: Test workerman-gateway
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-workerman-gateway
- name: Test roadrunner
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-roadrunner
- name: Test fpm
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-fpm
- name: Test jwt
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-jwt
- name: Test queue
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-queue
- name: Test amqp
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-amqp
- name: Test kafka
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-kafka
- name: Test grpc
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-grpc
- name: Test snowflake
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-snowflake
- name: Test mqtt
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-mqtt
- name: Test smarty
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-smarty
- name: Test pgsql
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-pgsql
- name: Test phar
if: ${{ env.test_prepared && always() }}
run: docker exec ${ENV_SERVICE} composer test-phar
- name: Print logs
if: failure()
run: docker exec ${ENV_SERVICE} php .github/print-logs.php
1 change: 0 additions & 1 deletion dev/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function getRectorConfigCallback(string $path): callable
\Rector\Php71\Rector\FuncCall\CountOnNullRector::class,
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
\Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector::class,
\Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector::class, // 性能很差
\Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector::class, // 调整包含默认值的参数顺序,会导致代码被破坏
\Rector\Php81\Rector\ClassConst\FinalizePublicClassConstantRector::class, // 常量自动加 final,无法继承覆盖了
]);
Expand Down
2 changes: 1 addition & 1 deletion doc/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* [事件监听](components/event/index.md)
* [事件列表](core/events.md)
* [中间件](core/middleware.md)
* [错误转为异常捕获](core/handleError.md)
* [全局异常处理](core/handleError.md)
* [内部进程间通讯](core/processCommunication.md)
* [Server 对象](core/server.md)
* [长连接分布式解决方案](core/long-connection-distributed.md)
Expand Down
4 changes: 2 additions & 2 deletions doc/base/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ return [
// 参考: http://wiki.swoole.com/#/server/setting
// 参考: http://wiki.swoole.com/#/websocket_server?id=%e9%80%89%e9%a1%b9
// 参考: http://wiki.swoole.com/#/http_server?id=%e9%85%8d%e7%bd%ae%e9%80%89%e9%a1%b9
'nonControlFrameType' => \Imi\Server\WebSocket\Enum\NonControlFrameType::TEXT, // 配置 WebSocket 纯文本通信协议
// 'nonControlFrameType' => \Imi\Server\WebSocket\Enum\NonControlFrameType::BINARY, // 配置 WebSocket 二进制通信协议
'nonControlFrameType' => \Imi\Server\WebSocket\Enum\NonControlFrameType::Text, // 配置 WebSocket 纯文本通信协议
// 'nonControlFrameType' => \Imi\Server\WebSocket\Enum\NonControlFrameType::Binary, // 配置 WebSocket 二进制通信协议
'configs' => [
'reactor_num' => 8,
'worker_num' => 8,
Expand Down
40 changes: 40 additions & 0 deletions doc/base/version/2.1-3.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ return [

* Bean 类默认不支持互相注入,需要使用注解声明 `#[Bean(recursion: true)]`

* 定时任务 `Imi\Cron\Annotation\Cron` 注解的 `unique` 值类型更改为 `\Imi\Cron\Consts\UniqueLevel` 枚举,大小写有所变化

### 模型

* UUID 发号器的 `type` 类型改为枚举,大小写有所变化

### WebSocket

* 重构 `Imi\Server\WebSocket\Enum::NonControlFrameType` 为枚举

### imi-access-control

废弃并移出主仓库,代码仓库:<https://github.com/imiphp/imi-access-control>
Expand All @@ -83,6 +93,10 @@ return [

* 废弃 `Imi\AMQP\Swoole\AMQPSwooleConnection` 客户端类

* 消费者类 `Imi\AMQP\Base\BaseConsumer::consume()` 方法返回值类型应设置为 `\Imi\AMQP\Enum\ConsumerResult`,且必须返回枚举值

* `Imi\Queue\Enum\QueueType` 改为原生注解,如需自定义请编写枚举并实现 `Imi\Queue\Enum\QueueType\IQueueType` 接口

### imi-macro

废弃并移出主仓库,代码仓库:<https://github.com/imiphp/imi-macro>
Expand Down Expand Up @@ -124,3 +138,29 @@ return [
`Imi\Tool\Annotation\Tool` => `Imi\Cli\Annotation\Command`

`Imi\Tool\ArgType` => `Imi\Cli\ArgType`

* 废弃 `Query::alias()`

* 废弃 `Query::chunkEach()`,改为:

```php
$query->chunkById($count, $column, $alias)->each();
// 或
$query->chunkByOffset($limit)->each();
```

* 废弃 `Imi\Pool\ResourceConfigMode::TURN` 改为 `Imi\Pool\ResourceConfigMode::ROUND_ROBIN`

* 废弃连接池类的 `createResource()` 方法,改为 `createNewResource()`,影响自定义连接池

* 废弃 `Imi\Util\DateTime::getLastWeek()`,错误的命名,改为 `Imi\Util\DateTime::getPrevWeek()`

* 废弃 `ExtractData` 注解,建议使用 `RequestParam`

* 废弃 `ErrorLog::onException()`,建议使用 `Imi\Log\Log::error()`

* 废弃 Swoole MySQL 客户端,建议使用 PDO 和 mysqli

* 废弃 gRPC 旧的 Server 相关类

* 废弃 `imiGetEnv()`、建议使用 `Imi\env()`
6 changes: 0 additions & 6 deletions doc/components/db/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ return [
// 'dbClass' => 'PdoMysqlDriver',
// 使用 hook mysqli 驱动
// 'dbClass' => 'MysqliDriver',
// 使用 Swoole MySQL 驱动
// 'dbClass' => 'SwooleMysqlDriver',
// 数据库连接后,执行初始化的 SQL
// 'initSqls' => [
// 'select 1',
Expand Down Expand Up @@ -137,8 +135,6 @@ return [
// 'dbClass' => 'PdoMysqlDriver',
// 使用 hook mysqli 驱动
// 'dbClass' => 'MysqliDriver',
// 使用 Swoole MySQL 驱动
// 'dbClass' => 'SwooleMysqlDriver',
// 数据库连接后,执行初始化的 SQL
// 'initSqls' => [
// 'select 1',
Expand Down Expand Up @@ -183,8 +179,6 @@ return [
// 'dbClass' => 'PdoMysqlDriver',
// 使用 hook mysqli 驱动
// 'dbClass' => 'MysqliDriver',
// 使用 Swoole MySQL 驱动
// 'dbClass' => 'SwooleMysqlDriver',
// 数据库连接后,执行初始化的 SQL
// 'initSqls' => [
// 'select 1',
Expand Down
4 changes: 0 additions & 4 deletions doc/components/db/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,6 @@ foreach (Db::query()->table('tb_test')->chunkByOffset(10)->each() as $row)
}
```

##### chunkEach

> 该方法已弃用并计划`3.0`移除,请使用`chunkById()->each()`or`chunkByOffset()->each()`替代。
#### 游标查询

游标查询能对于查询大结果集时能有效节约应用内存消耗,对于数据库的消耗与`select`无差别。
Expand Down
4 changes: 0 additions & 4 deletions doc/components/db/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@
### MysqliDriver

基于 MySQLi 实现,支持所有环境,支持 Swoole 协程。

### SwooleMysqlDriver

只支持 Swoole 环境
24 changes: 0 additions & 24 deletions doc/components/httpserver/request.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,27 +330,3 @@ public function requestParam2(
];
}
```

### ExtractData 注解

将在 imi 3.0 中废弃,推荐使用 `RequestParam` 注解。

**代码示例:**

```php
/**
* http参数验证测试
*
* @return void
*/
#[
Action,
ExtractData(name: '$get.id', to: 'id'),
ExtractData(name: '$get.name', to: 'name'),
ExtractData(name: '$get.age', to: 'age'),
]
public function httpValidation($id, $name, $age)
{
return compact('id', 'name', 'age');
}
```
9 changes: 0 additions & 9 deletions doc/components/httpserver/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

在 HTTP 验证器场景下,不推荐在验证注解上指定 `default` 参数,而是应该直接给方法参数加上默认值。

## ExtractData

还有一个`ExtractData`注解,它可以把`get/post/body`中的参数导出到`action`方法的参数中。

`ExtractData`注解可以独立使用,不依赖`HttpValidation`注解,但只能在控制器中使用。

## 示例

```php
Expand All @@ -40,9 +34,6 @@
Required(name: '$get.name', message: '用户姓名为必传参数'),
Text(name: '$get.name', min: 2, message: '用户姓名长度不得少于2位'),
Required(name: '$get.age'),
ExtractData(name: '$get.id', to: 'id'),
ExtractData(name: '$get.name', to: 'name'),
ExtractData(name: '$get.age', to: 'age'),
]
public function httpValidation($id, $name, $age = -1)
{
Expand Down
4 changes: 0 additions & 4 deletions doc/components/orm/RDModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,6 @@ foreach (TestModel::query()->chunkByOffset(10)->each() as $row)
}
```

##### chunkEach

> 该方法已弃用并计划`3.0`移除,请使用`chunkById()->each()`or`chunkByOffset()->each()`替代。
#### 游标查询

游标查询能对于查询大结果集时能有效节约应用内存消耗,对于数据库的消耗与`select`无差别。。
Expand Down
8 changes: 4 additions & 4 deletions doc/components/orm/RDModel/definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -550,19 +550,19 @@ ID 生成器指定参数:

`#[Id(generator: \Imi\Model\IdGenerator\UUIDGenerator::class)]`

`#[Id(generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::TIME])]`
`#[Id(generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::Time])]`

**随机算法:**`#[Id(generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::RANDOM])]`
**随机算法:**`#[Id(generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::Random])]`

**MD5、Sha1:**

使用方法基本一样,差别就是 `generatorOptions.type` 值不同。

`#[Id(index: false, generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::MD5, "ns" => "99e4edaf-8363-466e-bddf-7254db57675c", "nameField" => "名称字段名,该字段值必须唯一,否则会重复"])]`
`#[Id(index: false, generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::Md5, "ns" => "99e4edaf-8363-466e-bddf-7254db57675c", "nameField" => "名称字段名,该字段值必须唯一,否则会重复"])]`

> `ns` 必须是一个合法的 UUID
`#[Id(index: false, generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::SHA1, "nsField" => "命名空间字段名", "name" => "直接指定名称"])]`
`#[Id(index: false, generator: \Imi\Model\IdGenerator\UUIDGenerator::class, generatorOptions: ["type" => \Imi\Model\IdGenerator\UUIDGeneratorType::Sha1, "nsField" => "命名空间字段名", "name" => "直接指定名称"])]`

> 注意:`ns``name` 的值如果一样,生成的 UUID 也会一样!!!
Expand Down
4 changes: 3 additions & 1 deletion doc/components/struct/enum.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

[toc]

由于 PHP 本身不支持枚举类型,imi 特别基于注解实现了枚举类。
由于 PHP < 8.1 本身不支持枚举类型,imi 特别基于注解实现了枚举类。

> 此功能在 3.0 不会被内置,需要手动安装 `imi-old-enum` 组件。强烈建议使用 PHP 原生枚举!
## 枚举类定义

Expand Down
6 changes: 3 additions & 3 deletions doc/components/task/cron.md
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,9 @@ class TaskProcess implements IProcess
**unique:**

定时任务唯一性设置
当前实例唯一: current
所有实例唯一: all
不唯一: null
当前实例唯一: `\Imi\Cron\Consts\UniqueLevel::Current`
所有实例唯一: `\Imi\Cron\Consts\UniqueLevel::All`
不唯一: `null`

**redisPool:**

Expand Down
Loading

0 comments on commit e10759e

Please sign in to comment.