1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CultuurNet\UDB3\Role\ReadModel\Search; |
4
|
|
|
|
5
|
|
|
use Broadway\EventHandling\EventListenerInterface; |
6
|
|
|
use Broadway\Domain\DomainMessage; |
7
|
|
|
use CultuurNet\UDB3\EventHandling\DelegateEventHandlingToSpecificMethodTrait; |
8
|
|
|
use CultuurNet\UDB3\Role\Events\ConstraintAdded; |
9
|
|
|
use CultuurNet\UDB3\Role\Events\ConstraintRemoved; |
10
|
|
|
use CultuurNet\UDB3\Role\Events\ConstraintUpdated; |
11
|
|
|
use CultuurNet\UDB3\Role\Events\RoleCreated; |
12
|
|
|
use CultuurNet\UDB3\Role\Events\RoleRenamed; |
13
|
|
|
use CultuurNet\UDB3\Role\Events\RoleDeleted; |
14
|
|
|
|
15
|
|
|
class Projector implements EventListenerInterface |
16
|
|
|
{ |
17
|
|
|
use DelegateEventHandlingToSpecificMethodTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var RepositoryInterface |
21
|
|
|
*/ |
22
|
|
|
private $repository; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param RepositoryInterface $repository |
26
|
|
|
*/ |
27
|
|
|
public function __construct(RepositoryInterface $repository) |
28
|
|
|
{ |
29
|
|
|
$this->repository = $repository; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param RoleCreated $roleCreated |
34
|
|
|
* @param DomainMessage $domainMessage |
35
|
|
|
*/ |
36
|
|
|
public function applyRoleCreated( |
37
|
|
|
RoleCreated $roleCreated, |
38
|
|
|
DomainMessage $domainMessage |
|
|
|
|
39
|
|
|
) { |
40
|
|
|
$this->repository->save( |
41
|
|
|
$roleCreated->getUuid()->toNative(), |
42
|
|
|
$roleCreated->getName()->toNative() |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param RoleRenamed $roleRenamed |
48
|
|
|
* @param DomainMessage $domainMessage |
49
|
|
|
*/ |
50
|
|
|
public function applyRoleRenamed( |
51
|
|
|
RoleRenamed $roleRenamed, |
52
|
|
|
DomainMessage $domainMessage |
|
|
|
|
53
|
|
|
) { |
54
|
|
|
$this->repository->updateName( |
55
|
|
|
$roleRenamed->getUuid()->toNative(), |
56
|
|
|
$roleRenamed->getName()->toNative() |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param RoleDeleted $roleDeleted |
62
|
|
|
* @param DomainMessage $domainMessage |
63
|
|
|
*/ |
64
|
|
|
public function applyRoleDeleted( |
65
|
|
|
RoleDeleted $roleDeleted, |
66
|
|
|
DomainMessage $domainMessage |
|
|
|
|
67
|
|
|
) { |
68
|
|
|
$this->repository->remove($roleDeleted->getUuid()->toNative()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param ConstraintAdded $constraintAdded |
73
|
|
|
*/ |
74
|
|
|
protected function applyConstraintAdded(ConstraintAdded $constraintAdded) |
75
|
|
|
{ |
76
|
|
|
$this->repository->updateConstraint( |
77
|
|
|
$constraintAdded->getUuid(), |
78
|
|
|
$constraintAdded->getQuery() |
79
|
|
|
); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param ConstraintUpdated $constraintUpdated |
84
|
|
|
*/ |
85
|
|
|
protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated) |
86
|
|
|
{ |
87
|
|
|
$this->repository->updateConstraint( |
88
|
|
|
$constraintUpdated->getUuid(), |
89
|
|
|
$constraintUpdated->getQuery() |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param ConstraintRemoved $constraintRemoved |
95
|
|
|
*/ |
96
|
|
|
protected function applyConstraintRemoved(ConstraintRemoved $constraintRemoved) |
97
|
|
|
{ |
98
|
|
|
$this->repository->updateConstraint( |
99
|
|
|
$constraintRemoved->getUuid() |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.