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\BasicBlockDomainProfile\Domain\Profile\BoardConstruction; |
15
|
|
|
|
16
|
|
|
use Aggrego\DataDomainBoard\Board\Data; |
17
|
|
|
use Aggrego\DataDomainBoard\Board\Prototype\Board; |
18
|
|
|
use Aggrego\Domain\Board\Key; |
19
|
|
|
use Aggrego\Domain\Board\Prototype\Board as BoardPrototype; |
20
|
|
|
use Aggrego\Domain\Profile\BoardConstruction\Builder as DomainBuilder; |
21
|
|
|
use Aggrego\Domain\Profile\BoardConstruction\Exception\UnableToBuildBoardException; |
22
|
|
|
use Aggrego\Domain\Profile\Profile; |
23
|
|
|
use Assert\Assertion; |
24
|
|
|
use Exception; |
25
|
|
|
|
26
|
|
|
class Builder implements DomainBuilder |
27
|
|
|
{ |
28
|
|
|
private const KEY_UUID = 'uuid'; |
29
|
|
|
private const KEY_NAME = 'name'; |
30
|
|
|
private const KEY_VALUE = 'value'; |
31
|
|
|
|
32
|
|
|
/** @var Profile */ |
33
|
|
|
private $profile; |
34
|
|
|
|
35
|
|
|
public function __construct(Profile $profile) |
36
|
|
|
{ |
37
|
|
|
$this->profile = $profile; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param Key $key |
42
|
|
|
* @return BoardPrototype |
43
|
|
|
* @throws UnableToBuildBoardException |
44
|
|
|
*/ |
45
|
|
|
public function build(Key $key): BoardPrototype |
46
|
|
|
{ |
47
|
|
|
$keyValue = $key->getValue(); |
48
|
|
|
try { |
49
|
|
|
Assertion::keyExists($keyValue, self::KEY_UUID); |
50
|
|
|
Assertion::uuid($keyValue[self::KEY_UUID]); |
51
|
|
|
Assertion::keyExists($keyValue, self::KEY_NAME); |
52
|
|
|
Assertion::notEmpty($keyValue[self::KEY_NAME]); |
53
|
|
|
Assertion::keyExists($keyValue, self::KEY_VALUE); |
54
|
|
|
Assertion::notEmpty($keyValue[self::KEY_VALUE]); |
55
|
|
|
} catch (Exception $e) { |
56
|
|
|
throw new UnableToBuildBoardException('Unable to create board due to: ' . $e->getMessage(), 0, $e); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return new Board( |
60
|
|
|
new Key(['name' => $keyValue[self::KEY_NAME], 'uuid' => $keyValue[self::KEY_UUID]]), |
61
|
|
|
$this->profile, |
62
|
|
|
new Data($keyValue[self::KEY_VALUE]) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|