EachException.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /*
  3. * Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
  4. * SPDX-License-Identifier: MIT
  5. */
  6. declare(strict_types=1);
  7. namespace Respect\Validation\Exceptions;
  8. /**
  9. * @author Alexandre Gomes Gaigalas <alganet@gmail.com>
  10. * @author Henrique Moody <henriquemoody@gmail.com>
  11. * @author William Espindola <oi@williamespindola.com.br>
  12. */
  13. final class EachException extends NestedValidationException
  14. {
  15. /**
  16. * {@inheritDoc}
  17. */
  18. protected $defaultTemplates = [
  19. self::MODE_DEFAULT => [
  20. self::STANDARD => '{{name}} 中的每个项都必须有效',
  21. ],
  22. self::MODE_NEGATIVE => [
  23. self::STANDARD => '{{name}} 中的每个项都必须无效',
  24. ],
  25. ];
  26. /**
  27. * {@inheritDoc}
  28. *
  29. * @todo This method shares too much with the parent implementation
  30. */
  31. public function getMessages(array $templates = []): array
  32. {
  33. $messages = [];
  34. $count = -1;
  35. foreach ($this->getChildren() as $exception) {
  36. $count++;
  37. $id = $exception->getId();
  38. $messages[$id . '.' . $count] = $this->renderMessage(
  39. $exception,
  40. $this->findTemplates($templates, $this->getId())
  41. );
  42. }
  43. return $messages;
  44. }
  45. }