Subscription

RTM Subscription model.

package

Default

Methods

Creates a subscription model with specified options.

__construct(string $subscription_id, callable $callback, array $options = array()) 

When you create a channel subscription, you can specify additional properties, for example, add a filter to the subscription and specify the behavior of the SDK when resubscribing after a reconnection.

For more information about the options for a channel subscription, see Subscribe PDU in the online docs

Arguments

$subscription_id

string

String that identifies the channel. If you do not use the filter parameter, it is the channel name. Otherwise, it is a unique identifier for the channel (subscription id).

$callback

callable

Custom callback. Such callback will be called on any subscription events, described in {@see RtmClient\Subscription\Events} Callback function will get 3 arguments: $ctx - Context. Current subscription instance $type - Event type: {@see RtmClient\Subscription\Events} $data - Type-related data. Check Protocol Data Unit (PDU) to get information about data content

$options

array

Subscription options. Additional subscription options for a channel subscription. These options are sent to RTM in the body element of the Protocol Data Unit (PDU) that represents the subscribe request.

               For more information about the *body* element of a PDU,
               see *RTM API* in the online docs

Calls user callback.

callback(string $type, array $data = null) : void

Arguments

$type

string

Events::[NAME]

$data

array

Data to be passed to user callback

Returns user callback function for current subscription

getCallback() : callable

Response

callable

User callback

Returns current Subscription model options.

getOptions() : array

Response

array

Options

Returns last known Position.

getPosition() : integer

Response

integer

Position

Returns Subscription ID.

getSubscriptionId() : mixed

Response

mixed

Subscription ID

Marks subscription as unsubscribed. Fires UNSUBSCRIBED event.

markUnsubscribe(array $body = array()) : void

Arguments

$body

array

Processes PDU and executes relevant actions.

onPdu(\RtmClient\Pdu\Pdu $pdu) : true

Arguments

$pdu

\RtmClient\Pdu\Pdu

PDU object

Response

true

if PDU has been processed, false otherwise

Processes disconnect event.

processDisconnect() : void

Processes subscribe/ok PDU and fires event.

processSubscribeError(array $body) : void

Arguments

$body

array

Processes subscribe/ok PDU and fires event.

processSubscribeOk(array $body) : void

Arguments

$body

array

Processes subscription/data PDU and fires event.

processSubscriptionData(array $body) : void

Arguments

$body

array

Processes subscription/error PDU and fires event.

processSubscriptionError(array $body) : void

Arguments

$body

array

Processes subscription/info PDU and fires event.

processSubscriptionInfo(array $body) : void

Arguments

$body

array

Processes unsubscribe/error PDU and fires event.

processUnsubscribeError(array $body) : void

Arguments

$body

array

Processes unsubscribe/ok PDU and changes mark subscription as unsubscribed.

processUnsubscribeOk(array $body) : void

Arguments

$body

array

Sets new subscription context variable.

setContext(string $key, mixed $context) 

Context is passed to subscription callback.

Arguments

$key

string

Context key

$context

mixed

Context value

Sets new logger that implements PSR3 Logger interface.

setLogger(\Psr\Log\LoggerInterface $logger) : void

Arguments

$logger

\Psr\Log\LoggerInterface

Custom logger

Generates Subscribe PDU.

subscribePdu() : \RtmClient\Pdu\Pdu

Response

\RtmClient\Pdu\Pdu

Subscribe PDU

Processes all PDU and checks if PDU has 'position'. Fires POSITION event.

trackPosition(array $body) : void

Arguments

$body

array

Generates Unsubscribe PDU.

unsubscribePdu() : \RtmClient\Pdu\Pdu

Response

\RtmClient\Pdu\Pdu

Unsubscribe PDU

Properties

Subscription identifier

subscription_id : string
var

Type(s)

string

Stored subscription position

position : string
var

Type(s)

string

PDU bodu content

body : array
var

Type(s)

array

Subscription options

options : array
var

Type(s)

array