-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
OneSignalOptions.php
139 lines (114 loc) · 2.98 KB
/
OneSignalOptions.php
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Notifier\Bridge\OneSignal;
use Symfony\Component\Notifier\Message\MessageOptionsInterface;
use Symfony\Component\Notifier\Notification\Notification;
/**
* @author Tomas Norkūnas <[email protected]>
*/
final class OneSignalOptions implements MessageOptionsInterface
{
public function __construct(
private array $options = [],
) {
}
/**
* @return $this
*/
public static function fromNotification(Notification $notification): static
{
$options = new self();
$options->headings(['en' => $notification->getSubject()]);
$options->contents(['en' => $notification->getContent()]);
return $options;
}
/**
* @return $this
*/
public function headings(array $headings): static
{
$this->options['headings'] = $headings;
return $this;
}
/**
* @return $this
*/
public function contents(array $contents): static
{
$this->options['contents'] = $contents;
return $this;
}
/**
* @return $this
*/
public function url(string $url): static
{
$this->options['url'] = $url;
return $this;
}
/**
* @return $this
*/
public function data(array $data): static
{
$this->options['data'] = $data;
return $this;
}
/**
* @return $this
*/
public function sendAfter(\DateTimeInterface $datetime): static
{
$this->options['send_after'] = $datetime->format('Y-m-d H:i:sO');
return $this;
}
/**
* @return $this
*/
public function externalId(string $externalId): static
{
$this->options['external_id'] = $externalId;
return $this;
}
/**
* @return $this
*/
public function recipient(string $id): static
{
$this->options['recipient_id'] = $id;
return $this;
}
/**
* Indicates that the passed recipient is an external user id.
*
* For more information on how to set an external user id in OneSignal please see:
* https://documentation.onesignal.com/docs/aliases-external-id
*
* For more information on how targeting based on external user id works please see:
* https://documentation.onesignal.com/reference/create-notification
*
* @return $this
*/
public function isExternalUserId(bool $flag = true): static
{
$this->options['is_external_user_id'] = $flag;
return $this;
}
public function getRecipientId(): ?string
{
return $this->options['recipient_id'] ?? null;
}
public function toArray(): array
{
$options = $this->options;
unset($options['recipient_id']);
return $options;
}
}