Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Get.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
10class Get
11{
12 private array $settings;
13 private int $userid;
14 private string $userState;
15 private string $userName;
16 private array $loginNames;
17 private string $preferredLoginName;
18 private string $givenName;
19 private string $familyName;
20 private string $nickName;
21 private string $displayName;
22 private string $preferredLanguage;
23 private string $gender;
24 private string $email;
25 private bool $isEmailVerified;
26 private string $phone;
27 private bool $isPhoneVerified;
28 private string $profilePicture;
29 private string $rawUserData;
30
34 public function __construct(array $settings) {
35 $this->settings = $settings;
36 }
37
42 public function setUserId(int $userid) {
43 $this->userid = $userid;
44 }
45
49 public function getProfilePicture(): string {
50 return $this->profilePicture;
51 }
52
56 public function getUserState(): string {
57 return $this->userState;
58 }
59
63 public function getUsername(): string {
64 return $this->userName;
65 }
66
70 public function getLoginNames(): array {
71 return $this->loginNames;
72 }
73
77 public function getPreferredLoginName(): string {
78 return $this->preferredLoginName;
79 }
80
84 public function getGivenName(): string {
85 return $this->givenName;
86 }
87
91 public function getFamilyName(): string {
92 return $this->familyName;
93 }
94
98 public function getNickname(): string {
99 return $this->nickName;
100 }
101
105 public function getDisplayName(): string {
106 return $this->displayName;
107 }
108
112 public function getPreferredLanguage(): string {
113 return $this->preferredLanguage;
114 }
115
119 public function getGender(): string {
120 return $this->gender;
121 }
122
126 public function getEmail(): string {
127 return $this->email;
128 }
129
133 public function isEmailVerified(): bool {
134 return $this->isEmailVerified;
135 }
136
140 public function getPhone(): string {
141 return $this->phone;
142 }
143
147 public function isPhoneVerified(): bool {
148 return $this->isPhoneVerified;
149 }
150
154 public function getRawUserData(): string {
155 return $this->rawUserData;
156 }
157
162 public function fetch() {
163 $token = $this->settings["serviceUserToken"];
164 $curl = curl_init();
165 curl_setopt_array($curl, array(
166 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid",
167 CURLOPT_RETURNTRANSFER => true,
168 CURLOPT_ENCODING => '',
169 CURLOPT_MAXREDIRS => 10,
170 CURLOPT_TIMEOUT => 0,
171 CURLOPT_FOLLOWLOCATION => true,
172 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
173 CURLOPT_CUSTOMREQUEST => 'GET',
174 CURLOPT_HTTPHEADER => array(
175 "Content-Type: application/json",
176 "Accept: application/json",
177 "Authorization: Bearer $token"
178 ),
179 ));
180
181 $response = json_decode(curl_exec($curl));
182 if(isset($response->code)) {
183 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
184 } else {
185 $this->rawUserData = json_encode($response->user);
186
187 $this->userState = $response->user->state;
188 $this->userName = $response->user->username;
189 $this->loginNames = $response->user->loginNames;
190 $this->preferredLoginName = $response->user->preferredLoginName;
191 $this->givenName = $response->user->human->profile->givenName;
192 $this->familyName = $response->user->human->profile->familyName;
193 $this->nickName = $response->user->human->profile->nickName;
194 $this->displayName = $response->user->human->profile->displayName;
195 $this->preferredLanguage = $response->user->human->profile->preferredLanguage;
196
197 if(isset($response->user->human->profile->avatarUrl)) {
198 $this->profilePicture = $response->user->human->profile->avatarUrl;
199 }
200
201
202 $this->gender = $response->user->human->profile->gender;
203 $this->email = $response->user->human->email->email;
204
205 if(isset($response->user->human->email->isVerified)) {
206 $this->isEmailVerified = $response->user->human->email->isVerified;
207 } else {
208 $this->isEmailVerified = false;
209 }
210
211 if(isset($response->user->human->phone->phone)) {
212 $this->phone = $response->user->human->phone->phone;
213 }
214
215 if(isset($response->user->human->phone->isVerified)) {
216 $this->isPhoneVerified = $response->user->human->phone->isVerified;
217 } else {
218 $this->isPhoneVerified = false;
219 }
220 }
221 curl_close($curl);
222 }
223}
setUserId(int $userid)
Definition Get.php:42
__construct(array $settings)
Definition Get.php:34