1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright 2018 SURFnet B.V. |
4
|
|
|
* |
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
6
|
|
|
* you may not select this file except in compliance with the License. |
7
|
|
|
* You may obtain a copy of the License at |
8
|
|
|
* |
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
10
|
|
|
* |
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14
|
|
|
* See the License for the specific language governing permissions and |
15
|
|
|
* limitations under the License. |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace Surfnet\Stepup\Configuration\Value; |
19
|
|
|
|
20
|
|
|
use JsonSerializable; |
21
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
22
|
|
|
|
23
|
|
|
final class InstitutionRole implements JsonSerializable |
24
|
|
|
{ |
25
|
|
|
const ROLE_USE_RA = 'use_ra'; |
26
|
|
|
const ROLE_USE_RAA = 'use_raa'; |
27
|
|
|
const ROLE_SELECT_RAA = 'select_raa'; |
28
|
|
|
|
29
|
|
|
private static $validRoles = [ |
30
|
|
|
self::ROLE_USE_RA, |
31
|
|
|
self::ROLE_USE_RAA, |
32
|
|
|
self::ROLE_SELECT_RAA, |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $type; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* InstitutionRole constructor. |
42
|
|
|
* @param $type |
43
|
|
|
*/ |
44
|
|
|
private function __construct($type) |
45
|
|
|
{ |
46
|
|
|
if (!in_array($type, self::$validRoles)) { |
47
|
|
|
throw new InvalidArgumentException(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
$this->type = $type; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $type |
55
|
|
|
* @return InstitutionRole |
56
|
|
|
*/ |
57
|
|
|
public static function create($type) |
58
|
|
|
{ |
59
|
|
|
return new self($type); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return InstitutionRole |
64
|
|
|
*/ |
65
|
|
|
public static function useRa() |
66
|
|
|
{ |
67
|
|
|
return new self(self::ROLE_USE_RA); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return InstitutionRole |
72
|
|
|
*/ |
73
|
|
|
public static function useRaa() |
74
|
|
|
{ |
75
|
|
|
return new self(self::ROLE_USE_RAA); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @return InstitutionRole |
80
|
|
|
*/ |
81
|
|
|
public static function selectRaa() |
82
|
|
|
{ |
83
|
|
|
return new self(self::ROLE_SELECT_RAA); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param InstitutionRole $role |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function equals(InstitutionRole $role) |
91
|
|
|
{ |
92
|
|
|
return $this->type == $role->getType(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
|
|
public function getType() |
99
|
|
|
{ |
100
|
|
|
return $this->type; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function jsonSerialize() |
104
|
|
|
{ |
105
|
|
|
return $this->type; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return string |
110
|
|
|
*/ |
111
|
|
|
public function __toString() |
112
|
|
|
{ |
113
|
|
|
return $this->type; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
} |
117
|
|
|
|