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\FragmentedDataBoardDomain\Board; |
15
|
|
|
|
16
|
|
|
use Aggrego\AggregateEventConsumer\Shared\TraitAggregate; |
17
|
|
|
use Aggrego\AggregateEventConsumer\Uuid; |
18
|
|
|
use Aggrego\Domain\Board\Board as DomainBoard; |
19
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Events\BoardCreatedEvent; |
20
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Events\ShardAddedEvent; |
21
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Events\ShardUpdatedEvent; |
22
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Events\UpdatedLastStepsShardEvent; |
23
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Exception\UnprocessableBoardException; |
24
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Shard\FinalItem; |
25
|
|
|
use Aggrego\Domain\Board\Key; |
26
|
|
|
use Aggrego\Domain\Profile\Profile; |
27
|
|
|
use Aggrego\FragmentedDataBoardDomain\Board\Shard\Uuid as ShardUuid; |
28
|
|
|
|
29
|
|
|
class Board implements DomainBoard |
30
|
|
|
{ |
31
|
|
|
use TraitAggregate; |
32
|
|
|
|
33
|
|
|
/** @var Uuid */ |
34
|
|
|
private $uuid; |
35
|
|
|
|
36
|
|
|
/** @var Key */ |
37
|
|
|
private $key; |
38
|
|
|
|
39
|
|
|
/** @var Profile */ |
40
|
|
|
private $profile; |
41
|
|
|
|
42
|
|
|
/** @var Metadata */ |
43
|
|
|
private $metadata; |
44
|
|
|
|
45
|
|
|
private function __construct(Uuid $uuid, Key $key, Profile $profile, Metadata $metadata, ?Uuid $parentUuid) |
46
|
|
|
{ |
47
|
|
|
$this->uuid = $uuid; |
48
|
|
|
$this->key = $key; |
49
|
|
|
$this->profile = $profile; |
50
|
|
|
$this->metadata = $metadata; |
51
|
|
|
|
52
|
|
|
$this->pushEvent(new BoardCreatedEvent($uuid, $key, $profile, $parentUuid)); |
53
|
|
|
|
54
|
|
|
$this->metadata = $metadata; |
55
|
|
|
foreach ($metadata->getShards() as $shard) { |
56
|
|
|
$this->pushEvent(new ShardAddedEvent($this->uuid, $shard)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function updateShard(ShardUuid $shardUuid, Profile $profile, Data $data): void |
61
|
|
|
{ |
62
|
|
|
if (!$this->metadata->readyToTransformation()) { |
63
|
|
|
throw new UnprocessableBoardException(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$shard = new FinalItem($shardUuid, $profile, $data); |
67
|
|
|
$this->metadata->replace($shard); |
68
|
|
|
$this->pushEvent(new ShardUpdatedEvent($this->uuid, $shard)); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function getUuid(): Uuid |
72
|
|
|
{ |
73
|
|
|
return $this->uuid; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function getProfile(): Profile |
77
|
|
|
{ |
78
|
|
|
return $this->profile; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getMetadata(): Metadata |
82
|
|
|
{ |
83
|
|
|
return $this->metadata; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|