|
1
|
|
|
<?php |
|
2
|
|
|
/****************************************************************************** |
|
3
|
|
|
* Copyright (c) 2016 Constantin Galbenu <[email protected]> * |
|
4
|
|
|
******************************************************************************/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Gica\Cqrs\Event; |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
use Gica\Cqrs\Command\CommandMetadata; |
|
10
|
|
|
|
|
11
|
|
|
class MetaData |
|
12
|
|
|
{ |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* @var \DateTimeImmutable |
|
16
|
|
|
*/ |
|
17
|
|
|
private $dateCreated; |
|
18
|
|
|
|
|
19
|
|
|
private $aggregateId; |
|
20
|
|
|
private $authenticatedUserId; |
|
21
|
|
|
|
|
22
|
|
|
/* @var string */ |
|
23
|
|
|
private $aggregateClass; |
|
24
|
|
|
|
|
25
|
|
|
/** @var CommandMetadata|null */ |
|
26
|
|
|
private $commandMetadata; |
|
27
|
|
|
|
|
28
|
|
|
/** @var int */ |
|
29
|
|
|
private $sequence = null; |
|
30
|
|
|
|
|
31
|
|
|
/** @var int */ |
|
32
|
|
|
private $index = null; |
|
33
|
|
|
/** |
|
34
|
|
|
* @var string|null |
|
35
|
|
|
*/ |
|
36
|
|
|
private $eventId; |
|
37
|
|
|
|
|
38
|
28 |
|
public function __construct( |
|
39
|
|
|
$aggregateId, |
|
40
|
|
|
string $aggregateClass, |
|
41
|
|
|
\DateTimeImmutable $dateCreated, |
|
42
|
|
|
$authenticatedUserId = null, |
|
43
|
|
|
CommandMetadata $commandMetadata = null |
|
44
|
|
|
) |
|
45
|
|
|
{ |
|
46
|
28 |
|
$this->dateCreated = $this->addTimeZone($dateCreated); |
|
47
|
28 |
|
$this->aggregateId = $aggregateId; |
|
48
|
28 |
|
$this->authenticatedUserId = $authenticatedUserId; |
|
49
|
28 |
|
$this->aggregateClass = $aggregateClass; |
|
50
|
28 |
|
$this->commandMetadata = $commandMetadata; |
|
51
|
28 |
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
public function getDateCreated(): \DateTimeImmutable |
|
54
|
|
|
{ |
|
55
|
1 |
|
return $this->dateCreated; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
2 |
|
public function getAggregateId() |
|
59
|
|
|
{ |
|
60
|
2 |
|
return $this->aggregateId; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
public function getAggregateClass() |
|
64
|
|
|
{ |
|
65
|
2 |
|
return $this->aggregateClass; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
1 |
|
public function getAuthenticatedUserId() |
|
69
|
|
|
{ |
|
70
|
1 |
|
return $this->authenticatedUserId; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
1 |
|
public function getCommandMetadata():?CommandMetadata |
|
74
|
|
|
{ |
|
75
|
1 |
|
return $this->commandMetadata; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
28 |
|
private function addTimeZone(\DateTimeImmutable $dateCreated): \DateTimeImmutable |
|
79
|
|
|
{ |
|
80
|
28 |
|
return $dateCreated->getTimezone() ? $dateCreated : |
|
81
|
28 |
|
($dateCreated->setTimezone(new \DateTimeZone('Europe/Bucharest')) ?: $dateCreated); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
4 |
|
public function withSequenceAndIndex(int $sequence, int $index): self |
|
85
|
|
|
{ |
|
86
|
4 |
|
$other = clone $this; |
|
87
|
4 |
|
$other->sequence = $sequence; |
|
88
|
4 |
|
$other->index = $index; |
|
89
|
4 |
|
return $other; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
11 |
|
public function withEventId(string $eventId): self |
|
93
|
|
|
{ |
|
94
|
11 |
|
$other = clone $this; |
|
95
|
11 |
|
$other->eventId = $eventId; |
|
96
|
11 |
|
return $other; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
1 |
|
public function getSequence(): ?int |
|
100
|
|
|
{ |
|
101
|
1 |
|
return $this->sequence; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
1 |
|
public function getIndex(): ?int |
|
105
|
|
|
{ |
|
106
|
1 |
|
return $this->index; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
5 |
|
public function getEventId(): ?string |
|
110
|
|
|
{ |
|
111
|
5 |
|
return $this->eventId; |
|
112
|
|
|
} |
|
113
|
|
|
} |