mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
Get the proper exception when using findMessage()
This commit is contained in:
parent
494b67871f
commit
98443bad0c
4 changed files with 74 additions and 4 deletions
|
|
@ -34,6 +34,27 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param ValidationException $exception
|
||||
*
|
||||
* @return ValidationException
|
||||
*/
|
||||
private function getExceptionForPath($path, ValidationException $exception)
|
||||
{
|
||||
if ($path === $exception->guessId()) {
|
||||
return $exception;
|
||||
}
|
||||
|
||||
if (!$exception instanceof self) {
|
||||
return $exception;
|
||||
}
|
||||
|
||||
foreach ($exception as $subException) {
|
||||
return $subException;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $paths
|
||||
*
|
||||
|
|
@ -49,12 +70,19 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
|
||||
$exception = $this->findRelated($path);
|
||||
|
||||
if (is_object($exception) && !$numericKey) {
|
||||
$path = str_replace('.', '_', $path);
|
||||
|
||||
if (!$exception) {
|
||||
$messages[$path] = '';
|
||||
continue;
|
||||
}
|
||||
|
||||
$exception = $this->getExceptionForPath($path, $exception);
|
||||
if (!$numericKey) {
|
||||
$exception->setTemplate($value);
|
||||
}
|
||||
|
||||
$path = str_replace('.', '_', $path);
|
||||
$messages[$path] = $exception ? $exception->getMainMessage() : '';
|
||||
$messages[$path] = $exception->getMainMessage();
|
||||
}
|
||||
|
||||
return $messages;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue