1 | <?php |
||
17 | class Message |
||
18 | { |
||
19 | use ParameterTrait; |
||
20 | |||
21 | /** |
||
22 | * List of reserved payload data. |
||
23 | * |
||
24 | * @see https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG |
||
25 | * /Chapters/TheNotificationPayload.html |
||
26 | * @see https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected static $reservedRegex = [ |
||
31 | // APNS |
||
32 | '/^apc$/', |
||
33 | |||
34 | // GCM |
||
35 | '/^(google|gcm)/', |
||
36 | '/^from$/', |
||
37 | '/^collapse_key$/', |
||
38 | '/^delay_while_idle$/', |
||
39 | '/^time_to_live$/', |
||
40 | '/^restricted_package_name$/', |
||
41 | '/^dry_run$/', |
||
42 | '/^priority$/', |
||
43 | '/^content_available$/', |
||
44 | ]; |
||
45 | |||
46 | /** |
||
47 | * Default message parameters. |
||
48 | * |
||
49 | * @see self::$reserverRegex |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $defaultParameters = [ |
||
54 | 'title' => null, |
||
55 | 'body' => null, |
||
56 | |||
57 | // APNS |
||
58 | //'launch_image' => null, |
||
59 | //'action_loc_key' => null, |
||
60 | //'title_loc_key' => null, |
||
61 | //'title_loc_args' => null, |
||
62 | //'loc_key' => null, |
||
63 | //'loc_args' => null, |
||
64 | |||
65 | // GCM |
||
66 | //'icon' => null, |
||
67 | //'sound' => 'default', |
||
68 | //'tag' => null, |
||
69 | //'color' => '#rrggbb', |
||
70 | //'click_action' => null, |
||
71 | //'title_loc_key' => null, |
||
72 | //'title_loc_args' => null, |
||
73 | //'body_loc_key' => null, |
||
74 | //'body_loc_args' => null, |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Data payload. |
||
79 | * |
||
80 | * @var \Doctrine\Common\Collections\ArrayCollection |
||
81 | */ |
||
82 | protected $payload; |
||
83 | |||
84 | /** |
||
85 | * Constructor. |
||
86 | * |
||
87 | * @param array $parameters |
||
88 | * @param array $payload |
||
89 | */ |
||
90 | public function __construct(array $parameters = [], array $payload = []) |
||
98 | |||
99 | /** |
||
100 | * Convenience method to set message title. |
||
101 | * |
||
102 | * @param string $title |
||
103 | * |
||
104 | * @throws \InvalidArgumentException |
||
105 | * |
||
106 | * @return $this |
||
107 | */ |
||
108 | public function setTitle($title) |
||
114 | |||
115 | /** |
||
116 | * Convenience method to set message body. |
||
117 | * |
||
118 | * @param string $body |
||
119 | * |
||
120 | * @throws \InvalidArgumentException |
||
121 | * |
||
122 | * @return $this |
||
123 | */ |
||
124 | public function setBody($body) |
||
130 | |||
131 | /** |
||
132 | * Get payload data. |
||
133 | * |
||
134 | * @return array |
||
135 | */ |
||
136 | public function getPayloadData() |
||
140 | |||
141 | /** |
||
142 | * Set payload data. |
||
143 | * |
||
144 | * @param array $data |
||
145 | * |
||
146 | * @return $this |
||
147 | */ |
||
148 | public function setPayloadData(array $data) |
||
158 | |||
159 | /** |
||
160 | * Has payload data. |
||
161 | * |
||
162 | * @param string $payload |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | public function hasPayload($payload) |
||
170 | |||
171 | /** |
||
172 | * Get payload data. |
||
173 | * |
||
174 | * @param string $payload |
||
175 | * @param mixed $default |
||
176 | * |
||
177 | * @return mixed |
||
178 | */ |
||
179 | public function getPayload($payload, $default = null) |
||
183 | |||
184 | /** |
||
185 | * Set payload data. |
||
186 | * |
||
187 | * @param string $payload |
||
188 | * @param mixed $value |
||
189 | * |
||
190 | * @throws \InvalidArgumentException |
||
191 | * |
||
192 | * @return $this |
||
193 | */ |
||
194 | public function setPayload($payload, $value) |
||
212 | } |
||
213 |