1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Label; |
4
|
|
|
|
5
|
|
|
use Broadway\Repository\RepositoryInterface; |
6
|
|
|
use CultuurNet\UDB3\CommandHandling\Udb3CommandHandler as AbstractCommandHandler; |
7
|
|
|
use CultuurNet\UDB3\Label\Commands\Create; |
8
|
|
|
use CultuurNet\UDB3\Label\Commands\CreateCopy; |
9
|
|
|
use CultuurNet\UDB3\Label\Commands\MakeInvisible; |
10
|
|
|
use CultuurNet\UDB3\Label\Commands\MakePrivate; |
11
|
|
|
use CultuurNet\UDB3\Label\Commands\MakePublic; |
12
|
|
|
use CultuurNet\UDB3\Label\Commands\MakeVisible; |
13
|
|
|
use CultuurNet\UDB3\Label\Label as LabelAggregate; |
14
|
|
|
use ValueObjects\Identity\UUID; |
15
|
|
|
|
16
|
|
|
class CommandHandler extends AbstractCommandHandler |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var RepositoryInterface |
20
|
|
|
*/ |
21
|
|
|
private $repository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param RepositoryInterface $repository |
25
|
|
|
*/ |
26
|
|
|
public function __construct( |
27
|
|
|
RepositoryInterface $repository |
28
|
|
|
) { |
29
|
|
|
$this->repository = $repository; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Create $create |
34
|
|
|
*/ |
35
|
|
|
public function handleCreate(Create $create) |
36
|
|
|
{ |
37
|
|
|
$label = LabelAggregate::create( |
38
|
|
|
$create->getUuid(), |
39
|
|
|
$create->getName(), |
40
|
|
|
$create->getVisibility(), |
41
|
|
|
$create->getPrivacy() |
42
|
|
|
); |
43
|
|
|
|
44
|
|
|
$this->save($label); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param CreateCopy $createCopy |
49
|
|
|
*/ |
50
|
|
|
public function handleCreateCopy(CreateCopy $createCopy) |
51
|
|
|
{ |
52
|
|
|
$label = LabelAggregate::createCopy( |
53
|
|
|
$createCopy->getUuid(), |
54
|
|
|
$createCopy->getName(), |
55
|
|
|
$createCopy->getVisibility(), |
56
|
|
|
$createCopy->getPrivacy(), |
57
|
|
|
$createCopy->getParentUuid() |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->save($label); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param MakeVisible $makeVisible |
65
|
|
|
*/ |
66
|
|
|
public function handleMakeVisible(MakeVisible $makeVisible) |
67
|
|
|
{ |
68
|
|
|
$label = $this->load($makeVisible->getUuid()); |
69
|
|
|
|
70
|
|
|
$label->makeVisible(); |
71
|
|
|
|
72
|
|
|
$this->save($label); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param MakeInvisible $makeInvisible |
77
|
|
|
*/ |
78
|
|
|
public function handleMakeInvisible(MakeInvisible $makeInvisible) |
79
|
|
|
{ |
80
|
|
|
$label = $this->load($makeInvisible->getUuid()); |
81
|
|
|
|
82
|
|
|
$label->makeInvisible(); |
83
|
|
|
|
84
|
|
|
$this->save($label); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param MakePublic $makePublic |
89
|
|
|
*/ |
90
|
|
|
public function handleMakePublic(MakePublic $makePublic) |
91
|
|
|
{ |
92
|
|
|
$label = $this->load($makePublic->getUuid()); |
93
|
|
|
|
94
|
|
|
$label->makePublic(); |
95
|
|
|
|
96
|
|
|
$this->save($label); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param MakePrivate $makePrivate |
101
|
|
|
*/ |
102
|
|
|
public function handleMakePrivate(MakePrivate $makePrivate) |
103
|
|
|
{ |
104
|
|
|
$label = $this->load($makePrivate->getUuid()); |
105
|
|
|
|
106
|
|
|
$label->makePrivate(); |
107
|
|
|
|
108
|
|
|
$this->save($label); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param UUID $uuid |
113
|
|
|
* @return LabelAggregate |
114
|
|
|
*/ |
115
|
|
|
private function load(UUID $uuid) |
116
|
|
|
{ |
117
|
|
|
return $this->repository->load($uuid); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param LabelAggregate $label |
122
|
|
|
*/ |
123
|
|
|
private function save(LabelAggregate $label) |
124
|
|
|
{ |
125
|
|
|
$this->repository->save($label); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|