CreditCardException.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 Respect\Validation\Rules\CreditCard;
  9. /**
  10. * @author Henrique Moody <henriquemoody@gmail.com>
  11. * @author Jean Pimentel <jeanfap@gmail.com>
  12. * @author William Espindola <oi@williamespindola.com.br>
  13. */
  14. final class CreditCardException extends ValidationException
  15. {
  16. public const BRANDED = 'branded';
  17. /**
  18. * {@inheritDoc}
  19. */
  20. protected $defaultTemplates = [
  21. self::MODE_DEFAULT => [
  22. self::STANDARD => '{{name}} 必须是有效的信用卡号',
  23. self::BRANDED => '{{name}} 必须是有效的 {{brand}} 信用卡号',
  24. ],
  25. self::MODE_NEGATIVE => [
  26. self::STANDARD => '{{name}} 不能是有效的信用卡号',
  27. self::BRANDED => '{{name}} 不能是有效的 {{brand}} 信用卡号',
  28. ],
  29. ];
  30. /**
  31. * {@inheritDoc}
  32. */
  33. protected function chooseTemplate(): string
  34. {
  35. if ($this->getParam('brand') === CreditCard::ANY) {
  36. return self::STANDARD;
  37. }
  38. return self::BRANDED;
  39. }
  40. }