Luhn.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Symfony\Component\Validator\Constraint;
  12. /**
  13. * Metadata for the LuhnValidator.
  14. *
  15. * @Annotation
  16. * @Target({"PROPERTY", "METHOD", "ANNOTATION"})
  17. *
  18. * @author Tim Nagel <t.nagel@infinite.net.au>
  19. * @author Greg Knapp http://gregk.me/2011/php-implementation-of-bank-card-luhn-algorithm/
  20. * @author Bernhard Schussek <bschussek@gmail.com>
  21. */
  22. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  23. class Luhn extends Constraint
  24. {
  25. public const INVALID_CHARACTERS_ERROR = 'dfad6d23-1b74-4374-929b-5cbb56fc0d9e';
  26. public const CHECKSUM_FAILED_ERROR = '4d760774-3f50-4cd5-a6d5-b10a3299d8d3';
  27. protected static $errorNames = [
  28. self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
  29. self::CHECKSUM_FAILED_ERROR => 'CHECKSUM_FAILED_ERROR',
  30. ];
  31. public $message = 'Invalid card number.';
  32. public function __construct(
  33. array $options = null,
  34. string $message = null,
  35. array $groups = null,
  36. $payload = null
  37. ) {
  38. parent::__construct($options, $groups, $payload);
  39. $this->message = $message ?? $this->message;
  40. }
  41. }