Skip to content

Commit

Permalink
Dependencies changes and project updated for PHP 7.1 (#135)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Spomky authored and Minishlink committed Mar 11, 2018
1 parent 29e4419 commit b3fbd17
Show file tree
Hide file tree
Showing 18 changed files with 485 additions and 388 deletions.
9 changes: 8 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
/tests export-ignore
* text=auto

/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/README.md export-ignore
/tests export-ignore
File renamed without changes.
File renamed without changes.
19 changes: 13 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ cache:
directories:
- ~/.selenium-assistant

php:
- 7.0
- 7.1
- 7.2
matrix:
allow_failures:
- php: nightly
fast_finish: true
include:
- php: 7.1
- php: 7.2
- php: nightly

env:
- TRAVIS_NODE_VERSION="stable"
Expand All @@ -21,7 +25,7 @@ before_install:
- nvm install node

install:
- npm install https://github.com/GoogleChromeLabs/web-push-testing-service -g
- npm install web-push-testing-service -g

before_script:
- composer install --prefer-source -n
Expand All @@ -31,5 +35,8 @@ before_script:

script:
- web-push-testing-service start example -p 9012
- php ./vendor/phpunit/phpunit/phpunit -c phpunit.travis.xml
- ./vendor/bin/phpunit
- web-push-testing-service stop example

after_script:
- ./vendor/bin/phpstan analyse --level max src
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ the [Web Push protocol](https://tools.ietf.org/html/draft-thomson-webpush-protoc
As it is standardized, you don't have to worry about what server type it relies on.

## Requirements
* PHP 7.0+

* PHP 7.1+
* gmp
* mbstring
* curl
* openssl

PHP 7.1+ is recommended for better performance.
PHP 7.2+ is recommended for better performance.
For PHP 5.6 or HHVM compatibility, use the v1.x releases.

## Installation
Expand All @@ -30,24 +31,24 @@ Use [composer](https://getcomposer.org/) to download and install the library and
use Minishlink\WebPush\WebPush;

// array of notifications
$notifications = array(
array(
$notifications = [
[
'endpoint' => 'https://updates.push.services.mozilla.com/push/abc...', // Firefox 43+
'payload' => 'hello !',
'userPublicKey' => 'BPcMbnWQL5GOYX/5LKZXT6sLmHiMsJSiEvIFvfcDvX7IZ9qqtq68onpTPEYmyxSQNiH7UD/98AUcQ12kBoxz/0s=', // base 64 encoded, should be 88 chars
'userAuthToken' => 'CxVX6QsVToEGEcjfYPqXQw==', // base 64 encoded, should be 24 chars
), array(
], [
'endpoint' => 'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
'payload' => null,
'userPublicKey' => null,
'userAuthToken' => null,
), array(
], [
'endpoint' => 'https://example.com/other/endpoint/of/another/vendor/abcdef...',
'payload' => '{msg:"test"}',
'userPublicKey' => '(stringOf88Chars)',
'userAuthToken' => '(stringOf24Chars)',
),
);
],
];

$webPush = new WebPush();

Expand Down Expand Up @@ -90,16 +91,16 @@ use Minishlink\WebPush\WebPush;

$endpoint = 'https://android.googleapis.com/gcm/send/abcdef...'; // Chrome

$auth = array(
$auth = [
'GCM' => 'MY_GCM_API_KEY', // deprecated and optional, it's here only for compatibility reasons
'VAPID' => array(
'VAPID' => [
'subject' => 'mailto:[email protected]', // can be a mailto: or your website address
'publicKey' => '~88 chars', // (recommended) uncompressed public key P-256 encoded in Base64-URL
'privateKey' => '~44 chars', // (recommended) in fact the secret multiplier of the private key encoded in Base64-URL
'pemFile' => 'path/to/pem', // if you have a PEM file and can link to it on your filesystem
'pem' => 'pemFileContent', // if you have a PEM file and want to hardcode its content
),
);
],
];

$webPush = new WebPush($auth);
$webPush->sendNotification(...);
Expand Down Expand Up @@ -134,19 +135,19 @@ You can change the default options with `setDefaultOptions()` or in the construc

use Minishlink\WebPush\WebPush;

$defaultOptions = array(
$defaultOptions = [
'TTL' => 300, // defaults to 4 weeks
'urgency' => 'normal', // protocol defaults to "normal"
'topic' => 'new_event', // not defined by default,
'batchSize' => 200, // defaults to 1000
);
];

// for every notifications
$webPush = new WebPush(array(), $defaultOptions);
$webPush = new WebPush([], $defaultOptions);
$webPush->setDefaultOptions($defaultOptions);

// or for one notification
$webPush->sendNotification($endpoint, $payload, $userPublicKey, $userAuthToken, $flush, array('TTL' => 5000));
$webPush->sendNotification($endpoint, $payload, $userPublicKey, $userAuthToken, $flush, ['TTL' => 5000]);
```

#### TTL
Expand Down Expand Up @@ -174,23 +175,24 @@ You can see what the browser vendor's server sends back in case it encountered a
The `expired` key can be useful to clean your database of expired endpoints.

```php
$res = array(
array( // first notification (failed)
<?php
$res = [
[ // first notification (failed)
'success' => false,
'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired
'endpoint' => $theEndpointToDeleteInYourDatabaseIfExpired,
'message' => $responseMessage,
'statusCode' => $responseStatusCode,
'headers' => $responseHeaders,
'content' => $responseContent, // you may have more infos here
'expired' => $isTheEndpointWrongOrExpired,
),
array( // second notification (succeeded)
],
[ // second notification (succeeded)
'success' => true,
),
array( // third notification
],
[ // third notification
...
), ...
);
], ...
];
```

Firefox errors are listed in the [autopush documentation](https://autopush.readthedocs.io/en/latest/http.html#errors).
Expand Down Expand Up @@ -243,10 +245,10 @@ You can customize the default request options and timeout when instantiating Web
use Minishlink\WebPush\WebPush;

$timeout = 20; // seconds
$clientOptions = array(
$clientOptions = [
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => false,
); // see \GuzzleHttp\RequestOptions
$webPush = new WebPush(array(), array(), $timeout, $clientOptions);
]; // see \GuzzleHttp\RequestOptions
$webPush = new WebPush([], [], $timeout, $clientOptions);
```

## Common questions
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
}
],
"require": {
"php": "^7.0",
"mdanter/ecc": "^0.5.0",
"php": "^7.1",
"lib-openssl": "*",
"spomky-labs/base64url": "^1.0",
"spomky-labs/php-aes-gcm": "^1.2",
"spomky-labs/jose": "^7.0",
"guzzlehttp/guzzle": "^6.2"
"guzzlehttp/guzzle": "^6.2",
"web-token/jwt-signature": "^1.0",
"web-token/jwt-key-mgmt": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.5.0"
"phpunit/phpunit": "^7.0",
"phpstan/phpstan": "^0.9.2"
},
"autoload": {
"psr-4" : {
Expand Down
30 changes: 0 additions & 30 deletions phpunit.dist.xml

This file was deleted.

File renamed without changes.
Loading

0 comments on commit b3fbd17

Please sign in to comment.