File tree 1 file changed +23
-7
lines changed
1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change 7
7
8
8
use ComplexHeart \Domain \Contracts \Model \Identifier ;
9
9
use Exception ;
10
+ use Ramsey \Uuid \Codec \TimestampFirstCombCodec ;
11
+ use Ramsey \Uuid \Generator \CombGenerator ;
10
12
use Ramsey \Uuid \Uuid ;
13
+ use Ramsey \Uuid \UuidFactory ;
11
14
12
15
/**
13
16
* Class UUIDValue
17
20
*/
18
21
class UUIDValue extends Value implements Identifier
19
22
{
20
- private const RANDOM = 'random ' ;
21
-
22
23
/**
23
24
* The uuid string value.
24
25
*
@@ -33,9 +34,7 @@ class UUIDValue extends Value implements Identifier
33
34
*/
34
35
final public function __construct (string $ value )
35
36
{
36
- $ this ->initialize (
37
- ['value ' => ($ value === self ::RANDOM ) ? Uuid::uuid4 ()->toString () : $ value ]
38
- );
37
+ $ this ->initialize (['value ' => $ value ]);
39
38
}
40
39
41
40
/**
@@ -64,9 +63,26 @@ public function value(): string
64
63
* @return static
65
64
* @throws Exception
66
65
*/
67
- public static function random (): self
66
+ public static function random (bool $ ordered = true ): self
68
67
{
69
- return new static (self ::RANDOM );
68
+ if ($ ordered ) {
69
+ $ factory = new UuidFactory ;
70
+
71
+ $ factory ->setRandomGenerator (new CombGenerator (
72
+ $ factory ->getRandomGenerator (),
73
+ $ factory ->getNumberConverter ()
74
+ ));
75
+
76
+ $ factory ->setCodec (new TimestampFirstCombCodec (
77
+ $ factory ->getUuidBuilder ()
78
+ ));
79
+
80
+ $ uuid = $ factory ->uuid4 ();
81
+ } else {
82
+ $ uuid = Uuid::uuid4 ();
83
+ }
84
+
85
+ return new static ($ uuid ->toString ());
70
86
}
71
87
72
88
/**
You can’t perform that action at this time.
0 commit comments