1 | <?php |
||
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 | |||
294 |