1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Aggrego\Domain\Api\Application\Profile\BoardConstruction\InitialBoardModel; |
6
|
|
|
|
7
|
|
|
use Aggrego\Domain\Api\Application\Profile\BoardConstruction\InitialBoardModel\Shard\Collection; |
8
|
|
|
use Aggrego\Domain\Api\Application\Profile\BoardConstruction\InitialBoardModel\Shard\Item; |
9
|
|
|
use Aggrego\Domain\Profile\Profile; |
10
|
|
|
use Aggrego\Domain\Shared\ValueObject\Key; |
11
|
|
|
use Aggrego\Domain\Shared\ValueObject\Uuid; |
12
|
|
|
use Ramsey\Uuid\Uuid as RamseyUuid; |
13
|
|
|
use Traversable; |
14
|
|
|
|
15
|
|
|
class Board |
16
|
|
|
{ |
17
|
|
|
/** @var Uuid */ |
18
|
|
|
private $uuid; |
19
|
|
|
|
20
|
|
|
/** @var Key */ |
21
|
|
|
private $key; |
22
|
|
|
|
23
|
|
|
/** @var Profile */ |
24
|
|
|
private $profile; |
25
|
|
|
|
26
|
|
|
/** @var Collection */ |
27
|
|
|
private $shards; |
28
|
|
|
|
29
|
|
|
protected function __construct(Key $key, Profile $profile) |
30
|
|
|
{ |
31
|
|
|
$this->uuid = $this->produceUuid($key, $profile); |
32
|
|
|
$this->key = $key; |
33
|
|
|
$this->profile = $profile; |
34
|
|
|
$this->shards = new Collection(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getUuid(): Uuid |
38
|
|
|
{ |
39
|
|
|
return $this->uuid; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function getKey(): Key |
43
|
|
|
{ |
44
|
|
|
return $this->key; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function getProfile(): Profile |
48
|
|
|
{ |
49
|
|
|
return $this->profile; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getShards(): Traversable |
53
|
|
|
{ |
54
|
|
|
return $this->shards->getIterator(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function addShard(Key $key, Profile $shardProfile): void |
58
|
|
|
{ |
59
|
|
|
$this->shards->add( |
60
|
|
|
new Item( |
61
|
|
|
$this->produceShardUuid($key, $shardProfile), |
62
|
|
|
$shardProfile, |
63
|
|
|
$key |
64
|
|
|
) |
65
|
|
|
); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
private function produceUuid(Key $key, Profile $profile): Uuid |
69
|
|
|
{ |
70
|
|
|
return new Uuid( |
71
|
|
|
RamseyUuid::uuid5( |
72
|
|
|
RamseyUuid::NAMESPACE_DNS, |
73
|
|
|
serialize($key->getValue()) . $profile |
74
|
|
|
)->toString() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private function produceShardUuid(Key $key, Profile $shardProfile): Uuid |
79
|
|
|
{ |
80
|
|
|
return new Uuid( |
81
|
|
|
RamseyUuid::uuid5( |
82
|
|
|
RamseyUuid::NAMESPACE_DNS, |
83
|
|
|
serialize($key->getValue()) . $shardProfile . $this->getUuid()->getValue() |
84
|
|
|
)->toString() |
85
|
|
|
); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|