Implement Pubnub into your Symfony application.
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.
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(),
);
// ...
}
// ...
}
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
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.