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