PHP code example of lemmon / validator
1. Go to this page and download the library: Download lemmon/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/ */
lemmon / validator example snippets
use Lemmon\Validator\ValidationException;
use Lemmon\Validator\Validator;
$input = [
'name' => 'Ada Lovelace',
'age' => '36',
'email' => '[email protected]',
];
$userSchema = Validator::isAssociative([
'name' => Validator::isString()
->pipe('trim')
->notEmpty()
-> {
foreach ($errors as $error) {
echo $error->getPath() . ': ' . $error->getMessage() . PHP_EOL;
}
}
// Exception workflow
try {
$user = $userSchema->validate($input);
} catch (ValidationException $exception) {
$allErrors = $exception->getErrors();
$emailErrors = $exception->getErrors('email');
}