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 |
31
|
|
|
*/ |
32
|
|
|
private $eventId; |
33
|
|
|
|
34
|
23 |
|
public function __construct( |
35
|
|
|
$aggregateId, |
36
|
|
|
string $aggregateClass, |
37
|
|
|
string $eventId, |
38
|
|
|
\DateTimeImmutable $dateCreated, |
39
|
|
|
$authenticatedUserId = null, |
40
|
|
|
$commandMetadata = null |
41
|
|
|
) |
42
|
|
|
{ |
43
|
23 |
|
$this->dateCreated = $this->addTimeZone($dateCreated); |
44
|
23 |
|
$this->aggregateId = $aggregateId; |
45
|
23 |
|
$this->authenticatedUserId = $authenticatedUserId; |
46
|
23 |
|
$this->aggregateClass = $aggregateClass; |
47
|
23 |
|
$this->commandMetadata = $commandMetadata; |
48
|
23 |
|
$this->eventId = $eventId; |
49
|
23 |
|
} |
50
|
|
|
|
51
|
1 |
|
public function getDateCreated(): \DateTimeImmutable |
52
|
|
|
{ |
53
|
1 |
|
return $this->dateCreated; |
54
|
|
|
} |
55
|
|
|
|
56
|
5 |
|
public function getAggregateId() |
57
|
|
|
{ |
58
|
5 |
|
return $this->aggregateId; |
59
|
|
|
} |
60
|
|
|
|
61
|
2 |
|
public function getAggregateClass() |
62
|
|
|
{ |
63
|
2 |
|
return $this->aggregateClass; |
64
|
|
|
} |
65
|
|
|
|
66
|
1 |
|
public function getAuthenticatedUserId() |
67
|
|
|
{ |
68
|
1 |
|
return $this->authenticatedUserId; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function getCommandMetadata() |
72
|
|
|
{ |
73
|
1 |
|
return $this->commandMetadata; |
74
|
|
|
} |
75
|
|
|
|
76
|
23 |
|
private function addTimeZone(\DateTimeImmutable $dateCreated): \DateTimeImmutable |
77
|
|
|
{ |
78
|
23 |
|
return $dateCreated->getTimezone() ? $dateCreated : |
79
|
23 |
|
($dateCreated->setTimezone(new \DateTimeZone('Europe/Bucharest')) ?: $dateCreated); |
80
|
|
|
} |
81
|
|
|
|
82
|
4 |
|
public function withSequenceAndIndex(int $sequence, int $index): self |
83
|
|
|
{ |
84
|
4 |
|
$other = clone $this; |
85
|
4 |
|
$other->sequence = $sequence; |
86
|
4 |
|
$other->index = $index; |
87
|
4 |
|
return $other; |
88
|
|
|
} |
89
|
|
|
|
90
|
1 |
|
public function getSequence(): ?int |
91
|
|
|
{ |
92
|
1 |
|
return $this->sequence; |
93
|
|
|
} |
94
|
|
|
|
95
|
1 |
|
public function getIndex(): ?int |
96
|
|
|
{ |
97
|
1 |
|
return $this->index; |
98
|
|
|
} |
99
|
|
|
|
100
|
3 |
|
public function getEventId(): string |
101
|
|
|
{ |
102
|
3 |
|
return $this->eventId; |
103
|
|
|
} |
104
|
|
|
} |