@@ -9,13 +9,14 @@ the [Web Push protocol](https://tools.ietf.org/html/draft-thomson-webpush-protoc
9
9
As it is standardized, you don't have to worry about what server type it relies on.
10
10
11
11
## Requirements
12
- * PHP 7.0+
12
+
13
+ * PHP 7.1+
13
14
* gmp
14
15
* mbstring
15
16
* curl
16
17
* openssl
17
18
18
- PHP 7.1 + is recommended for better performance.
19
+ PHP 7.2 + is recommended for better performance.
19
20
For PHP 5.6 or HHVM compatibility, use the v1.x releases.
20
21
21
22
## Installation
@@ -30,24 +31,24 @@ Use [composer](https://getcomposer.org/) to download and install the library and
30
31
use Minishlink\WebPush\WebPush;
31
32
32
33
// array of notifications
33
- $notifications = array(
34
- array(
34
+ $notifications = [
35
+ [
35
36
'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+
36
37
'payload' => 'hello !',
37
38
'userPublicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
38
39
'userAuthToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
39
- ), array(
40
+ ], [
40
41
'endpoint' => 'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
41
42
'payload' => null,
42
43
'userPublicKey' => null,
43
44
'userAuthToken' => null,
44
- ), array(
45
+ ], [
45
46
'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
46
47
'payload' => '{msg:"test"}',
47
48
'userPublicKey' => '(stringOf88Chars)',
48
49
'userAuthToken' => '(stringOf24Chars)',
49
- ) ,
50
- ) ;
50
+ ] ,
51
+ ] ;
51
52
52
53
$webPush = new WebPush();
53
54
@@ -90,16 +91,16 @@ use Minishlink\WebPush\WebPush;
90
91
91
92
$endpoint = 'https://android.googleapis.com/gcm/send/abcdef...'; // Chrome
92
93
93
- $auth = array(
94
+ $auth = [
94
95
'GCM' => 'MY_GCM_API_KEY', // deprecated and optional, it's here only for compatibility reasons
95
- 'VAPID' => array(
96
+ 'VAPID' => [
96
97
'subject' => 'mailto:
[email protected] ', // can be a mailto: or your website address
97
98
'publicKey' => '~88 chars', // (recommended) uncompressed public key P-256 encoded in Base64-URL
98
99
'privateKey' => '~44 chars', // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL
99
100
'pemFile' => 'path/to/pem', // if you have a PEM file and can link to it on your filesystem
100
101
'pem' => 'pemFileContent', // if you have a PEM file and want to hardcode its content
101
- ) ,
102
- ) ;
102
+ ] ,
103
+ ] ;
103
104
104
105
$webPush = new WebPush($auth);
105
106
$webPush->sendNotification(...);
@@ -134,19 +135,19 @@ You can change the default options with `setDefaultOptions()` or in the construc
134
135
135
136
use Minishlink\WebPush\WebPush;
136
137
137
- $defaultOptions = array(
138
+ $defaultOptions = [
138
139
'TTL' => 300, // defaults to 4 weeks
139
140
'urgency' => 'normal', // protocol defaults to "normal"
140
141
'topic' => 'new_event', // not defined by default,
141
142
'batchSize' => 200, // defaults to 1000
142
- ) ;
143
+ ] ;
143
144
144
145
// for every notifications
145
- $webPush = new WebPush(array() , $defaultOptions);
146
+ $webPush = new WebPush([] , $defaultOptions);
146
147
$webPush->setDefaultOptions($defaultOptions);
147
148
148
149
// or for one notification
149
- $webPush->sendNotification($endpoint, $payload, $userPublicKey, $userAuthToken, $flush, array( 'TTL' => 5000) );
150
+ $webPush->sendNotification($endpoint, $payload, $userPublicKey, $userAuthToken, $flush, [ 'TTL' => 5000] );
150
151
```
151
152
152
153
#### TTL
@@ -174,23 +175,24 @@ You can see what the browser vendor's server sends back in case it encountered a
174
175
The ` expired ` key can be useful to clean your database of expired endpoints.
175
176
176
177
``` php
177
- $res = array(
178
- array( // first notification (failed)
178
+ <?php
179
+ $res = [
180
+ [ // first notification (failed)
179
181
'success' => false,
180
- 'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired
182
+ 'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired,
181
183
'message' => $responseMessage,
182
184
'statusCode' => $responseStatusCode,
183
185
'headers' => $responseHeaders,
184
186
'content' => $responseContent, // you may have more infos here
185
187
'expired' => $isTheEndpointWrongOrExpired,
186
- ) ,
187
- array( // second notification (succeeded)
188
+ ] ,
189
+ [ // second notification (succeeded)
188
190
'success' => true,
189
- ) ,
190
- array( // third notification
191
+ ] ,
192
+ [ // third notification
191
193
...
192
- ) , ...
193
- ) ;
194
+ ] , ...
195
+ ] ;
194
196
```
195
197
196
198
Firefox errors are listed in the [ autopush documentation] ( https://autopush.readthedocs.io/en/latest/http.html#errors ) .
@@ -243,10 +245,10 @@ You can customize the default request options and timeout when instantiating Web
243
245
use Minishlink\WebPush\WebPush;
244
246
245
247
$timeout = 20; // seconds
246
- $clientOptions = array(
248
+ $clientOptions = [
247
249
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false,
248
- ) ; // see \GuzzleHttp\RequestOptions
249
- $webPush = new WebPush(array(), array() , $timeout, $clientOptions);
250
+ ] ; // see \GuzzleHttp\RequestOptions
251
+ $webPush = new WebPush([], [] , $timeout, $clientOptions);
250
252
```
251
253
252
254
## Common questions
0 commit comments