1 | <?php |
||
7 | class ExpoMessage |
||
8 | { |
||
9 | /** |
||
10 | * The message body. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $body; |
||
15 | |||
16 | /** |
||
17 | * The sound to play when the recipient receives this notification. |
||
18 | * |
||
19 | * @var string|null |
||
20 | */ |
||
21 | protected $sound = 'default'; |
||
22 | |||
23 | /** |
||
24 | * The number to display next to the push notification (iOS). |
||
25 | * Specify zero to clear the badge. |
||
26 | * |
||
27 | * @var int |
||
28 | */ |
||
29 | protected $badge = 0; |
||
30 | |||
31 | /** |
||
32 | * The number of seconds for which the message may be kept around for redelivery if it has not been delivered yet. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $ttl = 0; |
||
37 | |||
38 | /** |
||
39 | * ID of the Notification Channel through which to display this notification on Android devices. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $channelId = "Default"; |
||
44 | |||
45 | /** |
||
46 | * The json data attached to the message. |
||
47 | * |
||
48 | * @var string |
||
49 | */ |
||
50 | protected $jsonData = ''; |
||
51 | |||
52 | /** |
||
53 | * Create a message with given body. |
||
54 | * |
||
55 | * @param string $body |
||
56 | * |
||
57 | * @return static |
||
58 | */ |
||
59 | 1 | public static function create($body = '') |
|
63 | |||
64 | /** |
||
65 | * ExpoMessage constructor. |
||
66 | * |
||
67 | * @param string $body |
||
68 | */ |
||
69 | 11 | public function __construct(string $body = '') |
|
73 | |||
74 | /** |
||
75 | * Set the message body. |
||
76 | * |
||
77 | * @param string $value |
||
78 | * |
||
79 | * @return $this |
||
80 | */ |
||
81 | 1 | public function body(string $value) |
|
87 | |||
88 | /** |
||
89 | * Enable the message sound. |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | 1 | public function enableSound() |
|
99 | |||
100 | /** |
||
101 | * Disable the message sound. |
||
102 | * |
||
103 | * @return $this |
||
104 | */ |
||
105 | 2 | public function disableSound() |
|
111 | |||
112 | /** |
||
113 | * Set the message badge (iOS). |
||
114 | * |
||
115 | * @param int $value |
||
116 | * |
||
117 | * @return $this |
||
118 | */ |
||
119 | 1 | public function badge(int $value) |
|
125 | |||
126 | /** |
||
127 | * Set the time to live of the notification. |
||
128 | * |
||
129 | * @param int $ttl |
||
130 | * |
||
131 | * @return $this |
||
132 | */ |
||
133 | 1 | public function setTtl(int $ttl) |
|
139 | |||
140 | /** |
||
141 | * Set the channelId of the notification for Android devices. |
||
142 | * |
||
143 | * @param string $channelId |
||
144 | */ |
||
145 | 1 | public function setChannelId(string $channelId) |
|
149 | |||
150 | /** |
||
151 | * Set the json Data attached to the message. |
||
152 | * |
||
153 | * @param array|string $data |
||
154 | * |
||
155 | * @return $this |
||
156 | * |
||
157 | * @throws CouldNotCreateMessage |
||
158 | */ |
||
159 | 1 | public function setJsonData($data) |
|
175 | |||
176 | /** |
||
177 | * Get an array representation of the message. |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 11 | public function toArray() |
|
192 | } |
||
193 |
If you suppress an error, we recommend checking for the error condition explicitly: