1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Dsantang\DomainEventsDoctrine\Outbox; |
6
|
|
|
|
7
|
|
|
use DateTimeImmutable; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
use Doctrine\ORM\Mapping\MappedSuperclass; |
10
|
|
|
use Ramsey\Uuid\Uuid; |
11
|
|
|
use Ramsey\Uuid\UuidInterface; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* @MappedSuperclass |
15
|
|
|
*/ |
16
|
|
|
abstract class OutboxMappedSuperclass |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @ORM\Id |
20
|
|
|
* @ORM\Column(type="uuid") |
21
|
|
|
* |
22
|
|
|
* @var UuidInterface |
23
|
|
|
*/ |
24
|
|
|
protected $id; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @ORM\Column(type="string") |
28
|
|
|
* |
29
|
|
|
* @var string |
30
|
|
|
*/ |
31
|
|
|
protected $messageKey; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @ORM\Column(type="string") |
35
|
|
|
* |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
protected $messageRoute; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @ORM\Column(type="string") |
42
|
|
|
* |
43
|
|
|
* @var string |
44
|
|
|
*/ |
45
|
|
|
protected $messageType; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @ORM\Column(type="uuid") |
49
|
|
|
* |
50
|
|
|
* @var UuidInterface |
51
|
|
|
*/ |
52
|
|
|
protected $aggregateId; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @ORM\Column(type="string") |
56
|
|
|
* |
57
|
|
|
* @var string |
58
|
|
|
*/ |
59
|
|
|
protected $aggregateType; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @ORM\Column(type="string") |
63
|
|
|
* |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
protected $payloadType; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @ORM\Column(type="json") |
70
|
|
|
* |
71
|
|
|
* @var string |
72
|
|
|
*/ |
73
|
|
|
protected $payload; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @ORM\Column(type="integer") |
77
|
|
|
* |
78
|
|
|
* @var int |
79
|
|
|
*/ |
80
|
|
|
protected $schemaVersion; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @ORM\Column(type="utc_datetime_immutable") |
84
|
|
|
* |
85
|
|
|
* @var DateTimeImmutable |
86
|
|
|
*/ |
87
|
|
|
protected $createdAt; |
88
|
|
|
|
89
|
2 |
|
public function fromOutboxEntry(OutboxEntry $outboxEntry) : OutboxMappedSuperclass |
90
|
|
|
{ |
91
|
2 |
|
$outbox = clone $this; |
92
|
|
|
|
93
|
2 |
|
$outbox->id = Uuid::uuid4(); |
94
|
2 |
|
$outbox->messageKey = $outboxEntry->getMessageKey(); |
95
|
2 |
|
$outbox->messageRoute = $outboxEntry->getMessageRoute(); |
96
|
2 |
|
$outbox->messageType = $outboxEntry->getMessageType(); |
97
|
2 |
|
$outbox->aggregateId = $outboxEntry->getAggregateId(); |
98
|
2 |
|
$outbox->aggregateType = $outboxEntry->getAggregateType(); |
99
|
2 |
|
$outbox->payloadType = $outboxEntry->getPayloadType(); |
100
|
2 |
|
$outbox->payload = $outboxEntry->getPayload(); |
101
|
2 |
|
$outbox->schemaVersion = $outboxEntry->getSchemaVersion(); |
102
|
2 |
|
$outbox->createdAt = new DateTimeImmutable(); |
103
|
|
|
|
104
|
2 |
|
return $outbox; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|