mirror of
https://github.com/Respect/Validation.git
synced 2024-06-06 07:42:15 +02:00
2ae1df177a
Because we now have a single "assert()" method, we have more freedom to add more customizations to it. This specific one is handy if someone wants to use the library to validate but wants to use their own exceptions. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
28 lines
864 B
PHP
28 lines
864 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))
|
|
->assert('really messed up screen#name', [
|
|
'alnum' => '{{name}} must contain only letters and digits',
|
|
'noWhitespace' => '{{name}} cannot contain spaces',
|
|
'length' => '{{name}} must not have more than 15 chars',
|
|
])
|
|
);
|
|
?>
|
|
--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',
|
|
'lengthBetween' => 'The length of "really messed up screen#name" must be between 1 and 15',
|
|
]
|