district5/validatorgroup
最新稳定版本:2.0.1
Composer 安装命令:
composer require district5/validatorgroup
包简介
District5 Validator Group Library
README 文档
README
Validator group for validating form and json body data.
Usage
Validation Group
Create a class and extend \District5\ValidatorGroup\Group, adding fields to be validated against.
/** * Creates a new instance of AuthValidationGroup */ public function __construct() { $stringTrim = new StringTrim(); $this->addField('username', [new StringLength(['min' => 4, 'max' => 254])], [$stringTrim], true); $this->addField('password', [new StringLength(['min' => 6, 'max' => 64])], [$stringTrim], true); $this->addField('device_id', [new StringLength(['min' => 6, 'max' => 64])], [], true); }
Validating
This can then be used in a route, with a handler, for example with the following code:
$request = $app->request(); $vg = new \Project\Validate\Group\AuthAuthValidationGroup();
The validation group can be used to validate against any custom data with the correct handler; the library as a default ships with a JSON handler:
$handler = new \District5\ValidatorGroup\Handler\JSON($request->getBody()); $valid = $vg->isValid($handler);
Custom Handlers
You can create your own handlers by implementing the \District5\ValidationGroup\Handler\HandlerInterface and passing this into the ValidationGroup.
Errors
If validation failed, the validation group will give you some hint as to why it failed by calling:
$vg->getLastErrorMessage();
统计信息
- 总下载量: 123
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: mit
- 更新时间: 2024-03-25