@@ -33,21 +33,23 @@ class WebPush
33
33
'GCM ' => 'https://android.googleapis.com/gcm/send ' ,
34
34
);
35
35
36
+ /** @var int Time To Live of notifications */
37
+ private $ TTL ;
38
+
36
39
/**
37
40
* WebPush constructor.
38
41
*
39
42
* @param array $apiKeys Some servers needs authentication. Provide your API keys here. (eg. array('GCM' => 'GCM_API_KEY'))
40
- * @param int|null $TTL Time to live of notifications
43
+ * @param int|null $TTL Time To Live of notifications, default being 4 weeks.
41
44
* @param int|null $timeout Timeout of POST request
42
45
* @param AbstractClient|null $client
43
46
*/
44
- public function __construct (array $ apiKeys = array (), $ TTL = null , $ timeout = null , AbstractClient $ client = null )
47
+ public function __construct (array $ apiKeys = array (), $ TTL = 2419200 , $ timeout = 30 , AbstractClient $ client = null )
45
48
{
46
49
$ this ->apiKeys = $ apiKeys ;
47
50
$ this ->TTL = $ TTL ;
48
51
49
52
$ client = isset ($ client ) ? $ client : new MultiCurl ();
50
- $ timeout = isset ($ timeout ) ? $ timeout : 30 ;
51
53
$ client ->setTimeout ($ timeout );
52
54
$ this ->browser = new Browser ($ client );
53
55
}
@@ -155,14 +157,11 @@ private function sendToStandardEndpoints(array $notifications)
155
157
{
156
158
$ headers = array (
157
159
'Content-Length ' => 0 ,
160
+ 'TTL ' => $ this ->TTL ,
158
161
);
159
162
160
163
$ content = '' ;
161
164
162
- if (isset ($ this ->TTL )) {
163
- $ headers ['TTL ' ] = $ this ->TTL ;
164
- }
165
-
166
165
$ responses = array ();
167
166
/** @var Notification $notification */
168
167
foreach ($ notifications as $ notification ) {
@@ -177,8 +176,11 @@ private function sendToGCMEndpoints(array $notifications)
177
176
$ maxBatchSubscriptionIds = 1000 ;
178
177
$ url = $ this ->urlByServerType ['GCM ' ];
179
178
180
- $ headers ['Authorization ' ] = 'key= ' .$ this ->apiKeys ['GCM ' ];
181
- $ headers ['Content-Type ' ] = 'application/json ' ;
179
+ $ headers = array (
180
+ 'Authorization ' => 'key= ' .$ this ->apiKeys ['GCM ' ],
181
+ 'Content-Type ' => 'application/json ' ,
182
+ 'TTL ' => $ this ->TTL ,
183
+ );
182
184
183
185
$ subscriptionIds = array ();
184
186
/** @var Notification $notification */
@@ -254,4 +256,20 @@ public function setBrowser($browser)
254
256
{
255
257
$ this ->browser = $ browser ;
256
258
}
259
+
260
+ /**
261
+ * @return int
262
+ */
263
+ public function getTTL ()
264
+ {
265
+ return $ this ->TTL ;
266
+ }
267
+
268
+ /**
269
+ * @param int $TTL
270
+ */
271
+ public function setTTL ($ TTL )
272
+ {
273
+ $ this ->TTL = $ TTL ;
274
+ }
257
275
}
0 commit comments