txtony/symfony-pubnub

Implement Pubnub into your Symfony application.

Installs: 973

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 1

Open Issues: 0

Type:symfony-bundle

dev-master 2020-04-10 09:05 UTC

This package is auto-updated.

Last update: 2020-06-08 19:31:19 UTC


README

Implement Pubnub into your Symfony application.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require txtony/symfony-pubnub

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new TxTony\SymfonyPubnub\TxTonySymfonyPubnubBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Configuration

All configuration options on the Pubnub\Pubnub class can be configured. Only publish_key and subscribe_key are required. Default reference is below.

tx_tony_symfony_pubnub:
    publish_key: <your_pub_key> # Required
    subscribe_key: <your_sub_key> # Required
    secret_key: false
    cipher_key: false
    ssl: true
    origin: false
    pem_path: "%kernel.root_dir%/../vendor/pubnub/pubnub/"
    uuid: symfony
    proxy: false
    auth_key: false
    verify_peer: true

Step 4: Usage

Get the pubnub client from the container.

$pubnub = $this->get('txtony.pubnub.client.pubnub');

In your code this is an exemple to publish message in 'myChannel'

// return a timetoken like this "timetoken": 123456789123456789
return $pubnub->getPubnub()->publish()
    ->channel("myChannel")
    ->message("Hello world")
    ->usePost(true)
    ->sync();

The $pubnub object is an instance of Pubnub\Pubnub. Usage documentation can be found in the Pubnub repository.