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
|
<?php
namespace Matrix\Requests;
use Matrix\Data\AuthenticationData;
use Matrix\Enums\ApiPathVersion;
use Matrix\Enums\UserRegistrationKind;
use Matrix\Request;
/**
* @see https://spec.matrix.org/v1.16/client-server-api/#post_matrixclientv3register
*/
class ClientRegisterPostRequest extends Request implements RateLimited
{
public function __construct(
private AuthenticationData $authenticationData,
private string $password,
private ?UserRegistrationKind $kind = null,
private ?string $deviceId = null,
private ?bool $inhibitLogin = null,
private ?string $initialDeviceDisplayName = null,
private ?string $username = null,
private ?bool $refreshToken = null,
)
{}
public function setDefaults(): void
{
$this->kind ??= UserRegistrationKind::USER;
$this->inhibitLogin ??= false;
}
public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string
{
return "{$scheme}://{$serverName}/_matrix/client/{$version}/register";
}
public function getQueryParameters(): array
{
return array_filter([
"kind" => $this->kind,
], fn ($value) => ! is_null($value));
}
public function getBody(): array
{
return array_filter([
"auth" => $this->authenticationData,
"device_id" => $this->deviceId,
"inhibit_login" => $this->inhibitLogin,
"initial_device_display_name" => $this->initialDeviceDisplayName,
"password" => $this->password,
"refresh_token" => $this->refreshToken,
"username" => $this->username,
], fn ($value) => ! is_null($value));
}
}
|