Ulid.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. * @Annotation
  14. *
  15. * @author Laurent Clouet <laurent35240@gmail.com>
  16. */
  17. #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
  18. class Ulid extends Constraint
  19. {
  20. public const TOO_SHORT_ERROR = '7b44804e-37d5-4df4-9bdd-b738d4a45bb4';
  21. public const TOO_LONG_ERROR = '9608249f-6da1-4d53-889e-9864b58c4d37';
  22. public const INVALID_CHARACTERS_ERROR = 'e4155739-5135-4258-9c81-ae7b44b5311e';
  23. public const TOO_LARGE_ERROR = 'df8cfb9a-ce6d-4a69-ae5a-eea7ab6f278b';
  24. protected static $errorNames = [
  25. self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
  26. self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
  27. self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
  28. self::TOO_LARGE_ERROR => 'TOO_LARGE_ERROR',
  29. ];
  30. public $message = 'This is not a valid ULID.';
  31. public function __construct(
  32. array $options = null,
  33. string $message = null,
  34. array $groups = null,
  35. $payload = null
  36. ) {
  37. parent::__construct($options, $groups, $payload);
  38. $this->message = $message ?? $this->message;
  39. }
  40. }