1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Factories; |
4
|
|
|
|
5
|
|
|
use Ramsey\Uuid\Codec\OrderedTimeCodec; |
6
|
|
|
use Ramsey\Uuid\UuidInterface; |
7
|
|
|
|
8
|
|
|
class UuidFactory |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var \Ramsey\Uuid\UuidFactory |
13
|
|
|
*/ |
14
|
|
|
private $orderedTimeFactory; |
15
|
|
|
/** |
16
|
|
|
* @var \Ramsey\Uuid\UuidFactory |
17
|
|
|
*/ |
18
|
|
|
private $uuidFactory; |
19
|
|
|
|
20
|
|
|
public function __construct(\Ramsey\Uuid\UuidFactory $uuidFactory) |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
$this->orderedTimeFactory = $this->createOrderedTimeFactory($uuidFactory); |
24
|
|
|
$this->uuidFactory = $uuidFactory; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
private function createOrderedTimeFactory(\Ramsey\Uuid\UuidFactory $uuidFactory): \Ramsey\Uuid\UuidFactory |
28
|
|
|
{ |
29
|
|
|
$this->orderedTimeFactory = clone $uuidFactory; |
30
|
|
|
$codec = new OrderedTimeCodec( |
31
|
|
|
$this->orderedTimeFactory->getUuidBuilder() |
32
|
|
|
); |
33
|
|
|
$this->orderedTimeFactory->setCodec($codec); |
34
|
|
|
|
35
|
|
|
return $this->orderedTimeFactory; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* This is used to get ordered time UUIDs as used in: |
40
|
|
|
* \EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\UuidFieldTrait |
41
|
|
|
* |
42
|
|
|
* @return UuidInterface |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
2 |
|
public function getOrderedTimeUuid(): UuidInterface |
46
|
|
|
{ |
47
|
2 |
|
return $this->orderedTimeFactory->uuid1(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* This is used to generate standard UUIDs, as used in |
52
|
|
|
* \EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\NonBinaryUuidFieldTrait |
53
|
|
|
* |
54
|
|
|
* @return UuidInterface |
55
|
|
|
* @throws \Exception |
56
|
|
|
*/ |
57
|
2 |
|
public function getUuid(): UuidInterface |
58
|
|
|
{ |
59
|
2 |
|
return $this->uuidFactory->uuid4(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return \Ramsey\Uuid\UuidFactory |
64
|
|
|
*/ |
65
|
|
|
public function getOrderedTimeFactory(): \Ramsey\Uuid\UuidFactory |
66
|
|
|
{ |
67
|
|
|
return $this->orderedTimeFactory; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return \Ramsey\Uuid\UuidFactory |
72
|
|
|
*/ |
73
|
|
|
public function getUuidFactory(): \Ramsey\Uuid\UuidFactory |
74
|
|
|
{ |
75
|
|
|
return $this->uuidFactory; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|