|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the overtrue/socialite. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) overtrue <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Overtrue\Socialite; |
|
13
|
|
|
|
|
14
|
|
|
use ArrayAccess; |
|
15
|
|
|
use JsonSerializable; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class User. |
|
19
|
|
|
*/ |
|
20
|
|
|
class User implements ArrayAccess, UserInterface, JsonSerializable, \Serializable |
|
21
|
|
|
{ |
|
22
|
|
|
use HasAttributes; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* User constructor. |
|
26
|
|
|
* |
|
27
|
|
|
* @param array $attributes |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct(array $attributes) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->attributes = $attributes; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get the unique identifier for the user. |
|
36
|
|
|
* |
|
37
|
|
|
* @return string |
|
38
|
|
|
*/ |
|
39
|
|
|
public function getId() |
|
40
|
|
|
{ |
|
41
|
|
|
return $this->getAttribute('id'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get the username for the user. |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
public function getUsername() |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->getAttribute('username', $this->getId()); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get the nickname / username for the user. |
|
56
|
|
|
* |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getNickname() |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getAttribute('nickname'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get the full name of the user. |
|
66
|
|
|
* |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getName() |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->getAttribute('name'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the e-mail address of the user. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
public function getEmail() |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->getAttribute('email'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Get the avatar / image URL for the user. |
|
86
|
|
|
* |
|
87
|
|
|
* @return string |
|
88
|
|
|
*/ |
|
89
|
|
|
public function getAvatar() |
|
90
|
|
|
{ |
|
91
|
|
|
return $this->getAttribute('avatar'); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Set the token on the user. |
|
96
|
|
|
* |
|
97
|
|
|
* @param \Overtrue\Socialite\AccessTokenInterface $token |
|
98
|
|
|
* |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
|
public function setToken(AccessTokenInterface $token) |
|
102
|
|
|
{ |
|
103
|
|
|
$this->setAttribute('token', $token); |
|
104
|
|
|
|
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* @param string $provider |
|
110
|
|
|
* |
|
111
|
|
|
* @return $this |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setProviderName($provider) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->setAttribute('provider', $provider); |
|
116
|
|
|
|
|
117
|
|
|
return $this; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* @return string |
|
122
|
|
|
*/ |
|
123
|
|
|
public function getProviderName() |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->getAttribute('provider'); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Get the authorized token. |
|
130
|
|
|
* |
|
131
|
|
|
* @return \Overtrue\Socialite\AccessToken |
|
132
|
|
|
*/ |
|
133
|
|
|
public function getToken() |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->getAttribute('token'); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* Get user access token. |
|
140
|
|
|
* |
|
141
|
|
|
* @return string |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getAccessToken() |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->getToken()->getToken(); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Get user refresh token. |
|
150
|
|
|
* |
|
151
|
|
|
* @return string |
|
152
|
|
|
*/ |
|
153
|
|
|
public function getRefreshToken() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->getToken()->getRefreshToken(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get the original attributes. |
|
160
|
|
|
* |
|
161
|
|
|
* @return array |
|
162
|
|
|
*/ |
|
163
|
|
|
public function getOriginal() |
|
164
|
|
|
{ |
|
165
|
|
|
return $this->getAttribute('original'); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* {@inheritdoc} |
|
170
|
|
|
*/ |
|
171
|
|
|
public function jsonSerialize() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->attributes; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function serialize() |
|
177
|
|
|
{ |
|
178
|
|
|
return serialize($this->attributes); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
/** |
|
182
|
|
|
* Constructs the object. |
|
183
|
|
|
* |
|
184
|
|
|
* @see https://php.net/manual/en/serializable.unserialize.php |
|
185
|
|
|
* |
|
186
|
|
|
* @param string $serialized <p> |
|
187
|
|
|
* The string representation of the object. |
|
188
|
|
|
* </p> |
|
189
|
|
|
* |
|
190
|
|
|
* @since 5.1.0 |
|
191
|
|
|
*/ |
|
192
|
|
|
public function unserialize($serialized) |
|
193
|
|
|
{ |
|
194
|
|
|
$this->attributes = unserialize($serialized) ?: []; |
|
195
|
|
|
} |
|
196
|
|
|
} |
|
197
|
|
|
|