Zitadel PHP Client 1.3.6
PHP Client for Zitadel
Loading...
Searching...
No Matches
Edit.php
Go to the documentation of this file.
1<?php
2
4
5use Exception;
6
10class Edit
11{
12 private array $settings;
13 private int $userid;
14 private array $userChanges;
18 public function __construct(array $settings)
19 {
20 $this->settings = $settings;
21 }
26 public function setUserId(int $userid) {
27 $this->userid = $userid;
28 }
33 public function setUserName(string $username) {
34 $this->userChanges["username"] = $username;
35 }
41 public function setName(string $givenName, string $familyName) {
42 $this->userChanges["profile.givenName"] = $givenName;
43 $this->userChanges["profile.familyName"] = $familyName;
44 }
49 public function setNickName(string $nickName) {
50 $this->userChanges["profile.nickName"] = $nickName;
51 }
56 public function setDisplayName(string $displayName) {
57 $this->userChanges["profile.displayName"] = $displayName;
58 }
63 public function setLanguage(string $lang) {
64 $this->userChanges["profile.preferredLanguage"] = $lang;
65 }
70 public function setGender(string $gender) {
71 if ($gender == "GENDER_FEMALE" or $gender == "GENDER_MALE" or $gender == "GENDER_DIVERSE") {
72 $this->userChanges["profile.gender"] = $gender;
73 } else {
74 $this->userChanges["profile.gender"] = "GENDER_UNSPECIFIED";
75 }
76 }
77
82 public function edit() {
83 $token = $this->settings["serviceUserToken"];
84 $curl = curl_init();
85 curl_setopt_array($curl, array(
86 CURLOPT_URL => $this->settings["domain"] . "/v2beta/users/$this->userid?" . $this->encodeUserData(),
87 CURLOPT_RETURNTRANSFER => true,
88 CURLOPT_ENCODING => '',
89 CURLOPT_MAXREDIRS => 10,
90 CURLOPT_TIMEOUT => 0,
91 CURLOPT_FOLLOWLOCATION => true,
92 CURLOPT_CUSTOMREQUEST => 'PUT',
93 CURLOPT_HTTPHEADER => array(
94 "Accept: application/json",
95 "Authorization: Bearer $token"
96 )
97 ));
98 $response = json_decode(curl_exec($curl));
99 if(isset($response->code)) {
100 throw new Exception("Error-Code: " . $response->code . " Message: " . $response->message);
101 }
102 curl_close($curl);
103 }
104 private function encodeUserData(): string {
105 $encodedString = "";
106 foreach ($this->userChanges as $key => $value) {
107 $encodedKey = urlencode($key);
108 $encodedValue = urlencode($value);
109 $encodedString .= "$encodedKey=$encodedValue&";
110 }
111 return rtrim($encodedString, '&');
112 }
113}
setName(string $givenName, string $familyName)
Definition Edit.php:41
setLanguage(string $lang)
Definition Edit.php:63
setUserName(string $username)
Definition Edit.php:33
setUserId(int $userid)
Definition Edit.php:26
setGender(string $gender)
Definition Edit.php:70
__construct(array $settings)
Definition Edit.php:18
setDisplayName(string $displayName)
Definition Edit.php:56
setNickName(string $nickName)
Definition Edit.php:49