Unverified Commit 26402d7c authored by Richard Weinhold's avatar Richard Weinhold Committed by GitHub
Browse files

removes cluttering php-tags from readme code-blocks

parent b25561aa
......@@ -8,8 +8,6 @@ Examples:
### Android: ###
```php
<?php
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
......@@ -17,16 +15,12 @@ $push = new PushNotification(new GCMHandler());
$push->setServerToken('ExampleGooglePushToken12345678987654321');
$push->addDevice('device-token');
$push->send('message', 'title', ['payload' => 'data']);
?>
```
### iOS: ###
```php
<?php
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\APNSHandler;
......@@ -37,16 +31,12 @@ $push->setServer([
]);
$push->addDevice('<device-token>');
$push->send('message', 'title', ['payload' => 'data']);
?>
```
### Windows: ###
```php
<?php
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\WNSHandler;
......@@ -60,14 +50,12 @@ $push->addDevice([
'OAuth2-Token',
]);
$push->send('message', 'title', ['payload' => 'data']);
?>
```
## usage: ##
This class uses the root-namespace `PushNotification`.
This class uses the root-namespace `ricwein\PushNotification`.
### init ###
......@@ -75,29 +63,21 @@ This class uses the root-namespace `PushNotification`.
It's possible to init the PushNotification class with a specific push-handler:
```php
<?php
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
$push = new PushNotification(new GCMHandler());
?>
```
or without, and adding the push-handler later:
```php
<?php
use ricwein\PushNotification\PushNotification;
use ricwein\PushNotification\Handler\GCMHandler;
$push = new PushNotification();
$pushHandler = new GCMHandler();
$push->setHandler($pushHandler);
?>
```
Available push-handler are:
......@@ -116,32 +96,22 @@ Since all push-settings are push-handler specific, the according handler has to
Settings as *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');
......@@ -153,8 +123,6 @@ $pushHandler->setServer([
// or even:
$pushHandler = new GCMHandler('server-token', 'server-url');
?>
```
### client-devices ###
......@@ -162,8 +130,6 @@ $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');
......@@ -172,8 +138,6 @@ $push->addDevice([
'push-token1',
'push-token2',
]);
?>
```
> Note: The WNSHandler allows adding either:
......@@ -186,44 +150,28 @@ $push->addDevice([
Sending a messages is as simple as that:
```php
<?php
$push->send('message');
?>
```
Adding a title?
```php
<?php
$push->send('message', 'title');
?>
```
It's possible to add a payload as an array:
```php
<?php
$payload = ['data'];
$push->send('message', null, $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
<?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