@@ -33,21 +33,23 @@ class WebPush
3333 'GCM ' => 'https://android.googleapis.com/gcm/send ' ,
3434 );
3535
36+ /** @var int Time To Live of notifications */
37+ private $ TTL ;
38+
3639 /**
3740 * WebPush constructor.
3841 *
3942 * @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.
4144 * @param int|null $timeout Timeout of POST request
4245 * @param AbstractClient|null $client
4346 */
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 )
4548 {
4649 $ this ->apiKeys = $ apiKeys ;
4750 $ this ->TTL = $ TTL ;
4851
4952 $ client = isset ($ client ) ? $ client : new MultiCurl ();
50- $ timeout = isset ($ timeout ) ? $ timeout : 30 ;
5153 $ client ->setTimeout ($ timeout );
5254 $ this ->browser = new Browser ($ client );
5355 }
@@ -155,14 +157,11 @@ private function sendToStandardEndpoints(array $notifications)
155157 {
156158 $ headers = array (
157159 'Content-Length ' => 0 ,
160+ 'TTL ' => $ this ->TTL ,
158161 );
159162
160163 $ content = '' ;
161164
162- if (isset ($ this ->TTL )) {
163- $ headers ['TTL ' ] = $ this ->TTL ;
164- }
165-
166165 $ responses = array ();
167166 /** @var Notification $notification */
168167 foreach ($ notifications as $ notification ) {
@@ -177,8 +176,11 @@ private function sendToGCMEndpoints(array $notifications)
177176 $ maxBatchSubscriptionIds = 1000 ;
178177 $ url = $ this ->urlByServerType ['GCM ' ];
179178
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+ );
182184
183185 $ subscriptionIds = array ();
184186 /** @var Notification $notification */
@@ -254,4 +256,20 @@ public function setBrowser($browser)
254256 {
255257 $ this ->browser = $ browser ;
256258 }
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+ }
257275}
0 commit comments