定制 simonisme/validator 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

simonisme/validator

Composer 安装命令:

composer require simonisme/validator

包简介

README 文档

README

How to use one validator?

$validator = new IsEmailValidator();
$result = $validator->valid('email@gmail.com');

//  $result contains 0 when evrything is ok
//  or value > 1 otherwise

How to check value with many validators?

validThroughAllValidators() method checks given value in ALL validators.

$collection = new ValidatorsCollection(
    [
        new IsNotNullValidator(),
        new IsEmailValidator(),
    ]
);

$result = $collection->validThroughAllValidators('email@gmail.com');

$result->isValid();     // returns true if value is passed thought all validators
$result->errors();      // returns array of error numbers for each of not-passed validators

validToFirstError() method checks given value in all validators TO FIRST FAIL.

$collection = new ValidatorsCollection(
    [
        new IsNotNullValidator(),
        new IsEmailValidator(),
    ]
);

$result = $collection->validToFirstError('email@gmail.com');

$result->isValid();     // returns true if value is passed thought all validators
$result->errors();      // returns array of error numbers (in this case there will be only single element in array) for each of not-passed validators

How to check array of values?

You can create array full of validators. This array can contain nested validators arrays:

$validators = [
    "email" => new IsEmailValidator(),
    "age" => new IsNumberValidator()
];

This $validators array can be used to validate $data array:

$data = [
    "email" => "incorrect email address",
    "age" => 35
];

$arrayValidator = mew ArrayValidator(); 
$result = $arrayValidator->validateArray($validators, $data);

$result variable contains ValidationResult objects. ValidationResult::errors() returns nested array with error codes.

For more example look into ./tests/unit/ArrayValidatorTest.php

LIST OF VALIDATORS

  • IsBoolValidator
  • IsDateTimeValidator
  • IsDateValidator
  • IsEmailValidator
  • IsIntegerValidatorTest
  • IsNotNullValidator
  • IsNullValidator
  • IsNumberEqualValidator
  • IsNumberGreaterOrEqualValidator
  • IsNumberGreaterThanValidator
  • IsNumberInExclusiveRangeValidator
  • IsNumberInInclusiveRangeValidator
  • IsNumberLessOrEqualValidator
  • IsNumberLessThanValidator
  • IsNumberValidator
  • IsSetValidator
  • IsStringValidator
  • IsTimeValidator
  • IsUrlValidator
  • IsValueFromSetValidatorTest
  • StringLengthValidator
  • SetValidator

License

MIT (https://en.wikipedia.org/wiki/MIT_License)

统计信息

  • 总下载量: 271
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固