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
|
|
|
/** |
22
|
|
|
* @var IRI A mailto IRI |
23
|
|
|
*/ |
24
|
|
|
private $mbox; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var string The SHA1 hash of a mailto IRI |
28
|
|
|
*/ |
29
|
|
|
private $mboxSha1Sum; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string An openID uniquely identifying an Agent |
33
|
|
|
*/ |
34
|
|
|
private $openId; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var Account A user account on an existing system |
38
|
|
|
*/ |
39
|
|
|
private $account; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Use one of the with*() factory methods to obtain an InverseFunctionalIdentifier |
43
|
|
|
* instance. |
44
|
|
|
*/ |
45
|
15 |
|
private function __construct() |
46
|
|
|
{ |
47
|
15 |
|
} |
48
|
|
|
|
49
|
10 |
|
public static function withMbox(IRI $mbox) |
50
|
|
|
{ |
51
|
10 |
|
$iri = new InverseFunctionalIdentifier(); |
52
|
10 |
|
$iri->mbox = $mbox; |
53
|
|
|
|
54
|
10 |
|
return $iri; |
55
|
|
|
} |
56
|
|
|
|
57
|
6 |
|
public static function withMboxSha1Sum($mboxSha1Sum) |
58
|
|
|
{ |
59
|
6 |
|
$iri = new InverseFunctionalIdentifier(); |
60
|
6 |
|
$iri->mboxSha1Sum = $mboxSha1Sum; |
61
|
|
|
|
62
|
6 |
|
return $iri; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public static function withOpenId($openId) |
66
|
|
|
{ |
67
|
|
|
$iri = new InverseFunctionalIdentifier(); |
68
|
|
|
$iri->openId = $openId; |
69
|
|
|
|
70
|
|
|
return $iri; |
71
|
|
|
} |
72
|
|
|
|
73
|
3 |
|
public static function withAccount(Account $account) |
74
|
|
|
{ |
75
|
3 |
|
$iri = new InverseFunctionalIdentifier(); |
76
|
3 |
|
$iri->account = $account; |
77
|
|
|
|
78
|
3 |
|
return $iri; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Returns the mailto IRI. |
83
|
|
|
* |
84
|
|
|
* @return IRI The mailto IRI |
85
|
|
|
*/ |
86
|
|
|
public function getMbox() |
87
|
|
|
{ |
88
|
|
|
return $this->mbox; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the SHA1 hash of a mailto IRI. |
93
|
|
|
* |
94
|
|
|
* @return string The SHA1 hash of a mailto IRI |
95
|
|
|
*/ |
96
|
|
|
public function getMboxSha1Sum() |
97
|
|
|
{ |
98
|
|
|
return $this->mboxSha1Sum; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Returns the openID. |
103
|
|
|
* |
104
|
|
|
* @return string The openID |
105
|
|
|
*/ |
106
|
|
|
public function getOpenId() |
107
|
|
|
{ |
108
|
|
|
return $this->openId; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Returns the user account of an existing system. |
113
|
|
|
* |
114
|
|
|
* @return Account The user account of an existing system |
115
|
|
|
*/ |
116
|
|
|
public function getAccount() |
117
|
|
|
{ |
118
|
|
|
return $this->account; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Checks if another IRI is equal. |
123
|
|
|
* |
124
|
|
|
* Two inverse functional identifiers are equal if and only if all of their |
125
|
|
|
* properties are equal. |
126
|
|
|
* |
127
|
|
|
* @param InverseFunctionalIdentifier $iri The iri to compare with |
128
|
|
|
* |
129
|
|
|
* @return bool True if the IRIs are equal, false otherwise |
130
|
|
|
*/ |
131
|
19 |
|
public function equals(InverseFunctionalIdentifier $iri) |
132
|
|
|
{ |
133
|
19 |
|
if (null !== $this->mbox && null !== $iri->mbox && !$this->mbox->equals($iri->mbox)) { |
134
|
2 |
|
return false; |
135
|
|
|
} |
136
|
|
|
|
137
|
17 |
|
if ($this->mboxSha1Sum !== $iri->mboxSha1Sum) { |
138
|
6 |
|
return false; |
139
|
|
|
} |
140
|
|
|
|
141
|
11 |
|
if ($this->openId !== $iri->openId) { |
142
|
2 |
|
return false; |
143
|
|
|
} |
144
|
|
|
|
145
|
9 |
|
if (null === $this->account && null !== $iri->account) { |
146
|
|
|
return false; |
147
|
|
|
} |
148
|
|
|
|
149
|
9 |
|
if (null !== $this->account && null === $iri->account) { |
150
|
|
|
return false; |
151
|
|
|
} |
152
|
|
|
|
153
|
9 |
|
if (null !== $this->account && !$this->account->equals($iri->account)) { |
154
|
4 |
|
return false; |
155
|
|
|
} |
156
|
|
|
|
157
|
5 |
|
return true; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function __toString() |
161
|
|
|
{ |
162
|
|
|
if (null !== $this->mbox) { |
163
|
|
|
return $this->mbox; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
if (null !== $this->mboxSha1Sum) { |
167
|
|
|
return $this->mboxSha1Sum; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
if (null !== $this->openId) { |
171
|
|
|
return $this->openId; |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
return $this->account; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|