1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2017 SURFnet bv |
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\StepupSelfService\SamlStepupProviderBundle\Provider; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Exception\LogicException; |
22
|
|
|
|
23
|
|
|
class ViewConfig |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
private $loa; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $logo; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private $alt; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
private $title; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
private $description; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
private $buttonUse; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
private $initiateTitle; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
private $initiateButton; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @var array |
67
|
|
|
*/ |
68
|
|
|
private $explanation; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @var array |
72
|
|
|
*/ |
73
|
|
|
private $authnFailed; |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @var array |
77
|
|
|
*/ |
78
|
|
|
private $popFailed; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @var null |
82
|
|
|
*/ |
83
|
|
|
public $currentLanguage = null; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* The arrays are arrays of translated text, indexed on locale. |
87
|
|
|
* |
88
|
|
|
* @param string $loa |
89
|
|
|
* @param string $logo |
90
|
|
|
* @param array $alt |
91
|
|
|
* @param array $title |
92
|
|
|
* @param array $description |
93
|
|
|
* @param array $buttonUse |
94
|
|
|
* @param array $initiateTitle |
95
|
|
|
* @param array $initiateButton |
96
|
|
|
* @param array $explanation |
97
|
|
|
* @param array $authnFailed |
98
|
|
|
* @param array $popFailed |
99
|
|
|
* @SuppressWarnings(PHPMD.ExcessiveParameterList) |
100
|
|
|
*/ |
101
|
|
|
public function __construct( |
102
|
|
|
$loa, |
103
|
|
|
$logo, |
104
|
|
|
array $alt, |
105
|
|
|
array $title, |
106
|
|
|
array $description, |
107
|
|
|
array $buttonUse, |
108
|
|
|
array $initiateTitle, |
109
|
|
|
array $initiateButton, |
110
|
|
|
array $explanation, |
111
|
|
|
array $authnFailed, |
112
|
|
|
array $popFailed |
113
|
|
|
) { |
114
|
|
|
$this->loa = $loa; |
115
|
|
|
$this->logo = $logo; |
116
|
|
|
$this->alt = $alt; |
117
|
|
|
$this->title = $title; |
118
|
|
|
$this->description = $description; |
119
|
|
|
$this->buttonUse = $buttonUse; |
120
|
|
|
$this->initiateTitle = $initiateTitle; |
121
|
|
|
$this->initiateButton = $initiateButton; |
122
|
|
|
$this->explanation = $explanation; |
123
|
|
|
$this->authnFailed = $authnFailed; |
124
|
|
|
$this->popFailed = $popFailed; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @return string |
129
|
|
|
*/ |
130
|
|
|
public function getLogo() |
131
|
|
|
{ |
132
|
|
|
return $this->logo; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return string |
137
|
|
|
*/ |
138
|
|
|
public function getLoa() |
139
|
|
|
{ |
140
|
|
|
return $this->loa; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getTitle() |
147
|
|
|
{ |
148
|
|
|
return $this->getTranslation($this->title); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @return string |
153
|
|
|
*/ |
154
|
|
|
public function getAlt() |
155
|
|
|
{ |
156
|
|
|
return $this->getTranslation($this->alt); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return string |
161
|
|
|
*/ |
162
|
|
|
public function getDescription() |
163
|
|
|
{ |
164
|
|
|
return $this->getTranslation($this->description); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getButtonUse() |
171
|
|
|
{ |
172
|
|
|
return $this->getTranslation($this->buttonUse); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
|
|
public function getInitiateTitle() |
179
|
|
|
{ |
180
|
|
|
return $this->getTranslation($this->initiateTitle); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* @return string |
185
|
|
|
*/ |
186
|
|
|
public function getInitiateButton() |
187
|
|
|
{ |
188
|
|
|
return $this->getTranslation($this->initiateButton); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
public function getExplanation() |
195
|
|
|
{ |
196
|
|
|
return $this->getTranslation($this->explanation); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
public function getAuthnFailed() |
203
|
|
|
{ |
204
|
|
|
return $this->getTranslation($this->authnFailed); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* @return string |
209
|
|
|
*/ |
210
|
|
|
public function getPopFailed() |
211
|
|
|
{ |
212
|
|
|
return $this->getTranslation($this->popFailed); |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* @param array $translations |
217
|
|
|
* @return mixed |
218
|
|
|
* @throws LogicException |
219
|
|
|
*/ |
220
|
|
|
private function getTranslation(array $translations) |
221
|
|
|
{ |
222
|
|
|
if (is_null($this->currentLanguage)) { |
223
|
|
|
throw new LogicException('The current language is not set'); |
224
|
|
|
} |
225
|
|
|
if (isset($translations[$this->currentLanguage])) { |
226
|
|
|
return $translations[$this->currentLanguage]; |
227
|
|
|
} |
228
|
|
|
throw new LogicException( |
229
|
|
|
sprintf( |
230
|
|
|
'The requested translation is not available in this language: %s. Available languages: %s', |
231
|
|
|
$this->currentLanguage, |
232
|
|
|
implode(', ', array_keys($translations)) |
233
|
|
|
) |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|