1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 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 Surfnet\StepupMiddlewareClientBundle\Configuration\Service; |
20
|
|
|
|
21
|
|
|
use Surfnet\StepupMiddlewareClient\Configuration\Service\InstitutionConfigurationOptionsService as LibraryInstitutionConfigurationOptionsService; |
|
|
|
|
22
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Configuration\Dto\InstitutionConfigurationOptions; |
23
|
|
|
use Surfnet\StepupMiddlewareClientBundle\Exception\InvalidResponseException; |
24
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
25
|
|
|
|
26
|
|
View Code Duplication |
final class InstitutionConfigurationOptionsService |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @var LibraryInstitutionConfigurationOptionsService |
30
|
|
|
*/ |
31
|
|
|
private $service; |
32
|
|
|
/** |
33
|
|
|
* @var ValidatorInterface |
34
|
|
|
*/ |
35
|
|
|
private $validator; |
36
|
|
|
|
37
|
|
|
public function __construct(LibraryInstitutionConfigurationOptionsService $service, ValidatorInterface $validator) |
38
|
|
|
{ |
39
|
|
|
$this->service = $service; |
40
|
|
|
$this->validator = $validator; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param $institution |
45
|
|
|
* @return null|InstitutionConfigurationOptions |
46
|
|
|
*/ |
47
|
|
|
public function getInstitutionConfigurationOptionsFor($institution) |
48
|
|
|
{ |
49
|
|
|
$data = $this->service->getInstitutionConfigurationOptionsFor($institution); |
50
|
|
|
|
51
|
|
|
if ($data === null) { |
52
|
|
|
return null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$institutionConfigurationOptions = InstitutionConfigurationOptions::fromData($data); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$violations = $this->validator->validate($institutionConfigurationOptions); |
58
|
|
|
if (count($violations) > 0) { |
59
|
|
|
throw InvalidResponseException::withViolations( |
60
|
|
|
sprintf('Could not get institution configuration options for "%s": invalid response', $institution), |
61
|
|
|
$violations |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $institutionConfigurationOptions; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.