1 | <?php |
||
8 | class EventStub implements Event |
||
9 | { |
||
10 | /** |
||
11 | * @var PointInTime |
||
12 | */ |
||
13 | private $pointInTime; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $value; |
||
19 | |||
20 | public function __construct(PointInTime $pointInTime, string $value) |
||
21 | { |
||
22 | $this->pointInTime = $pointInTime; |
||
23 | $this->value = $value; |
||
24 | } |
||
25 | |||
26 | public function timeOfRecording(): PointInTime |
||
27 | { |
||
28 | return $this->pointInTime; |
||
29 | } |
||
30 | |||
31 | public function toPayload(): array |
||
32 | { |
||
33 | return ['value' => $this->value]; |
||
34 | } |
||
35 | |||
36 | public static function fromPayload(array $payload, PointInTime $timeOfRecording): Event |
||
37 | { |
||
38 | return new static($timeOfRecording, $payload['value']); |
||
39 | } |
||
40 | |||
41 | public static function create(string $value = null) |
||
42 | { |
||
43 | return static::fromPayload(compact('value'), (new TestClock())->pointInTime()); |
||
44 | } |
||
45 | } |