tanuck/pusher

A CakePHP integration for the Pusher library.

Installs: 55

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:cakephp-plugin

2.0.0 2015-08-16 20:00 UTC

This package is not auto-updated.

Last update: 2024-10-26 18:44:07 UTC


README

Build Status License Total Downloads

A CakePHP plugin for interaction with the Pusher API.

Installation

Include the following in your composer.json file:

{
	"require": {
		"tanuck/pusher": "dev-master"
	}
}

Note: This plugin should install in your Plugin directory rather than the composer vendors directory.

Configuration

Firstly, you must load the plugin:

CakePlugin::load('CakePusher');

Include the component in your controller:

class MyController extends AppController {

	public $components = array(
		'CakePusher.Pusher' => array(
			'auth_key' => 'PUSHER_APP_AUTH_KEY',
			'secret' => 'PUSHER_APP_SECRET',
			'app_id' => 'PUSHER_APP_ID',
		),
	);
}

This is the most basic form taken by the Component constructor, for further configuration options see the Usage section below.

Then access the Component like so:

$this->Pusher->trigger('my-channel', 'my-event', 'My Message');

Usage

If you wish to use just the one Pusher app in your CakePHP application, then the $components definition above will be enough. The options available mirror those passed to the Pusher API constructor (see here form more information).

The plugin allows you to configure and use multiple Pusher apps with the Component. This can be done by nesting the configuration arrays in the component settings, the array index of each will become the internal alias to each Pusher app. For example:

class MyController extends AppController {

	public $components = array(
		'CakePusher.Pusher' => array(
			'main' => array(
				'auth_key' => 'PUSHER_APP_AUTH_KEY',
				'secret' => 'PUSHER_APP_SECRET',
				'app_id' => 'PUSHER_APP_ID',
			),
			'otherApp' => array(
				'auth_key' => 'PUSHER_APP_AUTH_KEY',
				'secret' => 'PUSHER_APP_SECRET',
				'app_id' => 'PUSHER_APP_ID',
			),
		),
	);
}

NOTE: When using more than one Pusher instance you must specifiy a main app.

You can interact with the default main app using the methods directly on the component or you can specify an app to use with the with method:

$this->Pusher->trigger('my-channel', 'my-event', 'My Message');
$this->Pusher->socketAuth('my-channel', '1234.1234');
$this->Pusher->presenceAuth('my-channel', '1234.1234', 'user-12', true);
$this->Pusher->get('/channels');

$this->Pusher->with('otherApp')->trigger('my-channel', 'my-event', 'My Message');

You can get and set the name of the default Pusher app like so:

$this->Pusher->getDefault();

$this->Pusher->setDefault('otherApp');

And you can add additional app configurations on the fly:

$this->Pusher->addAppConfig('myAppName', array(
	'auth_key' => 'PUSHER_APP_AUTH_KEY',
	'secret' => 'PUSHER_APP_SECRET',
	'app_id' => 'PUSHER_APP_ID',
));

License

cakephp-pusher is offered under an MIT license.