-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathNotification.php
More file actions
116 lines (107 loc) · 4.3 KB
/
Copy pathNotification.php
File metadata and controls
116 lines (107 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
namespace Appwrite\Event\Message;
use Appwrite\Event\Event;
use Utopia\Config\Config;
use Utopia\Database\Document;
final class Notification extends Base
{
/**
* @param array<int, array{address: string, channel: string, signatureKey?: string, resourceType?: string, resourceId?: string, resourceInternalId?: string, parentResourceType?: string, parentResourceId?: string, parentResourceInternalId?: string}> $recipients
* @param array<string> $channels
* @param array<string, mixed> $templateParams
* @param array<string> $permissions
* @param array<string, mixed> $variables
* @param array<string, mixed> $attachment
* @param array<string> $events
* @param array<string, mixed> $params
* @param array<string, mixed> $platform
*/
public function __construct(
public readonly ?Document $project = null,
public readonly string $recipient = '',
public readonly array $recipients = [],
public readonly array $channels = [],
public readonly string $template = '',
public readonly array $templateParams = [],
public readonly string $deduplicationKey = '',
public readonly array $permissions = [],
public readonly string $name = '',
public readonly string $subject = '',
public readonly string $bodyTemplate = '',
public readonly string $body = '',
public readonly string $preview = '',
public readonly array $variables = [],
public readonly array $attachment = [],
public readonly array $events = [],
public readonly string $event = '',
public readonly array $params = [],
public readonly array $platform = [],
) {
}
public function toArray(): array
{
$recipients = $this->recipients;
if (empty($recipients) && $this->recipient !== '') {
$recipients = [[
'address' => $this->recipient,
'channel' => NOTIFICATION_TYPE_EMAIL,
]];
}
$platform = !empty($this->platform) ? $this->platform : Config::getParam('platform', []);
return [
'project' => $this->project === null ? null : [
'$id' => $this->project->getId(),
'$sequence' => $this->project->getSequence(),
'database' => $this->project->getAttribute('database'),
],
'recipient' => $this->recipient,
'recipients' => $recipients,
'channels' => $this->channels,
'template' => $this->template,
'templateParams' => $this->templateParams,
'deduplicationKey' => $this->deduplicationKey,
'permissions' => $this->permissions,
'name' => $this->name,
'subject' => $this->subject,
'bodyTemplate' => $this->bodyTemplate,
'body' => $this->body,
'preview' => $this->preview,
'variables' => $this->variables,
'attachment' => $this->attachment,
'events' => !empty($this->events) ? $this->events : $this->generateEvents(),
'platform' => $platform,
];
}
public static function fromArray(array $data): static
{
return new self(
project: !empty($data['project']) ? new Document($data['project']) : null,
recipient: $data['recipient'] ?? '',
recipients: $data['recipients'] ?? [],
channels: $data['channels'] ?? [],
template: $data['template'] ?? '',
templateParams: $data['templateParams'] ?? [],
deduplicationKey: $data['deduplicationKey'] ?? '',
permissions: $data['permissions'] ?? [],
name: $data['name'] ?? '',
subject: $data['subject'] ?? '',
bodyTemplate: $data['bodyTemplate'] ?? '',
body: $data['body'] ?? '',
preview: $data['preview'] ?? '',
variables: $data['variables'] ?? [],
attachment: $data['attachment'] ?? [],
events: $data['events'] ?? [],
platform: $data['platform'] ?? [],
);
}
/**
* @return array<string>
*/
private function generateEvents(): array
{
if ($this->event === '') {
return [];
}
return Event::generateEvents($this->event, $this->params);
}
}