File tree Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Expand file tree Collapse file tree 1 file changed +23
-7
lines changed Original file line number Diff line number Diff line change 77
88use ComplexHeart \Domain \Contracts \Model \Identifier ;
99use Exception ;
10+ use Ramsey \Uuid \Codec \TimestampFirstCombCodec ;
11+ use Ramsey \Uuid \Generator \CombGenerator ;
1012use Ramsey \Uuid \Uuid ;
13+ use Ramsey \Uuid \UuidFactory ;
1114
1215/**
1316 * Class UUIDValue
1720 */
1821class UUIDValue extends Value implements Identifier
1922{
20- private const RANDOM = 'random ' ;
21-
2223 /**
2324 * The uuid string value.
2425 *
@@ -33,9 +34,7 @@ class UUIDValue extends Value implements Identifier
3334 */
3435 final public function __construct (string $ value )
3536 {
36- $ this ->initialize (
37- ['value ' => ($ value === self ::RANDOM ) ? Uuid::uuid4 ()->toString () : $ value ]
38- );
37+ $ this ->initialize (['value ' => $ value ]);
3938 }
4039
4140 /**
@@ -64,9 +63,26 @@ public function value(): string
6463 * @return static
6564 * @throws Exception
6665 */
67- public static function random (): self
66+ public static function random (bool $ ordered = true ): self
6867 {
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 ());
7086 }
7187
7288 /**
You can’t perform that action at this time.
0 commit comments