OptionalException.php 865 B

12345678910111213141516171819202122232425262728293031323334353637
  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 Henrique Moody <henriquemoody@gmail.com>
  10. */
  11. final class OptionalException extends ValidationException
  12. {
  13. public const NAMED = 'named';
  14. /**
  15. * {@inheritDoc}
  16. */
  17. protected $defaultTemplates = [
  18. self::MODE_DEFAULT => [
  19. self::STANDARD => '该值必须是可选的',
  20. self::NAMED => '{{name}} 必须是可选的',
  21. ],
  22. self::MODE_NEGATIVE => [
  23. self::STANDARD => '该值不能是可选的',
  24. self::NAMED => '{{name}} 不能是可选的',
  25. ],
  26. ];
  27. protected function chooseTemplate(): string
  28. {
  29. return $this->getParam('name') ? self::NAMED : self::STANDARD;
  30. }
  31. }