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)mitPHPPHP &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 today

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

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

22

—

LowBetter than 25% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

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

955d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/052aa4acd90ad5d672ae5abe8d27d1f576f9c07e1967e2f6bced03b84079310f?d=identicon)[yuanzhihai](/maintainers/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

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.3k184.5M2.4k](/packages/composer-composer)[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k591.0M4.7k](/packages/vlucas-phpdotenv)[league/commonmark

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

2.9k393.7M556](/packages/league-commonmark)[behat/behat

Scenario-oriented BDD framework for PHP

4.0k95.0M1.8k](/packages/behat-behat)[php-http/client-common

Common HTTP Client implementations and tools for HTTPlug

1.0k221.5M509](/packages/php-http-client-common)[sentry/sentry-symfony

Symfony integration for Sentry (http://getsentry.com)

73759.8M52](/packages/sentry-sentry-symfony)

PHPackages © 2026

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