KeySetException.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. use function count;
  9. /**
  10. * @author Henrique Moody <henriquemoody@gmail.com>
  11. */
  12. final class KeySetException extends GroupedValidationException implements NonOmissibleException
  13. {
  14. public const STRUCTURE = 'structure';
  15. public const STRUCTURE_EXTRA = 'structure_extra';
  16. /**
  17. * {@inheritDoc}
  18. */
  19. protected $defaultTemplates = [
  20. self::MODE_DEFAULT => [
  21. self::NONE => '所有必需的规则都必须传递给 {{name}}',
  22. self::SOME => '这些规则必须传递给 {{name}}',
  23. self::STRUCTURE => '必须有键 {{keys}}',
  24. self::STRUCTURE_EXTRA => '不能有键 {{keys}}',
  25. ],
  26. ];
  27. /**
  28. * {@inheritDoc}
  29. */
  30. protected function chooseTemplate(): string
  31. {
  32. if (count($this->getParam('extraKeys'))) {
  33. return self::STRUCTURE_EXTRA;
  34. }
  35. if (count($this->getChildren()) === 0) {
  36. return self::STRUCTURE;
  37. }
  38. return parent::chooseTemplate();
  39. }
  40. }