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