Download the PHP package hyperf-plus/validate without Composer
On this page you can find all versions of the php package hyperf-plus/validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Table of contents
Download hyperf-plus/validate
More information about hyperf-plus/validate
Files in hyperf-plus/validate
Download hyperf-plus/validate
More information about hyperf-plus/validate
Files in hyperf-plus/validate
Vendor hyperf-plus
Package validate
Short Description hyperf-plus validate 基于 hyperf/validation 的路由验证适配器,支持注解式验证
License Apache-2.0
Package validate
Short Description hyperf-plus validate 基于 hyperf/validation 的路由验证适配器,支持注解式验证
License Apache-2.0
Please rate this library. Is it a good library?
Informations about the package validate
HPlus Validate 4.0
基于 hyperf/validation 的请求验证组件,支持注解式验证和 FormRequest 验证器。
内置中文错误提示兜底、本地无语言包也能返回中文;默认安全过滤多余字段,可选安全模式拒绝未定义字段。
✨ 4.0 新特性
- 🚀 Hyperf 原生验证:完全基于 hyperf/validation,兼容所有 Laravel 规则
- 📝 双模式:内联规则 + FormRequest 验证器,支持场景
- ⚡ 性能优化:多层缓存(配置/类检查/字段列表),更快
- 🛡️ 安全稳定:可选安全模式拦截未定义字段,内置中文错误兜底,无语言包仍返回中文
- 🔧 Query/Body 分离:清晰区分 URL 参数与请求体校验
- ✅ CI 覆盖:GitHub Actions 多 PHP 版本自动化测试
⚠️ 破坏性变更: 4.0 版本移除了 ThinkPHP 风格的
Validate基类,仅支持 Hyperf 原生FormRequest。
📦 安装
依赖
🚀 快速开始
方式一:内联规则(推荐)
方式二:FormRequest 验证器
📋 注解参数
🎯 使用场景
验证 Query 参数(GET 请求)
同时验证 Query 和 Body
安全模式
拒绝请求中包含未定义的字段:
过滤模式
自动过滤多余字段,只保留规则中定义的字段:
📐 支持的验证规则
完全兼容 Laravel/Hyperf Validation 所有规则:
| 分类 | 规则 |
|---|---|
| 基础 | required, nullable, string, integer, numeric, boolean, array |
| 字符串 | email, url, ip, uuid, alpha, alpha_num, regex:pattern |
| 数值 | min:value, max:value, between:min,max, size:value, gt:field, gte:field |
| 日期 | date, date_format:format, before:date, after:date |
| 数组 | in:foo,bar, not_in:foo,bar, distinct, array |
| 数据库 | unique:table,column, exists:table,column |
| 文件 | file, image, mimes:jpg,png, max:size |
| 关系 | confirmed, same:field, different:field, required_if:field,value |
更多规则:https://laravel.com/docs/validation#available-validation-rules
🛠️ 高级用法
自定义验证规则
嵌套数组验证
条件验证
❌ 错误处理
验证失败抛出 ValidateException(HTTP 422):
🧪 测试覆盖
运行测试:
📊 与 3.x 版本对比
| 特性 | 3.x | 4.0 |
|---|---|---|
| ThinkPHP Validate | ✅ | ❌ 移除 |
| Hyperf FormRequest | ✅ | ✅ |
| 内联规则 | ✅ | ✅ |
dateType 参数 |
✅ | ❌ 改为 mode |
validate + scene |
分离注解 | 统一到 RequestValidation |
| 缓存统计 | ✅ | ❌ 移除(无意义开销) |
迁移指南
📄 License
MIT
All versions of validate with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.1
hyperf/di Version ^3.1.0
hyperf/http-message Version ^3.1.0
hyperf/utils Version ^3.1.0
hyperf/validation Version ^3.1.0
hyperf/translation Version ^3.1.0
hyperf/di Version ^3.1.0
hyperf/http-message Version ^3.1.0
hyperf/utils Version ^3.1.0
hyperf/validation Version ^3.1.0
hyperf/translation Version ^3.1.0
The package hyperf-plus/validate contains the following files
Loading the files please wait ...