mirror of
https://github.com/Respect/Validation.git
synced 2024-06-08 08:42:15 +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>
29 lines
874 B
PHP
29 lines
874 B
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
exceptionMessages(
|
|
static fn() => v::alnum()
|
|
->noWhitespace()
|
|
->length(v::between(1, 15))
|
|
->setTemplates([
|
|
'alnum' => '{{name}} must contain only letters and digits',
|
|
'noWhitespace' => '{{name}} cannot contain spaces',
|
|
'length' => '{{name}} must not have more than 15 chars',
|
|
])
|
|
->assert('really messed up screen#name')
|
|
);
|
|
?>
|
|
--EXPECT--
|
|
[
|
|
'__root__' => 'All of the required rules must pass for "really messed up screen#name"',
|
|
'alnum' => '"really messed up screen#name" must contain only letters and digits',
|
|
'noWhitespace' => '"really messed up screen#name" cannot contain spaces',
|
|
'length' => '"really messed up screen#name" must not have more than 15 chars',
|
|
]
|