22
33namespace PHPCR \Util ;
44
5+ use Rhumsaa \Uuid \Uuid ;
6+
57/**
68 * Static helper functions to deal with Universally Unique IDs (UUID).
79 *
@@ -13,8 +15,9 @@ class UUIDHelper
1315 /**
1416 * Checks if the string could be a UUID.
1517 *
16- * @param string $id Possible uuid
17- * @return boolean True if the test was passed, else false.
18+ * @param string $id Possible uuid
19+ *
20+ * @return bool True if the test was passed, else false.
1821 */
1922 public static function isUUID ($ id )
2023 {
@@ -29,31 +32,12 @@ public static function isUUID($id)
2932 /**
3033 * Generate a UUID.
3134 *
32- * This UUID can not be guaranteed to be unique within the repository.
33- * Ensuring this is the responsibility of the repository implementation.
34- *
3535 * @return string a random UUID
3636 */
3737 public static function generateUUID ()
3838 {
39- return sprintf ('%04x%04x-%04x-%04x-%04x-%04x%04x%04x ' ,
40- // 32 bits for "time_low"
41- mt_rand (0 , 0xffff ), mt_rand (0 , 0xffff ),
42-
43- // 16 bits for "time_mid"
44- mt_rand (0 , 0xffff ),
45-
46- // 16 bits for "time_hi_and_version",
47- // four most significant bits holds version number 4
48- mt_rand (0 , 0x0fff ) | 0x4000 ,
49-
50- // 16 bits, 8 bits for "clk_seq_hi_res",
51- // 8 bits for "clk_seq_low",
52- // two most significant bits holds zero and one for variant DCE1.1
53- mt_rand (0 , 0x3fff ) | 0x8000 ,
39+ $ uuid4 = Uuid::uuid4 ();
5440
55- // 48 bits for "node"
56- mt_rand (0 , 0xffff ), mt_rand (0 , 0xffff ), mt_rand (0 , 0xffff )
57- );
41+ return $ uuid4 ->toString ();
5842 }
5943}
0 commit comments