mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Fix wrong behavior when using templates
When a template is set for a chain of rules, does not really matter which messages the chain can have, the only message to be used should be the one based on the defined template. This commit set the same template of a parent rule to its children's exception. Our first thought was to set the template to its children however that would mean that if another rule would be added to the chain we would have to set it as well. Doing that to the children's exception make sure we only do that once. Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
e70c201691
commit
83bb6e3fc9
5 changed files with 79 additions and 9 deletions
|
|
@ -124,9 +124,27 @@ class NestedValidationException extends ValidationException implements IteratorA
|
|||
|
||||
private function isSkippable(ValidationException $exception)
|
||||
{
|
||||
return $exception instanceof self
|
||||
&& 1 === $exception->getRelated()->count()
|
||||
&& false === $exception->hasCustomTemplate();
|
||||
if (!$exception instanceof self) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (1 !== $exception->getRelated()->count()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$exception->hasCustomTemplate()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasChildTemplate($exception);
|
||||
}
|
||||
|
||||
private function hasChildTemplate(self $exception)
|
||||
{
|
||||
$exception->getRelated()->rewind();
|
||||
$childException = $exception->getRelated()->current();
|
||||
|
||||
return $childException->getMessage() === $exception->getMessage();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue