Skip to content

Commit ea24b46

Browse files
committed
Initial commit
0 parents  commit ea24b46

File tree

7 files changed

+506
-0
lines changed

7 files changed

+506
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor
2+
composer.lock
3+
phpunit.xml
4+

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2015 Louis Lagrange
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# WebPush
2+
> Web Push library for PHP
3+
4+
## Installation
5+
`composer require minishlink/web-push`
6+
7+
## Usage
8+
WebPush can be used to send notifications to endpoints which server delivers web push notifications as described in
9+
the [Web Push API specification](http://www.w3.org/TR/push-api/).
10+
As it is standardized, you don't have to worry about what server type it relies on.
11+
__*Currently, WebPush doesn't support payloads at all.
12+
It is under development (see ["payload" branch](https://github.com/Minishlink/web-push/tree/payload).*__
13+
14+
```php
15+
<?php
16+
17+
use Minishlink\WebPush\WebPush;
18+
19+
// array of endpoints
20+
$endpoints = array(
21+
'https://android.googleapis.com/gcm/send/abcdef...', // Chrome
22+
'https://updates.push.services.mozilla.com/push/adcdef...', // Firefox 43+
23+
'https://example.com/other/endpoint/of/another/vendor/abcdef...',
24+
);
25+
26+
$webPush = new WebPush();
27+
$webPush->sendNotification($endpoints[0]); // send one notification
28+
$webPush->sendNotifications($endpoints); // send multiple notifications
29+
```
30+
31+
### GCM servers notes (Chrome)
32+
For compatibility reasons, this library detects if the server is a GCM server and appropriately sends the notification.
33+
GCM servers don't support encrypted payloads yet so WebPush will skip the payload.
34+
If you still want to show that payload on your notification, you should get that data on client-side from your server
35+
where you will have to store somewhere the history of notifications.
36+
37+
You will need to specify your GCM api key when instantiating WebPush:
38+
```php
39+
<?php
40+
41+
use Minishlink\WebPush\WebPush;
42+
43+
$endpoint = 'https://android.googleapis.com/gcm/send/abcdef...'; // Chrome
44+
$apiKeys = array(
45+
'GCM' => 'MY_GCM_API_KEY',
46+
);
47+
48+
$webPush = new WebPush($apiKeys);
49+
$webPush->sendNotification($endpoints[0]); // send one notification
50+
$webPush->sendNotifications($endpoints); // send multiple notifications
51+
```
52+
53+
### Changing the browser client
54+
By default, WebPush will use `MultiCurl`, allowing to send multiple notifications in parallel.
55+
You can change the client to any client extending `\Buzz\Client\AbstractClient`.
56+
Timeout is configurable in the constructor.
57+
58+
```php
59+
<?php
60+
61+
use Minishlink\WebPush\WebPush;
62+
63+
$webPush = new WebPush(array(), null, null, $client);
64+
```
65+
66+
You have access to the inner browser if you want to configure it further.
67+
```php
68+
<?php
69+
70+
use Minishlink\WebPush\WebPush;
71+
72+
$webPush = new WebPush();
73+
74+
/** @var $browser \Buzz\Browser */
75+
$browser = $webPush->getBrowser();
76+
```
77+
78+
## Common questions
79+
80+
### Is the API stable?
81+
Not until the [Push API spec](http://www.w3.org/TR/push-api/) is finished.
82+
83+
### What about security?
84+
Internally, WebPush uses the [phpecc](https://github.com/phpecc/phpecc) Elliptic Curve Cryptography library.
85+
86+
### How to solve "SSL certificate problem: unable to get local issuer certificate" ?
87+
Your installation lacks some certificates.
88+
89+
1. Download [cacert.pem](http://curl.haxx.se/ca/cacert.pem).
90+
2. Edit your `php.ini`: after `[curl]`, type `curl.cainfo = /path/to/cacert.pem`.
91+
92+
You can also force using a client without peer verification.
93+
94+
### I need to send notifications to native apps. (eg. APNS for iOS)
95+
WebPush is for web apps.
96+
You need something like [RMSPushNotificationsBundle](https://github.com/richsage/RMSPushNotificationsBundle) (Symfony).
97+
98+
### This is PHP... I need Javascript!
99+
This library was inspired by the Node.js [marco-c/web-push](https://github.com/marco-c/web-push) library.
100+
101+
## Contributing
102+
See [CONTRIBUTING.md](https://github.com/Minishlink/web-push/blob/master/CONTRIBUTING.md).
103+
104+
## Tests
105+
Copy `phpunit.xml` from `phpunit.dist.xml` and fill it with your test endpoints and private keys.
106+
107+
## License
108+
[MIT](https://github.com/Minishlink/web-push/blob/master/LICENSE)

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "minishlink/web-push",
3+
"type": "library",
4+
"description": "Web Push library for PHP",
5+
"keywords": ["push", "notifications", "web"],
6+
"homepage": "https://github.com/Minishlink/web-push",
7+
"license": "MIT",
8+
"authors": [
9+
{
10+
"name": "Louis Lagrange",
11+
"email": "[email protected]",
12+
"homepage": "https://github.com/Minishlink"
13+
}
14+
],
15+
"require": {
16+
"php": ">=5.4",
17+
"kriswallsmith/buzz": ">=0.6"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "4.8.*"
21+
},
22+
"autoload": {
23+
"psr-4" : {
24+
"Minishlink\\WebPush\\" : "src"
25+
}
26+
}
27+
}

phpunit.dist.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false">
12+
<testsuites>
13+
<testsuite name="WebPush Test Suite">
14+
<directory suffix=".php">./tests/</directory>
15+
</testsuite>
16+
</testsuites>
17+
<php>
18+
<env name="STANDARD_ENDPOINT" value="" />
19+
<env name="GCM_ENDPOINT" value="" />
20+
<env name="USER_PUBLIC_KEY" value="" />
21+
<env name="GCM_API_KEY" value="" />
22+
</php>
23+
</phpunit>

0 commit comments

Comments
 (0)