2017 © Pedro Peláez
 

library mobile-notif

PHP library to send notifications to mobile devices.

image

linkvalue/mobile-notif

PHP library to send notifications to mobile devices.

  • Friday, September 16, 2016
  • by Oliboy50
  • Repository
  • 47 Watchers
  • 2 Stars
  • 89 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

MobileNotif

Build Status Code Coverage Scrutinizer Code Quality, (*1)

PHP library to send notifications to mobile devices., (*2)

If you're using Symfony framework, take a look at LinkValue/MobileNotifBundle to easily manage and profile multiple clients., (*3)

Installation

Using Composer through composer.json file:, (*4)

"require": {
    "linkvalue/mobile-notif": "^0.2"
}

Or using composer CLI:, (*5)

composer require linkvalue/mobile-notif

Examples

Send simple notification using Google Cloud Messaging (aka. GCM)

<?php

require 'path/to/composer/vendor/autoload.php';

use LinkValue\MobileNotif\Client\GcmClient;
use LinkValue\MobileNotif\Model\GcmMessage;

$client = new GcmClient();
$client->setUp(array(
    'endpoint' => 'https://android.googleapis.com/gcm/send',
    'api_access_key' => 'API ACCESS KEY',
));

$message = new GcmMessage();
$message
    ->addToken('DESTINATION DEVICE TOKEN HERE')
    ->setNotificationTitle('Message title')
    ->setNotificationBody('Message body')
    ->setNotificationIcon('myicon')
;

$client->push($message);

Send simple notification using Apple Push Notification Service (aka. APNS) in development mode

<?php

require 'path/to/composer/vendor/autoload.php';

use LinkValue\MobileNotif\Client\ApnsClient;
use LinkValue\MobileNotif\Model\ApnsMessage;

$client = new ApnsClient();
$client->setUp(array(
    'endpoint' => 'tls://gateway.sandbox.push.apple.com:2195',
    'ssl_pem_path' => __DIR__.'/BundleIncludingCertAndPrivateKey-dev.pem',
));

$message = new ApnsMessage();
$message
    ->addToken('DESTINATION DEVICE TOKEN HERE')
    ->setSimpleAlert('Hello World!')
;

$client->push($message);

Send notification using GCM to multiple devices and log everything in a file using Monolog as Psr/Log implementation

<?php

require 'path/to/composer/vendor/autoload.php';

use LinkValue\MobileNotif\Client\GcmClient;
use LinkValue\MobileNotif\Model\GcmMessage;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('notif');
$log->pushHandler(new StreamHandler(__DIR__.'/notif.log', Logger::INFO));

$client = new GcmClient();
$client
    ->setLogger($log);
    ->setUp(array(
        'endpoint' => 'https://android.googleapis.com/gcm/send',
        'api_access_key' => 'API ACCESS KEY',
    ))
;

$message = new GcmMessage();
$message
    ->addToken('DESTINATION DEVICE TOKEN1 HERE')
    ->addToken('DESTINATION DEVICE TOKEN2 HERE')
    ->setNotificationTitle('Message title')
    ->setNotificationBody('Message body')
    ->setNotificationIcon('myicon')
    ->setNotificationSound('default')
;

$client->push($message);

Send notification using APNS (in production mode) to multiple devices and log everything in a file using Monolog as Psr/Log implementation

<?php

require 'path/to/composer/vendor/autoload.php';

use LinkValue\MobileNotif\Client\ApnsClient;
use LinkValue\MobileNotif\Model\ApnsMessage;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$log = new Logger('notif');
$log->pushHandler(new StreamHandler(__DIR__.'/notif.log', Logger::INFO));

$client = new ApnsClient();
$client
    ->setLogger($log);
    ->setUp(array(
        'endpoint' => 'tls://gateway.push.apple.com:2195',
        'ssl_pem_path' => __DIR__.'/data/BundleIncludingCertAndPrivateKey-prod.pem',
        'ssl_passphrase' => 'my production PEM file passphrase',
    ))
;

$message = new ApnsMessage();
$message
    ->addToken('DESTINATION DEVICE TOKEN1 HERE')
    ->addToken('DESTINATION DEVICE TOKEN2 HERE')
    ->setAlertTitle('Message title')
    ->setAlertBody('Message body')
    ->setBadge(1)
    ->setSound('default')
;

$client->push($message);

Resources

APNS

GCM

Tests

We want this library to be fully covered by unit tests, so if you contribute to this project, be aware that your PR build will fail if the code coverage drops below 100%., (*6)

Running tests with HTML code coverage

# install dependencies
composer install
mkdir -p wallet

# if xdebug extension is enabled on PHP CLI
vendor/bin/phpunit --coverage-html wallet/coverage

# else if xdebug is installed but not enabled
php -dzend_extension=xdebug.so vendor/bin/phpunit --coverage-html wallet/coverage

The Versions

16/09 2016

dev-master

9999999-dev

PHP library to send notifications to mobile devices.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios push gcm apns android mobile push notification

16/09 2016

v0.2.1

0.2.1.0

PHP library to send notifications to mobile devices.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios push gcm apns android mobile push notification

14/03 2016

v0.2.0

0.2.0.0

PHP library to send notifications to mobile devices.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios push gcm apns android mobile push notification

06/03 2016

v0.1.1

0.1.1.0

PHP library to send notifications to mobile devices.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios push gcm apns android mobile push notification

01/03 2016

v0.1.0

0.1.0.0

PHP library to send notifications to mobile devices.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios push gcm apns android mobile push notification

02/12 2015

dev-change-specs

dev-change-specs

Push notification on your mobile notifications

  Sources   Download

MIT

The Requires

 

The Development Requires

by Bernard Caron
by Jamal Youssefi
by Valentin Coulon

notification ios android mobile push notification