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 | * Create a message with given body. |
||
61 | * |
||
62 | * @param string $body |
||
63 | * |
||
64 | * @return static |
||
65 | */ |
||
66 | 1 | public static function create($body = '') |
|
70 | |||
71 | /** |
||
72 | * ExpoMessage constructor. |
||
73 | * |
||
74 | * @param string $body |
||
75 | */ |
||
76 | 13 | public function __construct(string $body = '') |
|
80 | |||
81 | /** |
||
82 | * Set the message title. |
||
83 | * |
||
84 | * @param string $value |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function title(string $value) |
||
94 | |||
95 | /** |
||
96 | * Set the message body. |
||
97 | * |
||
98 | * @param string $value |
||
99 | * |
||
100 | * @return $this |
||
101 | */ |
||
102 | 1 | public function body(string $value) |
|
108 | |||
109 | /** |
||
110 | * Enable the message sound. |
||
111 | * |
||
112 | * @return $this |
||
113 | */ |
||
114 | 1 | public function enableSound() |
|
120 | |||
121 | /** |
||
122 | * Disable the message sound. |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | 2 | public function disableSound() |
|
132 | |||
133 | /** |
||
134 | * Set the message badge (iOS). |
||
135 | * |
||
136 | * @param int $value |
||
137 | * |
||
138 | * @return $this |
||
139 | */ |
||
140 | 1 | public function badge(int $value) |
|
146 | |||
147 | /** |
||
148 | * Set the time to live of the notification. |
||
149 | * |
||
150 | * @param int $ttl |
||
151 | * |
||
152 | * @return $this |
||
153 | */ |
||
154 | 1 | public function setTtl(int $ttl) |
|
160 | |||
161 | /** |
||
162 | * Set the channelId of the notification for Android devices. |
||
163 | * |
||
164 | * @param string $channelId |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | 1 | public function setChannelId(string $channelId) |
|
174 | |||
175 | /** |
||
176 | * Set the json Data attached to the message. |
||
177 | * |
||
178 | * @param array|string $data |
||
179 | * |
||
180 | * @return $this |
||
181 | * |
||
182 | * @throws CouldNotCreateMessage |
||
183 | */ |
||
184 | 1 | public function setJsonData($data) |
|
200 | |||
201 | /** |
||
202 | * Get an array representation of the message. |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | 13 | public function toArray() |
|
222 | } |
||
223 |
If you suppress an error, we recommend checking for the error condition explicitly: