morfu/validator
最新稳定版本:0.1.0
Composer 安装命令:
composer require morfu/validator
包简介
Composable pipeline of validators.
README 文档
README
NOT for production. API is NOT stable.
Example
use Morfu\Validator\ValidatorPipeline;
$badFormData = [
'username' => 'Ali_Baba',
'password' => 'ope sesme',
'confirmPassword' => 'open sesame',
];
$passValidator = (new ValidatorPipeline())
->check(function ($length, $min) {
return $length >= $min;
})->message('Password length should be at least %min%.')
->param('min', 10)
->param('length', 'strlen')
->check(function ($input) {
return (bool) preg_match('/\d+/', $input);
})->message('Password should contain digits.')
->check(function ($input) {
return (bool) preg_match('/[[:punct:]]+/', $input);
})->message('Password should contain punctuation marks.');
$formValidator = (new ValidatorPipeline())
->checkField('password', $passValidator)
->check(function ($password, $confirmPassword) {
return $password === $confirmPassword;
})->message('Password and confirm password does not match.');
array_column($formValidator->getErrors($badFormData), 'message');
// => [
// 'Password length should be at least 10.',
// 'Password should contain digits.',
// 'Password should contain punctuation marks.',
// 'Password and confirm password does not match.',
//];
$formData = array_merge($badFormData, [
'password' => 'open_sesame11',
'confirmPassword' => 'open_sesame11',
]);
$formValidator->isValid($formData);
// => true
For further examples see tests/.
What is Morfu
Morfu (from Ancient Greek: μετᾰμορφόω, metamorphóō, "transform") is a set of pipeline-oriented PHP libraries.
What is Validator
Validator is a library of Morfu that provides composable pipeline of validators.
Install
Via Composer
$ composer require morfu/validator
Testing
$ make test
Security
If you discover any security related issues, please email kilych@zoho.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-17