Allow setting event parameters as sensitive

This commit is contained in:
Jake Barnby
2024-04-03 16:36:21 +13:00
parent d5d45c5076
commit e224ca440b
2 changed files with 29 additions and 2 deletions
+1 -1
View File
@@ -590,7 +590,7 @@ App::shutdown()
Realtime::send(
projectId: $target['projectId'] ?? $project->getId(),
payload: $queueForEvents->getPayload(),
payload: $queueForEvents->getRealtimePayload(),
events: $allEvents,
channels: $target['channels'],
roles: $target['roles'],
+28 -1
View File
@@ -52,6 +52,7 @@ class Event
protected string $class = '';
protected string $event = '';
protected array $params = [];
protected array $sensitive = [];
protected array $payload = [];
protected array $context = [];
protected ?Document $project = null;
@@ -161,12 +162,17 @@ class Event
* Set payload for this event.
*
* @param array $payload
* @param array $sensitive
* @return self
*/
public function setPayload(array $payload): self
public function setPayload(array $payload, array $sensitive = []): self
{
$this->payload = $payload;
foreach ($sensitive as $key) {
$this->sensitive[$key] = true;
}
return $this;
}
@@ -180,6 +186,19 @@ class Event
return $this->payload;
}
public function getRealtimePayload(): array
{
$payload = [];
foreach ($this->payload as $key => $value) {
if (!isset($this->sensitive[$key])) {
$payload[$key] = $value;
}
}
return $payload;
}
/**
* Set context for this event.
*
@@ -242,6 +261,13 @@ class Event
return $this;
}
public function setParamSensitive(string $key): self
{
$this->sensitive[$key] = true;
return $this;
}
/**
* Get param of event.
*
@@ -294,6 +320,7 @@ class Event
public function reset(): self
{
$this->params = [];
$this->sensitive = [];
return $this;
}