summaryrefslogtreecommitdiff
path: root/matrix-specification/Responses/ClientRegisterPostResponse.php
blob: 6ed65ceefa064c0898e377c93098c7c0fe261ddb (plain)
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
<?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));
  }
}