melhorenvio / range-validator
Installs: 2 261
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 6
Forks: 0
Open Issues: 0
Requires
- php: >= 7.1
Requires (Dev)
- orchestra/testbench: 3.8.*|4.*|5.*|6.*
- phpunit/phpunit: ^7.0
This package is auto-updated.
Last update: 2024-10-27 21:21:15 UTC
README
This package has the objective of validate an array of ranges passed and define the invalid ranges with a message and code of the respective error. However, if there isn't problems with the ranges passed, the method will define a success message.
Installation
You can install the package via composer:
composer require melhorenvio/range-validator
Usage
First you need to instantiate a variable of the RangeValidator type.
$rangeValidator = new RangeValidator();
You will need to set the RangeValidator dependencie.
use Melhorenvio\RangeValidator\RangeValidator;
The setRanges() and addRanges() methods accept a parameter, this paramater must be an array in the format showed below.
$ranges = [ 'begin' => '12345678', 'end' => '87654321' ];
The "begin" and "end" values must be of the String or Integer type, otherwise will be showed an error message instead the invalid ranges.
The setRanges() method will define the ranges with the value passed as parameter, it will overwrite others already setted ranges.
$rangeValidator->setRanges($range);
The addRanges() method do the same as the setRanges() function, but it wont overwrite others already setted ranges.
$rangeValidator->addRanges($range);
The checkEmpty() method set the response with the ranges with empty values.
$rangeValidator->checkEmpty();
The checkBeginBiggerThanEnd() method set the response with the ranges with begin value bigger than the end value.
$rangeValidator->checkBeginBiggerThanEnd();
The checkRepeated() method set the response with the ranges that are found more than just one time.
$rangeValidator->checkRepeated();
The checkOverlapping() method set the response with the ranges that are overlapping others ranges.
$rangeValidator->checkOverlapping();
The useAirport() method will make the validator consider whether the ranges are of the same airport when looking for overlapping. If the ranges are of the same airport, the validator will disconsider the overlapping.
$rangeValidator->useAirport();
In this case, if the useAirport method is enable, the setRanges() and addRanges()'s parameters will change, because the string parameter 'airport' will be added. So the array's format will be like showed below.
$ranges = [ 'begin' => '12345678', 'end' => '87654321', 'airport' => 'AirportOne' ];
The validate() method will really validate the ranges and return the response, without this method the validation won't work. If you set one or more of the check methods above, the validator will consider just the setted attributes, if you don't set anyone of them so the validator will consider all attributes.
$rangeValidator->validate();
The getResponse() method will return the response attribute in array form.
$rangeValidator->getResponse();
The getRanges() method will return the ranges attribute in array form.
$rangeValidator->getRanges();
The response attribute will be an array of arrays with a "message", "code" and, if it has, a "data" attribute as showed below.
[ 'message' => String, 'code' => Int, 'data' => Array ]
If the getResponse() or getRanges() methods not be used, so the methods will return an object instance of the RangeValidator.