1 | <?php |
||
19 | class Notification |
||
20 | { |
||
21 | use ParameterTrait { |
||
22 | ParameterTrait::setParameter as setDefinedParameter; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Default notification parameters. |
||
27 | * |
||
28 | * For an iOS silent notification leave "badge" and "sound" to null and set "content-available" to true |
||
29 | * |
||
30 | * @see https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG |
||
31 | * /Chapters/TheNotificationPayload.html |
||
32 | * @see https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $defaultParameters = [ |
||
37 | // APNS |
||
38 | 'badge' => null, |
||
39 | 'sound' => null, |
||
40 | 'content-available' => null, // true|1 for silence notifications on iOS |
||
41 | 'category' => null, |
||
42 | 'url-args' => null, |
||
43 | 'expire' => null, |
||
44 | |||
45 | // GCM |
||
46 | 'collapse_key' => null, |
||
47 | 'delay_while_idle' => null, |
||
48 | 'time_to_live' => GcmMessage::DEFAULT_TTL, // 4 weeks |
||
49 | 'restricted_package_name' => null, |
||
50 | 'dry_run' => null, |
||
51 | ]; |
||
52 | |||
53 | /** |
||
54 | * @var \Jgut\Tify\Message |
||
55 | */ |
||
56 | protected $message; |
||
57 | |||
58 | /** |
||
59 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
60 | */ |
||
61 | protected $receivers; |
||
62 | |||
63 | /** |
||
64 | * Notification constructor. |
||
65 | * |
||
66 | * @param \Jgut\Tify\Message $message |
||
67 | * @param \Jgut\Tify\Receiver\AbstractReceiver|\Jgut\Tify\Receiver\AbstractReceiver[]| null $receivers |
||
68 | * @param array $parameters |
||
69 | * |
||
70 | * @throws \InvalidArgumentException |
||
71 | */ |
||
72 | public function __construct(Message $message, $receivers = null, array $parameters = []) |
||
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | * |
||
91 | * @throws \InvalidArgumentException |
||
92 | */ |
||
93 | public function setParameter($parameter, $value) |
||
101 | |||
102 | /** |
||
103 | * Get message. |
||
104 | * |
||
105 | * @return \Jgut\Tify\Message |
||
106 | */ |
||
107 | public function getMessage() |
||
111 | |||
112 | /** |
||
113 | * Set message. |
||
114 | * |
||
115 | * @param \Jgut\Tify\Message $message |
||
116 | * |
||
117 | * @throws \InvalidArgumentException |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | public function setMessage(Message $message) |
||
127 | |||
128 | /** |
||
129 | * Retrieve list of receivers. |
||
130 | * |
||
131 | * @return \Jgut\Tify\Receiver\AbstractReceiver[] |
||
132 | */ |
||
133 | public function getReceivers() |
||
137 | |||
138 | /** |
||
139 | * Register receivers. |
||
140 | * |
||
141 | * @param array $receivers |
||
142 | * |
||
143 | * @return $this |
||
144 | */ |
||
145 | public function setReceivers(array $receivers) |
||
155 | |||
156 | /** |
||
157 | * Add receiver. |
||
158 | * |
||
159 | * @param \Jgut\Tify\Receiver\AbstractReceiver $receiver |
||
160 | * |
||
161 | * @return $this |
||
162 | */ |
||
163 | public function addReceiver(AbstractReceiver $receiver) |
||
169 | |||
170 | /** |
||
171 | * Remove all receivers. |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | public function clearReceivers() |
||
181 | } |
||
182 |