定制 graze/config-validation 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

graze/config-validation

Composer 安装命令:

composer require graze/config-validation

包简介

validate and populate arrays and objects

README 文档

README

Latest Version on Packagist Software License CI Coverage Status Quality Score Total Downloads

Config Validation checks an input against a code defined schema for validation using short notation syntax.

It then populates optional fields with default data.

Install

Via Composer

composer require graze/config-validation

Usage

Long path definition

use Respect\Validation\Validator as v;

$validator = (new ArrayValidator())
    ->required('key', v::stringType())
    ->optional('parent.child', v::intVal(), 1)
    ->optional('parent.second', v::stringType()->date());

Using children

$validator = Validator::arr()
    ->required('key', v::stringType())
    ->addChild('parent', Validator::arr()
        ->optional('child', v::intVal(), 1)
        ->optional('second', v::stringType()->date()
    );

Validating with your validator

function thing (array $input) {
    return $validator->validate($input);
}

thing(['key' => 'value'])
// ['key' => 'value', 'parent' => ['child' => 1, 'second' => null]]
thing();
// throws new ConfigValidationFailed
thing(['key' => 'input', ['parent' => ['child' => 2]])
// ['key' => 'input', ['parent' => ['child' => 2, 'second' => null]]
thing(['key' => 'input', ['parent' => ['second' => '111']])
// throws new ConfigValidationFailed('expected data for parent.second')
thing(['key' => 'input', ['parent' => ['second' => 

Validating array items with variable keys

$childValidator = Validate::object()
    ->required('key->item', v::intVal()->min(2)->max(4))
    ->optional('key->second', v::stringType(), 'name');
$validator = Validate::object()
    ->required('items', v::arrayVal()->each(
        $childValidator->getValidator()
    ));

function thing ($input) {
    return $validator->validate($input);
}

thing((object) ['items' => [
    (object) ['key' => 3],
    ]]);
// (object) ['items' => [
//     (object) ['key' => (object) ['item' => 3, 'second' => 'name']]
// ]]

Testing

make build test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email security@graze.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 977
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 10
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固