-
Notifications
You must be signed in to change notification settings - Fork 0
/
TuleapResourceOwner.php
122 lines (107 loc) · 2.16 KB
/
TuleapResourceOwner.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
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace TuleapIntegration;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
class TuleapResourceOwner implements ResourceOwnerInterface {
/** @var string */
private $id;
/** @var string */
private $username;
/** @var string */
private $email;
/** @var string */
private $realname;
/** @var bool */
private $emailVerified;
/** @var string */
private $locale;
/**
* @param array $data
* @return static
*/
public static function factory( array $data ) {
return new static(
$data['sub'],
$data['preferred_username'],
$data['name'],
$data['email'],
$data['email_verified'],
$data['locale']
);
}
/**
* @param string $id
* @param string $username
* @param string $realname
* @param string $email
* @param bool $emailVerified
* @param string $locale
*/
public function __construct( $id, $username, $realname, $email, $emailVerified, $locale ) {
$this->id = $id;
$this->username = $username;
$this->realname = $realname;
$this->email = $email;
$this->emailVerified = $emailVerified;
$this->locale = $this->convertToLangCode( $locale );
}
/**
* @return string
*/
public function getId() {
return $this->id;
}
/**
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* @return string
*/
public function getRealName() {
return $this->realname ?: $this->getUsername();
}
/**
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* @return bool
*/
public function isEmailVerified() {
return $this->emailVerified;
}
/**
* @return string
*/
public function getLocale() {
return $this->locale;
}
/**
* @return array
*/
public function toArray() {
return [
'id' => $this->getId(),
'username' => $this->getUsername(),
'email' => $this->getEmail(),
'email_verified' => $this->isEmailVerified(),
'realname' => $this->getRealName(),
'locale' => $this->getLocale()
];
}
/**
* @param string $locale
* @return string|null
*/
private function convertToLangCode( $locale ) {
if ( !$locale ) {
return $locale;
}
$code = locale_get_primary_language( $locale );
return $code ?? '';
}
}