|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CrudSys\OAuth2\Client\Entity; |
|
4
|
|
|
|
|
5
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
|
6
|
|
|
use League\OAuth2\Client\Tool\ArrayAccessorTrait; |
|
7
|
|
|
use CrudSys\OAuth2\Client\Helper\Helper; |
|
8
|
|
|
|
|
9
|
|
|
class User implements ResourceOwnerInterface |
|
10
|
|
|
{ |
|
11
|
|
|
use ArrayAccessorTrait; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Raw response |
|
15
|
|
|
*/ |
|
16
|
|
|
protected array $response; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param array $response |
|
20
|
|
|
*/ |
|
21
|
14 |
|
public function __construct(array $response) |
|
22
|
|
|
{ |
|
23
|
14 |
|
$this->response = $response; |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
1 |
|
public function toArray(): array |
|
27
|
|
|
{ |
|
28
|
1 |
|
return $this->response; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
9 |
|
private function validateString($value): string |
|
32
|
|
|
{ |
|
33
|
9 |
|
if( !is_string($value) || Helper::isEmptyOrNull($value)) { |
|
34
|
|
|
$value = ''; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
9 |
|
return $value; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
1 |
|
public function getId(): string |
|
41
|
|
|
{ |
|
42
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'id') ); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
1 |
|
public function getUsername(): string |
|
46
|
|
|
{ |
|
47
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'username') ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function isPatron(): bool |
|
51
|
|
|
{ |
|
52
|
1 |
|
return $this->getValueByKey($this->response, 'patron'); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
1 |
|
public function isOnline(): bool |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->getValueByKey($this->response, 'online'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
1 |
|
public function getProfile(): array |
|
61
|
|
|
{ |
|
62
|
1 |
|
return $this->getValueByKey($this->response, 'profile'); |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
1 |
|
public function getCountry(): string |
|
66
|
|
|
{ |
|
67
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.country') ); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
1 |
|
public function getLocation(): string |
|
71
|
|
|
{ |
|
72
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.location') ); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
1 |
|
public function getBio(): string |
|
76
|
|
|
{ |
|
77
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.bio') ); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
public function getFirstName(): string |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.firstName') ); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
1 |
|
public function getLastName(): string |
|
86
|
|
|
{ |
|
87
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.lastName') ); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
1 |
|
public function getLinks(): string |
|
91
|
|
|
{ |
|
92
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'profile.links') ); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
1 |
|
public function getUrl(): string |
|
96
|
|
|
{ |
|
97
|
1 |
|
return $this->validateString( $this->getValueByKey($this->response, 'url') ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
1 |
|
public function getCompletionRate(): int |
|
101
|
|
|
{ |
|
102
|
1 |
|
return $this->getValueByKey($this->response, 'completionRate'); |
|
|
|
|
|
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|