Uuid.php 695 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace Drupal\Component\Uuid;
  3. /**
  4. * UUID Helper methods.
  5. */
  6. class Uuid {
  7. /**
  8. * The pattern used to validate a UUID string.
  9. */
  10. const VALID_PATTERN = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}';
  11. /**
  12. * Checks whether a string appears to be in the format of a UUID.
  13. *
  14. * Implementations should not implement validation, since UUIDs should be in
  15. * a consistent format across all implementations.
  16. *
  17. * @param string $uuid
  18. * The string to test.
  19. *
  20. * @return bool
  21. * TRUE if the string is well formed, FALSE otherwise.
  22. */
  23. public static function isValid($uuid) {
  24. return (bool) preg_match('/^' . self::VALID_PATTERN . '$/', $uuid);
  25. }
  26. }