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 | * The json data attached to the message. |
||
40 | * |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $jsonData = ''; |
||
44 | |||
45 | /** |
||
46 | * Create a message with given body. |
||
47 | * |
||
48 | * @param string $body |
||
49 | * |
||
50 | * @return static |
||
51 | */ |
||
52 | 1 | public static function create($body = '') |
|
56 | |||
57 | /** |
||
58 | * ExpoMessage constructor. |
||
59 | * |
||
60 | * @param string $body |
||
61 | */ |
||
62 | 10 | public function __construct(string $body = '') |
|
66 | |||
67 | /** |
||
68 | * Set the message body. |
||
69 | * |
||
70 | * @param string $value |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | 1 | public function body(string $value) |
|
80 | |||
81 | /** |
||
82 | * Enable the message sound. |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | 1 | public function enableSound() |
|
92 | |||
93 | /** |
||
94 | * Disable the message sound. |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | 2 | public function disableSound() |
|
104 | |||
105 | /** |
||
106 | * Set the message badge (iOS). |
||
107 | * |
||
108 | * @param int $value |
||
109 | * |
||
110 | * @return $this |
||
111 | */ |
||
112 | 1 | public function badge(int $value) |
|
118 | |||
119 | /** |
||
120 | * Set the time to live of the notification. |
||
121 | * |
||
122 | * @param int $ttl |
||
123 | * |
||
124 | * @return $this |
||
125 | */ |
||
126 | 1 | public function setTtl(int $ttl) |
|
132 | |||
133 | /** |
||
134 | * Set the json Data attached to the message. |
||
135 | * |
||
136 | * @param array|string $data |
||
137 | * |
||
138 | * @return $this |
||
139 | * |
||
140 | * @throws CouldNotCreateMessage |
||
141 | */ |
||
142 | 1 | public function setJsonData($data) |
|
158 | |||
159 | /** |
||
160 | * Get an array representation of the message. |
||
161 | * |
||
162 | * @return array |
||
163 | */ |
||
164 | 10 | public function toArray() |
|
174 | } |
||
175 |
If you suppress an error, we recommend checking for the error condition explicitly: