Skip to content

Commit b3fbd17

Browse files
SpomkyMinishlink
authored andcommitted
Dependencies changes and project updated for PHP 7.1 (#135)
* Dependencies changes and project updated for PHP 7.1 * Bug fixed * PHP nightly added * Bug fixed * Bug fixed * Minor corrections * Bugs fixed Bugs found by PHPStan lvl max found and fixed * Bugs fixed * Travis-CI tests * Trying to fix Travis (WIP) * Trying to fix Travis (WIP) * Tests fixed on travis * Minor change * Add test for serializePublicKey * Fix localPublicKey * Fix indentation
1 parent 29e4419 commit b3fbd17

18 files changed

+485
-388
lines changed

.gitattributes

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
/tests export-ignore
1+
* text=auto
2+
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/.travis.yml export-ignore
6+
/phpunit.xml.dist export-ignore
7+
/README.md export-ignore
8+
/tests export-ignore
File renamed without changes.
File renamed without changes.

.travis.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ cache:
99
directories:
1010
- ~/.selenium-assistant
1111

12-
php:
13-
- 7.0
14-
- 7.1
15-
- 7.2
12+
matrix:
13+
allow_failures:
14+
- php: nightly
15+
fast_finish: true
16+
include:
17+
- php: 7.1
18+
- php: 7.2
19+
- php: nightly
1620

1721
env:
1822
- TRAVIS_NODE_VERSION="stable"
@@ -21,7 +25,7 @@ before_install:
2125
- nvm install node
2226

2327
install:
24-
- npm install https://github.com/GoogleChromeLabs/web-push-testing-service -g
28+
- npm install web-push-testing-service -g
2529

2630
before_script:
2731
- composer install --prefer-source -n
@@ -31,5 +35,8 @@ before_script:
3135

3236
script:
3337
- web-push-testing-service start example -p 9012
34-
- php ./vendor/phpunit/phpunit/phpunit -c phpunit.travis.xml
38+
- ./vendor/bin/phpunit
3539
- web-push-testing-service stop example
40+
41+
after_script:
42+
- ./vendor/bin/phpstan analyse --level max src

README.md

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ the [Web Push protocol](https://tools.ietf.org/html/draft-thomson-webpush-protoc
99
As 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.
1920
For 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
3031
use 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

135136
use 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
174175
The `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

196198
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
243245
use 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

composer.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313
}
1414
],
1515
"require": {
16-
"php": "^7.0",
17-
"mdanter/ecc": "^0.5.0",
16+
"php": "^7.1",
1817
"lib-openssl": "*",
19-
"spomky-labs/base64url": "^1.0",
20-
"spomky-labs/php-aes-gcm": "^1.2",
21-
"spomky-labs/jose": "^7.0",
22-
"guzzlehttp/guzzle": "^6.2"
18+
"guzzlehttp/guzzle": "^6.2",
19+
"web-token/jwt-signature": "^1.0",
20+
"web-token/jwt-key-mgmt": "^1.0"
2321
},
2422
"require-dev": {
25-
"phpunit/phpunit": "^6.5.0"
23+
"phpunit/phpunit": "^7.0",
24+
"phpstan/phpstan": "^0.9.2"
2625
},
2726
"autoload": {
2827
"psr-4" : {

phpunit.dist.xml

Lines changed: 0 additions & 30 deletions
This file was deleted.
File renamed without changes.

0 commit comments

Comments
 (0)