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