summaryrefslogtreecommitdiff
path: root/matrix-specification/Data/PushCondition.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2026-04-10 22:38:59 +0200
committerDaniel Weipert <git@mail.dweipert.de>2026-04-10 22:38:59 +0200
commit875b9ece501de5937993c41a83c44f8ea59897d0 (patch)
tree04579bcb80c9fdb43502d178b3ee145a818afe28 /matrix-specification/Data/PushCondition.php
parent74a524ded12c6527745957ac219e1ca34828aa6c (diff)
register and login to Cinny client
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,
+ ];
+ }
+}