|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
|
|
|
|
|
6
|
|
|
* Copyright 2014 SURFnet bv |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Surfnet\Stepup\Identity\Value; |
|
22
|
|
|
|
|
23
|
|
|
use JsonSerializable; |
|
24
|
|
|
use Stringable; |
|
25
|
|
|
use Surfnet\Stepup\Exception\InvalidArgumentException; |
|
26
|
|
|
|
|
27
|
|
|
final class DocumentNumber implements JsonSerializable, Stringable |
|
28
|
|
|
{ |
|
29
|
|
|
private readonly string $documentNumber; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @return self |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function unknown(): self |
|
35
|
|
|
{ |
|
36
|
|
|
return new self('—'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function __construct(string $documentNumber) |
|
40
|
|
|
{ |
|
41
|
|
|
if ($documentNumber === '' || $documentNumber === '0') { |
|
42
|
|
|
throw InvalidArgumentException::invalidType('non-empty string', 'documentNumber', $documentNumber); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
$this->documentNumber = $documentNumber; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return string |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getDocumentNumber(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return $this->documentNumber; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function __toString(): string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->documentNumber; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function equals(DocumentNumber $other): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->documentNumber === $other->documentNumber; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
public function jsonSerialize(): string |
|
67
|
|
|
{ |
|
68
|
|
|
return $this->documentNumber; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|