PHPackages                             liyuze/parameter-validator - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. liyuze/parameter-validator

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

liyuze/parameter-validator
==========================

参数和变量的数据类型和格式验证。

120PHP

Since Jul 15Pushed 7y ago1 watchersCompare

[ Source](https://github.com/liyuze/validator)[ Packagist](https://packagist.org/packages/liyuze/parameter-validator)[ RSS](/packages/liyuze-parameter-validator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

简介
==

[](#简介)

PHP 语言的参数验证器和挂载器。

安装
==

[](#安装)

```
//file:compose.json
{
    "require": {
        "liyuze/parameter-validator": "dev-master"
    }
}
```

```
compose update
```

或

```
compose require liyuze/parameter-validator dev-master
```

示例
==

[](#示例)

参数集合对象初始化
---------

[](#参数集合对象初始化)

1. 单一指定

    ```
    function func ($name, $age) {
        $Parameters = new liyuze\validator\Parameters\Parameters([
            'name' => $name,
            'age'> $age,
        ]);
    }
    ```
2. 数组指定

    ```
    $Parameters = new liyuze\validator\Parameters\Parameters($_POST);
    ```

验证器
---

[](#验证器)

### 验证规则设置

[](#验证规则设置)

1. 设置验证规则

    ```
    $Parameters->setRule([
        'name' => 'required|string|maxLength=15|minLength=5',
        'age' => 'integer|max=120|min=1'
    ]);
    ```
2. 参数和验证规则一同设置

    ```
    $name = $_POST['name'];
    $age = $_POST['age'];

    $Parameters = new liyuze\validator\Parameters\Parameters();
    $Parameters->config([
        'name' => [$name, ['required', 'string', 'maxLength' => 15, 'minLength' => 5]],
        'age' => [$age, ['integer', 'max' => 120, 'min' => 1]]
    ]);
    ```

### 验证和验证消息

[](#验证和验证消息)

```
if ($Parameters->validate()) {
    //所有验证消息
    $Parameters->getErrors();
}
```

### 验证消息

[](#验证消息)

挂载器
---

[](#挂载器)

### 新增自定义挂载器

[](#新增自定义挂载器)

```
/**
 * 由年龄获取生肖、出生年份
 */
class AgeMounter extends liyuze\validator\Mounter\Mounter {

    public function registerKeys()
    {
        //挂载值的变量名
        return ['year', 'zodiac']
    }

    public function run()
    {
        //参数值
        $value = $this->getParameter()->getValue();
        //计算值
        $year = 2018;
        $zodiac = 'dog';
        //挂载值
        return [
            'year' => $year,
            'zodiac' => $zodiac
        ]
    }
}
```

### 挂载器配置

[](#挂载器配置)

```
$Parameters->addMounter('age', 'mounter\AgeMounter')
```

### 获取挂载值

[](#获取挂载值)

```
//获取出生年份
$year = $Parameters->getMounteValue('age', 'year');

//获取属相
$zodiac = $Parameters->getParam('age')->getMounteValue('zodiac');
```

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

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.

### Community

Maintainers

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

---

Top Contributors

[![liyuze](https://avatars.githubusercontent.com/u/4597092?v=4)](https://github.com/liyuze "liyuze (57 commits)")

---

Tags

paramatersphpvalidatorvariables

### Embed Badge

![Health badge](/badges/liyuze-parameter-validator/health.svg)

```
[![Health](https://phpackages.com/badges/liyuze-parameter-validator/health.svg)](https://phpackages.com/packages/liyuze-parameter-validator)
```

###  Alternatives

[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

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