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>
35 lines
914 B
PHP
35 lines
914 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
date_default_timezone_set('UTC');
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator;
|
|
|
|
exceptionMessages(static function (): void {
|
|
$input = [
|
|
'username' => 'u',
|
|
'birthdate' => 'Not a date',
|
|
'password' => '',
|
|
];
|
|
|
|
Validator::create()
|
|
->key('username', Validator::lengthBetween(2, 32))
|
|
->key('birthdate', Validator::dateTime())
|
|
->key('password', Validator::notEmpty())
|
|
->key('email', Validator::email())
|
|
->assert($input);
|
|
});
|
|
?>
|
|
--EXPECT--
|
|
[
|
|
'__root__' => 'All of the required rules must pass for `["username": "u", "birthdate": "Not a date", "password": ""]`',
|
|
'username' => 'The length of username must be between 2 and 32',
|
|
'birthdate' => 'birthdate must be a valid date/time',
|
|
'password' => 'password must not be empty',
|
|
'email' => 'email must be present',
|
|
]
|