2017 © Pedro Peláez
 

symfony-bundle pusher-bundle

Symfony bridge for bentools/pusher

image

bentools/pusher-bundle

Symfony bridge for bentools/pusher

  • Wednesday, February 8, 2017
  • by bpolaszek
  • Repository
  • 1 Watchers
  • 1 Stars
  • 47 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

⚠️ This bundle is now deprecated in favor of bentools/webpush-bundle, (*1)

Pusher Bundle

This bundle wraps the bentools/pusher library to send Push Notifications through your Symfony application., (*2)

Installation

Install the library:, (*3)

composer require bentools/pusher-bundle

Add the Bundle into your AppKernel:, (*4)

# app/AppKernel.php
$bundles = [
    // ...
    new BenTools\PusherBundle\BenToolsPusherBundle(),
    // ...
];

Define your handlers in your services.yml:, (*5)

services:
    bentools.pusher.handler.mozilla:
        class: BenTools\Pusher\Model\Handler\MozillaHandler
        arguments: ['@guzzle.client.default']

    bentools.pusher.handler.gcm:
        class: BenTools\Pusher\Model\Handler\GoogleCloudMessagingHandler
        arguments: ['@guzzle.client.default', '%gcm.api_key%']

Update your database to store push subscriptions:, (*6)

php bin/console doctrine:schema:update --dump-sql --force
# or use Doctrine Migrations

Mount the /webpush/registration route:, (*7)

# app/config/routing.yml
webpush_bundle:
    resource: "@BenToolsPusherBundle/Resources/config/routing.yml"
    prefix:   /webpush

Install the JS assets:, (*8)

php bin/console assets:install --symlink

Embed in twig (HTTPS or localhost, and authenticated user required), (*9)







Usage

Your BenTools\PusherBundle\Entity\Recipient entities implement BenTools\Pusher\Model\Recipient\RecipientInterface and can be used in Pusher., (*10)

PHP snippet to help:, (*11)

use AppBundle\Entity\User;
use BenTools\Pusher\Model\Message\Notification;
use BenTools\Pusher\Model\Push\Push;
use BenTools\PusherBundle\Entity\Recipient;

$pusher     = $this->getContainer()->get('bentools.pusher');
$user       = $this->getRepositoryOf(User::class)->findOneBy([
    'username' => 'johndoe',
]);
$recipients = $this->getContainer()->get('doctrine')->getManager()->getRepository(Recipient::class)->findRecipientsForUser($user);
$message    = new Notification('Ho hi');
$push       = new Push();

foreach ($recipients AS $recipient) {
    switch ($recipient->getClient()) {
        case Recipient::CHROME:
        case Recipient::CHROME_MOBILE:
            $push->addRecipient($recipient, $this->getContainer()->get('bentools.pusher.handler.gcm'));
            break;
        case Recipient::FIREFOX:
            $push->addRecipient($recipient, $this->getContainer()->get('bentools.pusher.handler.mozilla'));
            break;
    }

    $push->setMessage($message);

}

$pusher->push($push);

License

MIT, (*12)

The Versions

08/02 2017

dev-master

9999999-dev

Symfony bridge for bentools/pusher

  Sources   Download

MIT

The Requires

 

The Development Requires

08/02 2017

v0.4

0.4.0.0

Symfony bridge for bentools/pusher

  Sources   Download

MIT

The Requires

 

The Development Requires

08/02 2017

v0.3

0.3.0.0

Symfony bridge for bentools/pusher

  Sources   Download

MIT

The Requires

 

The Development Requires

08/02 2017

v0.2.1

0.2.1.0

Symfony bridge for bentools/pusher

  Sources   Download

MIT

The Requires

 

The Development Requires

01/02 2017

v0.2

0.2.0.0

Symfony bridge for bentools/pusher

  Sources   Download

MIT

The Requires

 

The Development Requires