Get the proper exception when using findMessage()

This commit is contained in:
Henrique Moody 2016-09-17 20:21:05 +02:00
commit 98443bad0c
No known key found for this signature in database
GPG key ID: 221E9281655813A6
4 changed files with 74 additions and 4 deletions

View file

@ -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;