|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Group\With\Defaults; |
|
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 EventWithDescription implements Event |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var AggregateRootId |
|
14
|
|
|
*/ |
|
15
|
|
|
private $aggregateRootId; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
private $description; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var PointInTime |
|
24
|
|
|
*/ |
|
25
|
|
|
private $timeOfRecording; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
AggregateRootId $aggregateRootId, |
|
29
|
|
|
PointInTime $timeOfRecording, |
|
30
|
|
|
string $description |
|
31
|
|
|
) { |
|
32
|
|
|
$this->aggregateRootId = $aggregateRootId; |
|
33
|
|
|
$this->timeOfRecording = $timeOfRecording; |
|
34
|
|
|
$this->description = $description; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function aggregateRootId(): AggregateRootId |
|
38
|
|
|
{ |
|
39
|
|
|
return $this->aggregateRootId; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function description(): string |
|
43
|
|
|
{ |
|
44
|
|
|
return $this->description; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function eventVersion(): int |
|
48
|
|
|
{ |
|
49
|
|
|
return 1; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function timeOfRecording(): PointInTime |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->timeOfRecording; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public static function fromPayload( |
|
58
|
|
|
array $payload, |
|
59
|
|
|
AggregateRootId $aggregateRootId, |
|
60
|
|
|
PointInTime $timeOfRecording): Event |
|
61
|
|
|
{ |
|
62
|
|
|
return new EventWithDescription( |
|
63
|
|
|
$aggregateRootId, |
|
64
|
|
|
$timeOfRecording, |
|
65
|
|
|
(string) $payload['description'] |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function toPayload(): array |
|
70
|
|
|
{ |
|
71
|
|
|
return [ |
|
72
|
|
|
'description' => (string) $this->description |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function withDescription(string $description): EventWithDescription |
|
77
|
|
|
{ |
|
78
|
|
|
$this->description = $description; |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): EventWithDescription |
|
84
|
|
|
{ |
|
85
|
|
|
return new EventWithDescription( |
|
86
|
|
|
$aggregateRootId, |
|
87
|
|
|
$timeOfRecording, |
|
88
|
|
|
(string) 'This is a description.' |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
|
|
95
|
|
|
|