PHP code example of nilportugues / validator
1. Go to this page and download the library: Download nilportugues/validator 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/ */
nilportugues / validator example snippets
use \NilPortugues\Validator\Validator;
$ageValidator = Validator::create()->isInteger('age');
$result = $ageValidator->isPositive()->isBetween(18, 100, true)->validate(28);
$errors = $ageValidator->getErrors();
use \NilPortugues\Validator\ValidatorFactory;
$rules = ['positive', 'between:18:100:true'];
$ageValidator = ValidatorFactory::create('age', 'integer', $rules);
$result = $ageValidator->validate(28);
$errors = $ageValidator->getErrors();
use \NilPortugues\Validator\BaseValidator;
class AgeValidator extends BaseValidator
{
/**
* @var string
*/
protected $type = 'integer';
/**
* @var array
*/
protected $rules = [
'positive',
'between:18:100:true'
];
}
$ageValidator = new AgeValidator();
$result = $ageValidator->validate('age', 28);
$errors = $ageValidator->getErrors();
use \NilPortugues\Validator\BaseValidator;
class AgeValidator extends BaseValidator
{
/**
* @var string
*/
protected $type = 'integer';
/**
* @var array
*/
protected $rules = ['positive'];
/**
* @param array $rules
*/
public function __construct(array $rules)
{
$this->rules = array_merge($this->rules, $rules);
}
}
$ageValidator = new AgeValidator(['between:18:100:true']);
$result = $ageValidator->validate('age', 28);
$errors = $ageValidator->getErrors();
use \NilPortugues\Validator\Validator;
$age = Validator::create()->isInteger('age');
$result = $age->isPositive()->isBetween(0, 100, true)->validate(-10, true);
$translationFile = 'full/path/to/alternate-translation.php';
$validator = Validator::create($translationFile);
$stringValidator = $validator->isString('username');
$errors = $stringValidator->getErrors(); //error array in the provided language.
$validator = Validator::create();
$username = $validator->isString('username');
$username->isRequired()->validate('Nil'); //true
$username->isNotNull()->validate(''); //false
//Or combined...
$username->isRequired()->isNotNull()->validate('Nil'); //true
$validator = Validator::create();
$genderValue = $validator->isInteger('gender');
$result = true;
if (isset($gender)) {
$result = $genderValue->isNotNull()->isBetween(0, 2, true)->validate($gender);
}
return $result;
$username = Validator::create()->isString('username');
use \NilPortugues\Validator\Validator;
$string = Validator::create()->isString('propertyName');
$string->isAlphanumeric()->validate('28a'); // true
$string->isAlphanumeric()->validate('[email protected] '); // false
use \NilPortugues\Validator\Validator;
$validator = Validator::create('propertyName', 'string', ['alphanumeric']);
$validator->validate('28a'); // true
$validator->validate('[email protected] '); // false
use \NilPortugues\Validator\BaseValidator;
class FieldValidator extends BaseValidator
{
protected $type = 'string';
protected $rules = ['alphanumeric'];
}
$fieldValidator = new FieldValidator();
$fieldValidator->validate('propertyName', '28a'); //true
$fieldValidator->validate('propertyName', '[email protected] ');
$string = Validator::create()->isString('propertyName');
$string->isAlpha()->validate('Hello World'); // true
$string->isAlpha()->validate('28a'); // false
$string->isAlpha()->validate('[email protected] '); // false
$string = Validator::create()->isString('propertyName');
$string->isBetween(2, 4)->validate('Nilo'); //false
$string->isBetween(2, 4, true)->validate('Nilo'); //true
$string = Validator::create()->isString('propertyName');
$string->isCharset(['UTF-8'])->validate('Portugués'); //true
$string = Validator::create()->isString('propertyName');
$string->isAllConsonants()->validate('a'); //false
$string->isAllConsonants()->validate('bs'); //true
$string = Validator::create()->isString('propertyName');
$string->contains(123)->validate('AAAAAAA123A'); //true
$string->contains(123, true)->validate('AAAAAAA123A'); //false
$string = Validator::create()->isString('propertyName');
$string->isControlCharacters()->validate("\n\t"); //true
$string->isControlCharacters()->validate("\nHello\tWorld"); //false
$string = Validator::create()->isString('propertyName');
$string->isDigit()->validate('10'); //true
$string->isDigit()->validate('A'); //false
$string->isDigit()->validate(145.6); //false
$string = Validator::create()->isString('propertyName');
$string->endsWith('aaaA')->validate('AAAAAAAaaaA'); //true
$string->endsWith(123, true)->validate('AAAAAAA123'); //false
$string = Validator::create()->isString('propertyName');
$string->equals('hello')->validate('hello'); //true
$string->equals(1)->validate('1'); //true
$string->equals(1, true)->validate('1'); //false
$string = Validator::create()->isString('propertyName');
$string->in('a12245 asdhsjasd 63-211', true)->validate('5 asd'); //true
$string->in(122, true)->validate('a12245 asdhsjasd 63-211'); //false
$string = Validator::create()->isString('propertyName');
$string->hasGraphicalCharsOnly()->validate('arf12'); //true
$string->hasGraphicalCharsOnly()->validate("asdf\n\r\t"); //false
$string = Validator::create()->isString('propertyName');
$string->hasLength(5)->validate('abcdefgh'); //false
$string->hasLength(8)->validate('abcdefgh'); //true
$string = Validator::create()->isString('propertyName');
$string->isLowercase()->validate('strtolower'); //true
$string->isLowercase()->validate('strtolOwer'); //false
$string = Validator::create()->isString('propertyName');
$string->notEmpty()->validate('a'); //true
$string->notEmpty()->validate(''); //false
$string = Validator::create()->isString('propertyName');
$string->noWhitespace()->validate('aaaaa'); //true
$string->noWhitespace()->validate('lorem ipsum'); //false
$string = Validator::create()->isString('propertyName');
$string->hasPrintableCharsOnly()->validate("LMKA0$%_123"); //true
$string->hasPrintableCharsOnly()->validate("LMKA0$%\t_123"); //false
$string = Validator::create()->isString('propertyName');
$string->isPunctuation()->validate('&,.;'); //true
$string->isPunctuation()->validate('a'); //false
$string = Validator::create()->isString('propertyName');
$string->matchesRegex('/[a-z]/')->validate('a'); //true
$string->matchesRegex('/[a-z]/')->validate('A'); //false
$string = Validator::create()->isString('propertyName');
$string->isSlug()->validate('hello-world-yeah'); //true
$string->isSlug()->validate('-hello-world-yeah'); //false
$string->isSlug()->validate('hello-world-yeah-'); //false
$string->isSlug()->validate('hello-world----yeah'); //false
$string = Validator::create()->isString('propertyName');
$string->isSpace()->validate(' '); //true
$string->isSpace()->validate('e e'); //false
$string = Validator::create()->isString('propertyName');
$string->startsWith('aaaA')->validate('aaaAAAAAAAA'); //true
$string->startsWith(123, true)->validate('123AAAAAAA'); //false
$string = Validator::create()->isString('propertyName');
$string->isUppercase()->validate('AAAAAA'); //true
$string->isUppercase()->validate('aaaa'); //false
$string = Validator::create()->isString('propertyName');
$string->isVersion()->validate('1.0.2'); //true
$string->isVersion()->validate('1.0.2-beta'); //true
$string->isVersion()->validate('1.0'); //true
$string->isVersion()->validate('1.0.2 beta'); //false
$string = Validator::create()->isString('propertyName');
$string->isVowel()->validate('aeA'); //true
$string->isVowel()->validate('cds'); //false
$string = Validator::create()->isString('propertyName');
$string->isHexDigit()->validate(100); //true
$string->isHexDigit()->validate('h0000'); //false
$string = Validator::create()->isString('propertyName');
$string->hasLowercase()->validate('HELLOWOrLD'); //true
$string->hasLowercase(3)->validate('HeLLoWOrLD'); //true
$string->hasLowercase()->validate('HELLOWORLD'); //false
$string->hasLowercase(3)->validate('el'); //false
$string = Validator::create()->isString('propertyName');
$string->hasUppercase()->validate('hello World'); //true
$string->hasUppercase(2)->validate('Hello World'); //true
$string->hasUppercase()->validate('hello world'); //false
$string->hasUppercase(2)->validate('helloWorld'); //false
$string = Validator::create()->isString('propertyName');
$string->hasNumeric()->validate('hell0 W0rld'); //true
$string->hasNumeric(3)->validate('H3ll0 W0rld'); //true
$string->hasNumeric()->validate('hello world'); //false
$string->hasNumeric(2)->validate('h3lloWorld'); //false
$string = Validator::create()->isString('propertyName');
$string->hasSpecialCharacters()->validate('hell0@W0rld'); //true
$string->hasSpecialCharacters(2)->validate('H3ll0@W0@rld'); //true
$string->hasSpecialCharacters()->validate('hello world'); //false
$string->hasSpecialCharacters(2)->validate('h3llo@World'); //false
$string = Validator::create()->isString('propertyName');
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('[email protected] '); //true
$string->isEmail()->validate('hello.earth+moon@localhost'); //false
$string = Validator::create()->isString('propertyName');
$string->->isUrl()->validate('http://google.com'); //true
$string->->isUrl()->validate('http://google.com/robots.txt'); //true
$string->->isUrl()->validate('https://google.com'); //true
$string->->isUrl()->validate('https://google.com/robots.txt'); //true
$string->->isUrl()->validate('//google.com'); //true
$string->->isUrl()->validate('//google.com/robots.txt'); //true
$string = Validator::create()->isString('propertyName');
$string->isUUID()->validate('6ba7b810-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID()->validate('6ba7b811-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID()->validate('6ba7b812-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID()->validate('6ba7b814-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID()->validate('00000000-0000-0000-0000-000000000000'); //true
$string->isUUID(false)->validate('6ba7b810-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID(false)->validate('6ba7b811-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID(false)->validate('6ba7b812-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID(false)->validate('6ba7b814-9dad-11d1-80b4-00c04fd430c8'); //true
$string->isUUID(false)->validate('00000000-0000-0000-0000-000000000000'); //true
$string->isUUID()->validate('{6ba7b810-9dad-11d1-80b4-00c04fd430c8}'); //false
$string->isUUID()->validate('216f-ff40-98d9-11e3-a5e2-0800-200c-9a66'); //false
$string->isUUID()->validate('{216fff40-98d9-11e3-a5e2-0800200c9a66}'); //false
$string->isUUID()->validate('216fff4098d911e3a5e20800200c9a66'); //false
$string->isUUID(false)->validate('{6ba7b810-9dad-11d1-80b4-00c04fd430c8}'); //true
$string->isUUID(false)->validate('216f-ff40-98d9-11e3-a5e2-0800-200c-9a66'); //true
$string->isUUID(false)->validate('{216fff40-98d9-11e3-a5e2-0800200c9a66}'); //true
$string->isUUID(false)->validate('216fff4098d911e3a5e20800200c9a66'); //true
$integer = Validator::create()->isInteger('propertyName');
$float = $validator->isFloat('propertyName');
$integer = Validator::create()->isInteger('propertyName');
$integer->isNotZero()->validate(1); //true
$integer->isNotZero()->validate(0); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isPositive()->validate(1); //true
$integer->isPositive()->validate(-10); //false
$integer->isPositive()->validate(0); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isPositiveOrZero()->validate(1); //true
$integer->isPositiveOrZero()->validate(-10); //false
$integer->isPositiveOrZero()->validate(0); //true
$integer = Validator::create()->isInteger('propertyName');
$integer->isNegative()->validate(-10); //true
$integer->isNegative()->validate(1); //false
$integer->isNegative()->validate(0); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isNegativeOrZero()->validate(-10); //true
$integer->isNegativeOrZero()->validate(1); //false
$integer->isNegativeOrZero()->validate(0); //true
$integer = Validator::create()->isInteger('propertyName');
$integer->isBetween(10,20, false)->validate(13); //true
$integer->isBetween(10, 20, true)->validate(10); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isOdd()->validate(3); //true
$integer->isOdd()->validate(2); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isEven()->validate(2); //true
$integer->isEven()->validate(3); //false
$integer = Validator::create()->isInteger('propertyName');
$integer->isMultiple(2)->validate(4); //true
$integer->isMultiple(2)->validate(3); //false
$object = Validator::create()->isObject('propertyName');
$object->isInstanceOf('DateTime')->validate(new \DateTime()); //true
$object->isInstanceOf('DateTime')->validate(new \stdClass()); //false
$object->isInstanceOf('DateTime')->validate('a'); //false
$object = Validator::create()->isObject('propertyName');
$dummy = new Dummy();
$object->hasProperty('userName')->validate($dummy); //true
$object->hasProperty('password')->validate($dummy); //false
$object = Validator::create()->isObject('propertyName');
$dummy = new Dummy();
$object->hasMethod('getUserName')->validate($dummy); //true
$object->hasMethod('getPassword')->validate($dummy); //false
$object = Validator::create()->isObject('propertyName');
$object->hasParentClass()->validate(new Dummy()); //true
$object->hasParentClass()->validate(new \stdClass()); //false
$object = Validator::create()->isObject('propertyName');
$dummy = new Dummy(); // class Dummy extends \DateTime
$object->isChildOf('DateTime')->validate($dummy); //true
$object->isChildOf('DateTimeZone')->validate($dummy); //false
$object = Validator::create()->isObject('propertyName');
$dummy = new Dummy(); // class Dummy extends \DateTime
$object->inheritsFrom('DateTime')->validate($dummy); //true
$object->inheritsFrom('DateTimeZone')->validate($dummy); //false
$object = Validator::create()->isObject('propertyName');
$object->hasInterface('Tests\NilPortugues\Validator\Resources\DummyInterface')->validate($dummy); //true
$object->inheritsFrom('DateTimeZone')->validate($dummy); //false
$datetime = Validator::create()->isDateTime('propertyName');
$date1 = '2014-01-01 00:00:00';
$date2 = new \DateTime($date1);
$limit1 = '2013-12-31 23:59:59';
$datetime->isAfter($limit1, false)->validate($date1); // true
$datetime->isAfter($limit1, false)->validate($date2); // true
$datetime->isAfter($date1, true)->validate($date1); // true
$datetime->isAfter($date2, true)->validate($date2); // true
$limit2 = '2015-01-01 00:00:00';
$datetime->isAfter($limit2)->validate($date1); // false
$datetime->isAfter($limit2)->validate($date2); // false
$datetime = Validator::create()->isDateTime('propertyName');
$date1 = '2012-01-01 00:00:00';
$date2 = new \DateTime($date1);
$limit1 = '2013-12-31 23:59:59';
$datetime->isBefore($limit1, false)->validate($date1); // true
$datetime->isBefore($limit1, false)->validate($date2); // true
$datetime->isBefore($date1, true)->validate($date1); // true
$datetime->isBefore($date2, true)->validate($date2); // true
$limit2 = '2010-01-01 00:00:00';
$datetime->isBefore($limit2)->validate($date1); // false
$datetime->isBefore($limit2)->validate($date2); // false
$datetime = Validator::create()->isDateTime('propertyName');
$date1 = '2014-01-01 00:00:00';
$date2 = new \DateTime($date1);
$minDate = '2013-01-01 00:00:00';
$maxDate = '2015-01-01 00:00:00';
$datetime->isBetween($minDate, $maxDate, false)->validate($date1); // true
$datetime->isBetween($minDate, $maxDate, false)->validate($date2); // true
$datetime->isBetween($minDate, $maxDate, true)->validate($date1); // true
$datetime->isBetween($minDate, $maxDate, true)->validate($date2); // true
$minDate = '2013-12-01 00:00:00';
$maxDate = '2013-12-30 00:00:00';
$datetime->isBetween($minDate, $maxDate, false)->validate($date1); // false
$datetime->isBetween($minDate, $maxDate, true)->validate($date1); // false
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isWeekend()->validate('2014-09-20'); // true
$datetime->isWeekend()->validate('2014-09-22'); // false
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isWeekday()->validate('2014-09-20'); // false
$datetime->isWeekday()->validate('2014-09-22'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isMonday()->validate('2014-09-22'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isTuesday()->validate('2014-09-23'); // true
$validator = Validator::create();
$datetime = $validator->isDateTime('propertyName');
$datetime->isWednesday()->validate('2014-09-24'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isThursday()->validate('2014-09-25'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isFriday()->validate('2014-09-26'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isSaturday()->validate('2014-09-27'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime->isSunday()->validate('2014-09-28'); // true
$datetime = Validator::create()->isDateTime('propertyName');
$date = new \DateTime('now');
$datetime->isToday()->validate($date); // true
$datetime = Validator::create()->isDateTime('propertyName');
$date = new \DateTime('now -1 day');
$datetime->isYesterday()->validate($date); // true
$datetime = Validator::create()->isDateTime('propertyName');
$date = new \DateTime('now +1 day');
$datetime->isTomorrow()->validate($date); // true
$datetime = Validator::create()->isDateTime('propertyName');
$date = new \DateTime('2016-01-01');
$datetime->isLeapYear()->validate($date); // true
$datetime = Validator::create()->isDateTime('propertyName');
$datetime = Validator::create()->isDateTime('propertyName');
$datetime = Validator::create()->isDateTime('propertyName');
$datetime = Validator::create()->isDateTime('propertyName');
$validator = Validator::create();
$collection = $validator->isArray('propertyName');
$valueIsString = $validator->isString('value')->isAlpha();
$keyIsInteger = $validator->isInteger('key')->isPositive();
$array = ['hello','world'];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray($array);
$collection->each($valueIsString)->validate($array); //true
$collection->each($valueIsString, $keyIsInteger)->validate($array); //true
$collection->each($valueIsString)->validate($arrayObject); //true
$collection->each($valueIsString, $keyIsInteger)->validate($arrayObject); //true
$collection->each($valueIsString)->validate($fixedArray); //true
$collection->each($valueIsString, $keyIsInteger)->validate($fixedArray); //true
$validator = Validator::create();
$collection = $validator->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 'world'];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$keyIsString = $validator->isString('key')->isAlpha();
$keyIsInteger = $validator->isInteger('key')->isPositive();
$collection->hasKeyFormat($keyIsString)->validate($array); //true
$collection->hasKeyFormat($keyIsString)->validate($arrayObject); //true
$collection->hasKeyFormat($keyIsInteger)->validate($fixedArray); //true
$collection = Validator::create()->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 1];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->endsWith('1')->validate($array); //true
$collection->endsWith('1')->validate($arrayObject); //true
$collection->endsWith('1')->validate($fixedArray); //true
$collection->endsWith('1', true)->validate($array); //false
$collection->endsWith('1', true)->validate($arrayObject); //false
$collection->endsWith('1', true)->validate($fixedArray); //false
$collection = Validator::create()->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 1];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->contains('hello')->validate($array); //true
$collection->contains('hello')->validate($arrayObject); //true
$collection->contains('hello')->validate($fixedArray); //true
$collection->contains(1, true)->validate($array); //true
$collection->contains(1, true)->validate($arrayObject); //true
$collection->contains(1, true)->validate($fixedArray); //true
$collection = Validator::create()->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 1];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->hasKey('one')->validate($array)); //true
$collection->hasKey('one')->validate($arrayObject)); //true
$collection->hasKey(0)->validate($fixedArray)); //true
$array = [];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->hasKey(0)->validate($array)); //false
$collection->hasKey(0)->validate($arrayObject)); //false
$collection->hasKey(0)->validate($fixedArray)); //false
$collection = Validator::create()->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 1];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->hasLength(2)->validate($array)); //true
$collection->hasLength(2)->validate($arrayObject)); //true
$collection->hasLength(2)->validate($fixedArray)); //true
$array = [];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->hasLength(0)->validate($array)); //true
$collection->hasLength(0)->validate($arrayObject)); //true
$collection->hasLength(0)->validate($fixedArray)); //true
$collection = Validator::create()->isArray('propertyName');
$array = ['one' => 'hello', 'two' => 1];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->isNotEmpty()->validate($array)); //true
$collection->isNotEmpty()->validate($arrayObject)); //true
$collection->isNotEmpty()->validate($fixedArray)); //true
$array = [];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray(array_values($array));
$collection->isNotEmpty()->validate($array)); //false
$collection->isNotEmpty()->validate($arrayObject)); //false
$collection->isNotEmpty()->validate($fixedArray)); //false
$collection = Validator::create()->isArray('propertyName');
$array = [1, 2, 3];
$arrayObject = new \ArrayObject($array);
$fixedArray = (new \SplFixedArray())->fromArray($array);
$collection->startsWith(1)->validate($array)); //true
$collection->startsWith(1)->validate($arrayObject)); //true
$collection->startsWith(1)->validate($fixedArray)); //true
$collection->startsWith('1', true)->validate($array)); //false
$collection->startsWith('1', true)->validate($arrayObject)); //false
$collection->startsWith('1', true)->validate($fixedArray)); //false
$fileValidator = Validator::create()->isFileUpload('image');
$fileValidator
->isBetween(0, 3, 'MB', true)
->isMimeType(['image/png', 'image/gif', 'image/jpeg'])
->hasValidUploadDirectory('./uploads/images')
->notOverwritingExistingFile('./uploads/images')
->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->isBetween(1, 3, 'MB', true)->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->isMimeType(['image/png', 'image/gif', 'image/jpeg'])->validate('image');
$validator = Validator::create();
$file = $validator->isFileUpload('image');
$stringValidator = $validator->isString('image')->isAlpha();
$file->hasFileNameFormat($stringValidator)->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->hasValidUploadDirectory('./uploads/images')->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->notOverwritingExistingFile('./uploads/images')->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->hasLength(1)->validate('image');
$file = Validator::create()->isFileUpload('image');
$file->isImage()->validate('image');
bash
php composer.phar install --dev
php bin/phpunit