diff options
Diffstat (limited to 'matrix-specification/Events/Room/CreateEvent.php')
| -rw-r--r-- | matrix-specification/Events/Room/CreateEvent.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/matrix-specification/Events/Room/CreateEvent.php b/matrix-specification/Events/Room/CreateEvent.php new file mode 100644 index 0000000..eccda10 --- /dev/null +++ b/matrix-specification/Events/Room/CreateEvent.php @@ -0,0 +1,54 @@ +<?php + +namespace Matrix\Events\Room; + +use Matrix\Data\Room\PreviousRoom; +use Matrix\Data\UnsignedData; +use Matrix\Enums\EventType; +use Matrix\Events\StateEvent; + +class CreateEvent extends StateEvent +{ + /** + * @param ?string[] $additionalCreators + */ + public function __construct( + string $eventId, + int $originServerTimestamp, + string $roomId, + string $sender, + string $roomVersion, + ?array $additionalCreators = null, + ?string $creator = null, + bool $federate = true, + ?PreviousRoom $predecessor = null, + ?string $roomType = null, + string $stateKey = "", + ?UnsignedData $unsigned = null, + ) + { + if (intval($roomVersion) <= 10) { + if (empty($creator)) { + throw new \InvalidArgumentException("creator is required in room versions 1 - 10"); + } + } + + parent::__construct( + array_filter([ + "additional_creators" => $additionalCreators, + "creator" => intval($roomVersion) <= 10 ? $creator : $sender, + "m.federate" => $federate, + "predecessor" => $predecessor, + "room_version" => $roomVersion, + "type" => $roomType, + ], fn ($value) => ! is_null($value)), + $eventId, + $originServerTimestamp, + $roomId, + $sender, + $stateKey, + EventType::ROOM_CREATE, + $unsigned, + ); + } +} |
