1 | <?php |
||
7 | class ExpoMessage |
||
8 | { |
||
9 | /** |
||
10 | * The message title. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $title; |
||
15 | |||
16 | /** |
||
17 | * The message body. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $body; |
||
22 | |||
23 | /** |
||
24 | * The sound to play when the recipient receives this notification. |
||
25 | * |
||
26 | * @var string|null |
||
27 | */ |
||
28 | protected $sound = 'default'; |
||
29 | |||
30 | /** |
||
31 | * The number to display next to the push notification (iOS). |
||
32 | * Specify zero to clear the badge. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $badge = 0; |
||
37 | |||
38 | /** |
||
39 | * The number of seconds for which the message may be kept around for redelivery if it has not been delivered yet. |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | protected $ttl = 0; |
||
44 | |||
45 | /** |
||
46 | * ID of the Notification Channel through which to display this notification on Android devices. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $channelId = ''; |
||
51 | |||
52 | /** |
||
53 | * The json data attached to the message. |
||
54 | * |
||
55 | * @var string |
||
56 | */ |
||
57 | protected $jsonData = '{}'; |
||
58 | |||
59 | /** |
||
60 | * The priority of notification message for Android devices. |
||
61 | * |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $priority = 'default'; |
||
65 | |||
66 | /** |
||
67 | * Create a message with given body. |
||
68 | * |
||
69 | * @param string $body |
||
70 | * |
||
71 | * @return static |
||
72 | */ |
||
73 | 1 | public static function create($body = '') |
|
77 | |||
78 | /** |
||
79 | * ExpoMessage constructor. |
||
80 | * |
||
81 | * @param string $body |
||
82 | */ |
||
83 | 13 | public function __construct(string $body = '') |
|
87 | |||
88 | /** |
||
89 | * Set the message title. |
||
90 | * |
||
91 | * @param string $value |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function title(string $value) |
||
101 | |||
102 | /** |
||
103 | * Set the message body. |
||
104 | * |
||
105 | * @param string $value |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 1 | public function body(string $value) |
|
115 | |||
116 | /** |
||
117 | * Enable the message sound. |
||
118 | * |
||
119 | * @return $this |
||
120 | */ |
||
121 | 1 | public function enableSound() |
|
127 | |||
128 | /** |
||
129 | * Disable the message sound. |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | 2 | public function disableSound() |
|
139 | |||
140 | /** |
||
141 | * Set the message badge (iOS). |
||
142 | * |
||
143 | * @param int $value |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | 1 | public function badge(int $value) |
|
153 | |||
154 | /** |
||
155 | * Set the time to live of the notification. |
||
156 | * |
||
157 | * @param int $ttl |
||
158 | * |
||
159 | * @return $this |
||
160 | */ |
||
161 | 1 | public function setTtl(int $ttl) |
|
167 | |||
168 | /** |
||
169 | * Set the channelId of the notification for Android devices. |
||
170 | * |
||
171 | * @param string $channelId |
||
172 | * |
||
173 | * @return $this |
||
174 | */ |
||
175 | 1 | public function setChannelId(string $channelId) |
|
181 | |||
182 | /** |
||
183 | * Set the json Data attached to the message. |
||
184 | * |
||
185 | * @param array|string $data |
||
186 | * |
||
187 | * @return $this |
||
188 | * |
||
189 | * @throws CouldNotCreateMessage |
||
190 | */ |
||
191 | 1 | public function setJsonData($data) |
|
207 | |||
208 | /** |
||
209 | * Set the priority of the notification, must be one of [default, normal, high]. |
||
210 | * |
||
211 | * @param string $priority |
||
212 | * |
||
213 | * @return $this |
||
214 | */ |
||
215 | public function priority(string $priority) |
||
221 | |||
222 | /** |
||
223 | * Get an array representation of the message. |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | 13 | public function toArray() |
|
244 | } |
||
245 |
If you suppress an error, we recommend checking for the error condition explicitly: