rossriley / validation
数据验证库。使用简单的API验证数组、数组对象、域模型等。轻松添加自己的验证器,基于已经构建的几十个内置验证规则。此分支维护PHP 5.3兼容性。
1.2.1
2014-06-23 18:21 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: 3.7
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-10 03:04:49 UTC
README
#Sirius Validation
Sirius Validation是一个数据验证库。它提供以下功能:
- 验证器对象,用于验证数组、
ArrayObjects
或具有toArray
方法的对象。它可以轻松扩展以验证其他类型。 - 值验证器对象,用于验证单个值
- 验证辅助器,用于简化单个值的验证(不生成错误消息,仅返回TRUE/FALSE)
- 内置验证规则,用于执行实际的数据验证。验证规则由辅助器和验证器对象使用。
默认情况下,该库可以处理array
、ArrayObject
以及实现了toArray
方法的对象。为了验证其他数据容器,您必须创建一个DataWrapper
,以便验证器能够从您的对象中提取数据。
##简介
$validation = new \Sirius\Validation\Validator; // add a validation rule $validator->add('title', 'required'); // add a rule that has a list of options $validator->add('title', 'maxlength', array('max' => 100)); // or use JSON $validator->add('title', 'maxlength', '{"max": 100}'); // or a URL query string $validator->add('title', 'maxlength', 'max=100'); // add a rule with a custom error message $validator->add('title', 'maxlength', 'max=100', 'Article title must have less than {max} characters'); // add a rule with a custom message and a label (very handy with forms) $validator->add('title', 'maxlength', 'max=100', '{label} must have less than {max} characters', 'Title'); // add all of rule's configuration in a string (you'll see later why it's handy') $validator->add('title', 'maxlength(max=255)({label} must have less than {max} characters)(Title)'); // add multiple rules at once (separate using [space][pipe][space]) $validator->add('title', 'required | maxlength(max=255) | minlength(min=10)'); // add all your rules at once $validator->add(array( 'title' => 'required | maxlength(max=10)({label} must have less than {max} characters)(Title)', 'content' => 'required', 'source' => 'website' )); // add nested rules $validator->add('recipients[*]', 'email'); //all recipients must be valid email addresses $validator->add('shipping_address[city]', 'MyApp\Validator\City'); // uses a custom validator to validate the shipping city
##文档
发行说明
1.1
- 添加了HHVM到Travis CI
- 将Validator*类重命名为Rule*类(如果您使用了自定义规则类,则会造成破坏性更改)
- 将ValidatorFactory重命名为RuleFactory(破坏性更改)