NullableException.php 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. * @author Jens Segers <segers.jens@gmail.com>
  11. */
  12. final class NullableException extends ValidationException
  13. {
  14. public const NAMED = 'named';
  15. /**
  16. * {@inheritDoc}
  17. */
  18. protected $defaultTemplates = [
  19. self::MODE_DEFAULT => [
  20. self::STANDARD => '值必须为nullable',
  21. self::NAMED => '{{name}} 必须为nullable',
  22. ],
  23. self::MODE_NEGATIVE => [
  24. self::STANDARD => '值不能为null',
  25. self::NAMED => '{{name}} 不能为null',
  26. ],
  27. ];
  28. /**
  29. * {@inheritDoc}
  30. */
  31. protected function chooseTemplate(): string
  32. {
  33. if ($this->getParam('input') || $this->getParam('name')) {
  34. return self::NAMED;
  35. }
  36. return self::STANDARD;
  37. }
  38. }