summaryrefslogtreecommitdiff
path: root/matrix-specification/Requests/ClientRegisterPostRequest.php
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Requests/ClientRegisterPostRequest.php')
-rw-r--r--matrix-specification/Requests/ClientRegisterPostRequest.php57
1 files changed, 57 insertions, 0 deletions
diff --git a/matrix-specification/Requests/ClientRegisterPostRequest.php b/matrix-specification/Requests/ClientRegisterPostRequest.php
new file mode 100644
index 0000000..74c0c1d
--- /dev/null
+++ b/matrix-specification/Requests/ClientRegisterPostRequest.php
@@ -0,0 +1,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));
+ }
+}