1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
5
|
|
|
* |
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
7
|
|
|
* you may not use this file except in compliance with the License. |
8
|
|
|
* You may obtain a copy of the License at |
9
|
|
|
* |
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
11
|
|
|
* |
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
15
|
|
|
* See the License for the specific language governing permissions and |
16
|
|
|
* limitations under the License. |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
namespace Surfnet\Stepup\Configuration; |
20
|
|
|
|
21
|
|
|
use Broadway\EventSourcing\EventSourcedAggregateRoot; |
22
|
|
|
use Surfnet\Stepup\Configuration\Api\InstitutionConfiguration as InstitutionConfigurationInterface; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\ContactInformation; |
24
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
25
|
|
|
use Surfnet\Stepup\Configuration\Value\InstitutionConfigurationId; |
26
|
|
|
use Surfnet\Stepup\Configuration\Value\Location; |
27
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationId; |
28
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationList; |
29
|
|
|
use Surfnet\Stepup\Configuration\Value\RaLocationName; |
30
|
|
|
use Surfnet\Stepup\Exception\DomainException; |
31
|
|
|
|
32
|
|
|
class InstitutionConfiguration extends EventSourcedAggregateRoot implements InstitutionConfigurationInterface |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var InstitutionConfigurationId |
36
|
|
|
*/ |
37
|
|
|
private $institutionConfigurationId; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var RaLocationList |
41
|
|
|
*/ |
42
|
|
|
private $raLocations; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param InstitutionConfigurationId $institutionConfigurationId |
46
|
|
|
* @param Institution $institution |
47
|
|
|
* @return InstitutionConfiguration |
|
|
|
|
48
|
|
|
*/ |
49
|
|
|
public static function create(InstitutionConfigurationId $institutionConfigurationId, Institution $institution) |
50
|
|
|
{ |
51
|
|
|
// new self |
52
|
|
|
// apply institution configuration created event |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
final private function __construct() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function addRaLocation( |
60
|
|
|
RaLocationId $raLocationId, |
61
|
|
|
RaLocationName $raLocationName, |
62
|
|
|
Location $location, |
63
|
|
|
ContactInformation $contactInformation |
64
|
|
|
) { |
65
|
|
View Code Duplication |
if ($this->raLocations->hasWith($raLocationId)) { |
|
|
|
|
66
|
|
|
throw new DomainException(sprintf( |
67
|
|
|
'Cannot add RaLocation with RaLocationId "%s" to RaLocations of InstitutionConfiguration "%s":' |
68
|
|
|
. 'it is already present', |
69
|
|
|
$raLocationId, |
70
|
|
|
$this->getAggregateRootId() |
71
|
|
|
)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// apply ra location added event |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function changeRaLocation( |
78
|
|
|
RaLocationId $raLocationId, |
79
|
|
|
RaLocationName $raLocationName, |
80
|
|
|
Location $location, |
81
|
|
|
ContactInformation $contactInformation |
82
|
|
|
) { |
83
|
|
View Code Duplication |
if (!$this->raLocations->hasWith($raLocationId)) { |
|
|
|
|
84
|
|
|
throw new DomainException(sprintf( |
85
|
|
|
'Cannot change RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":' |
86
|
|
|
. 'it is not present', |
87
|
|
|
$raLocationId, |
88
|
|
|
$this->getAggregateRootId() |
89
|
|
|
)); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$raLocation = $this->raLocations->getBy($raLocationId); |
93
|
|
|
|
94
|
|
|
if (!$raLocation->getLocationName()->equals($raLocationName)) { |
|
|
|
|
95
|
|
|
// apply renamed event |
96
|
|
|
} |
97
|
|
|
if (!$raLocation->getLocation()->equals($location)) { |
|
|
|
|
98
|
|
|
// apply relocated event |
99
|
|
|
} |
100
|
|
|
if (!$raLocation->getContactInformation()->equals($contactInformation)) { |
|
|
|
|
101
|
|
|
// apply contact information changed event |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function removeRaLocation(RaLocationId $raLocationId) |
106
|
|
|
{ |
107
|
|
View Code Duplication |
if (!$this->raLocations->hasWith($raLocationId)) { |
|
|
|
|
108
|
|
|
throw new DomainException(sprintf( |
109
|
|
|
'Cannot remove RaLocation with RaLocationId "%s" in RaLocations of InstitutionConfiguration "%s":' |
110
|
|
|
. 'it is not present', |
111
|
|
|
$raLocationId, |
112
|
|
|
$this->getAggregateRootId() |
113
|
|
|
)); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// apply ra location removed event |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getAggregateRootId() |
120
|
|
|
{ |
121
|
|
|
return $this->institutionConfigurationId; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function applyInstitutionConfigurationCreatedEvent() |
125
|
|
|
{ |
126
|
|
|
// Implement |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function applyRaLocationAddedEvent() |
130
|
|
|
{ |
131
|
|
|
// Implement |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function applyRaLocationRenamedEvent() |
135
|
|
|
{ |
136
|
|
|
// Implement |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function applyRaLocationRelocatedEvent() |
140
|
|
|
{ |
141
|
|
|
// Implement |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function applyRaLocationContactInformationChangedEvent() |
145
|
|
|
{ |
146
|
|
|
// Implement |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function applyRaLocationRemovedEvent() |
150
|
|
|
{ |
151
|
|
|
// Implement |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.