1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace J4k\OAuth2\Client\Provider; |
4
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* @see https://vk.com/dev/fields |
9
|
|
|
* |
10
|
|
|
* @package J4k\OAuth2\Client\Provider |
11
|
|
|
*/ |
12
|
|
|
class User implements ResourceOwnerInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* @type array |
16
|
|
|
*/ |
17
|
|
|
protected $response; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* User constructor. |
21
|
|
|
* |
22
|
|
|
* @param array $response |
23
|
|
|
*/ |
24
|
|
|
public function __construct(array $response) |
25
|
|
|
{ |
26
|
|
|
$this->response = $response; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function toArray() |
33
|
|
|
{ |
34
|
|
|
return $this->response; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @return integer |
39
|
|
|
*/ |
40
|
|
|
public function getId() |
41
|
|
|
{ |
42
|
|
|
return (int)($this->getField('uid') ?: $this->getField('id')); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Helper for get user data |
47
|
|
|
* @param $key |
48
|
|
|
* @return mixed|null |
49
|
|
|
*/ |
50
|
|
|
protected function getField($key) |
51
|
|
|
{ |
52
|
|
|
return !empty($this->response[$key]) ? $this->response[$key] : null; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string|null DD.MM.YYYY |
57
|
|
|
*/ |
58
|
|
|
public function getBirthday() |
59
|
|
|
{ |
60
|
|
|
return $this->getField('bdate'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return array [id =>, title => string] |
65
|
|
|
*/ |
66
|
|
|
public function getCity() |
67
|
|
|
{ |
68
|
|
|
return $this->getField('city'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @return array [id =>, title => string] |
73
|
|
|
*/ |
74
|
|
|
public function getCountry() |
75
|
|
|
{ |
76
|
|
|
return $this->getField('country'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Short address to user page |
81
|
|
|
* |
82
|
|
|
* @return string |
83
|
|
|
*/ |
84
|
|
|
public function getDomain() |
85
|
|
|
{ |
86
|
|
|
return $this->getField('domain'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @return string |
91
|
|
|
*/ |
92
|
|
|
public function getFirstName() |
93
|
|
|
{ |
94
|
|
|
return $this->getField('first_name'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @return int 0|1|2|3 => nobody|resquest_sent|incoming_request|friends |
99
|
|
|
*/ |
100
|
|
|
public function getFriendStatus() |
101
|
|
|
{ |
102
|
|
|
return $this->getField('friend_Status'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Has user avatar? |
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
|
|
public function isHasPhoto() |
111
|
|
|
{ |
112
|
|
|
return (bool)$this->getField('has_photo'); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @return string |
117
|
|
|
*/ |
118
|
|
|
public function getHomeTown() |
119
|
|
|
{ |
120
|
|
|
return $this->getField('home_town'); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Detect if current user is freind to this |
125
|
|
|
* |
126
|
|
|
* @return bool |
127
|
|
|
*/ |
128
|
|
|
public function isFriend() |
129
|
|
|
{ |
130
|
|
|
return (bool)$this->getField('is_friend'); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getLastName() |
137
|
|
|
{ |
138
|
|
|
return $this->getField('last_name'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getMaidenName() |
145
|
|
|
{ |
146
|
|
|
return $this->getField('maiden_name'); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
|
|
public function getNickname() |
153
|
|
|
{ |
154
|
|
|
return $this->getField('nickname'); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* It's square! |
159
|
|
|
* |
160
|
|
|
* @return string URL |
161
|
|
|
*/ |
162
|
|
|
public function getPhotoMax() |
163
|
|
|
{ |
164
|
|
|
return $this->getField('photo_max'); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Any sizes |
169
|
|
|
* |
170
|
|
|
* @return string URL |
171
|
|
|
*/ |
172
|
|
|
public function getPhotoMaxOrig() |
173
|
|
|
{ |
174
|
|
|
return $this->getField('photo_max_orig'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @return string |
179
|
|
|
*/ |
180
|
|
|
public function getScreenName() |
181
|
|
|
{ |
182
|
|
|
return $this->getField('screen_name'); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @return int 1|2 => woman|man |
187
|
|
|
*/ |
188
|
|
|
public function getSex() |
189
|
|
|
{ |
190
|
|
|
return $this->getField('sex'); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @return string |
195
|
|
|
*/ |
196
|
|
|
public function getEmail() |
197
|
|
|
{ |
198
|
|
|
return $this->getField('email'); |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|