mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
fefe905e0b
When converting an object into an array, we exclude the message root message from it. Since we're using a convention to template those messages as an array, we could also use the same convention to return those messages. While working on it, I noticed that the name "__self__" wasn't reflecting what that really meant, so I renamed it "__root__" because it better reflects the meaning of those messages/templates. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionMessages(static function (): void {
|
|
v::create()
|
|
->key(
|
|
'mysql',
|
|
v::create()
|
|
->key('host', v::stringType())
|
|
->key('user', v::stringType())
|
|
->key('password', v::stringType())
|
|
->key('schema', v::stringType())
|
|
)
|
|
->key(
|
|
'postgresql',
|
|
v::create()
|
|
->key('host', v::stringType())
|
|
->key('user', v::stringType())
|
|
->key('password', v::stringType())
|
|
->key('schema', v::stringType())
|
|
)
|
|
->assert([
|
|
'mysql' => [
|
|
'host' => 42,
|
|
'schema' => 42,
|
|
],
|
|
'postgresql' => [
|
|
'user' => 42,
|
|
'password' => 42,
|
|
],
|
|
]);
|
|
});
|
|
?>
|
|
--EXPECT--
|
|
[
|
|
'__root__' => 'All of the required rules must pass for `["mysql": ["host": 42, "schema": 42], "postgresql": ["user": 42, "password": 42]]`',
|
|
'mysql' => [
|
|
'__root__' => 'All of the required rules must pass for mysql',
|
|
'host' => 'host must be of type string',
|
|
'user' => 'user must be present',
|
|
'password' => 'password must be present',
|
|
'schema' => 'schema must be of type string',
|
|
],
|
|
'postgresql' => [
|
|
'__root__' => 'All of the required rules must pass for postgresql',
|
|
'host' => 'host must be present',
|
|
'user' => 'user must be of type string',
|
|
'password' => 'password must be of type string',
|
|
'schema' => 'schema must be present',
|
|
],
|
|
]
|