summaryrefslogtreecommitdiff
path: root/matrix-specification/Responses/WellKnownMatrixSupportGetResponse.php
blob: f38e2b0fff06c533e540376648a70761d2a2f0fa (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
<?php

namespace Matrix\Responses;

use Matrix\Data\Contact;

class WellKnownMatrixSupportGetResponse implements \JsonSerializable
{
  /**
   * @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 jsonSerialize(): array
  {
    return array_filter([
      "contacts" => $this->contacts,
      "support_page" => $this->supportPage,
    ], "is_null");
  }
}