1. Go to this page and download the library: Download juanchosl/validators library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$validator = new StringValidations();
$validator
->is()
->isNotEmpty()
->isValueEqualsAny('juan','pepe','antonio');
$validator('juan'); //true
$datas = [
["nombre" => "pepe", "apellidos" => "salmuera", "email" => "[email protected]", "telephone" => 123456789],
["nombre" => "juan", "apellidos" => "benito", "email" => "[email protected]", "telephone" => 123456789],
];
// Option 1
$validator = new EntityValidations();
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));
foreach($datas as $data){
$result = $validator($data);// We have the unitary result or each element
if($result === true){
...//our code execution
}
}
//Option 2
$validator = new CollectionValidations();
$validator->isValueAttributeValidating('email', (new StringValidations())->isEmail());
$validator->isValueAttributeValidating('telephone', (new IntegerValidations())->isLengthGreatherOrEqualsThan(9)->isLengthLessOrEqualsThan(12));
$validator($datas);//We have the global result, for all elements