PHPackages                             angletf/php-verify - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. angletf/php-verify

ActiveLibrary[HTTP &amp; Networking](/categories/http)

angletf/php-verify
==================

php参数验证器, 方便! 好用! 快捷! php validate form data, support for regex and custom error returns

3.0.1(3y ago)638MITPHP

Since May 13Pushed 3y agoCompare

[ Source](https://github.com/AngleTF/php-verify)[ Packagist](https://packagist.org/packages/angletf/php-verify)[ RSS](/packages/angletf-php-verify/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

### 安装

[](#安装)

```
composer require angletf/php-verify

```

### 引入自动加载和命名空间

[](#引入自动加载和命名空间)

```
include_once "../vendor/autoload.php";
use angletf\Verify;
```

### 注册规则&amp;错误

[](#注册规则错误)

```
const EType = new Exception("参数类型错误", 1);
const ERequire = new Exception("参数没有传入", 2);
const EFormat = new Exception("参数格式不正确", 3);
const ELen = new Exception("name参数长度不正确", 4);

$rule = [
    'age' => [
        //age参数不是必传, 如果没有传入 设置默认值为 '99'
        //也可以将默认值设置为 `NULL` 在程序中进行判断
        'required' => [
            'value' => false,
            'default' => '99',
            'error' => ERequire
        ],
    ],
    'desc' => [

    ],
    'name' => [
        //name 参数必传
        'required' => [
            'value' => true,
            'error' => ERequire
        ],
        'type' => [
            'value' => VerifyType::String,
            'error' => EType
        ],
        'regex' => [
            'value' => '/^\w+$/',
            'error' => EFormat
        ],
        'min' => [
            'value' => 1,
            'error' => ELen
        ],
        'max' => [
            'value' => 20,
            'error' => ELen
        ],
    ],
];
```

### 快速使用

[](#快速使用)

```
//伪造一个post请求
$_POST = [
    'name' => 'tao',
    'age' => '22'
];

try {

    //注册规则, 并且返回实例
    $instance = Verify::registerRule($rule);

    //第一个参数是需要验证的数组($_POST, $_GET)
    //第二个参数是需要验证哪些参数
    //第三个参数是按照第二个参数的顺序返回参数, 是一个引用类型
    //如果验证失败, 则输出规则中对应的信息
    if (!$instance->checkParams($_POST, ['name', 'age', 'desc'], $args)) {
        echo $instance->getError()->getMessage();
        return;
    }

    list($name, $age, $desc) = $args;

    var_dump($name);
    var_dump($age);
    var_dump($desc);

} catch (\Exception $e) {
    //handle an exception
    echo 'Exception: ' . $e->getMessage();
}
```

### 注册规则参数说明

[](#注册规则参数说明)

**规则名&amp;参数名**

> 规则注册接收一个二维数组

```
[
    '参数名' => [
        '验证器1' => [
            'value' => '验证器1的value',
            'error' => '当验证失败时, 验证器1返回的错误, Exception类型'
        ],
        '验证器2' => [
        ...
        ]
    ]
    ...
]
```

**required验证器**

参数名允许的值value是否为必须参数, 如果为true, 则必须传入, 如果为false, 则未传入时将赋予默认值errorException错误default默认值**type验证器**

参数名允许的值value`VerifyType::String`, `VerifyType::Float`, `VerifyType::Int`, `VerifyType::Array`, `VerifyType::Json`, `VerifyType::Base64`errorException错误**regex验证器**

参数名允许的值value正则内容errorException错误**min验证器**

参数名允许的值value参数不能小于xxx, 如果验证对象是数字类型则验证大小, 如果是字符类型则使用`utf-8`编码验证长度errorException错误**max验证器**

参数名允许的值value参数不能小于xxx, 如果验证对象是数字类型则验证大小, 如果是字符类型则使用`utf-8`编码验证长度errorException错误**len验证器**

参数名允许的值value验证参数长度, 如果验证对象是数字则转化为字符, 使用`utf-8`编码验证长度errorException错误**错误信息返回**

> 通过 checkParams 方法, 来判断验证是否通过, 如果未通过 可以打印error来获取精准的信息

```
if (!$instance->checkParams($_POST, ['name', 'age', 'desc'], $args)) {
    //返回你在规则中提供的 error => \Exception
    var_dump($instance->getError());
    return;
}
```

**Verify API**

方法类型方法介绍静态registerRule ( array rules): Verify注册规则, 并且返回实例实例checkParams (array request\_params, array check\_params, &amp;array result):bool验证参数

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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 ~1063 days

Total

2

Last Release

1132d ago

Major Versions

v2.x-dev → 3.0.12023-04-12

### Community

Maintainers

![](https://www.gravatar.com/avatar/e19a44b5b9daa51de13fce8bff9c8369f7c8fe159ae2ba78bc1d31fc9fa3b07b?d=identicon)[AngleTF](/maintainers/AngleTF)

---

Top Contributors

[![AngleTF](https://avatars.githubusercontent.com/u/30068994?v=4)](https://github.com/AngleTF "AngleTF (25 commits)")

---

Tags

checkcomposerphpverifyhttpphpgetpost

### Embed Badge

![Health badge](/badges/angletf-php-verify/health.svg)

```
[![Health](https://phpackages.com/badges/angletf-php-verify/health.svg)](https://phpackages.com/packages/angletf-php-verify)
```

###  Alternatives

[hannesvdvreken/guzzle-debugbar

A Guzzle middleware that logs requests to debugbar's timeline

76410.4k1](/packages/hannesvdvreken-guzzle-debugbar)[phpgt/fetch

Asynchronous HTTP client with promises.

3724.0k3](/packages/phpgt-fetch)[elementaryframework/water-pipe

URL routing framework and requests/responses handler for PHP

254.6k4](/packages/elementaryframework-water-pipe)

PHPackages © 2026

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