gabrieljmj / simple-validator
To simple validations in PHP.
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
pkg:composer/gabrieljmj/simple-validator
Requires
- php: >=5.3.0
 
This package is auto-updated.
Last update: 2022-02-01 12:35:34 UTC
README
To simple validations in PHP. ##Autoload ####Via composer
{
    "psr-4": {
        "SimpleValidator\\": "vendor/gabrieljmj/simple-validator/lib/SimpleValidator/"
    }
}
####Autoload file
require_once SIMPLE_VALIDATOR_DIR . DIRECTORY_SEPARATOR . 'autoload' . DIRECTORY_SEPARATOR . 'autoload.php'
##Validations ####Chain The implementation will be in a chain, where you'll show what the next validation for that element. ####SimpleValidatorException This is the exception that is thrown when one validation to fail and the exception are enabled.
SimpleValidatorException::getInvalidParameterName()
Return what validation failure
####Validations list
ArrVerify if element is an arrayBooleanVerify if element is a booleanCallableVerify if element is a callableCpfVerify if element is a CpfDirectoryVerify if element is a directoryDoubleVerify if element is a dubleEmailVerify if element is an emailEqualVerify if element is equal to anotherFileVerify if element is a fileFloatVerify if element is a floatFuncVerify if element is a functionIntVerify if element is an integerLenghtVerify if element is the specified sizeMaximumLenghtVerify if element have the maximum specified sizeMethodVerify if element is a class's methodMinimumLenghtVerify if element have the minimum specified sizeNotEmptyVerify if element is not emptyNullVerify if element is nullNumericVerify if element is numericObjectVerify if element is an objectStringVerify if element is a stringUrlVerify if element is an URL
##Implemeting ####Enabled exception
use SimpleValidator\Validator\NotEmpty; use SimpleValidator\Validator\Url; use SimpleValidator\Exception\SimpleValidatorException; //... $url = 'http://example.com'; $validator = new NotEmpty; // verify if string is not empty $validator->setSucessor( new Url ); // verify if string is an URL try{ $validator->validate( $url, true ); // realize all validations predefined }catch( SimpleValidatorException $e ){ echo '<b>Error:</b> ' . $e->getMessage() . '<br /> <b>On test:</b> ' . $e->getInvalidParameterName(); }
####Disabled exception
use SimpleValidator\Validator\NotEmpty; use SimpleValidator\Validator\Url; //... $url = 'http://example.com'; $validator = new NotEmpty; // verify if string is not empty $validator->setSucessor( new Url ); // verify if string is an URL if( $validator->validate( $url ) ){ // realize all validations predefined //Success }{ //Fail }