qlimix / validation
单独或按组验证数据
3.0.0
2021-02-22 20:26 UTC
Requires
- php: >7.4
Requires (Dev)
- infection/infection: ^0.21
- qlimix/code-standard: ^3.0
This package is auto-updated.
Last update: 2024-09-23 04:10:33 UTC
README
单独或按组验证数据。
安装
使用 Composer
$ composer require qlimix/validation
用法
示例 1 收集
[ { "foo": "bar", "foobar": { "bar": 1, "foo": "example" } }, { "foo": "foo", "foobar": { "bar": 2, "foo": "example1" } } ]
<?php use Qlimix\Validation\CollectionValidation; use Qlimix\Validation\Inspector\HashInspector; use Qlimix\Validation\Inspector\KeyInspector; use Qlimix\Validation\Key; $example1 = new CollectionValidation([ new HashInspector([new Key('foo', true, [])]), // add validators new KeyInspector('foobar', true, [ new HashInspector([ new Key('bar', true, []), // add validators new Key('foo', true, []), // add validators ]) ]) ]);
示例 2 关键值
{ "foo": "foobar", "foobar": { "bar": 42, "foo": "example2" } }
<?php use Qlimix\Validation\Inspector\HashInspector; use Qlimix\Validation\Inspector\KeyInspector; use Qlimix\Validation\InspectorValidation; use Qlimix\Validation\Key; $example2 = new InspectorValidation([ new HashInspector([new Key('foo', true, [])]), // add validators new KeyInspector('foobar', true, [ new HashInspector([ new Key('bar', true, []), // add validators new Key('bar', true, []), // add validators ]) ]) ]);
测试
要本地运行所有单元测试,请使用 PHPUnit
$ vendor/bin/phpunit
质量
为了确保代码质量,运行 grumphp,它将运行所有工具
$ vendor/bin/grumphp run
贡献
有关详细信息,请参阅 CONTRIBUTING