mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
8573bc5d45
When you have a chain of rules in the Validation and overwrite the name with "setName()," it's impossible to get the messages from all rules in the chain as an array because they all have the same name. These changes will change that behavior by creating a more explicit distinction between "IDs" and "names." The "IDs" will remain unchangeable, while we can always overwrite the names. That means that the array messages will look more similar to the chain, and it will be possible to overwrite the messages from multiple rules in the same chain. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
49 lines
1 KiB
PHP
49 lines
1 KiB
PHP
--FILE--
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require 'vendor/autoload.php';
|
|
|
|
use Respect\Validation\Validator as v;
|
|
|
|
run([
|
|
'Default mode' => [v::keyExists('foo'), ['bar' => 'baz']],
|
|
'Negative mode' => [v::not(v::keyExists('foo')), ['foo' => 'baz']],
|
|
'Custom name' => [v::keyExists('foo')->setName('Custom name'), ['bar' => 'baz']],
|
|
'Custom template' => [v::keyExists('foo'), ['bar' => 'baz'], 'Custom template for `{{name}}`'],
|
|
]);
|
|
?>
|
|
--EXPECT--
|
|
Default mode
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
foo must be present
|
|
- foo must be present
|
|
[
|
|
'foo' => 'foo must be present',
|
|
]
|
|
|
|
Negative mode
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
foo must not be present
|
|
- foo must not be present
|
|
[
|
|
'foo' => 'foo must not be present',
|
|
]
|
|
|
|
Custom name
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
Custom name must be present
|
|
- Custom name must be present
|
|
[
|
|
'foo' => 'Custom name must be present',
|
|
]
|
|
|
|
Custom template
|
|
⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺⎺
|
|
Custom template for `foo`
|
|
- Custom template for `foo`
|
|
[
|
|
'foo' => 'Custom template for `foo`',
|
|
]
|