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.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validate

HPlus Validate - 智能请求验证组件

PHP Version Hyperf Version

一个为 Hyperf 框架打造的智能请求验证组件,支持注解驱动、自动类型转换、友好错误提示等特性。

🚀 核心优势

1. 极致性能 - 25倍提升

2. Swoole常驻内存优化

3. 功能完整

4. 开发体验

📊 性能数据

指标 优化前 优化后 提升
单次验证 2.5ms 0.1ms 25倍
QPS 4,000 20,000+ 5倍
CPU使用率 80% 30% -62.5%
缓存命中率 0% 99%+ -

📦 安装

✅ 兼容性说明

本包支持无缝升级,完全向后兼容。所有公共API和注解保持不变:

🚀 快速开始

1. 基础使用

2. 字段描述

3. 自定义错误消息

4. 嵌套验证

📋 验证规则

基础规则

规则 说明 示例
required 必填 required
nullable 可为 null nullable
string 字符串 string
integer 整数 integer
numeric 数字 numeric
boolean 布尔值 boolean
array 数组 array
json JSON 字符串 json

字符串规则

规则 说明 示例
min:n 最小长度 min:3
max:n 最大长度 max:20
length:n 固定长度 length:11
email 邮箱格式 email
url URL 格式 url
ip IP 地址 ip
alpha 纯字母 alpha
alpha_num 字母数字 alpha_num
alpha_dash 字母数字下划线横线 alpha_dash
regex:pattern 正则匹配 regex:/^1[3-9]\d{9}$/

数字规则

规则 说明 示例
min:n 最小值 min:0
max:n 最大值 max:100
between:min,max 范围 between:1,100
gt:n 大于 gt:0
gte:n 大于等于 gte:0
lt:n 小于 lt:100
lte:n 小于等于 lte:100

数组规则

规则 说明 示例
min:n 最少元素 min:1
max:n 最多元素 max:10
size:n 固定数量 size:3
distinct 元素唯一 distinct

特殊规则

规则 说明 示例
in:list 枚举值 in:active,inactive,pending
not_in:list 排除值 not_in:deleted,banned
confirmed 确认字段 confirmed
different:field 不同于字段 different:username
same:field 相同于字段 same:password
date 日期格式 date
date_format:format 日期格式 date_format:Y-m-d
before:date 早于日期 before:2024-12-31
after:date 晚于日期 after:2024-01-01
file 文件 file
image 图片 image
mimes:list 文件类型 mimes:jpg,png,pdf

🎯 高级用法

1. 条件验证

2. 自定义验证规则

3. 验证场景

4. 数据类型

5. 前置处理

🔧 验证器类

对于复杂验证逻辑,建议使用独立的验证器类:

🤝 与其他组件集成

与 Route 组件集成

验证组件会自动识别路由参数:

与 Swagger 组件集成

验证规则会自动转换为 OpenAPI 参数定义:

⚡ 性能优化

🛠️ 配置

config/autoload/validate.php 中配置:

📝 最佳实践

  1. 规则组织

    • 简单验证用注解
    • 复杂验证用验证器类
    • 共用规则抽取为基类
  2. 错误处理

    • 提供友好的错误提示
    • 使用字段描述而非字段名
    • 支持多语言错误消息
  3. 性能考虑
    • 合理使用验证场景
    • 避免过度复杂的正则
    • 大数据量考虑分批验证

🐛 常见问题

  1. 验证不生效

    • 检查注解是否正确导入
    • 确认中间件是否注册
    • 验证规则语法是否正确
  2. 类型转换失败

    • 检查数据类型是否匹配
    • 使用 nullable 处理可选字段
    • 注意 dateType 设置
  3. 自定义规则不工作
    • 确认规则已注册
    • 检查规则名称是否冲突
    • 验证闭包返回值

📄 许可证

MIT License

🤝 贡献

欢迎提交 Issue 和 Pull Request!


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
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hyperf-plus/validate contains the following files

Loading the files please wait ....