1
|
|
|
<?php namespace Arcanedev\Socialite\OAuth; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Socialite\Contracts\User; |
4
|
|
|
use ArrayAccess; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class AbstractUser |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\Socialite\OAuth |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class AbstractUser implements ArrayAccess, User |
13
|
|
|
{ |
14
|
|
|
/* ------------------------------------------------------------------------------------------------ |
15
|
|
|
| Properties |
16
|
|
|
| ------------------------------------------------------------------------------------------------ |
17
|
|
|
*/ |
18
|
|
|
/** |
19
|
|
|
* The user's access token. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
public $token; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* The unique identifier for the user. |
27
|
|
|
* |
28
|
|
|
* @var mixed |
29
|
|
|
*/ |
30
|
|
|
public $id; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The user's nickname / username. |
34
|
|
|
* |
35
|
|
|
* @var string |
36
|
|
|
*/ |
37
|
|
|
public $nickname; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The user's full name. |
41
|
|
|
* |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
public $name; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The user's e-mail address. |
48
|
|
|
* |
49
|
|
|
* @var string |
50
|
|
|
*/ |
51
|
|
|
public $email; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The user's avatar image URL. |
55
|
|
|
* |
56
|
|
|
* @var string |
57
|
|
|
*/ |
58
|
|
|
public $avatar; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* The user's raw attributes. |
62
|
|
|
* |
63
|
|
|
* @var array |
64
|
|
|
*/ |
65
|
|
|
public $user = []; |
66
|
|
|
|
67
|
|
|
/* ------------------------------------------------------------------------------------------------ |
68
|
|
|
| Getters & Setters |
69
|
|
|
| ------------------------------------------------------------------------------------------------ |
70
|
|
|
*/ |
71
|
|
|
/** |
72
|
|
|
* Get the unique identifier for the user. |
73
|
|
|
* |
74
|
|
|
* @return string |
75
|
|
|
*/ |
76
|
|
|
public function getId() |
77
|
|
|
{ |
78
|
|
|
return $this->id; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get the nickname / username for the user. |
83
|
|
|
* |
84
|
|
|
* @return string |
85
|
|
|
*/ |
86
|
|
|
public function getNickname() |
87
|
|
|
{ |
88
|
|
|
return $this->nickname; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Get the full name of the user. |
93
|
|
|
* |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function getName() |
97
|
|
|
{ |
98
|
|
|
return $this->name; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the e-mail address of the user. |
103
|
|
|
* |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
public function getEmail() |
107
|
|
|
{ |
108
|
|
|
return $this->email; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get the avatar / image URL for the user. |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getAvatar() |
117
|
|
|
{ |
118
|
|
|
return $this->avatar; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get the raw user array. |
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function getRaw() |
127
|
|
|
{ |
128
|
|
|
return $this->user; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Set the raw user array from the provider. |
133
|
|
|
* |
134
|
|
|
* @param array $user |
135
|
|
|
* |
136
|
|
|
* @return self |
137
|
|
|
*/ |
138
|
12 |
|
public function setRaw(array $user) |
139
|
|
|
{ |
140
|
12 |
|
$this->user = $user; |
141
|
|
|
|
142
|
12 |
|
return $this; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Map the given array onto the user's properties. |
147
|
|
|
* |
148
|
|
|
* @param array $attributes |
149
|
|
|
* |
150
|
|
|
* @return self |
151
|
|
|
*/ |
152
|
18 |
|
public function map(array $attributes) |
153
|
|
|
{ |
154
|
18 |
|
foreach ($attributes as $key => $value) { |
155
|
18 |
|
$this->{$key} = $value; |
156
|
9 |
|
} |
157
|
|
|
|
158
|
18 |
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Determine if the given raw user attribute exists. |
163
|
|
|
* |
164
|
|
|
* @param string $offset |
165
|
|
|
* |
166
|
|
|
* @return bool |
167
|
|
|
*/ |
168
|
|
|
public function offsetExists($offset) |
169
|
|
|
{ |
170
|
|
|
return array_key_exists($offset, $this->user); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Get the given key from the raw user. |
175
|
|
|
* |
176
|
|
|
* @param string $offset |
177
|
|
|
* |
178
|
|
|
* @return mixed |
179
|
|
|
*/ |
180
|
|
|
public function offsetGet($offset) |
181
|
|
|
{ |
182
|
|
|
return $this->user[$offset]; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Set the given attribute on the raw user array. |
187
|
|
|
* |
188
|
|
|
* @param string $offset |
189
|
|
|
* @param mixed $value |
190
|
|
|
*/ |
191
|
|
|
public function offsetSet($offset, $value) |
192
|
|
|
{ |
193
|
|
|
$this->user[$offset] = $value; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Unset the given value from the raw user array. |
198
|
|
|
* |
199
|
|
|
* @param string $offset |
200
|
|
|
*/ |
201
|
|
|
public function offsetUnset($offset) |
202
|
|
|
{ |
203
|
|
|
unset($this->user[$offset]); |
204
|
|
|
} |
205
|
|
|
} |
206
|
|
|
|