1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/message-bus 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
|
|
|
namespace Daikon\Tests\MessageBus\Fixture; |
10
|
|
|
|
11
|
|
|
use Daikon\MessageBus\MessageInterface; |
12
|
|
|
|
13
|
|
|
final class ChangeUsername implements MessageInterface |
14
|
|
|
{ |
15
|
|
|
private UserId $userId; |
16
|
|
|
|
17
|
|
|
private KnownRevision $knownRevision; |
18
|
|
|
|
19
|
|
|
private Username $username; |
20
|
|
|
|
21
|
|
|
public function __construct(UserId $userId, KnownRevision $knownRevision, Username $username) |
22
|
|
|
{ |
23
|
|
|
$this->userId = $userId; |
24
|
|
|
$this->knownRevision = $knownRevision; |
25
|
|
|
$this->username = $username; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function getUserId(): UserId |
29
|
|
|
{ |
30
|
|
|
return $this->userId; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getKnownRevision(): KnownRevision |
34
|
|
|
{ |
35
|
|
|
return $this->knownRevision; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getUsername(): Username |
39
|
|
|
{ |
40
|
|
|
return $this->username; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function toNative(): array |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
'userId' => $this->userId->toNative(), |
47
|
|
|
'knownRevision' => $this->knownRevision->toNative(), |
48
|
|
|
'username' => $this->username->toNative() |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** @param array $state */ |
53
|
|
|
public static function fromNative($state): MessageInterface |
54
|
|
|
{ |
55
|
|
|
return new self( |
56
|
|
|
new UserId($state['userId']), |
57
|
|
|
new KnownRevision((int)$state['knownRevision']), |
58
|
|
|
new Username($state['username']) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|