Skip to content

Commit 7cf0018

Browse files
committed
feat: 增强ValidationAspect的内置错误消息和缓存统计功能
- 在ValidationAspect中添加多个新的内置错误消息,支持不同的验证场景 - 新增获取缓存统计的方法,提供缓存使用情况的详细信息,便于测试和优化
1 parent 423da21 commit 7cf0018

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/Aspect/ValidationAspect.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ class ValidationAspect extends AbstractAspect
3131
*/
3232
private static array $builtinMessages = [
3333
'required' => ':attribute 为必填项。',
34-
'email' => ':attribute 必须是有效的邮箱地址。',
34+
'required_if' => '当 :other 为 :value 时,:attribute 不能为空。',
35+
'required_unless' => '当 :other 不为 :value 时,:attribute 不能为空。',
36+
'required_with' => '当 :values 存在时,:attribute 不能为空。',
37+
'required_with_all' => '当 :values 都存在时,:attribute 不能为空。',
38+
'required_without' => '当 :values 不存在时,:attribute 不能为空。',
39+
'required_without_all' => '当 :values 都不存在时,:attribute 不能为空。',
40+
'email' => ':attribute 必须是有效的电子邮件地址。',
3541
'phone' => ':attribute 必须是有效的手机号。',
3642
'mobile' => ':attribute 必须是有效的手机号。',
3743
'integer' => ':attribute 必须是整数。',
@@ -278,6 +284,18 @@ private function normalizeRules(array $rules, array $attributes): array
278284
return [$normalizedRules, $attributes];
279285
}
280286

287+
/**
288+
* 获取缓存统计(测试使用)
289+
*/
290+
public static function getCacheStats(): array
291+
{
292+
return [
293+
'rule_cache_size' => count(self::$configCache),
294+
'form_request_cache_size' => count(self::$formRequestCache),
295+
'fields_cache_size' => count(self::$fieldsCache),
296+
];
297+
}
298+
281299
private function getBodyData(ServerRequestInterface $request, string $mode): array
282300
{
283301
return match ($mode) {

0 commit comments

Comments
 (0)