2017 © Pedro Peláez
 

library simple-validator

To simple validations in PHP.

image

gabrieljmj/simple-validator

To simple validations in PHP.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Simple Validator

Total Downloads Latest Unstable Version License Quality, (*1)

To simple validations in PHP., (*2)

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

SimpleValidatorException

This is the exception that is thrown when one validation to fail and the exception are enabled., (*4)

SimpleValidatorException::getInvalidParameterName() Return what validation failure, (*5)

Validations list

  • Arr Verify if element is an array
  • Boolean Verify if element is a boolean
  • Callable Verify if element is a callable
  • Cpf Verify if element is a Cpf
  • Directory Verify if element is a directory
  • Double Verify if element is a duble
  • Email Verify if element is an email
  • Equal Verify if element is equal to another
  • File Verify if element is a file
  • Float Verify if element is a float
  • Func Verify if element is a function
  • Int Verify if element is an integer
  • Lenght Verify if element is the specified size
  • MaximumLenght Verify if element have the maximum specified size
  • Method Verify if element is a class's method
  • MinimumLenght Verify if element have the minimum specified size
  • NotEmpty Verify if element is not empty
  • Null Verify if element is null
  • Numeric Verify if element is numeric
  • Object Verify if element is an object
  • String Verify if element is a string
  • Url Verify 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
}

The Versions

29/07 2014

dev-master

9999999-dev https://github.com/GabrielJMJ/simple-validator

To simple validations in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

library