summaryrefslogtreecommitdiff
path: root/matrix-specification/Responses
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Responses')
-rw-r--r--matrix-specification/Responses/ClientAccountWhoamiGetResponse.php24
-rw-r--r--matrix-specification/Responses/ClientDirectoryRoomAliasGetResponse.php25
-rw-r--r--matrix-specification/Responses/ClientKeysUploadPostResponse.php26
-rw-r--r--matrix-specification/Responses/ClientLoginGetResponse.php24
-rw-r--r--matrix-specification/Responses/ClientLoginPostResponse.php31
-rw-r--r--matrix-specification/Responses/ClientRefreshPostResponse.php24
-rw-r--r--matrix-specification/Responses/ClientRegisterPostResponse.php39
-rw-r--r--matrix-specification/Responses/ClientSyncGetResponse.php40
-rw-r--r--matrix-specification/Responses/ClientUserIdFilterPostResponse.php27
-rw-r--r--matrix-specification/Responses/ClientVersionsGetResponse.php26
-rw-r--r--matrix-specification/Responses/WellKnownMatrixClientGetResponse.php19
-rw-r--r--matrix-specification/Responses/WellKnownMatrixSupportGetResponse.php34
12 files changed, 339 insertions, 0 deletions
diff --git a/matrix-specification/Responses/ClientAccountWhoamiGetResponse.php b/matrix-specification/Responses/ClientAccountWhoamiGetResponse.php
new file mode 100644
index 0000000..2f7ff81
--- /dev/null
+++ b/matrix-specification/Responses/ClientAccountWhoamiGetResponse.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+class ClientAccountWhoamiGetResponse extends Response
+{
+ public function __construct(
+ private string $userId,
+ private ?string $deviceId = null,
+ private ?bool $isGuest = null,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "device_id" => $this->deviceId,
+ "is_guest" => $this->isGuest,
+ "user_id" => $this->userId,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/ClientDirectoryRoomAliasGetResponse.php b/matrix-specification/Responses/ClientDirectoryRoomAliasGetResponse.php
new file mode 100644
index 0000000..4a5977a
--- /dev/null
+++ b/matrix-specification/Responses/ClientDirectoryRoomAliasGetResponse.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+class ClientDirectoryRoomAliasGetResponse extends Response
+{
+ /**
+ * @param string[] $servers
+ */
+ public function __construct(
+ private string $roomId,
+ private array $servers,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return [
+ "room_id" => $this->roomId,
+ "servers" => $this->servers,
+ ];
+ }
+}
diff --git a/matrix-specification/Responses/ClientKeysUploadPostResponse.php b/matrix-specification/Responses/ClientKeysUploadPostResponse.php
new file mode 100644
index 0000000..3d335e4
--- /dev/null
+++ b/matrix-specification/Responses/ClientKeysUploadPostResponse.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+/**
+ * @see https://spec.matrix.org/v1.16/client-server-api/#post_matrixclientv3keysupload
+ */
+class ClientKeysUploadPostResponse extends Response
+{
+ /**
+ * @param array<string, integer> $oneTimeKeyCounts
+ */
+ public function __construct(
+ private array $oneTimeKeyCounts,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return [
+ "one_time_keys_counts" => $this->oneTimeKeyCounts,
+ ];
+ }
+}
diff --git a/matrix-specification/Responses/ClientLoginGetResponse.php b/matrix-specification/Responses/ClientLoginGetResponse.php
new file mode 100644
index 0000000..b8badbd
--- /dev/null
+++ b/matrix-specification/Responses/ClientLoginGetResponse.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Data\LoginFlow;
+use Matrix\Response;
+
+class ClientLoginGetResponse extends Response
+{
+ /**
+ * @param LoginFlow[] $loginFlows
+ */
+ public function __construct(
+ private array $loginFlows,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return [
+ "flows" => $this->loginFlows,
+ ];
+ }
+}
diff --git a/matrix-specification/Responses/ClientLoginPostResponse.php b/matrix-specification/Responses/ClientLoginPostResponse.php
new file mode 100644
index 0000000..4a0fa7d
--- /dev/null
+++ b/matrix-specification/Responses/ClientLoginPostResponse.php
@@ -0,0 +1,31 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Data\DiscoveryInformation;
+use Matrix\Response;
+
+class ClientLoginPostResponse extends Response
+{
+ public function __construct(
+ private string $accessToken,
+ private string $deviceId,
+ private string $userId,
+ private ?int $expiresInMilliseconds = null,
+ private ?string $refreshToken = null,
+ private ?DiscoveryInformation $wellKnown = null,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "access_token" => $this->accessToken,
+ "device_id" => $this->deviceId,
+ "expires_in_ms" => $this->expiresInMilliseconds,
+ "refresh_token" => $this->refreshToken,
+ "user_id" => $this->userId,
+ "well_known" => $this->wellKnown,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/ClientRefreshPostResponse.php b/matrix-specification/Responses/ClientRefreshPostResponse.php
new file mode 100644
index 0000000..38519a3
--- /dev/null
+++ b/matrix-specification/Responses/ClientRefreshPostResponse.php
@@ -0,0 +1,24 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+class ClientRefreshPostResponse extends Response
+{
+ public function __construct(
+ private string $accessToken,
+ private ?int $expiresInMilliseconds = null,
+ private ?string $refreshToken = null,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "access_token" => $this->accessToken,
+ "expires_in_ms" => $this->expiresInMilliseconds,
+ "refresh_token" => $this->refreshToken,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/ClientRegisterPostResponse.php b/matrix-specification/Responses/ClientRegisterPostResponse.php
new file mode 100644
index 0000000..6ed65ce
--- /dev/null
+++ b/matrix-specification/Responses/ClientRegisterPostResponse.php
@@ -0,0 +1,39 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Requests\ClientRegisterPostRequest;
+use Matrix\Response;
+
+class ClientRegisterPostResponse extends Response
+{
+ public function __construct(
+ private string $userId,
+ private ?string $accessToken = null,
+ private ?string $deviceId = null,
+ private ?int $expiresInMilliseconds = null,
+ private ?string $homeServer = null,
+ private ?string $refreshToken = null,
+ )
+ {}
+
+ public function validateRequired(ClientRegisterPostRequest $request): void
+ {
+ $requestBody = $request->getBody();
+ if ($requestBody["inhibit_login"] === false) {
+ # TODO: validate
+ }
+ }
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "access_token" => $this->accessToken,
+ "device_id" => $this->deviceId,
+ "expires_in_ms" => $this->expiresInMilliseconds,
+ "home_server" => $this->homeServer,
+ "refresh_token" => $this->refreshToken,
+ "user_id" => $this->userId,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/ClientSyncGetResponse.php b/matrix-specification/Responses/ClientSyncGetResponse.php
new file mode 100644
index 0000000..dbe2a29
--- /dev/null
+++ b/matrix-specification/Responses/ClientSyncGetResponse.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Data\AccountData;
+use Matrix\Data\DeviceLists;
+use Matrix\Data\Presence;
+use Matrix\Data\Room\Rooms;
+use Matrix\Data\ToDevice;
+use Matrix\Response;
+
+class ClientSyncGetResponse extends Response
+{
+ /**
+ * @param array<string, int> $deviceOneTimeKeysCount
+ */
+ public function __construct(
+ private string $nextBatch,
+ private ?AccountData $accountData = null,
+ private ?DeviceLists $deviceLists = null,
+ private ?array $deviceOneTimeKeysCount = null,
+ private ?Presence $presence = null,
+ private ?Rooms $rooms = null,
+ private ?ToDevice $toDevice = null,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "account_data" => $this->accountData,
+ "device_lists" => $this->deviceLists,
+ "device_one_time_keys_count" => $this->deviceOneTimeKeysCount,
+ "next_batch" => $this->nextBatch,
+ "presence" => $this->presence,
+ "rooms" => $this->rooms,
+ "to_device" => $this->toDevice,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/ClientUserIdFilterPostResponse.php b/matrix-specification/Responses/ClientUserIdFilterPostResponse.php
new file mode 100644
index 0000000..0a5d062
--- /dev/null
+++ b/matrix-specification/Responses/ClientUserIdFilterPostResponse.php
@@ -0,0 +1,27 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+class ClientUserIdFilterPostResponse extends Response
+{
+ public function __construct(
+ private string $filterId,
+ )
+ {
+ if (str_starts_with($filterId, "{")) {
+ throw new \InvalidArgumentException(
+ "filterId cannot start with a { as this character is used to determine if the filter provided is inline JSON " .
+ "or a previously declared filter by homeservers on some APIs"
+ );
+ }
+ }
+
+ public function getBody(): array
+ {
+ return [
+ "filter_id" => $this->filterId,
+ ];
+ }
+}
diff --git a/matrix-specification/Responses/ClientVersionsGetResponse.php b/matrix-specification/Responses/ClientVersionsGetResponse.php
new file mode 100644
index 0000000..44d2cd0
--- /dev/null
+++ b/matrix-specification/Responses/ClientVersionsGetResponse.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Response;
+
+class ClientVersionsGetResponse extends Response
+{
+ /**
+ * @param string[] $versions
+ * @param array<string, bool> $unstableFeatures
+ */
+ public function __construct(
+ private array $versions,
+ private ?array $unstableFeatures = null,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "unstable_features" => $this->unstableFeatures,
+ "versions" => $this->versions,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Responses/WellKnownMatrixClientGetResponse.php b/matrix-specification/Responses/WellKnownMatrixClientGetResponse.php
new file mode 100644
index 0000000..2a0c6d1
--- /dev/null
+++ b/matrix-specification/Responses/WellKnownMatrixClientGetResponse.php
@@ -0,0 +1,19 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Data\DiscoveryInformation;
+use Matrix\Response;
+
+class WellKnownMatrixClientGetResponse extends Response
+{
+ public function __construct(
+ private DiscoveryInformation $discoveryInformation,
+ )
+ {}
+
+ public function getBody(): array
+ {
+ return $this->discoveryInformation->jsonSerialize();
+ }
+}
diff --git a/matrix-specification/Responses/WellKnownMatrixSupportGetResponse.php b/matrix-specification/Responses/WellKnownMatrixSupportGetResponse.php
new file mode 100644
index 0000000..bdd971a
--- /dev/null
+++ b/matrix-specification/Responses/WellKnownMatrixSupportGetResponse.php
@@ -0,0 +1,34 @@
+<?php
+
+namespace Matrix\Responses;
+
+use Matrix\Data\Contact;
+use Matrix\Response;
+
+class WellKnownMatrixSupportGetResponse extends Response
+{
+ /**
+ * @param Contact[] $contacts
+ */
+ public function __construct(
+ private ?array $contacts = null,
+ private ?string $supportPage = null,
+ )
+ {
+ if (is_null($contacts) && is_null($supportPage)) {
+ throw new \InvalidArgumentException("at least one of contacts or supportPage is required");
+ }
+
+ if (! is_null($contacts) && is_null($supportPage) && empty($contacts)) {
+ throw new \InvalidArgumentException("if only contacts is set, it must contain at least one item");
+ }
+ }
+
+ public function getBody(): array
+ {
+ return array_filter([
+ "contacts" => $this->contacts,
+ "support_page" => $this->supportPage,
+ ], fn ($value) => ! is_null($value));
+ }
+}