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