1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Xabbuh\XApi\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* The inverse functional identifier of an {@link Actor}. |
16
|
|
|
* |
17
|
|
|
* @author Christian Flothmann <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
final class InverseFunctionalIdentifier |
20
|
|
|
{ |
21
|
|
|
private $mbox; |
22
|
|
|
private $mboxSha1Sum; |
23
|
|
|
private $openId; |
24
|
|
|
private $account; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Use one of the with*() factory methods to obtain an InverseFunctionalIdentifier |
28
|
|
|
* instance. |
29
|
|
|
*/ |
30
|
|
|
private function __construct() |
31
|
|
|
{ |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public static function withMbox(IRI $mbox): self |
35
|
|
|
{ |
36
|
|
|
$iri = new InverseFunctionalIdentifier(); |
37
|
|
|
$iri->mbox = $mbox; |
38
|
|
|
|
39
|
|
|
return $iri; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function withMboxSha1Sum(string $mboxSha1Sum): self |
43
|
|
|
{ |
44
|
|
|
$iri = new InverseFunctionalIdentifier(); |
45
|
15 |
|
$iri->mboxSha1Sum = $mboxSha1Sum; |
46
|
|
|
|
47
|
15 |
|
return $iri; |
48
|
|
|
} |
49
|
10 |
|
|
50
|
|
|
public static function withOpenId(string $openId): self |
51
|
10 |
|
{ |
52
|
10 |
|
$iri = new InverseFunctionalIdentifier(); |
53
|
|
|
$iri->openId = $openId; |
54
|
10 |
|
|
55
|
|
|
return $iri; |
56
|
|
|
} |
57
|
6 |
|
|
58
|
|
|
public static function withAccount(Account $account): self |
59
|
6 |
|
{ |
60
|
6 |
|
$iri = new InverseFunctionalIdentifier(); |
61
|
|
|
$iri->account = $account; |
62
|
6 |
|
|
63
|
|
|
return $iri; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Returns the mailto IRI. |
68
|
|
|
*/ |
69
|
|
|
public function getMbox(): ?IRI |
70
|
|
|
{ |
71
|
|
|
return $this->mbox; |
72
|
|
|
} |
73
|
3 |
|
|
74
|
|
|
/** |
75
|
3 |
|
* Returns the SHA1 hash of a mailto IRI. |
76
|
3 |
|
*/ |
77
|
|
|
public function getMboxSha1Sum(): ?string |
78
|
3 |
|
{ |
79
|
|
|
return $this->mboxSha1Sum; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Returns the openID. |
84
|
|
|
*/ |
85
|
|
|
public function getOpenId(): ?string |
86
|
|
|
{ |
87
|
|
|
return $this->openId; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Returns the user account of an existing system. |
92
|
|
|
*/ |
93
|
|
|
public function getAccount(): ?Account |
94
|
|
|
{ |
95
|
|
|
return $this->account; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Checks if another IRI is equal. |
100
|
|
|
* |
101
|
|
|
* Two inverse functional identifiers are equal if and only if all of their |
102
|
|
|
* properties are equal. |
103
|
|
|
*/ |
104
|
|
|
public function equals(InverseFunctionalIdentifier $iri): bool |
105
|
|
|
{ |
106
|
|
|
if (null !== $this->mbox && null !== $iri->mbox && !$this->mbox->equals($iri->mbox)) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if ($this->mboxSha1Sum !== $iri->mboxSha1Sum) { |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
if ($this->openId !== $iri->openId) { |
115
|
|
|
return false; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (null === $this->account && null !== $iri->account) { |
119
|
|
|
return false; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
if (null !== $this->account && null === $iri->account) { |
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (null !== $this->account && !$this->account->equals($iri->account)) { |
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
return true; |
131
|
19 |
|
} |
132
|
|
|
|
133
|
19 |
|
public function __toString(): string |
134
|
2 |
|
{ |
135
|
|
|
if (null !== $this->mbox) { |
136
|
|
|
return $this->mbox->getValue(); |
137
|
17 |
|
} |
138
|
6 |
|
|
139
|
|
|
if (null !== $this->mboxSha1Sum) { |
140
|
|
|
return $this->mboxSha1Sum; |
141
|
11 |
|
} |
142
|
2 |
|
|
143
|
|
|
if (null !== $this->openId) { |
144
|
|
|
return $this->openId; |
145
|
9 |
|
} |
146
|
|
|
|
147
|
|
|
return sprintf('%s (%s)', $this->account->getName(), $this->account->getHomePage()->getValue()); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
|