1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Role\Services; |
4
|
|
|
|
5
|
|
|
use Broadway\CommandHandling\CommandBusInterface; |
6
|
|
|
use Broadway\Repository\RepositoryInterface; |
7
|
|
|
use Broadway\UuidGenerator\UuidGeneratorInterface; |
8
|
|
|
use CultuurNet\UDB3\Role\Commands\AddConstraint; |
9
|
|
|
use CultuurNet\UDB3\Role\Commands\AddLabel; |
10
|
|
|
use CultuurNet\UDB3\Role\Commands\AddPermission; |
11
|
|
|
use CultuurNet\UDB3\Role\Commands\AddUser; |
12
|
|
|
use CultuurNet\UDB3\Role\Commands\DeleteRole; |
13
|
|
|
use CultuurNet\UDB3\Role\Commands\RemoveConstraint; |
14
|
|
|
use CultuurNet\UDB3\Role\Commands\RemoveLabel; |
15
|
|
|
use CultuurNet\UDB3\Role\Commands\RemovePermission; |
16
|
|
|
use CultuurNet\UDB3\Role\Commands\RemoveUser; |
17
|
|
|
use CultuurNet\UDB3\Role\Commands\RenameRole; |
18
|
|
|
use CultuurNet\UDB3\Role\Commands\UpdateConstraint; |
19
|
|
|
use CultuurNet\UDB3\Role\Role; |
20
|
|
|
use CultuurNet\UDB3\Role\ValueObjects\Permission; |
21
|
|
|
use CultuurNet\UDB3\Role\ValueObjects\Query; |
22
|
|
|
use CultuurNet\UDB3\ValueObject\SapiVersion; |
23
|
|
|
use ValueObjects\Identity\UUID; |
24
|
|
|
use ValueObjects\StringLiteral\StringLiteral; |
25
|
|
|
|
26
|
|
|
class DefaultRoleEditingService implements RoleEditingServiceInterface |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var CommandBusInterface |
30
|
|
|
*/ |
31
|
|
|
private $commandBus; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @var UuidGeneratorInterface |
35
|
|
|
*/ |
36
|
|
|
private $uuidGenerator; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var RepositoryInterface |
40
|
|
|
*/ |
41
|
|
|
private $writeRepository; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* DefaultRoleEditingService constructor. |
45
|
|
|
* |
46
|
|
|
* @param CommandBusInterface $commandBus |
47
|
|
|
* @param UuidGeneratorInterface $uuidGenerator |
48
|
|
|
* @param RepositoryInterface $writeRepository |
49
|
|
|
*/ |
50
|
|
|
public function __construct( |
51
|
|
|
CommandBusInterface $commandBus, |
52
|
|
|
UuidGeneratorInterface $uuidGenerator, |
53
|
|
|
RepositoryInterface $writeRepository |
54
|
|
|
) { |
55
|
|
|
$this->commandBus = $commandBus; |
56
|
|
|
$this->uuidGenerator = $uuidGenerator; |
57
|
|
|
$this->writeRepository = $writeRepository; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritdoc |
62
|
|
|
*/ |
63
|
|
|
public function create(StringLiteral $name) |
64
|
|
|
{ |
65
|
|
|
$uuid = new UUID($this->uuidGenerator->generate()); |
66
|
|
|
|
67
|
|
|
$role = Role::create($uuid, $name); |
68
|
|
|
|
69
|
|
|
$this->writeRepository->save($role); |
70
|
|
|
|
71
|
|
|
return $uuid->toNative(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
*/ |
77
|
|
|
public function rename(UUID $uuid, StringLiteral $name) |
78
|
|
|
{ |
79
|
|
|
$command = new RenameRole( |
80
|
|
|
$uuid, |
81
|
|
|
$name |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
return $this->commandBus->dispatch($command); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritdoc |
89
|
|
|
*/ |
90
|
|
|
public function addPermission(UUID $uuid, Permission $permission) |
91
|
|
|
{ |
92
|
|
|
$command = new AddPermission( |
93
|
|
|
$uuid, |
94
|
|
|
$permission |
95
|
|
|
); |
96
|
|
|
|
97
|
|
|
return $this->commandBus->dispatch($command); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @inheritdoc |
102
|
|
|
*/ |
103
|
|
|
public function removePermission(UUID $uuid, Permission $permission) |
104
|
|
|
{ |
105
|
|
|
$command = new RemovePermission( |
106
|
|
|
$uuid, |
107
|
|
|
$permission |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
return $this->commandBus->dispatch($command); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @inheritdoc |
115
|
|
|
*/ |
116
|
|
|
public function addUser(UUID $uuid, StringLiteral $userId) |
117
|
|
|
{ |
118
|
|
|
$command = new AddUser( |
119
|
|
|
$uuid, |
120
|
|
|
$userId |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
return $this->commandBus->dispatch($command); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* @inheritdoc |
128
|
|
|
*/ |
129
|
|
|
public function removeUser(UUID $uuid, StringLiteral $userId) |
130
|
|
|
{ |
131
|
|
|
$command = new RemoveUser( |
132
|
|
|
$uuid, |
133
|
|
|
$userId |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
return $this->commandBus->dispatch($command); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @inheritdoc |
141
|
|
|
*/ |
142
|
|
|
public function addConstraint(UUID $uuid, SapiVersion $sapiVersion, Query $query): string |
143
|
|
|
{ |
144
|
|
|
$command = new AddConstraint( |
145
|
|
|
$uuid, |
146
|
|
|
$sapiVersion, |
147
|
|
|
$query |
148
|
|
|
); |
149
|
|
|
|
150
|
|
|
return $this->commandBus->dispatch($command); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritdoc |
155
|
|
|
*/ |
156
|
|
|
public function updateConstraint(UUID $uuid, SapiVersion $sapiVersion, Query $query): string |
157
|
|
|
{ |
158
|
|
|
$command = new UpdateConstraint( |
159
|
|
|
$uuid, |
160
|
|
|
$sapiVersion, |
161
|
|
|
$query |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
return $this->commandBus->dispatch($command); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @inheritdoc |
169
|
|
|
*/ |
170
|
|
|
public function removeConstraint(UUID $uuid, SapiVersion $sapiVersion): string |
171
|
|
|
{ |
172
|
|
|
$command = new RemoveConstraint( |
173
|
|
|
$uuid, |
174
|
|
|
$sapiVersion |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
return $this->commandBus->dispatch($command); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @inheritdoc |
182
|
|
|
*/ |
183
|
|
|
public function addLabel(UUID $uuid, UUID $labelId) |
184
|
|
|
{ |
185
|
|
|
$command = new AddLabel( |
186
|
|
|
$uuid, |
187
|
|
|
$labelId |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
return $this->commandBus->dispatch($command); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* {@inheritdoc} |
195
|
|
|
*/ |
196
|
|
|
public function removeLabel(UUID $uuid, UUID $labelId) |
197
|
|
|
{ |
198
|
|
|
$command = new RemoveLabel( |
199
|
|
|
$uuid, |
200
|
|
|
$labelId |
201
|
|
|
); |
202
|
|
|
|
203
|
|
|
return $this->commandBus->dispatch($command); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* {@inheritdoc} |
208
|
|
|
*/ |
209
|
|
|
public function delete(UUID $uuid) |
210
|
|
|
{ |
211
|
|
|
$command = new DeleteRole( |
212
|
|
|
$uuid |
213
|
|
|
); |
214
|
|
|
|
215
|
|
|
return $this->commandBus->dispatch($command); |
216
|
|
|
} |
217
|
|
|
} |
218
|
|
|
|