2017 © Pedro Peláez
 

library validator

image

simonisme/validator

  • Sunday, September 17, 2017
  • by SimonIsMe
  • Repository
  • 1 Watchers
  • 0 Stars
  • 254 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 5 % Grown

The README.md

Validators

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., (*1)

$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., (*2)

$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:, (*3)

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

This $validators array can be used to validate $data array:, (*4)

$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., (*5)

For more example look into ./tests/unit/ArrayValidatorTest.php, (*6)

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), (*7)

The Versions

17/09 2017

dev-master

9999999-dev https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

17/09 2017

2.5.1

2.5.1.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

17/09 2017

2.5.0

2.5.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

17/09 2017

2.4.0

2.4.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

12/09 2017

2.3.0

2.3.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

09/09 2017

2.2.0

2.2.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

09/09 2017

2.1.0

2.1.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

09/09 2017

2.0.0

2.0.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

03/09 2017

1.2.0

1.2.0.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

03/09 2017

1.1.1

1.1.1.0 https://github.com/SimonIsMe/Validator

  Sources   Download

MIT

The Requires

  • php >=7.0.0

 

The Development Requires

15/07 2017