mirror of
https://github.com/Respect/Validation.git
synced 2024-06-03 06:12:17 +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
785 B
PHP
36 lines
785 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;
|
|
|
|
$config = [
|
|
'host' => 1,
|
|
'password' => 'my_password',
|
|
'schema' => 'my_schema',
|
|
];
|
|
|
|
$validator = v::arrayType();
|
|
$validator->setName('Settings');
|
|
$validator->key('host', v::stringType());
|
|
$validator->key('user', v::stringType());
|
|
$validator->key('password', v::stringType());
|
|
$validator->key('schema', v::stringType());
|
|
|
|
try {
|
|
$validator->assert($config);
|
|
} catch (AllOfException $exception) {
|
|
echo $exception->getFullMessage() . PHP_EOL;
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
- These rules must pass for Settings
|
|
- host must be of type string
|
|
- user must be present
|