Stefanius67 /
PNServer
| 1 | <?php |
||
| 2 | require_once 'MyVapid.php'; |
||
| 3 | |||
| 4 | use SKien\PNServer\PNServer; |
||
| 5 | use SKien\PNServer\PNSubscription; |
||
| 6 | use SKien\PNServer\PNPayload; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Example to demonstarte how to send a welcome notification to each |
||
| 10 | * user newly subscribed our service. |
||
| 11 | * |
||
| 12 | * This function is called within the Handler for the HTTP-Request send from |
||
| 13 | * the ServiceWorker to subscribe. (PNSubscriber.php) |
||
| 14 | * After the subscription was saved in the database, this function is called, |
||
| 15 | * if the var $bSendWelcome is set to true! |
||
| 16 | * |
||
| 17 | * THIS CODE IS INTENDED ONLY AS EXAMPLE - DONT USE IT DIRECT IN YOU PROJECT |
||
| 18 | * |
||
| 19 | * @author Stefanius <[email protected]> |
||
| 20 | * @copyright MIT License - see the LICENSE file for details |
||
| 21 | */ |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param PNSubscription $oSubscription |
||
| 25 | */ |
||
| 26 | function sendWelcome(PNSubscription $oSubscription) |
||
| 27 | { |
||
| 28 | // create server. Since we are sending to a single subscription that was |
||
| 29 | // passed as argument, we do not need a dataprovider |
||
| 30 | $oServer = new PNServer(); |
||
| 31 | |||
| 32 | // create payload message for welcome... |
||
| 33 | $oPayload = new PNPayload('Welcome to PNServer', 'We warmly welcome you to our homepage.', './elephpant.png'); |
||
| 34 | |||
| 35 | // set VAPID, payload and the passed subscription |
||
| 36 | $oServer->setVapid(getMyVapid()); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 37 | $oServer->setPayload($oPayload); |
||
| 38 | $oServer->addSubscription($oSubscription); |
||
| 39 | |||
| 40 | // ... and finally push the notification! |
||
| 41 | $oServer->push(); |
||
| 42 | } |