mirror of
https://github.com/Respect/Validation.git
synced 2024-06-13 19:22: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>
76 lines
2 KiB
PHP
76 lines
2 KiB
PHP
--CREDITS--
|
|
Henrique Moody <henriquemoody@gmail.com>
|
|
--FILE--
|
|
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Exceptions\NestedValidationException;
|
|
use Respect\Validation\Validator as v;
|
|
|
|
try {
|
|
v::create()
|
|
->key(
|
|
'mysql',
|
|
v::create()
|
|
->key('host', v::stringType(), true)
|
|
->key('user', v::stringType(), true)
|
|
->key('password', v::stringType(), true)
|
|
->key('schema', v::stringType(), true),
|
|
true
|
|
)
|
|
->key(
|
|
'postgresql',
|
|
v::create()
|
|
->key('host', v::stringType(), true)
|
|
->key('user', v::stringType(), true)
|
|
->key('password', v::stringType(), true)
|
|
->key('schema', v::stringType(), true),
|
|
true
|
|
)
|
|
->assert([
|
|
'mysql' => [
|
|
'host' => 42,
|
|
'schema' => 42,
|
|
],
|
|
'postgresql' => [
|
|
'user' => 42,
|
|
'password' => 42,
|
|
],
|
|
]);
|
|
} catch (NestedValidationException $exception) {
|
|
print_r($exception->getMessages([
|
|
'mysql' => [
|
|
'user' => 'Value should be a MySQL username',
|
|
'host' => '{{input}} should be a MySQL host',
|
|
],
|
|
'postgresql' => [
|
|
'schema' => 'You must provide a valid PostgreSQL schema',
|
|
],
|
|
]));
|
|
}
|
|
?>
|
|
--EXPECT--
|
|
Array
|
|
(
|
|
[mysql] => Array
|
|
(
|
|
[host] => 42 should be a MySQL host
|
|
[user] => Value should be a MySQL username
|
|
[password] => password must be present
|
|
[schema] => schema must be of type string
|
|
)
|
|
|
|
[postgresql] => Array
|
|
(
|
|
[host] => host must be present
|
|
[user] => user must be of type string
|
|
[password] => password must be of type string
|
|
[schema] => You must provide a valid PostgreSQL schema
|
|
)
|
|
|
|
)
|