Commit fb4208ec authored by Richard Weinhold's avatar Richard Weinhold 🔨

added missing php-tags for syntax-highlighting

parent b893263d
......@@ -8,21 +8,27 @@ Examples:
### Android: ###
```php
use PushNotification\PushNotification;
<?php
use PushNotification\Handler\APNSHandler;
use PushNotification\Handler\GCMHandler;
$push = new PushNotification(new GCMHandler());
$push->setServerToken('ExampleGooglePushToken12345678987654321');
$push->addDevice('device-token');
$push->send('message', ['payload'=>'data']);
$push->send('message', ['payload' => 'data']);
?>
```
### iOS: ###
```php
use PushNotification\PushNotification;
use PushNotification\Handler\APNSHandler;
<?php
use PushNotification\Handler\GCMHandler;
use PushNotification\Handler\GCMHandler;
$push = new PushNotification(new APNSHandler());
$push->setServer([
......@@ -30,26 +36,32 @@ $push->setServer([
'url' => 'ssl://gateway.sandbox.push.apple.com:2195',
]);
$push->addDevice('<device-token>');
$push->send('message', ['payload'=>'data']);
$push->send('message', ['payload' => 'data']);
?>
```
### Windows: ###
```php
use PushNotification\PushNotification;
<?php
use PushNotification\Handler\WNSHandler;
use PushNotification\PushNotification;
$push = new PushNotification(new WNSHandler());
$push->setServer([
'token' => 'wns-push-token',
'url' => 'server.url',
'token' => 'wns-push-token',
'url' => 'server.url',
]);
$push->addDevice([
'clientID' => 'clientSecret',
'OAuth2-Token',
]);
$push->send('message', ['payload'=>'data']);
$push->send('message', ['payload' => 'data']);
?>
```
......@@ -63,21 +75,29 @@ This class uses the root-namespace `PushNotification`.
It's possible to init the PushNotification class with a specific push-handler:
```php
<?php
use PushNotification\PushNotification;
use PushNotification\PushNotification;
use PushNotification\Handler\GCMHandler;
$push = new PushNotification(new GCMHandler());
?>
```
or without, and adding the push-handler later:
```php
<?php
use PushNotification\PushNotification;
use PushNotification\PushNotification;
use PushNotification\Handler\GCMHandler;
$push = new PushNotification();
$push = new PushNotification();
$pushHandler = new GCMHandler();
$push->setHandler($pushHandler);
?>
```
Available push-handler are:
......@@ -96,22 +116,32 @@ Since all push-settings are push-handler specific, the according handler has to
Settings like *server-token* and *server-url* can be set like:
```php
<?php
$push->setServerToken('server-token');
$push->setServerUrl('server-url');
?>
```
or as an array:
```php
<?php
$push->setServer([
'token' => 'server-token',
'url' => 'server-url',
]);
?>
```
It's also possible to set the configuration directly at the push-handler:
```php
<?php
$pushHandler->setServerToken('server-token');
$pushHandler->setServerUrl('server-url');
......@@ -123,6 +153,8 @@ $pushHandler->setServer([
// or even:
$pushHandler = new GCMHandler('server-token', 'server-url');
?>
```
### client-devices ###
......@@ -130,6 +162,8 @@ $pushHandler = new GCMHandler('server-token', 'server-url');
The class can send notifications to multiple devices at once. The device-push-tokens are escaped by default.
```php
<?php
$push->addDevice('push-token1');
$push->addDevice('push-token2');
......@@ -138,6 +172,8 @@ $push->addDevice([
'push-token1',
'push-token2',
]);
?>
```
> Note: The WNSHandler allows adding either:
......@@ -150,22 +186,34 @@ $push->addDevice([
Sending a messages is simple as that:
```php
<?php
$push->send('message');
?>
```
It's possible to add a payload as an array:
```php
<?php
$payload = ['data'];
$push->send('message', $payload);
?>
```
Sometimes the given server or device-tokens are expired or sending simply failed. To check if sending was successfully you can use the return-value of send():
```php
if(!$push->send('message')) {
<?php
if (!$push->send('message')) {
throw new \Exception('oh-no: Sending PushNotifications failed.');
}
?>
```
### Exceptions ###
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment