|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* |
|
4
|
|
|
* This file is part of the Aggrego. |
|
5
|
|
|
* (c) Tomasz Kunicki <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types = 1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Aggrego\FragmentedDataBoard\Board; |
|
15
|
|
|
|
|
16
|
|
|
use Aggrego\AggregateEventConsumer\Shared\TraitAggregate; |
|
17
|
|
|
use Aggrego\AggregateEventConsumer\Uuid; |
|
18
|
|
|
use Aggrego\Domain\Board\Board as DomainBoard; |
|
19
|
|
|
use Aggrego\Domain\Board\Key; |
|
20
|
|
|
use Aggrego\Domain\Profile\Profile; |
|
21
|
|
|
use Aggrego\FragmentedDataBoard\Board\Events\BoardCreatedEvent; |
|
22
|
|
|
use Aggrego\FragmentedDataBoard\Board\Events\ShardAddedEvent; |
|
23
|
|
|
use Aggrego\FragmentedDataBoard\Board\Events\ShardUpdatedEvent; |
|
24
|
|
|
use Aggrego\FragmentedDataBoard\Board\Exception\UnprocessableBoardException; |
|
25
|
|
|
use Aggrego\FragmentedDataBoard\Board\Shard\FinalItem; |
|
26
|
|
|
use Aggrego\FragmentedDataBoard\Board\Shard\Uuid as ShardUuid; |
|
27
|
|
|
|
|
28
|
|
|
class Board implements DomainBoard |
|
29
|
|
|
{ |
|
30
|
|
|
use TraitAggregate; |
|
31
|
|
|
|
|
32
|
|
|
/** @var Uuid */ |
|
33
|
|
|
private $uuid; |
|
34
|
|
|
|
|
35
|
|
|
/** @var Key */ |
|
36
|
|
|
private $key; |
|
37
|
|
|
|
|
38
|
|
|
/** @var Profile */ |
|
39
|
|
|
private $profile; |
|
40
|
|
|
|
|
41
|
|
|
/** @var Metadata */ |
|
42
|
|
|
private $metadata; |
|
43
|
|
|
|
|
44
|
|
|
private function __construct(Uuid $uuid, Key $key, Profile $profile, Metadata $metadata, ?Uuid $parentUuid) |
|
45
|
|
|
{ |
|
46
|
|
|
$this->uuid = $uuid; |
|
47
|
|
|
$this->key = $key; |
|
48
|
|
|
$this->profile = $profile; |
|
49
|
|
|
$this->metadata = $metadata; |
|
50
|
|
|
|
|
51
|
|
|
$this->pushEvent(new BoardCreatedEvent($uuid, $key, $profile, $parentUuid)); |
|
52
|
|
|
|
|
53
|
|
|
$this->metadata = $metadata; |
|
54
|
|
|
foreach ($metadata->getShards() as $shard) { |
|
55
|
|
|
$this->pushEvent(new ShardAddedEvent($this->uuid, $shard)); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function updateShard(ShardUuid $shardUuid, Profile $profile, Data $data): void |
|
60
|
|
|
{ |
|
61
|
|
|
if (!$this->metadata->readyToTransformation()) { |
|
62
|
|
|
throw new UnprocessableBoardException(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$shard = new FinalItem($shardUuid, $profile, $data); |
|
66
|
|
|
$this->metadata->replace($shard); |
|
67
|
|
|
$this->pushEvent(new ShardUpdatedEvent($this->uuid, $shard)); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public function getUuid(): Uuid |
|
71
|
|
|
{ |
|
72
|
|
|
return $this->uuid; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function getProfile(): Profile |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->profile; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
public function getFinalMetadata(): Metadata |
|
81
|
|
|
{ |
|
82
|
|
|
if (!$this->metadata->readyToTransformation()) { |
|
83
|
|
|
throw new UnprocessableBoardException(); |
|
84
|
|
|
} |
|
85
|
|
|
return $this->metadata; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|