From 2386148b8f048ba40d9f26cc97898bdcdc778ea2 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 13 Dec 2025 16:27:53 +0100 Subject: matrix specification split --- .../Requests/ClientAccountWhoamiGetRequest.php | 27 ++++++++++ .../ClientDirectoryRoomAliasGetRequest.php | 4 +- .../Requests/ClientKeysUploadPostRequest.php | 18 +++++-- .../Requests/ClientLoginPostRequest.php | 18 +++++-- .../Requests/ClientRefreshPostRequest.php | 17 ++++++- .../Requests/ClientRegisterPostRequest.php | 57 ++++++++++++++++++++++ .../Requests/ClientSyncGetRequest.php | 16 +++++- .../Requests/ClientUserIdFilterPostRequest.php | 17 +++++-- matrix-specification/Requests/RateLimited.php | 4 +- .../Requests/RequiresAuthentication.php | 4 +- .../Requests/RequiresAuthenticationOptional.php | 6 +++ 11 files changed, 167 insertions(+), 21 deletions(-) create mode 100644 matrix-specification/Requests/ClientAccountWhoamiGetRequest.php create mode 100644 matrix-specification/Requests/ClientRegisterPostRequest.php create mode 100644 matrix-specification/Requests/RequiresAuthenticationOptional.php (limited to 'matrix-specification/Requests') diff --git a/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php b/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php new file mode 100644 index 0000000..50313bb --- /dev/null +++ b/matrix-specification/Requests/ClientAccountWhoamiGetRequest.php @@ -0,0 +1,27 @@ +roomAlias}"; + return "{$scheme}://{$serverName}/_matrix/client/{$version}/directory/room/{$this->roomAlias}"; } public function getQueryParameters(): array diff --git a/matrix-specification/Requests/ClientKeysUploadPostRequest.php b/matrix-specification/Requests/ClientKeysUploadPostRequest.php index 40d9eae..05b2fde 100644 --- a/matrix-specification/Requests/ClientKeysUploadPostRequest.php +++ b/matrix-specification/Requests/ClientKeysUploadPostRequest.php @@ -4,8 +4,10 @@ namespace Matrix\Requests; use Matrix\Data\DeviceKeys; use Matrix\Data\KeyObject; +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; -class ClientKeysUploadPostRequest implements RateLimited, RequiresAuthentication, \JsonSerializable +class ClientKeysUploadPostRequest extends Request implements RateLimited, RequiresAuthentication { /** * @param array $fallbackKeys @@ -18,12 +20,22 @@ class ClientKeysUploadPostRequest implements RateLimited, RequiresAuthentication ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/keys/upload"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return array_filter([ "device_keys" => $this->deviceKeys, "fallback_keys" => $this->fallbackKeys, "one_time_keys" => $this->oneTimeKeys, - ], "is_null"); + ], fn ($value) => ! is_null($value)); } } diff --git a/matrix-specification/Requests/ClientLoginPostRequest.php b/matrix-specification/Requests/ClientLoginPostRequest.php index 44497e7..161c6de 100644 --- a/matrix-specification/Requests/ClientLoginPostRequest.php +++ b/matrix-specification/Requests/ClientLoginPostRequest.php @@ -3,9 +3,11 @@ namespace Matrix\Requests; use Matrix\Data\UserIdentifier; +use Matrix\Enums\ApiPathVersion; use Matrix\Enums\LoginType; +use Matrix\Request; -class ClientLoginPostRequest implements RateLimited, \JsonSerializable +class ClientLoginPostRequest extends Request implements RateLimited { public function __construct( private LoginType $type, @@ -26,7 +28,17 @@ class ClientLoginPostRequest implements RateLimited, \JsonSerializable } } - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/login"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { $request = [ "device_id" => $this->deviceId, @@ -48,6 +60,6 @@ class ClientLoginPostRequest implements RateLimited, \JsonSerializable default => [], }; - return array_filter($request, "is_null"); + return array_filter($request, fn ($value) => ! is_null($value)); } } diff --git a/matrix-specification/Requests/ClientRefreshPostRequest.php b/matrix-specification/Requests/ClientRefreshPostRequest.php index 733ca75..3733945 100644 --- a/matrix-specification/Requests/ClientRefreshPostRequest.php +++ b/matrix-specification/Requests/ClientRefreshPostRequest.php @@ -2,14 +2,27 @@ namespace Matrix\Requests; -class ClientRefreshPostRequest implements RateLimited, \JsonSerializable +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; + +class ClientRefreshPostRequest extends Request implements RateLimited { public function __construct( private string $refreshToken, ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/refresh"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return [ "refresh_token" => $this->refreshToken, 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 @@ +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)); + } +} diff --git a/matrix-specification/Requests/ClientSyncGetRequest.php b/matrix-specification/Requests/ClientSyncGetRequest.php index 2ab7d9e..f19e820 100644 --- a/matrix-specification/Requests/ClientSyncGetRequest.php +++ b/matrix-specification/Requests/ClientSyncGetRequest.php @@ -2,9 +2,11 @@ namespace Matrix\Requests; +use Matrix\Enums\ApiPathVersion; use Matrix\Enums\PresenceState; +use Matrix\Request; -class ClientSyncGetRequest implements RequiresAuthentication +class ClientSyncGetRequest extends Request implements RequiresAuthentication { public function __construct( private ?string $filter = null, @@ -24,6 +26,11 @@ class ClientSyncGetRequest implements RequiresAuthentication $this->useStateAfter ??= false; } + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/sync"; + } + public function getQueryParameters(): array { return array_filter([ @@ -33,6 +40,11 @@ class ClientSyncGetRequest implements RequiresAuthentication "since" => $this->since, "timeout" => $this->timeout, "use_state_after" => $this->useStateAfter, - ], "is_null"); + ], fn ($value) => ! is_null($value)); + } + + public function getBody(): array + { + return []; } } diff --git a/matrix-specification/Requests/ClientUserIdFilterPostRequest.php b/matrix-specification/Requests/ClientUserIdFilterPostRequest.php index 2edc4c5..cd01532 100644 --- a/matrix-specification/Requests/ClientUserIdFilterPostRequest.php +++ b/matrix-specification/Requests/ClientUserIdFilterPostRequest.php @@ -4,9 +4,10 @@ namespace Matrix\Requests; use Matrix\Data\Filters\EventFilter; use Matrix\Data\Filters\RoomFilter; +use Matrix\Enums\ApiPathVersion; +use Matrix\Request; - # ClientUserUserIdFilterPostRequest? -class ClientUserIdFilterPostRequest implements RequiresAuthentication, \JsonSerializable +class ClientUserIdFilterPostRequest extends Request implements RequiresAuthentication { /** * @param string[] $eventFields @@ -21,7 +22,17 @@ class ClientUserIdFilterPostRequest implements RequiresAuthentication, \JsonSeri ) {} - public function jsonSerialize(): array + public function getUri(string $scheme, string $serverName, ApiPathVersion $version): string + { + return "{$scheme}://{$serverName}/_matrix/client/{$version}/user/{$this->userId}/filter"; + } + + public function getQueryParameters(): array + { + return []; + } + + public function getBody(): array { return [ "account_data" => $this->accountData, diff --git a/matrix-specification/Requests/RateLimited.php b/matrix-specification/Requests/RateLimited.php index 9f917a4..a75054f 100644 --- a/matrix-specification/Requests/RateLimited.php +++ b/matrix-specification/Requests/RateLimited.php @@ -3,6 +3,4 @@ namespace Matrix\Requests; interface RateLimited -{ - # TODO -} +{} diff --git a/matrix-specification/Requests/RequiresAuthentication.php b/matrix-specification/Requests/RequiresAuthentication.php index a762405..cc4b3e6 100644 --- a/matrix-specification/Requests/RequiresAuthentication.php +++ b/matrix-specification/Requests/RequiresAuthentication.php @@ -3,6 +3,4 @@ namespace Matrix\Requests; interface RequiresAuthentication -{ - //public function authenticateUser(): bool; -} +{} diff --git a/matrix-specification/Requests/RequiresAuthenticationOptional.php b/matrix-specification/Requests/RequiresAuthenticationOptional.php new file mode 100644 index 0000000..2ff7980 --- /dev/null +++ b/matrix-specification/Requests/RequiresAuthenticationOptional.php @@ -0,0 +1,6 @@ +