@@ -9,13 +9,14 @@ the [Web Push protocol](https://tools.ietf.org/html/draft-thomson-webpush-protoc
99As it is standardized, you don't have to worry about what server type it relies on.
1010
1111## Requirements
12- * PHP 7.0+
12+
13+ * PHP 7.1+
1314 * gmp
1415 * mbstring
1516 * curl
1617 * openssl
1718
18- PHP 7.1 + is recommended for better performance.
19+ PHP 7.2 + is recommended for better performance.
1920For PHP 5.6 or HHVM compatibility, use the v1.x releases.
2021
2122## Installation
@@ -30,24 +31,24 @@ Use [composer](https://getcomposer.org/) to download and install the library and
3031use Minishlink\WebPush\WebPush;
3132
3233// array of notifications
33- $notifications = array(
34- array(
34+ $notifications = [
35+ [
3536 'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+
3637 'payload' => 'hello !',
3738 'userPublicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
3839 'userAuthToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
39- ), array(
40+ ], [
4041 'endpoint' => 'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
4142 'payload' => null,
4243 'userPublicKey' => null,
4344 'userAuthToken' => null,
44- ), array(
45+ ], [
4546 'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
4647 'payload' => '{msg:"test"}',
4748 'userPublicKey' => '(stringOf88Chars)',
4849 'userAuthToken' => '(stringOf24Chars)',
49- ) ,
50- ) ;
50+ ] ,
51+ ] ;
5152
5253$webPush = new WebPush();
5354
@@ -90,16 +91,16 @@ use Minishlink\WebPush\WebPush;
9091
9192$endpoint = 'https://android.googleapis.com/gcm/send/abcdef...'; // Chrome
9293
93- $auth = array(
94+ $auth = [
9495 'GCM' => 'MY_GCM_API_KEY', // deprecated and optional, it's here only for compatibility reasons
95- 'VAPID' => array(
96+ 'VAPID' => [
9697 'subject' => 'mailto:
[email protected] ', // can be a mailto: or your website address
9798 'publicKey' => '~88 chars', // (recommended) uncompressed public key P-256 encoded in Base64-URL
9899 'privateKey' => '~44 chars', // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL
99100 'pemFile' => 'path/to/pem', // if you have a PEM file and can link to it on your filesystem
100101 'pem' => 'pemFileContent', // if you have a PEM file and want to hardcode its content
101- ) ,
102- ) ;
102+ ] ,
103+ ] ;
103104
104105$webPush = new WebPush($auth);
105106$webPush->sendNotification(...);
@@ -134,19 +135,19 @@ You can change the default options with `setDefaultOptions()` or in the construc
134135
135136use Minishlink\WebPush\WebPush;
136137
137- $defaultOptions = array(
138+ $defaultOptions = [
138139 'TTL' => 300, // defaults to 4 weeks
139140 'urgency' => 'normal', // protocol defaults to "normal"
140141 'topic' => 'new_event', // not defined by default,
141142 'batchSize' => 200, // defaults to 1000
142- ) ;
143+ ] ;
143144
144145// for every notifications
145- $webPush = new WebPush(array() , $defaultOptions);
146+ $webPush = new WebPush([] , $defaultOptions);
146147$webPush->setDefaultOptions($defaultOptions);
147148
148149// 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] );
150151```
151152
152153#### TTL
@@ -174,23 +175,24 @@ You can see what the browser vendor's server sends back in case it encountered a
174175The ` expired ` key can be useful to clean your database of expired endpoints.
175176
176177``` php
177- $res = array(
178- array( // first notification (failed)
178+ <?php
179+ $res = [
180+ [ // first notification (failed)
179181 'success' => false,
180- 'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired
182+ 'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired,
181183 'message' => $responseMessage,
182184 'statusCode' => $responseStatusCode,
183185 'headers' => $responseHeaders,
184186 'content' => $responseContent, // you may have more infos here
185187 'expired' => $isTheEndpointWrongOrExpired,
186- ) ,
187- array( // second notification (succeeded)
188+ ] ,
189+ [ // second notification (succeeded)
188190 'success' => true,
189- ) ,
190- array( // third notification
191+ ] ,
192+ [ // third notification
191193 ...
192- ) , ...
193- ) ;
194+ ] , ...
195+ ] ;
194196```
195197
196198Firefox 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
243245use Minishlink\WebPush\WebPush;
244246
245247$timeout = 20; // seconds
246- $clientOptions = array(
248+ $clientOptions = [
247249 \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);
250252```
251253
252254## Common questions
0 commit comments