1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Votifier PHP Client |
5
|
|
|
* |
6
|
|
|
* @package OAuth2-OrbitronDev |
7
|
|
|
* |
8
|
|
|
* @author Manuele Vaccari <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2017-2018 Manuele Vaccari <[email protected]> |
10
|
|
|
* @license https://github.com/D3strukt0r/oauth2-orbitrondev/blob/master/LICENSE.md MIT License |
11
|
|
|
* |
12
|
|
|
* @link https://github.com/D3strukt0r/oauth2-orbitrondev |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace OrbitronDev\OAuth2\Client\Provider; |
16
|
|
|
|
17
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The Class which can be used with league/oauth2-client. |
21
|
|
|
*/ |
22
|
|
|
class OrbitronDevResourceOwner implements ResourceOwnerInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Raw response. |
26
|
|
|
* |
27
|
|
|
* @var array |
28
|
|
|
*/ |
29
|
|
|
protected $response; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates new resource owner. |
33
|
|
|
* |
34
|
|
|
* @param array $response Data received from the server about the user |
35
|
|
|
*/ |
36
|
8 |
|
public function __construct(array $response = []) |
37
|
|
|
{ |
38
|
8 |
|
$this->response = $response; |
39
|
8 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Returns the identifier of the authorized resource owner. |
43
|
|
|
* |
44
|
|
|
* @return int|null |
45
|
|
|
*/ |
46
|
2 |
|
public function getId() |
47
|
|
|
{ |
48
|
2 |
|
return (int) $this->response['id'] ?: null; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Return the username. |
53
|
|
|
* |
54
|
|
|
* @return string|null |
55
|
|
|
*/ |
56
|
2 |
|
public function getUsername() |
57
|
|
|
{ |
58
|
2 |
|
return $this->response['username'] ?: null; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Return the email. |
63
|
|
|
* |
64
|
|
|
* @return string|null |
65
|
|
|
*/ |
66
|
2 |
|
public function getEmail() |
67
|
|
|
{ |
68
|
2 |
|
return $this->response['email'] ?: null; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Return the first name. |
73
|
|
|
* |
74
|
|
|
* @return string|null |
75
|
|
|
*/ |
76
|
2 |
|
public function getFirstName() |
77
|
|
|
{ |
78
|
2 |
|
return $this->response['name'] ?: null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Return the surname. |
83
|
|
|
* |
84
|
|
|
* @return string|null |
85
|
|
|
*/ |
86
|
2 |
|
public function getSurname() |
87
|
|
|
{ |
88
|
2 |
|
return $this->response['surname'] ?: null; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Return the birthday. |
93
|
|
|
* |
94
|
|
|
* @return \DateTime|null |
95
|
|
|
*/ |
96
|
2 |
|
public function getBirthday() |
97
|
|
|
{ |
98
|
2 |
|
return $this->response['birthday'] ? (new \DateTime())->setTimestamp($this->response['birthday']) : null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Return the surname. |
103
|
|
|
* |
104
|
|
|
* @return array|null |
105
|
|
|
*/ |
106
|
8 |
|
public function getActiveAddress() |
107
|
|
|
{ |
108
|
8 |
|
if (null === $this->getAddresses()) { |
109
|
2 |
|
return null; |
110
|
|
|
} |
111
|
|
|
|
112
|
6 |
|
if (1 === count($this->getAddresses())) { |
113
|
2 |
|
foreach ($this->getAddresses() as $address) { |
114
|
2 |
|
return $address; |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
4 |
|
if (null === $this->response['active_address']) { |
119
|
2 |
|
return null; |
120
|
|
|
} |
121
|
|
|
|
122
|
2 |
|
return $this->getAddresses()[$this->response['active_address']]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Return the surname. |
127
|
|
|
* |
128
|
|
|
* @return array|null |
129
|
|
|
*/ |
130
|
8 |
|
public function getAddresses() |
131
|
|
|
{ |
132
|
8 |
|
return $this->response['addresses'] ?: null; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Return the subscription. |
137
|
|
|
* |
138
|
|
|
* @return string|null |
139
|
|
|
*/ |
140
|
2 |
|
public function getSubscription() |
141
|
|
|
{ |
142
|
2 |
|
return $this->response['subscription_type'] ?: null; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* Return all of the owner details available as an array. |
147
|
|
|
* |
148
|
|
|
* @return array |
149
|
|
|
*/ |
150
|
8 |
|
public function toArray() |
151
|
|
|
{ |
152
|
8 |
|
return $this->response; |
153
|
|
|
} |
154
|
|
|
} |
155
|
|
|
|