1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2018 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\StepupGateway\SamlStepupProviderBundle\Provider; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupBundle\Value\Provider\ViewConfigInterface; |
22
|
|
|
use Surfnet\StepupGateway\SamlStepupProviderBundle\Exception\LogicException; |
23
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
24
|
|
|
|
25
|
|
|
class ViewConfig implements ViewConfigInterface |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var |
29
|
|
|
*/ |
30
|
|
|
private $requestStack; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
private $logo; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
private $title; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* The arrays are arrays of translated text, indexed on locale. |
44
|
|
|
* |
45
|
|
|
* @param RequestStack $requestStack |
46
|
|
|
* @param string $logo |
47
|
|
|
* @param array $title |
48
|
|
|
*/ |
49
|
|
|
public function __construct( |
50
|
|
|
RequestStack $requestStack, |
51
|
|
|
$logo, |
52
|
|
|
array $title |
53
|
|
|
) { |
54
|
|
|
$this->requestStack = $requestStack; |
55
|
|
|
$this->logo = $logo; |
56
|
|
|
$this->title = $title; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return string |
61
|
|
|
*/ |
62
|
|
|
public function getLogo() |
63
|
|
|
{ |
64
|
|
|
return $this->logo; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getTitle() |
71
|
|
|
{ |
72
|
|
|
return $this->getTranslation($this->title); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param array $translations |
77
|
|
|
* @return mixed |
78
|
|
|
* @throws LogicException |
79
|
|
|
*/ |
80
|
|
|
private function getTranslation(array $translations) |
81
|
|
|
{ |
82
|
|
|
$currentLocale = $this->requestStack->getCurrentRequest()->getLocale(); |
83
|
|
|
if (is_null($currentLocale)) { |
84
|
|
|
throw new LogicException('The current language is not set'); |
85
|
|
|
} |
86
|
|
|
if (isset($translations[$currentLocale])) { |
87
|
|
|
return $translations[$currentLocale]; |
88
|
|
|
} |
89
|
|
|
throw new LogicException( |
90
|
|
|
sprintf( |
91
|
|
|
'The requested translation is not available in this language: %s. Available languages: %s', |
92
|
|
|
$currentLocale, |
93
|
|
|
implode(', ', array_keys($translations)) |
94
|
|
|
) |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|