DateTimeException.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. */
  12. final class DateTimeException extends ValidationException
  13. {
  14. public const FORMAT = 'format';
  15. /**
  16. * {@inheritDoc}
  17. */
  18. protected $defaultTemplates = [
  19. self::MODE_DEFAULT => [
  20. self::STANDARD => '{{name}} 必须是有效的日期/时间',
  21. self::FORMAT => '{{name}} 必须是格式为 {{sample}} 的有效日期/时间',
  22. ],
  23. self::MODE_NEGATIVE => [
  24. self::STANDARD => '{{name}} 不能是有效的日期/时间',
  25. self::FORMAT => '{{name}} 不能是格式为 {{sample}} 的有效日期/时间',
  26. ],
  27. ];
  28. /**
  29. * {@inheritDoc}
  30. */
  31. protected function chooseTemplate(): string
  32. {
  33. return $this->getParam('format') ? self::FORMAT : self::STANDARD;
  34. }
  35. }