Skip to content

Commit 8a5361e

Browse files
committed
Merge pull request #159 from takeit/master
fixes jackalope/jackalope-doctrine-dbal#298
2 parents 42db960 + 6f4d873 commit 8a5361e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ valid UUID.
6666
We recommend all implementations to use this implementation to guarantee
6767
consistent behaviour.
6868

69+
**Note**
70+
71+
You can use [ramsey/uuid](https://github.com/ramsey/uuid) library to generate UUIDs. In this case,
72+
install it using Composer and generating UUIDs will be taken over by `ramsey/uuid`.
73+
6974
### QOM QueryBuilder
7075

7176
The ``QueryBuilder`` is a fluent query builder with method names matching the

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
"phpcr/phpcr": "~2.1.0",
3232
"symfony/console": "~2.3|~3.0"
3333
},
34+
"suggest": {
35+
"ramsey/uuid": "A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID)."
36+
},
3437
"conflict": {
3538
"jackalope/jackalope-jackrabbit": "<1.2.1"
3639
},

src/PHPCR/Util/UUIDHelper.php

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

33
namespace PHPCR\Util;
44

5+
use Ramsey\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
{
@@ -32,10 +35,18 @@ public static function isUUID($id)
3235
* This UUID can not be guaranteed to be unique within the repository.
3336
* Ensuring this is the responsibility of the repository implementation.
3437
*
38+
* It also allows the use of Ramsey\Uuid\Uuid class.
39+
*
3540
* @return string a random UUID
3641
*/
3742
public static function generateUUID()
3843
{
44+
if (class_exists('Ramsey\Uuid\Uuid')) {
45+
$uuid4 = Uuid::uuid4();
46+
47+
return $uuid4->toString();
48+
}
49+
3950
return sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
4051
// 32 bits for "time_low"
4152
mt_rand(0, 0xffff), mt_rand(0, 0xffff),

0 commit comments

Comments
 (0)