Page MenuHomeDevCentral

D1631.id4163.diff
No OneTemporary

D1631.id4163.diff

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

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)

Event Timeline