PHPackages                             yzh52521/webman-validate - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. yzh52521/webman-validate

ActiveLibrary

yzh52521/webman-validate
========================

The webman Validate Package

v0.1.6(2y ago)61.9k1[2 issues](https://github.com/yzh52521/webman-validate/issues)1mitPHPPHP &gt;=7.2.0

Since Apr 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yzh52521/webman-validate)[ Packagist](https://packagist.org/packages/yzh52521/webman-validate)[ RSS](/packages/yzh52521-webman-validate/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (8)Used By (1)

webman-validate
===============

[](#webman-validate)

> 基于PHP7.4 + 的Validate实现。基于ThinkPHP6修改的可用于 webman 的通用validate数据验证器。

- 支持助手函数validate(),无需手动创建。
- 支持场景验证scene
- 支持表单令牌token
- 支持unique唯一性验证(基于TP think-orm Db类)
- 支持图片验证

安装
--

[](#安装)

```
composer require yzh52521/webman-validate
```

使用
--

[](#使用)

> 用法跟TP6完全一致

\###定义验证器：

```
namespace app\validate;

use yzh52521\validate\Validate;

class User extends Validate
{
    protected $rule =   [
        'name'  => 'require|max:25',
        'age'   => 'require|number|between:1,120',
        'email' => 'require|email'
    ];

    protected $message  =   [
        'name.require' => '名称必须填写',
        'name.max'     => '名称最多不能超过25个字符',
        'age.require'   => '年龄必须填写',
        'age.number'   => '年龄必须是数字',
        'age.between'  => '年龄只能在1-120之间',
        'email.require' => '邮箱必须填写',
        'email.email'   => '邮箱格式错误'
    ];

}
```

\##验证器调用代码如下：

```
$data = [
    'name'  => 'thinkphp',
    'age'  => 24,
    'email' => 'thinkphp@163.com'
];
$validate = new \app\validate\User;

if (!$validate->check($data)) {
    var_dump($validate->getError());
}

```

\##助手函数（推荐） 自定义函数 functions.php 添加validate()函数

```
/**
 * @desc 验证器助手函数
 * @param string|array $validate 验证器类名或者验证规则数组
 * @param array $message 错误提示信息
 * @param bool $batch 是否批量验证
 * @param bool $failException 是否抛出异常
 * @return bool
 * @author yzh52521
 */
function validate($validate = '', array $message = [], bool $batch = false, bool $failException = true)
{
    if (is_array($validate) || ''===$validate) {
        $v = new \yzh52521\validate\Validate();
        $v->rule($validate);
    } else {
        if (strpos($validate, '.')) {
            [$validate, $scene] = explode('.', $validate);
        }
        $v = new $validate();
        if (!empty($scene)) {
            $v->scene($scene);
        }
    }
     return $v->message($message)->batch($batch)->failException($failException);
}

```

> 验证器调用代码如下：

```
namespace app\controller;

use app\validate\User;
use yzh52521\validate\exception\ValidateException;

class Index
{
    public function index()
    {
        try {
            validate(User::class)->check([
                'name'  => 'thinkphp',
                'email' => 'thinkphp@qq.com',
            ]);
        } catch (ValidateException $e) {
            // 验证失败 输出错误信息
            dump($e->getError());
        }
    }
}

    //场景校验方法
    $data = [
        'name'  => 'thinkphp',
        'age'   => 10,
        'email' => 'thinkphp@qq.com',
    ];

    try {
        validate(app\validate\User::class)
            ->scene('edit')
            ->check($data);
    } catch (ValidateException $e) {
        // 验证失败 输出错误信息
        dump($e->getError());
    }

    // 静态方法验证
    $validate = \yzh52521\validate\facade\Validate::rule('age', 'number|between:1,120')
    ->rule([
        'name'  => 'require|max:25',
        'email' => 'email'
    ]);

    $data = [
        'name'  => 'thinkphp',
        'email' => 'thinkphp@qq.com'
    ];

    if (!$validate->check($data)) {
        dump($validate->getError());
    }
```

更多用法可以参考6.0完全开发手册的[验证](https://www.kancloud.cn/manual/thinkphp6_0/1037623)章节

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~81 days

Recently: every ~122 days

Total

7

Last Release

1007d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15060466?v=4)[听风吹雨](/maintainers/yuanzhihai)[@yuanzhihai](https://github.com/yuanzhihai)

---

Top Contributors

[![yuanzhihai](https://avatars.githubusercontent.com/u/15060466?v=4)](https://github.com/yuanzhihai "yuanzhihai (17 commits)")

### Embed Badge

![Health badge](/badges/yzh52521-webman-validate/health.svg)

```
[![Health](https://phpackages.com/badges/yzh52521-webman-validate/health.svg)](https://phpackages.com/packages/yzh52521-webman-validate)
```

###  Alternatives

[league/commonmark

Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)

2.9k404.0M702](/packages/league-commonmark)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k96.8M2.0k](/packages/behat-behat)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[nesbot/carbon

An API extension for DateTime that supports 281 different languages.

169661.4M4.8k](/packages/nesbot-carbon)[silverstripe/framework

The SilverStripe framework

7213.5M2.5k](/packages/silverstripe-framework)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
