mirror of
https://github.com/Respect/Validation.git
synced 2024-06-26 17:20:16 +02:00
029fa7fe73
Most Validation errors are sent to Users/Visitors or Clients and as such might not need to know it was a Key their inputs are being validated upon. Co-authored-by: Henrique Moody <henriquemoody@gmail.com> Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
36 lines
791 B
PHP
36 lines
791 B
PHP
--CREDITS--
|
|
Henrique Moody <henriquemoody@gmail.com>
|
|
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Exceptions\AllOfException;
|
|
use Respect\Validation\Validator as v;
|
|
|
|
$validator = v::create()
|
|
->key('age', v::intType()->notEmpty()->noneOf(v::stringType()))
|
|
->key('reference', v::stringType()->notEmpty()->length(1, 50));
|
|
|
|
try {
|
|
$validator->assert(['age' => 1]);
|
|
} catch (AllOfException $e) {
|
|
echo $e->getFullMessage();
|
|
}
|
|
|
|
echo PHP_EOL;
|
|
|
|
try {
|
|
$validator->assert(['reference' => 'QSF1234']);
|
|
} catch (AllOfException $e) {
|
|
echo $e->getFullMessage();
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
- These rules must pass for `{ "age": 1 }`
|
|
- reference must be present
|
|
- These rules must pass for `{ "reference": "QSF1234" }`
|
|
- age must be present
|