Skip to content

Commit c39979e

Browse files
committed
改进checked方法
1 parent ae37170 commit c39979e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Validate.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class Validate
204204
'multipleOf' => ':attribute必须是 :rule 的倍数',
205205
'fileSize' => '文件大小不符',
206206
'fileExt' => '文件后缀不允许',
207-
'fileMime' => '文件类型不允许',
207+
'fileMime' => '文件类型不允许',
208208
'method' => '无效的请求类型',
209209
'token' => '令牌数据无效',
210210
];
@@ -750,20 +750,21 @@ public function check(array $data, array | string $rules = []): bool
750750
* @param array|string $rules
751751
* @return array
752752
*/
753-
public function checked(array $data, array|string $rules = []): array
753+
public function checked(array $data, array | string $rules = []): array
754754
{
755755
$checkRes = $this->check($data, $rules);
756756

757757
if (!$checkRes) {
758758
throw new ValidateException($this->error);
759759
}
760760

761-
$results = [];
761+
$results = [];
762762
$missingValue = Str::random(10);
763763

764-
// 注意 这里只支持 原生 形式的 key , tp 的特有格式的 "key|title" 这种格式的就不支持了
765-
// 原生格式的 key 指的是 类似 key.item_key.item 这种完全由 key 和 . 组合的字符串
766764
foreach (array_keys($this->getRules()) as $key) {
765+
if (str_contains($key, '|')) {
766+
[$key] = explode('|', $key);
767+
}
767768
$value = data_get($data, $key, $missingValue);
768769

769770
if ($value !== $missingValue) {

0 commit comments

Comments
 (0)