承接 district5/validatorgroup 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: mit
  • 更新时间: 2024-03-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固