PHP code example of bentools / pusher-bundle

1. Go to this page and download the library: Download bentools/pusher-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bentools / pusher-bundle example snippets


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

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);

php bin/console assets:install --symlink