1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/cqrs project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
declare(strict_types=1); |
10
|
|
|
|
11
|
|
|
namespace Daikon\EventSourcing\EventStore; |
12
|
|
|
|
13
|
|
|
use Daikon\EventSourcing\Aggregate\AggregateRevision; |
14
|
|
|
use Daikon\EventSourcing\Aggregate\DomainEventSequence; |
15
|
|
|
use Daikon\MessageBus\MessageInterface; |
16
|
|
|
use Daikon\MessageBus\Metadata\Metadata; |
17
|
|
|
|
18
|
|
|
final class Commit implements CommitInterface |
19
|
|
|
{ |
20
|
|
|
/** @var StreamId */ |
21
|
|
|
private $streamId; |
22
|
|
|
|
23
|
|
|
/** @var StreamRevision */ |
24
|
|
|
private $streamRevision; |
25
|
|
|
|
26
|
|
|
/** @var DomainEventSequence */ |
27
|
|
|
private $eventLog; |
28
|
|
|
|
29
|
|
|
/** @var Metadata */ |
30
|
|
|
private $metadata; |
31
|
|
|
|
32
|
|
|
public static function make( |
33
|
|
|
StreamId $streamId, |
34
|
|
|
StreamRevision $streamRevision, |
35
|
|
|
DomainEventSequence $eventLog, |
36
|
|
|
Metadata $metadata |
37
|
|
|
): CommitInterface { |
38
|
|
|
return new self($streamId, $streamRevision, $eventLog, $metadata); |
39
|
|
|
} |
40
|
|
|
|
41
|
1 |
|
public static function fromArray(array $state): MessageInterface |
42
|
|
|
{ |
43
|
1 |
|
return new self( |
44
|
1 |
|
StreamId::fromNative($state['streamId']), |
|
|
|
|
45
|
1 |
|
StreamRevision::fromNative((int)$state['streamRevision']), |
|
|
|
|
46
|
1 |
|
DomainEventSequence::fromArray($state['eventLog']), |
47
|
1 |
|
Metadata::fromArray($state['metadata']) |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getStreamId(): StreamId |
52
|
|
|
{ |
53
|
|
|
return $this->streamId; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function getStreamRevision(): StreamRevision |
57
|
|
|
{ |
58
|
|
|
return $this->streamRevision; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function getAggregateRevision(): AggregateRevision |
62
|
|
|
{ |
63
|
|
|
return $this->eventLog->getHeadRevision(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function getEventLog(): DomainEventSequence |
67
|
|
|
{ |
68
|
|
|
return $this->eventLog; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getMetadata(): Metadata |
72
|
|
|
{ |
73
|
|
|
return $this->metadata; |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
public function toArray(): array |
77
|
|
|
{ |
78
|
|
|
return [ |
79
|
1 |
|
'@type' => static::class, |
80
|
1 |
|
'streamId' => $this->streamId->toNative(), |
81
|
1 |
|
'streamRevision' => $this->streamRevision->toNative(), |
82
|
1 |
|
'eventLog' => $this->eventLog->toNative(), |
83
|
1 |
|
'metadata' => $this->metadata->toArray() |
84
|
|
|
]; |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
private function __construct( |
88
|
|
|
StreamId $streamId, |
89
|
|
|
StreamRevision $streamRevision, |
90
|
|
|
DomainEventSequence $eventLog, |
91
|
|
|
Metadata $metadata |
92
|
|
|
) { |
93
|
1 |
|
$this->streamId = $streamId; |
94
|
1 |
|
$this->streamRevision = $streamRevision; |
95
|
1 |
|
$this->eventLog = $eventLog; |
96
|
1 |
|
$this->metadata = $metadata; |
97
|
1 |
|
} |
98
|
|
|
} |
99
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.