1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Simple\Definition\Group; |
4
|
|
|
|
5
|
|
|
use EventSauce\EventSourcing\AggregateRootId; |
6
|
|
|
use EventSauce\EventSourcing\Command; |
7
|
|
|
use EventSauce\EventSourcing\Event; |
8
|
|
|
use EventSauce\EventSourcing\PointInTime; |
9
|
|
|
|
10
|
|
|
final class SomethingHappened implements Event |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var AggregateRootId |
14
|
|
|
*/ |
15
|
|
|
private $aggregateRootId; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
private $what; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var bool |
24
|
|
|
*/ |
25
|
|
|
private $yolo; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var PointInTime |
29
|
|
|
*/ |
30
|
|
|
private $timeOfRecording; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
AggregateRootId $aggregateRootId, |
34
|
|
|
PointInTime $timeOfRecording, |
35
|
|
|
string $what, |
36
|
|
|
bool $yolo |
37
|
|
|
) { |
38
|
|
|
$this->aggregateRootId = $aggregateRootId; |
39
|
|
|
$this->timeOfRecording = $timeOfRecording; |
40
|
|
|
$this->what = $what; |
41
|
|
|
$this->yolo = $yolo; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function aggregateRootId(): AggregateRootId |
45
|
|
|
{ |
46
|
|
|
return $this->aggregateRootId; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function what(): string |
50
|
|
|
{ |
51
|
|
|
return $this->what; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function yolo(): bool |
55
|
|
|
{ |
56
|
|
|
return $this->yolo; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function eventVersion(): int |
60
|
|
|
{ |
61
|
|
|
return 1; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function timeOfRecording(): PointInTime |
65
|
|
|
{ |
66
|
|
|
return $this->timeOfRecording; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public static function fromPayload( |
70
|
|
|
array $payload, |
71
|
|
|
AggregateRootId $aggregateRootId, |
72
|
|
|
PointInTime $timeOfRecording): Event |
73
|
|
|
{ |
74
|
|
|
return new SomethingHappened( |
75
|
|
|
$aggregateRootId, |
76
|
|
|
$timeOfRecording, |
77
|
|
|
(string) $payload['what'], |
78
|
|
|
(bool) $payload['yolo'] |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function toPayload(): array |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
'what' => (string) $this->what, |
86
|
|
|
'yolo' => (bool) $this->yolo |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @codeCoverageIgnore |
92
|
|
|
*/ |
93
|
|
|
public function withWhat(string $what): SomethingHappened |
94
|
|
|
{ |
95
|
|
|
$this->what = $what; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @codeCoverageIgnore |
102
|
|
|
*/ |
103
|
|
|
public function withYolo(bool $yolo): SomethingHappened |
104
|
|
|
{ |
105
|
|
|
$this->yolo = $yolo; |
106
|
|
|
|
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): SomethingHappened |
111
|
|
|
{ |
112
|
|
|
return new SomethingHappened( |
113
|
|
|
$aggregateRootId, |
114
|
|
|
$timeOfRecording, |
115
|
|
|
(string) 'Example Event', |
116
|
|
|
(bool) true |
117
|
|
|
); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
|