diff options
| author | Daniel Weipert <git@mail.dweipert.de> | 2025-09-19 17:03:47 +0200 |
|---|---|---|
| committer | Daniel Weipert <git@mail.dweipert.de> | 2025-09-19 17:03:47 +0200 |
| commit | b08047ba485f86038f33175162943c0a9878ab1a (patch) | |
| tree | 49980e78eb3e641b04ddcc0817f74e89dc07f2b7 /matrix-specification/UserIdentifier.php | |
| parent | 2ae0c2fa2a0bb5a7cd1fd9da1c6d2a6090126e67 (diff) | |
Diffstat (limited to 'matrix-specification/UserIdentifier.php')
| -rw-r--r-- | matrix-specification/UserIdentifier.php | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/matrix-specification/UserIdentifier.php b/matrix-specification/UserIdentifier.php new file mode 100644 index 0000000..63f939a --- /dev/null +++ b/matrix-specification/UserIdentifier.php @@ -0,0 +1,45 @@ +<?php + +namespace Matrix; + +use Matrix\Enums\UserIdentifierType; + +class UserIdentifier implements \JsonSerializable +{ + public function __construct( + private UserIdentifierType $type, + private ?string $user = null, + private ?string $thirdPartyMedium = null, + private ?string $thirdPartyAddress = null, + private ?string $phoneCountry = null, + private ?string $phoneNumber = null, + ) + {} + + public function jsonSerialize(): array + { + $userIdentifier = [ + "type" => $this->type, + ]; + + $userIdentifier += match ($this->type) { + UserIdentifierType::USER => [ + "user" => $this->user, + ], + + UserIdentifierType::THIRDPARTY => [ + "medium" => $this->thirdPartyMedium, + "address" => $this->thirdPartyAddress, + ], + + UserIdentifierType::PHONE => [ + "country" => $this->phoneCountry, + "phone" => $this->phoneNumber, + ], + + default => [], + }; + + return $userIdentifier; + } +} |
