|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 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\Stepup\Identity\Value; |
|
20
|
|
|
|
|
21
|
|
|
use Broadway\Serializer\Serializable as SerializableInterface; |
|
22
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
23
|
|
|
|
|
24
|
|
|
final class RegistrationAuthorityRole implements SerializableInterface |
|
|
|
|
|
|
25
|
|
|
{ |
|
26
|
|
|
const ROLE_RA = 1; |
|
27
|
|
|
const ROLE_RAA = 2; |
|
28
|
|
|
const ROLE_SRAA = 3; |
|
29
|
|
|
|
|
30
|
|
|
/**RegistrationAuthorityRole |
|
|
|
|
|
|
31
|
|
|
* @var int |
|
|
|
|
|
|
32
|
|
|
*/ |
|
33
|
|
|
private $role; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param string $role may not be an empty string |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct($role) |
|
39
|
|
|
{ |
|
40
|
|
|
if (!is_int($role) || !in_array($role, [self::ROLE_RA, self::ROLE_RAA, self::ROLE_SRAA])) { |
|
|
|
|
|
|
41
|
|
|
throw new InvalidArgumentException( |
|
42
|
|
|
'Invalid role given, role must be one of RegistrationAuthorityRole::[ROLE_RA|ROLE_RAA|ROLE_SRAA]' |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
$this->role = $role; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public static function ra() |
|
50
|
|
|
{ |
|
51
|
|
|
return new self(self::ROLE_RA); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public static function raa() |
|
55
|
|
|
{ |
|
56
|
|
|
return new self(self::ROLE_RAA); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @param RegistrationAuthorityRole $role |
|
|
|
|
|
|
61
|
|
|
* @return bool |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function equals(RegistrationAuthorityRole $role) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->role === $role->role; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @return bool |
|
70
|
|
|
*/ |
|
71
|
|
|
public function isRa() |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->role === self::ROLE_RA; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
public function isRaa() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->role === self::ROLE_RAA; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function jsonSerialize() |
|
85
|
|
|
{ |
|
86
|
|
|
return $this->role; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function __toString() |
|
90
|
|
|
{ |
|
91
|
|
|
return (string) $this->role; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
public static function deserialize(array $data) |
|
95
|
|
|
{ |
|
96
|
|
|
return new self($data['role']); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function serialize(): array |
|
100
|
|
|
{ |
|
101
|
|
|
return ['role' => $this->role]; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|