Mercurial > hg > isophonics-drupal-site
annotate core/lib/Drupal/Component/Uuid/Uuid.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\Component\Uuid; |
Chris@0 | 4 |
Chris@0 | 5 /** |
Chris@0 | 6 * UUID Helper methods. |
Chris@0 | 7 */ |
Chris@0 | 8 class Uuid { |
Chris@0 | 9 |
Chris@0 | 10 /** |
Chris@0 | 11 * The pattern used to validate a UUID string. |
Chris@0 | 12 */ |
Chris@0 | 13 const VALID_PATTERN = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}'; |
Chris@0 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * Checks whether a string appears to be in the format of a UUID. |
Chris@0 | 17 * |
Chris@0 | 18 * Implementations should not implement validation, since UUIDs should be in |
Chris@0 | 19 * a consistent format across all implementations. |
Chris@0 | 20 * |
Chris@0 | 21 * @param string $uuid |
Chris@0 | 22 * The string to test. |
Chris@0 | 23 * |
Chris@0 | 24 * @return bool |
Chris@0 | 25 * TRUE if the string is well formed, FALSE otherwise. |
Chris@0 | 26 */ |
Chris@0 | 27 public static function isValid($uuid) { |
Chris@0 | 28 return (bool) preg_match('/^' . self::VALID_PATTERN . '$/', $uuid); |
Chris@0 | 29 } |
Chris@0 | 30 |
Chris@0 | 31 } |