|
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
|
|
|
public function withWhat(string $what): SomethingHappened |
|
91
|
|
|
{ |
|
92
|
|
|
$this->what = $what; |
|
93
|
|
|
|
|
94
|
|
|
return $this; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function withYolo(bool $yolo): SomethingHappened |
|
98
|
|
|
{ |
|
99
|
|
|
$this->yolo = $yolo; |
|
100
|
|
|
|
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): SomethingHappened |
|
105
|
|
|
{ |
|
106
|
|
|
return new SomethingHappened( |
|
107
|
|
|
$aggregateRootId, |
|
108
|
|
|
$timeOfRecording, |
|
109
|
|
|
(string) 'Example Event', |
|
110
|
|
|
(bool) true |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
|
|
117
|
|
|
|