2
2
3
3
namespace PHPCR \Util ;
4
4
5
+ use Rhumsaa \Uuid \Uuid ;
6
+
5
7
/**
6
8
* Static helper functions to deal with Universally Unique IDs (UUID).
7
9
*
@@ -13,8 +15,9 @@ class UUIDHelper
13
15
/**
14
16
* Checks if the string could be a UUID.
15
17
*
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.
18
21
*/
19
22
public static function isUUID ($ id )
20
23
{
@@ -29,31 +32,12 @@ public static function isUUID($id)
29
32
/**
30
33
* Generate a UUID.
31
34
*
32
- * This UUID can not be guaranteed to be unique within the repository.
33
- * Ensuring this is the responsibility of the repository implementation.
34
- *
35
35
* @return string a random UUID
36
36
*/
37
37
public static function generateUUID ()
38
38
{
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 ();
54
40
55
- // 48 bits for "node"
56
- mt_rand (0 , 0xffff ), mt_rand (0 , 0xffff ), mt_rand (0 , 0xffff )
57
- );
41
+ return $ uuid4 ->toString ();
58
42
}
59
43
}
0 commit comments