mirror of
https://github.com/Respect/Validation.git
synced 2024-06-07 16:22:16 +02:00
Try to use the getRelatedByName()
method first
Then using the `findMessages()` method, tries to use the method `getRelatedByName()` before using the `findRelated()` method. This change was made because since on `KeyNested` rule you may have names with '.' we'll never get the proper exception using `findRelated()`.
This commit is contained in:
parent
98443bad0c
commit
4bcc4027f8
|
@ -68,7 +68,9 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
$numericKey = is_numeric($key);
|
||||
$path = $numericKey ? $value : $key;
|
||||
|
||||
$exception = $this->findRelated($path);
|
||||
if (!($exception = $this->getRelatedByName($path))) {
|
||||
$exception = $this->findRelated($path);
|
||||
}
|
||||
|
||||
$path = str_replace('.', '_', $path);
|
||||
|
||||
|
|
57
tests/integration/issue-689.phpt
Normal file
57
tests/integration/issue-689.phpt
Normal file
|
@ -0,0 +1,57 @@
|
|||
--FILE--
|
||||
<?php
|
||||
|
||||
require 'vendor/autoload.php';
|
||||
|
||||
use Respect\Validation\Exceptions\NestedValidationException;
|
||||
use Respect\Validation\Validator as v;
|
||||
|
||||
$input = [
|
||||
'organization' => [
|
||||
'name' => 'N',
|
||||
'address' => 'A',
|
||||
],
|
||||
'contact' => [
|
||||
'name' => 'wd',
|
||||
'email' => 'ffesfewf2232313123212',
|
||||
'password' => ' ',
|
||||
'position' => 'wdwdwf',
|
||||
'number' => '£"!@£;21#£:"!:£~!":£\'21;',
|
||||
],
|
||||
];
|
||||
|
||||
try {
|
||||
v::create()
|
||||
->key(
|
||||
'organization',
|
||||
v::create()
|
||||
->key('name', v::length(2, 50)->notEmpty())
|
||||
->key('address', v::length(2, 50)->notEmpty())
|
||||
)
|
||||
->keyNested('contact.name', v::length(1, 50)->notEmpty())
|
||||
->keyNested('contact.email', v::email()->notEmpty())
|
||||
->keyNested('contact.password', v::length(3, 100)->notEmpty())
|
||||
->keyNested('contact.position', v::length(1, 100)->notEmpty())
|
||||
->keyNested('contact.number', v::phone()->notEmpty())
|
||||
->assert($input);
|
||||
} catch (NestedValidationException $exception) {
|
||||
print_r(array_filter($exception->findMessages([
|
||||
'organization.name' => 'Center name',
|
||||
'organization.address' => 'Center address',
|
||||
'contact.name' => 'Contact name',
|
||||
'contact.password' => 'Contact name',
|
||||
'contact.position' => 'Contact name',
|
||||
'contact.number' => 'Contact name',
|
||||
'contact.email' => 'Contact name',
|
||||
])));
|
||||
}
|
||||
?>
|
||||
--EXPECTF--
|
||||
Array
|
||||
(
|
||||
[organization_name] => Center name
|
||||
[organization_address] => Center address
|
||||
[contact_password] => Contact name
|
||||
[contact_number] => Contact name
|
||||
[contact_email] => Contact name
|
||||
)
|
Loading…
Reference in a new issue