carlosv2/can
Composer 安装命令:
composer require carlosv2/can
包简介
Tool for easy and powerful data validations
README 文档
README
Tool for easy and powerful data validations.
Why
Imagine I give you this data:
$data = [
'key1' => 123,
'key2' => 'abc',
'key3' => true
];
And then I ask you to validate it according to the following constraints:
- It must be an array.
key1must contain an integer between100and200.key2must contain a non-empty string.key3must contain either a boolean or a callable.- If
key4is set, it must be an array with a maximum of3items. - It cannot have any other key.
How long would your code to validate $data be?
Using this project, it can be validated with this code:
can($data)->claim(To::beArray()
->withKey('key1')->expected(To::beInteger()->withMin(100)->withMax(200))
->withKey('key2')->expected(To::beString()->withMinLength(1))
->withKey('key3')->expected(To::beOneOf(To::beBoolean(), To::beCallable()))
->withKey('key4')->expected(To::beOptionalAnd(To::beArray()->withMaxCount(3)))
->withNoOtherKeys()
);
Install
Open a command console, enter your project directory and execute the following command to download the latest stable version of this project:
$ composer require carlosv2/can
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Documentation
Available documentation:
统计信息
- 总下载量: 1.26k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-28