Skip to content

Commit 4fbfb1d

Browse files
committed
added ramsey/uuid generator
1 parent 42db960 commit 4fbfb1d

File tree

2 files changed

+9
-24
lines changed

2 files changed

+9
-24
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"require": {
3030
"php": ">=5.3.3",
3131
"phpcr/phpcr": "~2.1.0",
32-
"symfony/console": "~2.3|~3.0"
32+
"symfony/console": "~2.3|~3.0",
33+
"ramsey/uuid": "~2.8"
3334
},
3435
"conflict": {
3536
"jackalope/jackalope-jackrabbit": "<1.2.1"

src/PHPCR/Util/UUIDHelper.php

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace 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

Comments
 (0)