|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Bouncer package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) François Hodierne <[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 Bouncer\Resource; |
|
13
|
|
|
|
|
14
|
|
|
use Bouncer\Bouncer; |
|
15
|
|
|
use Bouncer\Resource; |
|
16
|
|
|
|
|
17
|
|
|
class Identity extends Resource |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The unique id |
|
22
|
|
|
* |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $id; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Type: browser or robot |
|
29
|
|
|
* |
|
30
|
|
|
* @var string |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $type; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* The Address |
|
36
|
|
|
* |
|
37
|
|
|
* @var Address |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $address; |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* The Signature |
|
43
|
|
|
* |
|
44
|
|
|
* @var Signature |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $signature; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* The HTTP Headers |
|
50
|
|
|
* |
|
51
|
|
|
* @var array |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $headers; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* The User Agent |
|
57
|
|
|
* |
|
58
|
|
|
* @var UserAgent |
|
59
|
|
|
*/ |
|
60
|
|
|
protected $userAgent; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Session |
|
64
|
|
|
* |
|
65
|
|
|
* @var Session |
|
66
|
|
|
*/ |
|
67
|
|
|
protected $session; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Reputation |
|
71
|
|
|
* |
|
72
|
|
|
* @var array |
|
73
|
|
|
*/ |
|
74
|
|
|
protected $reputation; |
|
75
|
|
|
|
|
76
|
|
|
public function __construct($attributes = null) |
|
77
|
|
|
{ |
|
78
|
|
|
parent::__construct($attributes); |
|
79
|
|
|
$address = $this->getAddress(); |
|
80
|
|
|
$signature = $this->getSignature(); |
|
81
|
|
|
if ($address && $signature) { |
|
82
|
|
|
$this->id = Bouncer::hash($signature->getId() . $address->getId()); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
public function getId() |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->id; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function setId($id) |
|
92
|
|
|
{ |
|
93
|
|
|
$this->id = $id; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function getType() |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->type; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function setType($type) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->type = $type; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function getAddress() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->address; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function setAddress($address) |
|
112
|
|
|
{ |
|
113
|
|
|
if (is_object($address)) { |
|
114
|
|
|
$this->address = $address; |
|
115
|
|
|
} elseif (is_string($address) || is_array($address)) { |
|
116
|
|
|
$this->address = new Address($address); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
public function getHeaders() |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->headers; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
public function setHeaders($headers) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->headers = $headers; |
|
128
|
|
|
$signature = new Signature(array('headers' => $headers)); |
|
129
|
|
|
$this->setSignature($signature); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
public function getSignature() |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->signature; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
public function setSignature($signature) |
|
138
|
|
|
{ |
|
139
|
|
|
if (is_object($signature)) { |
|
140
|
|
|
$this->signature = $signature; |
|
141
|
|
|
} elseif (is_array($signature)) { |
|
142
|
|
|
$this->signature = new Signature($signature); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getUserAgent() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->userAgent; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function setUserAgent($userAgent) |
|
152
|
|
|
{ |
|
153
|
|
|
if (is_object($userAgent)) { |
|
154
|
|
|
$this->userAgent = $userAgent; |
|
155
|
|
|
} elseif (is_array($userAgent)) { |
|
156
|
|
|
$this->userAgent = new UserAgent($userAgent); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
public function getSession() |
|
161
|
|
|
{ |
|
162
|
|
|
return $this->session; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function setSession($session) |
|
166
|
|
|
{ |
|
167
|
|
|
if (is_object($session)) { |
|
168
|
|
|
$this->session = $session; |
|
169
|
|
|
} elseif (is_array($session)) { |
|
170
|
|
|
$this->session = new Session($session); |
|
171
|
|
|
} |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/* |
|
175
|
|
|
* @return array|null |
|
176
|
|
|
*/ |
|
177
|
|
|
public function getReputation() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->reputation; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
/* |
|
183
|
|
|
* @param array $reputation |
|
184
|
|
|
*/ |
|
185
|
|
|
public function setReputation($reputation) |
|
186
|
|
|
{ |
|
187
|
|
|
$this->reputation = $reputation; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
/* |
|
191
|
|
|
* @return string|null |
|
192
|
|
|
*/ |
|
193
|
|
|
public function getStatus() |
|
194
|
|
|
{ |
|
195
|
|
|
$reputation = $this->getReputation(); |
|
196
|
|
|
if (is_array($reputation) && array_key_exists('status', $reputation)) { |
|
197
|
|
|
return $reputation['status']; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
public function toArray() |
|
202
|
|
|
{ |
|
203
|
|
|
$identity = array(); |
|
204
|
|
|
|
|
205
|
|
|
if ($this->id) { |
|
206
|
|
|
$identity['id'] = $this->id; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return $identity; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
} |
|
213
|
|
|
|