SizeException.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * Exception class for Size rule.
  10. *
  11. * @author Henrique Moody <henriquemoody@gmail.com>
  12. */
  13. final class SizeException extends NestedValidationException
  14. {
  15. public const BOTH = 'both';
  16. public const LOWER = 'lower';
  17. public const GREATER = 'greater';
  18. /**
  19. * {@inheritDoc}
  20. */
  21. protected $defaultTemplates = [
  22. self::MODE_DEFAULT => [
  23. self::BOTH => '{{name}} 必须介于 {{minSize}} 和 {{maxSize}} 之间',
  24. self::LOWER => '{{name}} 必须大于 {{minSize}}',
  25. self::GREATER => '{{name}} 必须小于 {{maxSize}}',
  26. ],
  27. self::MODE_NEGATIVE => [
  28. self::BOTH => '{{name}} 不能介于 {{minSize}} 和 {{maxSize}} 之间',
  29. self::LOWER => '{{name}} 不能大于 {{minSize}}',
  30. self::GREATER => '{{name}} 不能小于 {{maxSize}}',
  31. ],
  32. ];
  33. /**
  34. * {@inheritDoc}
  35. */
  36. protected function chooseTemplate(): string
  37. {
  38. if (!$this->getParam('minValue')) {
  39. return self::GREATER;
  40. }
  41. if (!$this->getParam('maxValue')) {
  42. return self::LOWER;
  43. }
  44. return self::BOTH;
  45. }
  46. }