1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DefinedWith\Yaml; |
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 WeWentYamling implements Event |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var AggregateRootId |
14
|
|
|
*/ |
15
|
|
|
private $aggregateRootId; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var \Ramsey\Uuid\UuidInterface |
19
|
|
|
*/ |
20
|
|
|
private $reference; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
private $slogan; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var PointInTime |
29
|
|
|
*/ |
30
|
|
|
private $timeOfRecording; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
AggregateRootId $aggregateRootId, |
34
|
|
|
PointInTime $timeOfRecording, |
35
|
|
|
\Ramsey\Uuid\UuidInterface $reference, |
36
|
|
|
string $slogan |
37
|
|
|
) { |
38
|
|
|
$this->aggregateRootId = $aggregateRootId; |
39
|
|
|
$this->timeOfRecording = $timeOfRecording; |
40
|
|
|
$this->reference = $reference; |
41
|
|
|
$this->slogan = $slogan; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function aggregateRootId(): AggregateRootId |
45
|
|
|
{ |
46
|
|
|
return $this->aggregateRootId; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function reference(): \Ramsey\Uuid\UuidInterface |
50
|
|
|
{ |
51
|
|
|
return $this->reference; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function slogan(): string |
55
|
|
|
{ |
56
|
|
|
return $this->slogan; |
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 WeWentYamling( |
75
|
|
|
$aggregateRootId, |
76
|
|
|
$timeOfRecording, |
77
|
|
|
\Ramsey\Uuid\Uuid::fromString($payload['reference']), |
78
|
|
|
(string) $payload['slogan'] |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function toPayload(): array |
83
|
|
|
{ |
84
|
|
|
return [ |
85
|
|
|
'reference' => $this->reference->toString(), |
86
|
|
|
'slogan' => (string) $this->slogan |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function withReference(\Ramsey\Uuid\UuidInterface $reference): WeWentYamling |
91
|
|
|
{ |
92
|
|
|
$this->reference = $reference; |
93
|
|
|
|
94
|
|
|
return $this; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public static function withSlogan(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording, string $slogan): WeWentYamling |
98
|
|
|
{ |
99
|
|
|
return new WeWentYamling( |
100
|
|
|
$aggregateRootId, |
101
|
|
|
$timeOfRecording, |
102
|
|
|
\Ramsey\Uuid\Uuid::fromString("c0b47bc5-2aaa-497b-83cb-11d97da03a95"), |
103
|
|
|
$slogan |
104
|
|
|
); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
final class VersionedEvent implements Event |
110
|
|
|
{ |
111
|
|
|
/** |
112
|
|
|
* @var AggregateRootId |
113
|
|
|
*/ |
114
|
|
|
private $aggregateRootId; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @var string |
118
|
|
|
*/ |
119
|
|
|
private $title; |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @var PointInTime |
123
|
|
|
*/ |
124
|
|
|
private $timeOfRecording; |
125
|
|
|
|
126
|
|
|
public function __construct( |
127
|
|
|
AggregateRootId $aggregateRootId, |
128
|
|
|
PointInTime $timeOfRecording, |
129
|
|
|
string $title |
130
|
|
|
) { |
131
|
|
|
$this->aggregateRootId = $aggregateRootId; |
132
|
|
|
$this->timeOfRecording = $timeOfRecording; |
133
|
|
|
$this->title = $title; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function aggregateRootId(): AggregateRootId |
137
|
|
|
{ |
138
|
|
|
return $this->aggregateRootId; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function title(): string |
142
|
|
|
{ |
143
|
|
|
return $this->title; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function eventVersion(): int |
147
|
|
|
{ |
148
|
|
|
return 2; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function timeOfRecording(): PointInTime |
152
|
|
|
{ |
153
|
|
|
return $this->timeOfRecording; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public static function fromPayload( |
157
|
|
|
array $payload, |
158
|
|
|
AggregateRootId $aggregateRootId, |
159
|
|
|
PointInTime $timeOfRecording): Event |
160
|
|
|
{ |
161
|
|
|
return new VersionedEvent( |
162
|
|
|
$aggregateRootId, |
163
|
|
|
$timeOfRecording, |
164
|
|
|
(string) $payload['title'] |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public function toPayload(): array |
169
|
|
|
{ |
170
|
|
|
return [ |
171
|
|
|
'title' => (string) $this->title |
172
|
|
|
]; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
public function withTitle(string $title): VersionedEvent |
176
|
|
|
{ |
177
|
|
|
$this->title = $title; |
178
|
|
|
|
179
|
|
|
return $this; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): VersionedEvent |
183
|
|
|
{ |
184
|
|
|
return new VersionedEvent( |
185
|
|
|
$aggregateRootId, |
186
|
|
|
$timeOfRecording, |
187
|
|
|
(string) 'Some Example Title' |
188
|
|
|
); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
final class HideFinancialDetailsOfFraudulentCompany implements Command |
195
|
|
|
{ |
196
|
|
|
/** |
197
|
|
|
* @var PointInTime |
198
|
|
|
*/ |
199
|
|
|
private $timeOfRequest; |
200
|
|
|
|
201
|
|
|
/** |
202
|
|
|
* @var AggregateRootId |
203
|
|
|
*/ |
204
|
|
|
private $aggregateRootId; |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @var \Ramsey\Uuid\UuidInterface |
208
|
|
|
*/ |
209
|
|
|
private $companyId; |
210
|
|
|
|
211
|
|
|
public function __construct( |
212
|
|
|
AggregateRootId $aggregateRootId, |
213
|
|
|
PointInTime $timeOfRequest, |
214
|
|
|
\Ramsey\Uuid\UuidInterface $companyId |
215
|
|
|
) { |
216
|
|
|
$this->aggregateRootId = $aggregateRootId; |
217
|
|
|
$this->timeOfRequest = $timeOfRequest; |
218
|
|
|
$this->companyId = $companyId; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
public function timeOfRequest(): PointInTime |
222
|
|
|
{ |
223
|
|
|
return $this->timeOfRequest; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function aggregateRootId(): AggregateRootId |
227
|
|
|
{ |
228
|
|
|
return $this->aggregateRootId; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function companyId(): \Ramsey\Uuid\UuidInterface |
232
|
|
|
{ |
233
|
|
|
return $this->companyId; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
final class GoYamling implements Command |
239
|
|
|
{ |
240
|
|
|
/** |
241
|
|
|
* @var PointInTime |
242
|
|
|
*/ |
243
|
|
|
private $timeOfRequest; |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* @var AggregateRootId |
247
|
|
|
*/ |
248
|
|
|
private $aggregateRootId; |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @var \Ramsey\Uuid\UuidInterface |
252
|
|
|
*/ |
253
|
|
|
private $reference; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @var string |
257
|
|
|
*/ |
258
|
|
|
private $slogan; |
259
|
|
|
|
260
|
|
|
public function __construct( |
261
|
|
|
AggregateRootId $aggregateRootId, |
262
|
|
|
PointInTime $timeOfRequest, |
263
|
|
|
\Ramsey\Uuid\UuidInterface $reference, |
264
|
|
|
string $slogan |
265
|
|
|
) { |
266
|
|
|
$this->aggregateRootId = $aggregateRootId; |
267
|
|
|
$this->timeOfRequest = $timeOfRequest; |
268
|
|
|
$this->reference = $reference; |
269
|
|
|
$this->slogan = $slogan; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
public function timeOfRequest(): PointInTime |
273
|
|
|
{ |
274
|
|
|
return $this->timeOfRequest; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function aggregateRootId(): AggregateRootId |
278
|
|
|
{ |
279
|
|
|
return $this->aggregateRootId; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function reference(): \Ramsey\Uuid\UuidInterface |
283
|
|
|
{ |
284
|
|
|
return $this->reference; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function slogan(): string |
288
|
|
|
{ |
289
|
|
|
return $this->slogan; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
|