summaryrefslogtreecommitdiff
path: root/matrix-specification/Data
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Data')
-rw-r--r--matrix-specification/Data/Capabilities.php44
-rw-r--r--matrix-specification/Data/Capability/BooleanCapability.php18
-rw-r--r--matrix-specification/Data/Capability/ProfileFieldsCapability.php26
-rw-r--r--matrix-specification/Data/Capability/RoomVersionsCapability.php23
-rw-r--r--matrix-specification/Data/PushCondition.php56
-rw-r--r--matrix-specification/Data/PushRule.php32
-rw-r--r--matrix-specification/Data/Ruleset.php33
7 files changed, 232 insertions, 0 deletions
diff --git a/matrix-specification/Data/Capabilities.php b/matrix-specification/Data/Capabilities.php
new file mode 100644
index 0000000..3aa54a7
--- /dev/null
+++ b/matrix-specification/Data/Capabilities.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Matrix\Data;
+
+use Matrix\Data\Capability\BooleanCapability;
+use Matrix\Data\Capability\ProfileFieldsCapability;
+use Matrix\Data\Capability\RoomVersionsCapability;
+
+class Capabilities implements \JsonSerializable
+{
+ /**
+ * @param array<string, mixed> $otherProperties
+ */
+ public function __construct(
+ private ?BooleanCapability $threePidChanges = null,
+ private ?BooleanCapability $changePassword = null,
+ private ?BooleanCapability $getLoginToken = null,
+ private ?ProfileFieldsCapability $profileFields = null,
+ private ?RoomVersionsCapability $roomVersions = null,
+ private ?BooleanCapability $setAvatarUrl = null,
+ private ?BooleanCapability $setDisplayname = null,
+ private ?array $otherProperties = null,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ $data = [
+ "m.3pid_changes" => $this->threePidChanges,
+ "m.change_password" => $this->changePassword,
+ "m.get_login_token" => $this->getLoginToken,
+ "m.profile_fields" => $this->profileFields,
+ "m.room_versions" => $this->roomVersions,
+ "m.set_avatar_url" => $this->setAvatarUrl,
+ "m.set_displayname" => $this->setDisplayname,
+ ];
+
+ if (! empty($this->otherProperties)) {
+ $data += $this->otherProperties;
+ }
+
+ return array_filter($data, fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Data/Capability/BooleanCapability.php b/matrix-specification/Data/Capability/BooleanCapability.php
new file mode 100644
index 0000000..13cb4de
--- /dev/null
+++ b/matrix-specification/Data/Capability/BooleanCapability.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Matrix\Data\Capability;
+
+class BooleanCapability implements \JsonSerializable
+{
+ public function __construct(
+ private bool $enabled,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "enabled" => $this->enabled,
+ ];
+ }
+}
diff --git a/matrix-specification/Data/Capability/ProfileFieldsCapability.php b/matrix-specification/Data/Capability/ProfileFieldsCapability.php
new file mode 100644
index 0000000..91b0fc4
--- /dev/null
+++ b/matrix-specification/Data/Capability/ProfileFieldsCapability.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace Matrix\Data\Capability;
+
+class ProfileFieldsCapability implements \JsonSerializable
+{
+ /**
+ * @param string[] $allowed
+ * @param string[] $disallowed
+ */
+ public function __construct(
+ private bool $enabled,
+ private ?array $allowed = null,
+ private ?array $disallowed = null,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ return array_filter([
+ "allowed" => $this->allowed,
+ "disallowed" => $this->disallowed,
+ "enabled" => $this->enabled,
+ ], fn ($value) => ! is_null($value));
+ }
+}
diff --git a/matrix-specification/Data/Capability/RoomVersionsCapability.php b/matrix-specification/Data/Capability/RoomVersionsCapability.php
new file mode 100644
index 0000000..d2a5cd7
--- /dev/null
+++ b/matrix-specification/Data/Capability/RoomVersionsCapability.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Matrix\Data\Capability;
+
+class RoomVersionsCapability implements \JsonSerializable
+{
+ /**
+ * @param array<string, string> $available
+ */
+ public function __construct(
+ private array $available,
+ private string $default,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "available" => $this->available,
+ "default" => $this->default,
+ ];
+ }
+}
diff --git a/matrix-specification/Data/PushCondition.php b/matrix-specification/Data/PushCondition.php
new file mode 100644
index 0000000..ca94de9
--- /dev/null
+++ b/matrix-specification/Data/PushCondition.php
@@ -0,0 +1,56 @@
+<?php
+
+namespace Matrix\Data;
+
+use Matrix\Enums\PushConditionKind;
+use Matrix\Events\Event;
+
+class PushCondition implements \JsonSerializable
+{
+ /**
+ * @param Event[] $events
+ */
+ public function __construct(
+ private PushConditionKind $kind,
+ private ?string $is = null,
+ private ?string $key = null,
+ private ?string $pattern = null,
+ private string|int|bool|null $value = null,
+ )
+ {
+ if ($kind === PushConditionKind::ROOM_MEMBER_COUNT && is_null($is)) {
+ throw new \InvalidArgumentException("\"is\" is required for room_member_count conditions");
+ }
+
+ if (
+ (
+ $kind === PushConditionKind::EVENT_MATCH ||
+ $kind === PushConditionKind::EVENT_PROPERTY_IS ||
+ $kind === PushConditionKind::EVENT_PROPERTY_CONTAINS ||
+ $kind === PushConditionKind::SENDER_NOTIFICATION_PERMISSION
+ )
+ && is_null($key)
+ ) {
+ throw new \InvalidArgumentException("\"key\" is required for event_match, event_property_is and event_property_contains conditions");
+ }
+
+ if ($kind === PushConditionKind::EVENT_MATCH && is_null($pattern)) {
+ throw new \InvalidArgumentException("\"pattern\" is required for event_match conditions");
+ }
+
+ if (($kind === PushConditionKind::EVENT_PROPERTY_IS or $kind === PushConditionKind::EVENT_PROPERTY_CONTAINS) && is_null($value)) {
+ throw new \InvalidArgumentException("\"value\" is required for event_property_is and event_property_contains conditions");
+ }
+ }
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "is" => $this->is,
+ "key" => $this->key,
+ "kind" => $this->kind,
+ "pattern" => $this->pattern,
+ "value" => $this->value,
+ ];
+ }
+}
diff --git a/matrix-specification/Data/PushRule.php b/matrix-specification/Data/PushRule.php
new file mode 100644
index 0000000..f904b3a
--- /dev/null
+++ b/matrix-specification/Data/PushRule.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Matrix\Data;
+
+class PushRule implements \JsonSerializable
+{
+ /**
+ * @param array<string|array<string, mixed>> $actions
+ * @param PushCondition[] $conditions
+ */
+ public function __construct(
+ private array $actions,
+ private bool $default,
+ private bool $enabled,
+ private string $ruleId,
+ private ?array $conditions = null,
+ private ?string $pattern = null,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "actions" => $this->actions,
+ "conditions" => $this->conditions,
+ "default" => $this->default,
+ "enabled" => $this->enabled,
+ "pattern" => $this->pattern,
+ "rule_id" => $this->ruleId,
+ ];
+ }
+}
diff --git a/matrix-specification/Data/Ruleset.php b/matrix-specification/Data/Ruleset.php
new file mode 100644
index 0000000..af75579
--- /dev/null
+++ b/matrix-specification/Data/Ruleset.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Matrix\Data;
+
+class Ruleset implements \JsonSerializable
+{
+ /**
+ * @param PushRule[] $content
+ * @param PushRule[] $override
+ * @param PushRule[] $room
+ * @param PushRule[] $sender
+ * @param PushRule[] $underride
+ */
+ public function __construct(
+ private array $content,
+ private array $override,
+ private array $room,
+ private array $sender,
+ private array $underride,
+ )
+ {}
+
+ public function jsonSerialize(): array
+ {
+ return [
+ "content" => $this->content,
+ "override" => $this->override,
+ "room" => $this->room,
+ "sender" => $this->sender,
+ "underride" => $this->underride,
+ ];
+ }
+}