Uuid.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Colin O'Dell <colinodell@gmail.com>
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. */
  18. class Uuid extends Constraint
  19. {
  20. const TOO_SHORT_ERROR = 'aa314679-dac9-4f54-bf97-b2049df8f2a3';
  21. const TOO_LONG_ERROR = '494897dd-36f8-4d31-8923-71a8d5f3000d';
  22. const INVALID_CHARACTERS_ERROR = '51120b12-a2bc-41bf-aa53-cd73daf330d0';
  23. const INVALID_HYPHEN_PLACEMENT_ERROR = '98469c83-0309-4f5d-bf95-a496dcaa869c';
  24. const INVALID_VERSION_ERROR = '21ba13b4-b185-4882-ac6f-d147355987eb';
  25. const INVALID_VARIANT_ERROR = '164ef693-2b9d-46de-ad7f-836201f0c2db';
  26. protected static $errorNames = array(
  27. self::TOO_SHORT_ERROR => 'TOO_SHORT_ERROR',
  28. self::TOO_LONG_ERROR => 'TOO_LONG_ERROR',
  29. self::INVALID_CHARACTERS_ERROR => 'INVALID_CHARACTERS_ERROR',
  30. self::INVALID_HYPHEN_PLACEMENT_ERROR => 'INVALID_HYPHEN_PLACEMENT_ERROR',
  31. self::INVALID_VERSION_ERROR => 'INVALID_VERSION_ERROR',
  32. self::INVALID_VARIANT_ERROR => 'INVALID_VARIANT_ERROR',
  33. );
  34. // Possible versions defined by RFC 4122
  35. const V1_MAC = 1;
  36. const V2_DCE = 2;
  37. const V3_MD5 = 3;
  38. const V4_RANDOM = 4;
  39. const V5_SHA1 = 5;
  40. /**
  41. * Message to display when validation fails.
  42. *
  43. * @var string
  44. */
  45. public $message = 'This is not a valid UUID.';
  46. /**
  47. * Strict mode only allows UUIDs that meet the formal definition and formatting per RFC 4122.
  48. *
  49. * Set this to `false` to allow legacy formats with different dash positioning or wrapping characters
  50. *
  51. * @var bool
  52. */
  53. public $strict = true;
  54. /**
  55. * Array of allowed versions (see version constants above).
  56. *
  57. * All UUID versions are allowed by default
  58. *
  59. * @var int[]
  60. */
  61. public $versions = array(
  62. self::V1_MAC,
  63. self::V2_DCE,
  64. self::V3_MD5,
  65. self::V4_RANDOM,
  66. self::V5_SHA1,
  67. );
  68. }