mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-11-29 18:27:44 +08:00
Release v2.2.7 (#4008)
This commit is contained in:
parent
dcbb709f56
commit
c8aa5d398b
@ -1,4 +1,6 @@
|
||||
# v2.2.7 - TBD
|
||||
# v2.2.8 - TBD
|
||||
|
||||
# v2.2.7 - 2021-09-06
|
||||
|
||||
# Fixed
|
||||
|
||||
|
@ -1,5 +1,21 @@
|
||||
# 版本更新记录
|
||||
|
||||
# v2.2.7 - 2021-09-06
|
||||
|
||||
# 修复
|
||||
|
||||
- [#3997](https://github.com/hyperf/hyperf/pull/3997) 修复 `Nats` 消费者会在连接超时后崩溃的问题。
|
||||
- [#3998](https://github.com/hyperf/hyperf/pull/3998) 修复 `Apollo` 不支持 `https` 协议的问题。
|
||||
|
||||
## 优化
|
||||
|
||||
- [#4009](https://github.com/hyperf/hyperf/pull/4009) 优化方法 `MethodDefinitionCollector::getOrParse()`,避免在 PHP8 环境下,触发即将废弃的错误。
|
||||
|
||||
## 新增
|
||||
|
||||
- [#4002](https://github.com/hyperf/hyperf/pull/4002) [#4012](https://github.com/hyperf/hyperf/pull/4012) 为验证器增加场景功能,允许不同场景下,使用不同的验证规则。
|
||||
- [#4011](https://github.com/hyperf/hyperf/pull/4011) 为工具类 `Hyperf\Utils\Str` 增加了一些新的便捷方法。
|
||||
|
||||
# v2.2.6 - 2021-08-30
|
||||
|
||||
## 修复
|
||||
|
@ -27,7 +27,7 @@ return [
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
'guzzle' => [
|
||||
'config' => [],
|
||||
'config' => null,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -349,6 +349,79 @@ if ($errors->has('foo')) {
|
||||
}
|
||||
```
|
||||
|
||||
### 场景
|
||||
|
||||
验证器增加了场景功能,我们可以很方便的按需修改验证规则。
|
||||
|
||||
> 此功能需要本组件版本大于等于 2.2.7
|
||||
|
||||
创建一个 `SceneRequest` 如下:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class SceneRequest extends FormRequest
|
||||
{
|
||||
protected $scenes = [
|
||||
'foo' => ['username'],
|
||||
'bar' => ['username', 'password'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required',
|
||||
'gender' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
当我们正常使用时,会使用所有的验证规则,即 `username` 和 `gender` 都是必填的。
|
||||
|
||||
我们可以设定场景,让此次请求只验证 `username` 必填。
|
||||
|
||||
> 如果我们配置了 `Hyperf\Validation\Middleware\ValidationMiddleware`,且将 `SceneRequest` 注入到方法上,就会导致入参在中间件中直接进行验证,故场景值无法生效,所以我们需要在方法里从容器中获取对应的 `SceneRequest`,进行场景切换。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Request\DebugRequest;
|
||||
use App\Request\SceneRequest;
|
||||
use Hyperf\HttpServer\Annotation\AutoController;
|
||||
|
||||
#[AutoController(prefix: 'foo')]
|
||||
class FooController extends Controller
|
||||
{
|
||||
public function scene()
|
||||
{
|
||||
$request = $this->container->get(SceneRequest::class);
|
||||
$request->scene('foo')->validateResolved();
|
||||
|
||||
return $this->response->success($request->all());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 验证规则
|
||||
|
||||
下面是有效规则及其函数列表:
|
||||
|
@ -1,5 +1,21 @@
|
||||
# 版本更新記錄
|
||||
|
||||
# v2.2.7 - 2021-09-06
|
||||
|
||||
# 修復
|
||||
|
||||
- [#3997](https://github.com/hyperf/hyperf/pull/3997) 修復 `Nats` 消費者會在連接超時後崩潰的問題。
|
||||
- [#3998](https://github.com/hyperf/hyperf/pull/3998) 修復 `Apollo` 不支持 `https` 協議的問題。
|
||||
|
||||
## 優化
|
||||
|
||||
- [#4009](https://github.com/hyperf/hyperf/pull/4009) 優化方法 `MethodDefinitionCollector::getOrParse()`,避免在 PHP8 環境下,觸發即將廢棄的錯誤。
|
||||
|
||||
## 新增
|
||||
|
||||
- [#4002](https://github.com/hyperf/hyperf/pull/4002) [#4012](https://github.com/hyperf/hyperf/pull/4012) 為驗證器增加場景功能,允許不同場景下,使用不同的驗證規則。
|
||||
- [#4011](https://github.com/hyperf/hyperf/pull/4011) 為工具類 `Hyperf\Utils\Str` 增加了一些新的便捷方法。
|
||||
|
||||
# v2.2.6 - 2021-08-30
|
||||
|
||||
## 修復
|
||||
@ -11,7 +27,7 @@
|
||||
## 新增
|
||||
|
||||
- [#3987](https://github.com/hyperf/hyperf/pull/3987) AMQP 組件支持延時隊列。
|
||||
- [#3989](https://github.com/hyperf/hyperf/pull/3989) 為熱更新組件新增了配置 `command`,可以用來定義自己的啟動腳本,支持 [nano](https://github.com/hyperf/nano) 組件。
|
||||
- [#3989](https://github.com/hyperf/hyperf/pull/3989) [#3992](https://github.com/hyperf/hyperf/pull/3992) 為熱更新組件新增了配置 `command`,可以用來定義自己的啟動腳本,支持 [nano](https://github.com/hyperf/nano) 組件。
|
||||
|
||||
# v2.2.5 - 2021-08-23
|
||||
|
||||
|
@ -27,7 +27,7 @@ return [
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
'guzzle' => [
|
||||
'config' => [],
|
||||
'config' => null,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -349,6 +349,79 @@ if ($errors->has('foo')) {
|
||||
}
|
||||
```
|
||||
|
||||
### 場景
|
||||
|
||||
驗證器增加了場景功能,我們可以很方便的按需修改驗證規則。
|
||||
|
||||
> 此功能需要本組件版本大於等於 2.2.7
|
||||
|
||||
創建一個 `SceneRequest` 如下:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class SceneRequest extends FormRequest
|
||||
{
|
||||
protected $scenes = [
|
||||
'foo' => ['username'],
|
||||
'bar' => ['username', 'password'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required',
|
||||
'gender' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
當我們正常使用時,會使用所有的驗證規則,即 `username` 和 `gender` 都是必填的。
|
||||
|
||||
我們可以設定場景,讓此次請求只驗證 `username` 必填。
|
||||
|
||||
> 如果我們配置了 `Hyperf\Validation\Middleware\ValidationMiddleware`,且將 `SceneRequest` 注入到方法上,就會導致入參在中間件中直接進行驗證,故場景值無法生效,所以我們需要在方法裏從容器中獲取對應的 `SceneRequest`,進行場景切換。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Request\DebugRequest;
|
||||
use App\Request\SceneRequest;
|
||||
use Hyperf\HttpServer\Annotation\AutoController;
|
||||
|
||||
#[AutoController(prefix: 'foo')]
|
||||
class FooController extends Controller
|
||||
{
|
||||
public function scene()
|
||||
{
|
||||
$request = $this->container->get(SceneRequest::class);
|
||||
$request->scene('foo')->validateResolved();
|
||||
|
||||
return $this->response->success($request->all());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 驗證規則
|
||||
|
||||
下面是有效規則及其函數列表:
|
||||
|
@ -1,5 +1,21 @@
|
||||
# 版本更新記錄
|
||||
|
||||
# v2.2.7 - 2021-09-06
|
||||
|
||||
# 修復
|
||||
|
||||
- [#3997](https://github.com/hyperf/hyperf/pull/3997) 修復 `Nats` 消費者會在連線超時後崩潰的問題。
|
||||
- [#3998](https://github.com/hyperf/hyperf/pull/3998) 修復 `Apollo` 不支援 `https` 協議的問題。
|
||||
|
||||
## 優化
|
||||
|
||||
- [#4009](https://github.com/hyperf/hyperf/pull/4009) 優化方法 `MethodDefinitionCollector::getOrParse()`,避免在 PHP8 環境下,觸發即將廢棄的錯誤。
|
||||
|
||||
## 新增
|
||||
|
||||
- [#4002](https://github.com/hyperf/hyperf/pull/4002) [#4012](https://github.com/hyperf/hyperf/pull/4012) 為驗證器增加場景功能,允許不同場景下,使用不同的驗證規則。
|
||||
- [#4011](https://github.com/hyperf/hyperf/pull/4011) 為工具類 `Hyperf\Utils\Str` 增加了一些新的便捷方法。
|
||||
|
||||
# v2.2.6 - 2021-08-30
|
||||
|
||||
## 修復
|
||||
@ -11,7 +27,7 @@
|
||||
## 新增
|
||||
|
||||
- [#3987](https://github.com/hyperf/hyperf/pull/3987) AMQP 元件支援延時佇列。
|
||||
- [#3989](https://github.com/hyperf/hyperf/pull/3989) 為熱更新元件新增了配置 `command`,可以用來定義自己的啟動指令碼,支援 [nano](https://github.com/hyperf/nano) 元件。
|
||||
- [#3989](https://github.com/hyperf/hyperf/pull/3989) [#3992](https://github.com/hyperf/hyperf/pull/3992) 為熱更新元件新增了配置 `command`,可以用來定義自己的啟動指令碼,支援 [nano](https://github.com/hyperf/nano) 元件。
|
||||
|
||||
# v2.2.5 - 2021-08-23
|
||||
|
||||
|
@ -27,7 +27,7 @@ return [
|
||||
'username' => null,
|
||||
'password' => null,
|
||||
'guzzle' => [
|
||||
'config' => [],
|
||||
'config' => null,
|
||||
],
|
||||
];
|
||||
|
||||
|
@ -349,6 +349,79 @@ if ($errors->has('foo')) {
|
||||
}
|
||||
```
|
||||
|
||||
### 場景
|
||||
|
||||
驗證器增加了場景功能,我們可以很方便的按需修改驗證規則。
|
||||
|
||||
> 此功能需要本元件版本大於等於 2.2.7
|
||||
|
||||
建立一個 `SceneRequest` 如下:
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Request;
|
||||
|
||||
use Hyperf\Validation\Request\FormRequest;
|
||||
|
||||
class SceneRequest extends FormRequest
|
||||
{
|
||||
protected $scenes = [
|
||||
'foo' => ['username'],
|
||||
'bar' => ['username', 'password'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => 'required',
|
||||
'gender' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
當我們正常使用時,會使用所有的驗證規則,即 `username` 和 `gender` 都是必填的。
|
||||
|
||||
我們可以設定場景,讓此次請求只驗證 `username` 必填。
|
||||
|
||||
> 如果我們配置了 `Hyperf\Validation\Middleware\ValidationMiddleware`,且將 `SceneRequest` 注入到方法上,就會導致入參在中介軟體中直接進行驗證,故場景值無法生效,所以我們需要在方法裡從容器中獲取對應的 `SceneRequest`,進行場景切換。
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Request\DebugRequest;
|
||||
use App\Request\SceneRequest;
|
||||
use Hyperf\HttpServer\Annotation\AutoController;
|
||||
|
||||
#[AutoController(prefix: 'foo')]
|
||||
class FooController extends Controller
|
||||
{
|
||||
public function scene()
|
||||
{
|
||||
$request = $this->container->get(SceneRequest::class);
|
||||
$request->scene('foo')->validateResolved();
|
||||
|
||||
return $this->response->success($request->all());
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 驗證規則
|
||||
|
||||
下面是有效規則及其函式列表:
|
||||
|
Loading…
Reference in New Issue
Block a user