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\Domain\Board; |
15
|
|
|
|
16
|
|
|
use Aggrego\AggregateEventConsumer\Uuid; |
17
|
|
|
use Aggrego\Domain\Board\Builder as BoardBuilder; |
18
|
|
|
use Aggrego\Domain\Board\Exception\UnsupportedPrototypeBuilderException; |
19
|
|
|
use Aggrego\Domain\Profile\BoardConstruction\Factory as BoardConstructionFactory; |
20
|
|
|
use Aggrego\Domain\Profile\Profile; |
21
|
|
|
use Assert\Assertion; |
22
|
|
|
use Ramsey\Uuid\Uuid as RamseyUuid; |
23
|
|
|
|
24
|
|
|
class NewBoardFactory |
25
|
|
|
{ |
26
|
|
|
/** @var BoardBuilder[] */ |
27
|
|
|
private $builders; |
28
|
|
|
|
29
|
|
|
/** @var BoardConstructionFactory */ |
30
|
|
|
private $boardConstructionFactory; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
array $builders, |
34
|
|
|
BoardConstructionFactory $boardConstructionFactory |
35
|
|
|
) |
36
|
|
|
{ |
37
|
|
|
Assertion::allIsInstanceOf($builders, BoardBuilder::class); |
38
|
|
|
$this->builders = $builders; |
39
|
|
|
$this->boardConstructionFactory = $boardConstructionFactory; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function newBoard(Key $key, Profile $profile): Board |
43
|
|
|
{ |
44
|
|
|
$factory = $this->boardConstructionFactory->factory($profile); |
45
|
|
|
$prototype = $factory->build($key); |
46
|
|
|
$key = $prototype->getKey(); |
47
|
|
|
$profile = $prototype->getProfile(); |
48
|
|
|
|
49
|
|
|
$uuid = new Uuid( |
50
|
|
|
RamseyUuid::uuid5( |
|
|
|
|
51
|
|
|
RamseyUuid::NAMESPACE_DNS, |
52
|
|
|
serialize($key->getValue()) . $profile |
53
|
|
|
)->toString() |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
foreach ($this->builders as $builder) { |
57
|
|
|
if ($builder->isSupported($prototype)) { |
58
|
|
|
continue; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $builder->build( |
62
|
|
|
$uuid, |
63
|
|
|
$prototype->getKey(), |
64
|
|
|
$prototype->getProfile(), |
65
|
|
|
$prototype->getMetadata(), |
66
|
|
|
null |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
throw new UnsupportedPrototypeBuilderException(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.