mirror of
https://github.com/Respect/Validation.git
synced 2024-06-03 06:12:17 +02:00
642602fd43
Some amazing features had to be ignored because it conflicts with out coring standards. I hope to soon fix them so we can use PHPStan to its fullest potential. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
--CREDITS--
|
|
Henrique Moody <henriquemoody@gmail.com>
|
|
Jonathan Stewmon <jstewmon@rmn.com>
|
|
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
|
use Respect\Validation\Validator as v;
|
|
|
|
try {
|
|
$array = [
|
|
'mysql' => [
|
|
'host' => 42,
|
|
'user' => 'user',
|
|
'password' => 'password',
|
|
'schema' => 'schema',
|
|
],
|
|
'postgresql' => [
|
|
'host' => 'host',
|
|
'user' => 42,
|
|
'password' => 'password',
|
|
'schema' => 'schema',
|
|
],
|
|
];
|
|
$object = json_decode((string) json_encode($array));
|
|
v::create()
|
|
->attribute(
|
|
'mysql',
|
|
v::create()
|
|
->attribute('host', v::stringType(), true)
|
|
->attribute('user', v::stringType(), true)
|
|
->attribute('password', v::stringType(), true)
|
|
->attribute('schema', v::stringType(), true),
|
|
true
|
|
)
|
|
->attribute(
|
|
'postgresql',
|
|
v::create()
|
|
->attribute('host', v::stringType(), true)
|
|
->attribute('user', v::stringType(), true)
|
|
->attribute('password', v::stringType(), true)
|
|
->attribute('schema', v::stringType(), true),
|
|
true
|
|
)
|
|
->setName('the given data')
|
|
->assert($object);
|
|
} catch (NestedValidationException $exception) {
|
|
echo $exception->getFullMessage() . PHP_EOL;
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
- All of the required rules must pass for the given data
|
|
- These rules must pass for mysql
|
|
- host must be of type string
|
|
- These rules must pass for postgresql
|
|
- user must be of type string
|