1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2022 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 Stringable; |
22
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
23
|
|
|
|
24
|
|
|
final class RecoveryTokenType implements Stringable |
|
|
|
|
25
|
|
|
{ |
26
|
|
|
public const TYPE_SMS = 'sms'; |
27
|
|
|
public const TYPE_SAFE_STORE = 'safe-store'; |
28
|
|
|
|
29
|
|
|
private readonly string $type; |
30
|
|
|
|
31
|
|
|
public function __construct(string $type) |
32
|
|
|
{ |
33
|
|
|
if (!in_array($type, [self::TYPE_SMS, self::TYPE_SAFE_STORE])) { |
34
|
|
|
throw new InvalidArgumentException('The RecoveryTokenType must be one of "sms" or "safe-store".'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
$this->type = $type; |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public static function sms(): RecoveryTokenType |
41
|
|
|
{ |
42
|
|
|
return new RecoveryTokenType(self::TYPE_SMS); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public static function safeStore(): RecoveryTokenType |
46
|
|
|
{ |
47
|
|
|
return new RecoveryTokenType(self::TYPE_SAFE_STORE); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function isSms(): bool |
51
|
|
|
{ |
52
|
|
|
return $this->type === self::TYPE_SMS; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function isSafeStore(): bool |
56
|
|
|
{ |
57
|
|
|
return $this->type === self::TYPE_SAFE_STORE; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function getType(): string |
64
|
|
|
{ |
65
|
|
|
return $this->type; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function __toString(): string |
69
|
|
|
{ |
70
|
|
|
return $this->type; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function equals(RecoveryTokenType $other): bool |
74
|
|
|
{ |
75
|
|
|
return $this->type === $other->getType(); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|