1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the wohali/oauth2-discord-new library |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright Copyright (c) Joan Touzet <[email protected]> |
9
|
|
|
* @license http://opensource.org/licenses/MIT MIT |
10
|
|
|
* @link https://packagist.org/packages/wohali/oauth2-discord-new Packagist |
11
|
|
|
* @link https://github.com/wohali/oauth2-discord-new GitHub |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Wohali\OAuth2\Client\Provider; |
15
|
|
|
|
16
|
|
|
use League\OAuth2\Client\Provider\ResourceOwnerInterface; |
17
|
|
|
use League\OAuth2\Client\Tool\ArrayAccessorTrait; |
18
|
|
|
|
19
|
|
|
class DiscordResourceOwner implements ResourceOwnerInterface |
20
|
|
|
{ |
21
|
|
|
use ArrayAccessorTrait; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Raw response |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $response; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Creates new resource owner. |
32
|
|
|
* |
33
|
|
|
* @param array $response |
34
|
|
|
*/ |
35
|
3 |
|
public function __construct(array $response = array()) |
36
|
|
|
{ |
37
|
3 |
|
$this->response = $response; |
38
|
3 |
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Get resource owner ID |
42
|
|
|
* |
43
|
|
|
* @return string|null |
44
|
|
|
*/ |
45
|
3 |
|
public function getId() |
46
|
|
|
{ |
47
|
3 |
|
return $this->getValueByKey($this->response, 'id'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get resource owner username |
52
|
|
|
* |
53
|
|
|
* @return string|null |
54
|
|
|
*/ |
55
|
3 |
|
public function getUsername() |
56
|
|
|
{ |
57
|
3 |
|
return $this->getValueByKey($this->response, 'username'); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get resource owner discriminator |
62
|
|
|
* |
63
|
|
|
* @return string|null |
64
|
|
|
*/ |
65
|
3 |
|
public function getDiscriminator() |
66
|
|
|
{ |
67
|
3 |
|
return $this->getValueByKey($this->response, 'discriminator'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get resource owner avatar hash |
72
|
|
|
* |
73
|
|
|
* @return string|null |
74
|
|
|
*/ |
75
|
3 |
|
public function getAvatarHash() |
76
|
|
|
{ |
77
|
3 |
|
return $this->getValueByKey($this->response, 'avatar'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Get resource owner verified flag |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
3 |
|
public function getVerified() |
86
|
|
|
{ |
87
|
3 |
|
return $this->getValueByKey($this->response, 'verified', false); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get resource owner email |
92
|
|
|
* |
93
|
|
|
* @return string|null |
94
|
|
|
*/ |
95
|
3 |
|
public function getEmail() |
96
|
|
|
{ |
97
|
3 |
|
return $this->getValueByKey($this->response, 'email'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Returns the raw resource owner response. |
102
|
|
|
* |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
3 |
|
public function toArray() |
106
|
|
|
{ |
107
|
3 |
|
return $this->response; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|