PHP Class Pusher

Mostrar archivo Open project: pusher/pusher-php-server Class Usage Examples

Public Properties

Property Type Description
$VERSION

Public Methods

Method Description
__construct ( string $auth_key, string $secret, integer $app_id, boolean $options = [], string $host = null, integer $port = null, integer $timeout = null ) PHP5 Constructor.
array_implode ( string $glue, string $separator, array $array ) : string Implode an array with the key and value pair giving a glue, a separator between pairs and the array to implode.
build_auth_query_string ( string $auth_key, string $auth_secret, string $request_method, string $request_path, array $query_params = [], string $auth_version = '1.0', string $auth_timestamp = null ) : string Build the required HMAC'd auth string.
get ( $path, $params = [] ) : See GET arbitrary REST API resource using a synchronous http client.
getSettings ( ) : array Fetch the settings.
get_channel_info ( string $channel, array $params = [] ) : object Fetch channel information for a specific channel.
get_channels ( array $params = [] ) : array Fetch a list containing all channels.
notify ( array $interests, $data = [], boolean $debug = false ) : boolean | string Send a native notification via the Push Notifications Api.
presence_auth ( $channel, string $socket_id, string $user_id, mixed $user_info = null ) : string Creates a presence signature (an extension of socket signing).
set_logger ( $logger ) Set a logger to be informed of internal log messages.
socket_auth ( $channel, string $socket_id, string $custom_data = null ) : string Creates a socket signature.
trigger ( array $channels, string $event, mixed $data, string $socket_id = null, boolean $debug = false, boolean $already_encoded = false ) : boolean | string Trigger an event by providing event name and payload.
triggerBatch ( array $batch = [], boolean $debug = false, boolean $already_encoded = false ) : boolean | string Trigger multiple events at the same time.

Private Methods

Method Description
check_compatibility ( ) Check if the current PHP setup is sufficient to run this class.
create_curl ( $domain, $s_url, $request_method = 'GET', $query_params = [] ) Utility function used to create the curl object with common settings.
ddn_domain ( ) : string Build the ddn domain.
exec_curl ( $ch ) Utility function to execute curl and create capture response information.
log ( string $msg ) Log a string.
notification_domain ( ) : string Build the notification domain.
validate_channel ( $channel ) Ensure a channel name is valid based on our spec.
validate_channels ( string[] $channels ) Validate number of channels and channel name format.
validate_socket_id ( string $socket_id ) Ensure a socket_id is valid based on our spec.

Method Details

__construct() public method

Initializes a new Pusher instance with key, secret , app ID and channel. You can optionally turn on debugging for all requests by setting debug to true.
public __construct ( string $auth_key, string $secret, integer $app_id, boolean $options = [], string $host = null, integer $port = null, integer $timeout = null )
$auth_key string
$secret string
$app_id integer
$options boolean [optional] Options to configure the Pusher instance. Was previously a debug flag. Legacy support for this exists if a boolean is passed. scheme - e.g. http or https host - the host e.g. api.pusherapp.com. No trailing forward slash. port - the http port timeout - the http timeout encrypted - quick option to use scheme of https and port 443. cluster - cluster name to connect to. notification_host - host to connect to for native notifications. notification_scheme - scheme for the notification_host.
$host string [optional] - deprecated
$port integer [optional] - deprecated
$timeout integer [optional] - deprecated

array_implode() public static method

Implode an array with the key and value pair giving a glue, a separator between pairs and the array to implode.
public static array_implode ( string $glue, string $separator, array $array ) : string
$glue string The glue between key and value
$separator string Separator between pairs
$array array The array to implode
return string The imploded array

build_auth_query_string() public static method

Build the required HMAC'd auth string.
public static build_auth_query_string ( string $auth_key, string $auth_secret, string $request_method, string $request_path, array $query_params = [], string $auth_version = '1.0', string $auth_timestamp = null ) : string
$auth_key string
$auth_secret string
$request_method string
$request_path string
$query_params array
$auth_version string [optional]
$auth_timestamp string [optional]
return string

get() public method

All request signing is handled automatically.
public get ( $path, $params = [] ) : See
return See Pusher API docs

getSettings() public method

Fetch the settings.
public getSettings ( ) : array
return array

get_channel_info() public method

Fetch channel information for a specific channel.
public get_channel_info ( string $channel, array $params = [] ) : object
$channel string The name of the channel
$params array Additional parameters for the query e.g. $params = array( 'info' => 'connection_count' )
return object

get_channels() public method

Fetch a list containing all channels.
public get_channels ( array $params = [] ) : array
$params array Additional parameters for the query e.g. $params = array( 'info' => 'connection_count' )
return array

notify() public method

Send a native notification via the Push Notifications Api.
public notify ( array $interests, $data = [], boolean $debug = false ) : boolean | string
$interests array
$debug boolean
return boolean | string

presence_auth() public method

Creates a presence signature (an extension of socket signing).
public presence_auth ( $channel, string $socket_id, string $user_id, mixed $user_info = null ) : string
$socket_id string
$user_id string
$user_info mixed
return string

set_logger() public method

Set a logger to be informed of internal log messages.
public set_logger ( $logger )

socket_auth() public method

Creates a socket signature.
public socket_auth ( $channel, string $socket_id, string $custom_data = null ) : string
$socket_id string
$custom_data string
return string

trigger() public method

Optionally provide a socket ID to exclude a client (most likely the sender).
public trigger ( array $channels, string $event, mixed $data, string $socket_id = null, boolean $debug = false, boolean $already_encoded = false ) : boolean | string
$channels array An array of channel names to publish the event on.
$event string
$data mixed Event data
$socket_id string [optional]
$debug boolean [optional]
$already_encoded boolean [optional]
return boolean | string

triggerBatch() public method

Trigger multiple events at the same time.
public triggerBatch ( array $batch = [], boolean $debug = false, boolean $already_encoded = false ) : boolean | string
$batch array An array of events to send
$debug boolean [optional]
$already_encoded boolean [optional]
return boolean | string

Property Details

$VERSION public_oe static_oe property

public static $VERSION