1. Go to this page and download the library: Download phramework/validate 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/ */
phramework / validate example snippets
use \Phramework\Validate\IntegerValidator;
$validator = new IntegerValidator(-1, 1);
$value = $validator->parse('0');
var_dump($value);
$personalInformationValidator = new ObjectValidator(
(object) [
'name' => new StringValidator(2, 30),
'city' => new StringValidator(2, 30),
'age' => new IntegerValidator(1, 200),
],
['name', 'city', 'age'], //
/*
* A validator that allows you to pick one or two colors between blue, green and red
*/
$colorsValidator = new ArrayValidator(
1, //minItems
2, //maxItems
(new StringValidator()) //items
->setEnum([
'blue',
'green',
'red',
]),
true //unique items
);
/*
* $parsedOneItem will be validated successfully
*/
$parsedOneItem = $colorsValidator->parse(['blue']); //will be [blue]
/*
* $parsedTwoItems will be validated successfully
*/
$parsedTwoItems = $colorsValidator->parse(['blue', 'red']); //will be [blue, red]
/*
* $resultOfZeroItemsStatus cannot be validated true the validator ltOfIncorrectItemsStatus->getException();
$exception->getFailure(); // will be items
/*
* Following will throw \Phramework\Exceptions\IncorrectParameterException
* with failure maxItems because validator
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.