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
|
|
|
/** |
91
|
|
|
* @codeCoverageIgnore |
92
|
|
|
*/ |
93
|
|
|
public function withReference(\Ramsey\Uuid\UuidInterface $reference): WeWentYamling |
94
|
|
|
{ |
95
|
|
|
$this->reference = $reference; |
96
|
|
|
|
97
|
|
|
return $this; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public static function withSlogan(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording, string $slogan): WeWentYamling |
101
|
|
|
{ |
102
|
|
|
return new WeWentYamling( |
103
|
|
|
$aggregateRootId, |
104
|
|
|
$timeOfRecording, |
105
|
|
|
\Ramsey\Uuid\Uuid::fromString("c0b47bc5-2aaa-497b-83cb-11d97da03a95"), |
106
|
|
|
$slogan |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
final class VersionedEvent implements Event |
|
|
|
|
113
|
|
|
{ |
114
|
|
|
/** |
115
|
|
|
* @var AggregateRootId |
116
|
|
|
*/ |
117
|
|
|
private $aggregateRootId; |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @var string |
121
|
|
|
*/ |
122
|
|
|
private $title; |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @var PointInTime |
126
|
|
|
*/ |
127
|
|
|
private $timeOfRecording; |
128
|
|
|
|
129
|
|
|
public function __construct( |
130
|
|
|
AggregateRootId $aggregateRootId, |
131
|
|
|
PointInTime $timeOfRecording, |
132
|
|
|
string $title |
133
|
|
|
) { |
134
|
|
|
$this->aggregateRootId = $aggregateRootId; |
135
|
|
|
$this->timeOfRecording = $timeOfRecording; |
136
|
|
|
$this->title = $title; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function aggregateRootId(): AggregateRootId |
140
|
|
|
{ |
141
|
|
|
return $this->aggregateRootId; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function title(): string |
145
|
|
|
{ |
146
|
|
|
return $this->title; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function eventVersion(): int |
150
|
|
|
{ |
151
|
|
|
return 2; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function timeOfRecording(): PointInTime |
155
|
|
|
{ |
156
|
|
|
return $this->timeOfRecording; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public static function fromPayload( |
160
|
|
|
array $payload, |
161
|
|
|
AggregateRootId $aggregateRootId, |
162
|
|
|
PointInTime $timeOfRecording): Event |
163
|
|
|
{ |
164
|
|
|
return new VersionedEvent( |
165
|
|
|
$aggregateRootId, |
166
|
|
|
$timeOfRecording, |
167
|
|
|
(string) $payload['title'] |
168
|
|
|
); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function toPayload(): array |
172
|
|
|
{ |
173
|
|
|
return [ |
174
|
|
|
'title' => (string) $this->title |
175
|
|
|
]; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* @codeCoverageIgnore |
180
|
|
|
*/ |
181
|
|
|
public function withTitle(string $title): VersionedEvent |
182
|
|
|
{ |
183
|
|
|
$this->title = $title; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): VersionedEvent |
189
|
|
|
{ |
190
|
|
|
return new VersionedEvent( |
191
|
|
|
$aggregateRootId, |
192
|
|
|
$timeOfRecording, |
193
|
|
|
(string) 'Some Example Title' |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
final class HideFinancialDetailsOfFraudulentCompany implements Command |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
/** |
202
|
|
|
* @var PointInTime |
203
|
|
|
*/ |
204
|
|
|
private $timeOfRequest; |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* @var AggregateRootId |
208
|
|
|
*/ |
209
|
|
|
private $aggregateRootId; |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @var \Ramsey\Uuid\UuidInterface |
213
|
|
|
*/ |
214
|
|
|
private $companyId; |
215
|
|
|
|
216
|
|
|
public function __construct( |
217
|
|
|
AggregateRootId $aggregateRootId, |
218
|
|
|
PointInTime $timeOfRequest, |
219
|
|
|
\Ramsey\Uuid\UuidInterface $companyId |
220
|
|
|
) { |
221
|
|
|
$this->aggregateRootId = $aggregateRootId; |
222
|
|
|
$this->timeOfRequest = $timeOfRequest; |
223
|
|
|
$this->companyId = $companyId; |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
public function timeOfRequest(): PointInTime |
227
|
|
|
{ |
228
|
|
|
return $this->timeOfRequest; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public function aggregateRootId(): AggregateRootId |
232
|
|
|
{ |
233
|
|
|
return $this->aggregateRootId; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
public function companyId(): \Ramsey\Uuid\UuidInterface |
237
|
|
|
{ |
238
|
|
|
return $this->companyId; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
final class GoYamling implements Command |
|
|
|
|
244
|
|
|
{ |
245
|
|
|
/** |
246
|
|
|
* @var PointInTime |
247
|
|
|
*/ |
248
|
|
|
private $timeOfRequest; |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @var AggregateRootId |
252
|
|
|
*/ |
253
|
|
|
private $aggregateRootId; |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @var \Ramsey\Uuid\UuidInterface |
257
|
|
|
*/ |
258
|
|
|
private $reference; |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* @var string |
262
|
|
|
*/ |
263
|
|
|
private $slogan; |
264
|
|
|
|
265
|
|
|
public function __construct( |
266
|
|
|
AggregateRootId $aggregateRootId, |
267
|
|
|
PointInTime $timeOfRequest, |
268
|
|
|
\Ramsey\Uuid\UuidInterface $reference, |
269
|
|
|
string $slogan |
270
|
|
|
) { |
271
|
|
|
$this->aggregateRootId = $aggregateRootId; |
272
|
|
|
$this->timeOfRequest = $timeOfRequest; |
273
|
|
|
$this->reference = $reference; |
274
|
|
|
$this->slogan = $slogan; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function timeOfRequest(): PointInTime |
278
|
|
|
{ |
279
|
|
|
return $this->timeOfRequest; |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
public function aggregateRootId(): AggregateRootId |
283
|
|
|
{ |
284
|
|
|
return $this->aggregateRootId; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function reference(): \Ramsey\Uuid\UuidInterface |
288
|
|
|
{ |
289
|
|
|
return $this->reference; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
public function slogan(): string |
293
|
|
|
{ |
294
|
|
|
return $this->slogan; |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
} |
298
|
|
|
|
Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.