1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2018 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\Stepup\Configuration\Value; |
20
|
|
|
|
21
|
|
|
use JsonSerializable; |
22
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
23
|
|
|
|
24
|
|
|
class UseRaaOption implements JsonSerializable |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var InstitutionSet|null |
28
|
|
|
*/ |
29
|
|
|
private $institutions; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* UseRaaOption constructor. |
33
|
|
|
* @param string[]|null $useRaaOption |
34
|
|
|
*/ |
35
|
|
|
public function __construct($useRaaOption) |
36
|
|
|
{ |
37
|
|
|
if (!is_null($useRaaOption) && !is_array($useRaaOption)) { |
38
|
|
|
throw InvalidArgumentException::invalidType( |
39
|
|
|
'null or string[]', |
40
|
|
|
'useRaaOption', |
41
|
|
|
$useRaaOption |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Sort the array values alphabetically |
46
|
|
|
if (is_array($useRaaOption)) { |
47
|
|
|
sort($useRaaOption); |
48
|
|
|
$this->institutions = InstitutionSet::fromInstitutionConfig($useRaaOption); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function getDefault() |
53
|
|
|
{ |
54
|
|
|
return new self(null); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* If array, returns the array sorted |
59
|
|
|
* @return null|string[] |
|
|
|
|
60
|
|
|
*/ |
61
|
|
|
public function getUseRaaOption() |
62
|
|
|
{ |
63
|
|
|
if (is_array($this->institutions)) { |
64
|
|
|
sort($this->institutions); |
65
|
|
|
} |
66
|
|
|
return $this->institutions; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function isOption($option){ |
70
|
|
|
return is_array($this->institutions) && in_array($this->institutions, $option); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function hasOptions(){ |
74
|
|
|
return is_array($this->institutions); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function equals(UseRaaOption $other) |
78
|
|
|
{ |
79
|
|
|
$thisValue = null; |
80
|
|
|
$otherValue = null; |
81
|
|
|
if (!is_null($this->getInstitutions())) { |
82
|
|
|
$thisValue = $this->getInstitutions()->toScalarArray(); |
83
|
|
|
} |
84
|
|
|
if (!is_null($other->getInstitutions())) { |
85
|
|
|
$otherValue = $other->getInstitutions()->toScalarArray(); |
86
|
|
|
} |
87
|
|
|
return $thisValue === $otherValue; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function getInstitutions() |
91
|
|
|
{ |
92
|
|
|
return $this->institutions; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function jsonSerialize() |
96
|
|
|
{ |
97
|
|
|
return $this->getInstitutions()->toScalarArray(); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.