blob: 54a48e4ecb4060251da065063d765043554b7510 (
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
|
<?php
namespace Matrix\Data;
use Matrix\Enums\Role;
class Contact implements \JsonSerializable
{
public function __construct(
private Role|string $role,
private ?string $emailAddress = null,
private ?string $matrixId = null,
)
{
if (is_null($emailAddress) && is_null($matrixId)) {
throw new \InvalidArgumentException("at least one of emailAddress or matrixId is required");
}
}
public function jsonSerialize(): array
{
return array_filter([
"email_address" => $this->emailAddress,
"matrix_id" => $this->matrixId,
"role" => $this->role,
], fn ($value) => ! is_null($value));
}
}
|