summaryrefslogtreecommitdiff
path: root/matrix-specification/Requests
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Requests')
-rw-r--r--matrix-specification/Requests/ClientLoginGetRequest.php6
-rw-r--r--matrix-specification/Requests/ClientLoginPostRequest.php53
-rw-r--r--matrix-specification/Requests/ClientSyncGetRequest.php8
-rw-r--r--matrix-specification/Requests/RateLimited.php8
-rw-r--r--matrix-specification/Requests/RequiresAuthentication.php8
5 files changed, 83 insertions, 0 deletions
diff --git a/matrix-specification/Requests/ClientLoginGetRequest.php b/matrix-specification/Requests/ClientLoginGetRequest.php
new file mode 100644
index 0000000..73cc24c
--- /dev/null
+++ b/matrix-specification/Requests/ClientLoginGetRequest.php
@@ -0,0 +1,6 @@
+<?php
+
+namespace Matrix\Requests;
+
+class ClientLoginGetRequest implements RateLimited
+{}
diff --git a/matrix-specification/Requests/ClientLoginPostRequest.php b/matrix-specification/Requests/ClientLoginPostRequest.php
new file mode 100644
index 0000000..d17c558
--- /dev/null
+++ b/matrix-specification/Requests/ClientLoginPostRequest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Matrix\Requests;
+
+use Matrix\Enums\LoginType;
+use Matrix\UserIdentifier;
+
+class ClientLoginPostRequest implements RateLimited, \JsonSerializable
+{
+ public function __construct(
+ private LoginType $type,
+ private ?string $deviceId = null,
+ private ?UserIdentifier $identifier = null,
+ private ?string $initialDeviceDisplayName = null,
+ private ?string $password = null,
+ private ?bool $refreshToken = null,
+ private ?string $token = null,
+ )
+ {
+ if ($type == LoginType::PASSWORD && is_null($password)) {
+ throw new \InvalidArgumentException("password is required when using LoginType password");
+ }
+
+ if ($type == LoginType::TOKEN && is_null($token)) {
+ throw new \InvalidArgumentException("token is required when using LoginType token");
+ }
+ }
+
+ public function jsonSerialize(): array
+ {
+ $request = [
+ "device_id" => $this->deviceId,
+ "identifier" => $this->identifier,
+ "initial_device_display_name" => $this->initialDeviceDisplayName,
+ "refresh_token" => $this->refreshToken,
+ "type" => $this->type,
+ ];
+
+ $request += match ($this->type) {
+ LoginType::PASSWORD => [
+ "password" => $this->password,
+ ],
+
+ LoginType::TOKEN => [
+ "token" => $this->token,
+ ],
+
+ default => [],
+ };
+
+ return array_filter($request, "is_null");
+ }
+}
diff --git a/matrix-specification/Requests/ClientSyncGetRequest.php b/matrix-specification/Requests/ClientSyncGetRequest.php
new file mode 100644
index 0000000..2921fcf
--- /dev/null
+++ b/matrix-specification/Requests/ClientSyncGetRequest.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Matrix\Requests;
+
+class ClientSyncGetRequest
+{
+ # TODO
+}
diff --git a/matrix-specification/Requests/RateLimited.php b/matrix-specification/Requests/RateLimited.php
new file mode 100644
index 0000000..9f917a4
--- /dev/null
+++ b/matrix-specification/Requests/RateLimited.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Matrix\Requests;
+
+interface RateLimited
+{
+ # TODO
+}
diff --git a/matrix-specification/Requests/RequiresAuthentication.php b/matrix-specification/Requests/RequiresAuthentication.php
new file mode 100644
index 0000000..c494f13
--- /dev/null
+++ b/matrix-specification/Requests/RequiresAuthentication.php
@@ -0,0 +1,8 @@
+<?php
+
+namespace Matrix\Requests;
+
+interface RequiresAuthentication
+{
+ public function authenticateUser(): bool;
+}