|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2015 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 OpenConext\Profile\Value\Consent; |
|
20
|
|
|
|
|
21
|
|
|
use OpenConext\EngineBlockApiClientBundle\Exception\LogicException; |
|
22
|
|
|
use OpenConext\Profile\Assert; |
|
23
|
|
|
use OpenConext\Profile\Value\DisplayName; |
|
24
|
|
|
use OpenConext\Profile\Value\NameIdFormat; |
|
25
|
|
|
use OpenConext\Profile\Value\ContactEmailAddress; |
|
26
|
|
|
use OpenConext\Profile\Value\Entity; |
|
27
|
|
|
use OpenConext\Profile\Value\Url; |
|
28
|
|
|
|
|
29
|
|
|
final class ServiceProvider |
|
30
|
|
|
{ |
|
31
|
|
|
/** |
|
32
|
|
|
* @var Entity |
|
33
|
|
|
*/ |
|
34
|
|
|
private $entity; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @var DisplayName |
|
38
|
|
|
*/ |
|
39
|
|
|
private $displayName; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var NameIdFormat |
|
43
|
|
|
*/ |
|
44
|
|
|
private $nameIdFormat; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var Url|null |
|
48
|
|
|
*/ |
|
49
|
|
|
private $eulaUrl; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @var ContactEmailAddress|null |
|
53
|
|
|
*/ |
|
54
|
|
|
private $supportEmail; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @var Url|null |
|
58
|
|
|
*/ |
|
59
|
|
|
private $supportUrlEn; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var Url|null |
|
63
|
|
|
*/ |
|
64
|
|
|
private $supportUrlNl; |
|
65
|
|
|
|
|
66
|
|
|
public function __construct( |
|
67
|
|
|
Entity $entity, |
|
68
|
|
|
DisplayName $displayName, |
|
69
|
|
|
NameIdFormat $nameIdFormat, |
|
70
|
|
|
Url $eulaUrl = null, |
|
71
|
|
|
ContactEmailAddress $supportEmail = null, |
|
72
|
|
|
Url $supportUrlEn = null, |
|
73
|
|
|
Url $supportUrlNl = null |
|
74
|
|
|
) { |
|
75
|
|
|
$this->entity = $entity; |
|
76
|
|
|
$this->displayName = $displayName; |
|
77
|
|
|
$this->nameIdFormat = $nameIdFormat; |
|
78
|
|
|
$this->eulaUrl = $eulaUrl; |
|
79
|
|
|
$this->supportEmail = $supportEmail; |
|
80
|
|
|
$this->supportUrlEn = $supportUrlEn; |
|
81
|
|
|
$this->supportUrlNl = $supportUrlNl; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @return Entity |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getEntity() |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->entity; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @return DisplayName |
|
94
|
|
|
*/ |
|
95
|
|
|
public function getDisplayName() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->displayName; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @return NameIdFormat |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getNameIdFormat() |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->nameIdFormat; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $locale |
|
110
|
|
|
* @return string |
|
111
|
|
|
*/ |
|
112
|
|
|
public function getLocaleAwareEntityName($locale) |
|
113
|
|
|
{ |
|
114
|
|
|
Assert::string($locale); |
|
115
|
|
|
|
|
116
|
|
|
if ($this->displayName->hasFilledTranslationForLocale($locale)) { |
|
117
|
|
|
return $this->displayName->getTranslation($locale); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $this->entity->getEntityId()->getEntityId(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @return bool |
|
125
|
|
|
*/ |
|
126
|
|
|
public function hasEulaUrl() |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->eulaUrl !== null; |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @return Url |
|
|
|
|
|
|
133
|
|
|
*/ |
|
134
|
|
|
public function getEulaUrl() |
|
135
|
|
|
{ |
|
136
|
|
|
if (!$this->hasEulaUrl()) { |
|
137
|
|
|
throw new LogicException('Service provider has no EULA url'); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
return $this->eulaUrl; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
/** |
|
144
|
|
|
* @return bool |
|
145
|
|
|
*/ |
|
146
|
|
|
public function hasSupportEmail() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->supportEmail !== null; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @return ContactEmailAddress |
|
|
|
|
|
|
153
|
|
|
*/ |
|
154
|
|
|
public function getSupportEmail() |
|
155
|
|
|
{ |
|
156
|
|
|
if (!$this->hasSupportEmail()) { |
|
157
|
|
|
throw new LogicException('Service provider has no support e-mail address'); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return $this->supportEmail; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param string $locale |
|
165
|
|
|
* @return null|Url |
|
166
|
|
|
*/ |
|
167
|
|
|
public function getSupportUrl($locale) |
|
168
|
|
|
{ |
|
169
|
|
|
if ($locale === 'nl') { |
|
170
|
|
|
return $this->supportUrlNl; |
|
171
|
|
|
} else { |
|
172
|
|
|
return $this->supportUrlEn; |
|
173
|
|
|
} |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* @param $locale |
|
178
|
|
|
* @return bool |
|
179
|
|
|
*/ |
|
180
|
|
|
public function hasSupportUrl($locale) |
|
181
|
|
|
{ |
|
182
|
|
|
if ($locale === 'nl') { |
|
183
|
|
|
return $this->supportUrlNl !== null; |
|
184
|
|
|
} else { |
|
185
|
|
|
return $this->supportUrlEn !== null; |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
} |
|
189
|
|
|
|
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.