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
|
|
|
public $loa; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $logo; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
public $alt; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var array |
42
|
|
|
*/ |
43
|
|
|
public $title; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
public $description; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
public $buttonUse; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var null |
57
|
|
|
*/ |
58
|
|
|
public $currentLanguage = null; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The alt, title, description and buttonUse are arrays of translated text. |
62
|
|
|
* |
63
|
|
|
* @param string $loa |
64
|
|
|
* @param string $logo |
65
|
|
|
* @param array $alt |
66
|
|
|
* @param array $title |
67
|
|
|
* @param array $description |
68
|
|
|
* @param array $buttonUse |
69
|
|
|
*/ |
70
|
|
|
public function __construct($loa, $logo, array $alt, array $title, array $description, array $buttonUse) |
71
|
|
|
{ |
72
|
|
|
$this->loa = $loa; |
73
|
|
|
$this->logo = $logo; |
74
|
|
|
$this->alt = $alt; |
75
|
|
|
$this->title = $title; |
76
|
|
|
$this->description = $description; |
77
|
|
|
$this->buttonUse = $buttonUse; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return array |
82
|
|
|
*/ |
83
|
|
|
public function getTitle() |
84
|
|
|
{ |
85
|
|
|
return $this->getTranslation($this->title); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* @return array |
90
|
|
|
*/ |
91
|
|
|
public function getAlt() |
92
|
|
|
{ |
93
|
|
|
return $this->getTranslation($this->alt); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getDescription() |
100
|
|
|
{ |
101
|
|
|
return $this->getTranslation($this->description); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @return array |
106
|
|
|
*/ |
107
|
|
|
public function getButtonUse() |
108
|
|
|
{ |
109
|
|
|
return $this->getTranslation($this->buttonUse); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @param array $translations |
114
|
|
|
* @return mixed |
115
|
|
|
* @throws LogicException |
116
|
|
|
*/ |
117
|
|
|
private function getTranslation(array $translations) |
118
|
|
|
{ |
119
|
|
|
if (is_null($this->currentLanguage)) { |
120
|
|
|
throw new LogicException('The current language is not set'); |
121
|
|
|
} |
122
|
|
|
if (isset($translations[$this->currentLanguage])) { |
123
|
|
|
return $translations[$this->currentLanguage]; |
124
|
|
|
} |
125
|
|
|
throw new LogicException( |
126
|
|
|
sprintf( |
127
|
|
|
'The requested translation is not available in this language: %s. Available languages: %s', |
128
|
|
|
$this->currentLanguage, |
129
|
|
|
implode(', ', array_keys($translations)) |
130
|
|
|
) |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|