summaryrefslogtreecommitdiff
path: root/matrix-specification/Data/PushCondition.php
diff options
context:
space:
mode:
Diffstat (limited to 'matrix-specification/Data/PushCondition.php')
-rw-r--r--matrix-specification/Data/PushCondition.php56
1 files changed, 56 insertions, 0 deletions
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,
+ ];
+ }
+}