-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathGoogleUser.php
109 lines (96 loc) · 1.88 KB
/
GoogleUser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace League\OAuth2\Client\Provider;
class GoogleUser implements ResourceOwnerInterface
{
/**
* @var array
*/
protected $response;
/**
* @param array $response
*/
public function __construct(array $response)
{
$this->response = $response;
}
public function getId()
{
return $this->response['sub'];
}
/**
* Get preferred display name.
*
* @return string
*/
public function getName(): string
{
return $this->response['name'];
}
/**
* Get preferred first name.
*
* @return string|null
*/
public function getFirstName(): ?string
{
return $this->getResponseValue('given_name');
}
/**
* Get preferred last name.
*
* @return string|null
*/
public function getLastName(): ?string
{
return $this->getResponseValue('family_name');
}
/**
* Get locale.
*
* @return string|null
*/
public function getLocale(): ?string
{
return $this->getResponseValue('locale');
}
/**
* Get email address.
*
* @return string|null
*/
public function getEmail(): ?string
{
return $this->getResponseValue('email');
}
/**
* Get hosted domain.
*
* @return string|null
*/
public function getHostedDomain(): ?string
{
return $this->getResponseValue('hd');
}
/**
* Get avatar image URL.
*
* @return string|null
*/
public function getAvatar(): ?string
{
return $this->getResponseValue('picture');
}
/**
* Get user data as an array.
*
* @return array
*/
public function toArray(): array
{
return $this->response;
}
private function getResponseValue($key)
{
return $this->response[$key] ?? null;
}
}