klapuch/validation

此包的最新版本(2.6.3)没有可用的许可信息。

验证的广泛变化

2.6.3 2019-01-01 14:11 UTC

This package is auto-updated.

Last update: 2024-08-29 04:18:08 UTC


README

Build Status Build status Coverage Status

文档

安装

composer require klapuch/validation

使用方法

单个规则

(new EmptyRule())->satified('abc'); // false
(new EmptyRule())->satified(''); // true
(new EmptyRule())->apply('abc'); // \UnexpectedValueException - 'Subject is not empty'
(new FriendlyRule(new EmptyRule(), 'Not empty!'))->apply('abc'); // \UnexpectedValueException - 'Not empty!'

链式规则

(new ChainedRule(
	new FriendlyRule(
		new NegateRule(new EmptyRule()),
		'Value can not be empty'
	),
	new LengthRule(10),
	new PassiveRule, // it does nothing
	new EmailRule(),
))->apply('abc');

以上代码表明值不能为空,值的长度必须是确切的10个字符,并且值必须是电子邮件。