Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3751417
D1631.id4163.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D1631.id4163.diff
View Options
diff --git a/src/Identifiers/UUID.php b/src/Identifiers/UUID.php
--- a/src/Identifiers/UUID.php
+++ b/src/Identifiers/UUID.php
@@ -5,6 +5,8 @@
class UUID {
+ const UUID_REGEXP = "/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/";
+
/**
* @return string A RFC 4122 compliant v4 UUID
*/
@@ -40,4 +42,8 @@
return str_replace("-", "", self::UUIDv4());
}
+ public static function isUUID ($string) : bool {
+ return (bool)preg_match(self::UUID_REGEXP, $string);
+ }
+
}
diff --git a/tests/Identifiers/UUIDTest.php b/tests/Identifiers/UUIDTest.php
--- a/tests/Identifiers/UUIDTest.php
+++ b/tests/Identifiers/UUIDTest.php
@@ -36,4 +36,14 @@
$this->assertNotEquals(UUID::UUIDv4(), UUID::UUIDv4());
}
+ public function testIsUUID () : void {
+ $this->assertTrue(UUID::isUUID("e14d5045-4959-11e8-a2e6-0007cb03f249"));
+ $this->assertFalse(
+ UUID::isUUID("e14d5045-4959-11e8-a2e6-0007cb03f249c"),
+ "The method shouldn't allow arbitrary size strings."
+ );
+ $this->assertFalse(UUID::isUUID("d825a90a27e7f161a07161c3a37dce8e"));
+
+ }
+
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Nov 18, 08:24 (21 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2250480
Default Alt Text
D1631.id4163.diff (1 KB)
Attached To
Mode
D1631: Allow to determine if a string is an UUID
Attached
Detach File
Event Timeline
Log In to Comment