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
|
|
|
$this->sapiVersion = $sapiVersion; |
38
|
|
|
$this->repository = $repository; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param RoleCreated $roleCreated |
43
|
|
|
* @param DomainMessage $domainMessage |
44
|
|
|
*/ |
45
|
|
|
public function applyRoleCreated( |
46
|
|
|
RoleCreated $roleCreated, |
47
|
|
|
DomainMessage $domainMessage |
|
|
|
|
48
|
|
|
) { |
49
|
|
|
$this->repository->save( |
50
|
|
|
$roleCreated->getUuid()->toNative(), |
51
|
|
|
$roleCreated->getName()->toNative() |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param RoleRenamed $roleRenamed |
57
|
|
|
* @param DomainMessage $domainMessage |
58
|
|
|
*/ |
59
|
|
|
public function applyRoleRenamed( |
60
|
|
|
RoleRenamed $roleRenamed, |
61
|
|
|
DomainMessage $domainMessage |
|
|
|
|
62
|
|
|
) { |
63
|
|
|
$this->repository->updateName( |
64
|
|
|
$roleRenamed->getUuid()->toNative(), |
65
|
|
|
$roleRenamed->getName()->toNative() |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param RoleDeleted $roleDeleted |
71
|
|
|
* @param DomainMessage $domainMessage |
72
|
|
|
*/ |
73
|
|
|
public function applyRoleDeleted( |
74
|
|
|
RoleDeleted $roleDeleted, |
75
|
|
|
DomainMessage $domainMessage |
|
|
|
|
76
|
|
|
) { |
77
|
|
|
$this->repository->remove($roleDeleted->getUuid()->toNative()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param ConstraintAdded $constraintAdded |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
protected function applyConstraintAdded(ConstraintAdded $constraintAdded) { |
|
|
|
|
84
|
|
|
if ($constraintAdded->getSapiVersion() |
85
|
|
|
->toNative() === $this->sapiVersion->toNative()) { |
86
|
|
|
$this->repository->updateConstraint( |
87
|
|
|
$constraintAdded->getUuid(), |
88
|
|
|
$constraintAdded->getQuery() |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param ConstraintUpdated $constraintUpdated |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
protected function applyConstraintUpdated(ConstraintUpdated $constraintUpdated) |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
if ($constraintUpdated->getSapiVersion() |
99
|
|
|
->toNative() === $this->sapiVersion->toNative()) { |
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() |
113
|
|
|
->toNative() === $this->sapiVersion->toNative()) { |
114
|
|
|
$this->repository->updateConstraint( |
115
|
|
|
$constraintRemoved->getUuid() |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.