summaryrefslogtreecommitdiff
path: root/matrix-specification/Data/Contact.php
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Data/Contact.php')
-rw-r--r--matrix-specification/Data/Contact.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/matrix-specification/Data/Contact.php b/matrix-specification/Data/Contact.php
new file mode 100644
index 0000000..9eeefe5
--- /dev/null
+++ b/matrix-specification/Data/Contact.php
@@ -0,0 +1,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,
+ ], "is_null");
+ }
+}