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
|
|
|
use CultuurNet\UDB3\ValueObject\SapiVersion; |
15
|
|
|
|
16
|
|
|
class Projector implements EventListenerInterface |
17
|
|
|
{ |
18
|
|
|
use DelegateEventHandlingToSpecificMethodTrait; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var RepositoryInterface |
22
|
|
|
*/ |
23
|
|
|
private $repository; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var SapiVersion |
27
|
|
|
*/ |
28
|
|
|
private $sapiVersion; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param RepositoryInterface $repository |
32
|
|
|
* @param SapiVersion $sapiVersion |
33
|
|
|
*/ |
34
|
|
|
public function __construct( |
35
|
|
|
RepositoryInterface $repository, |
36
|
|
|
SapiVersion $sapiVersion |
37
|
|
|
) { |
38
|
|
|
$this->sapiVersion = $sapiVersion; |
39
|
|
|
$this->repository = $repository; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @param RoleCreated $roleCreated |
44
|
|
|
* @param DomainMessage $domainMessage |
45
|
|
|
*/ |
46
|
|
|
public function applyRoleCreated( |
47
|
|
|
RoleCreated $roleCreated, |
48
|
|
|
DomainMessage $domainMessage |
|
|
|
|
49
|
|
|
) { |
50
|
|
|
$this->repository->save( |
51
|
|
|
$roleCreated->getUuid()->toNative(), |
52
|
|
|
$roleCreated->getName()->toNative() |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param RoleRenamed $roleRenamed |
58
|
|
|
* @param DomainMessage $domainMessage |
59
|
|
|
*/ |
60
|
|
|
public function applyRoleRenamed( |
61
|
|
|
RoleRenamed $roleRenamed, |
62
|
|
|
DomainMessage $domainMessage |
|
|
|
|
63
|
|
|
) { |
64
|
|
|
$this->repository->updateName( |
65
|
|
|
$roleRenamed->getUuid()->toNative(), |
66
|
|
|
$roleRenamed->getName()->toNative() |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param RoleDeleted $roleDeleted |
72
|
|
|
* @param DomainMessage $domainMessage |
73
|
|
|
*/ |
74
|
|
|
public function applyRoleDeleted( |
75
|
|
|
RoleDeleted $roleDeleted, |
76
|
|
|
DomainMessage $domainMessage |
|
|
|
|
77
|
|
|
) { |
78
|
|
|
$this->repository->remove($roleDeleted->getUuid()->toNative()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param ConstraintAdded $constraintAdded |
83
|
|
|
*/ |
84
|
|
|
protected function applyConstraintAdded(ConstraintAdded $constraintAdded) |
85
|
|
|
{ |
86
|
|
|
if ($constraintAdded->getSapiVersion()->sameValueAs($this->sapiVersion)) { |
87
|
|
|
$this->repository->updateConstraint( |
88
|
|
|
$constraintAdded->getUuid(), |
89
|
|
|
$constraintAdded->getQuery() |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param ConstraintUpdated $constraintUpdated |
96
|
|
|
*/ |
97
|
|
|
protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated) |
98
|
|
|
{ |
99
|
|
|
if ($constraintUpdated->getSapiVersion()->sameValueAs($this->sapiVersion)) { |
100
|
|
|
$this->repository->updateConstraint( |
101
|
|
|
$constraintUpdated->getUuid(), |
102
|
|
|
$constraintUpdated->getQuery() |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @param ConstraintRemoved $constraintRemoved |
109
|
|
|
*/ |
110
|
|
|
protected function applyConstraintRemoved(ConstraintRemoved $constraintRemoved) |
111
|
|
|
{ |
112
|
|
|
if ($constraintRemoved->getSapiVersion()->sameValueAs($this->sapiVersion)) { |
113
|
|
|
$this->repository->updateConstraint( |
114
|
|
|
$constraintRemoved->getUuid() |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.