Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update phpDoc & bump version in header #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 58 additions & 48 deletions api/php/Dklab/Realplexor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Dklab_Realplexor PHP API.
*
* @version 1.31
* @version 1.41
*/
class Dklab_Realplexor
{
Expand All @@ -13,14 +13,16 @@ class Dklab_Realplexor
private $_login;
private $_password;

/**
* Create new realplexor API instance.
*
* @param string $host Host of IN line.
* @param string $port Port of IN line (if 443, SSL is used).
* @param string $namespace Namespace to use.
* @param string $identifier Use this "identifier" marker instead of the default one.
*/
/**
* Create new realplexor API instance.
*
* @param string $host Host of IN line.
* @param string $port Port of IN line (if 443, SSL is used).
* @param string $namespace Namespace to use.
* @param string $identifier Use this "identifier" marker instead of the default one.
*
* @throws Dklab_Realplexor_Exception
*/
public function __construct($host, $port, $namespace = null, $identifier = "identifier")
{
$this->_host = $host;
Expand All @@ -32,14 +34,15 @@ public function __construct($host, $port, $namespace = null, $identifier = "iden
}
}

/**
* Set login and password to access Realplexor (if the server needs it).
* This method does not check credentials correctness.
*
* @param string $login
* @param string $password
* @return void
*/
/**
* Set login and password to access Realplexor (if the server needs it).
* This method does not check credentials correctness.
*
* @param string $login
* @param string $password
*
* @return void
*/
public function logon($login, $password)
{
$this->_login = $login;
Expand All @@ -48,20 +51,22 @@ public function logon($login, $password)
$this->_namespace = $this->_login . "_" . $this->_namespace;
}

/**
* Send data to realplexor.
* Throw Dklab_Realplexor_Exception in case of error.
*
* @param mixed $idsAndCursors Target IDs in form of: array(id1 => cursor1, id2 => cursor2, ...)
* of array(id1, id2, id3, ...). If sending to a single ID,
* you may pass it as a plain string, not array.
* @param mixed $data Data to be sent (any format, e.g. nested arrays are OK).
* @param array $showOnlyForIds Send this message to only those who also listen any of these IDs.
* This parameter may be used to limit the visibility to a closed
* number of cliens: give each client an unique ID and enumerate
* client IDs in $showOnlyForIds to not to send messages to others.
* @return void
*/
/**
* Send data to realplexor.
* Throw Dklab_Realplexor_Exception in case of error.
*
* @param mixed $idsAndCursors Target IDs in form of: array(id1 => cursor1, id2 => cursor2, ...)
* of array(id1, id2, id3, ...). If sending to a single ID,
* you may pass it as a plain string, not array.
* @param mixed $data Data to be sent (any format, e.g. nested arrays are OK).
* @param array $showOnlyForIds Send this message to only those who also listen any of these IDs.
* This parameter may be used to limit the visibility to a closed
* number of cliens: give each client an unique ID and enumerate
* client IDs in $showOnlyForIds to not to send messages to others.
*
* @throws Dklab_Realplexor_Exception
* @throws Exception
*/
public function send($idsAndCursors, $data, $showOnlyForIds = null)
{
$data = json_encode($data);
Expand Down Expand Up @@ -137,14 +142,16 @@ public function cmdOnline($idPrefixes = null)
return array_keys($this->cmdOnlineWithCounters($idPrefixes));
}

/**
* Return all Realplexor events (e.g. ID offline/offline changes)
* happened after $fromPos cursor.
*
* @param string $fromPos Start watching from this cursor.
* @param array $idPrefixes Watch only changes of IDs with these prefixes.
* @return array List of array("event" => ..., "cursor" => ..., "id" => ...).
*/
/**
* Return all Realplexor events (e.g. ID offline/offline changes)
* happened after $fromPos cursor.
*
* @param string $fromPos Start watching from this cursor.
* @param array $idPrefixes Watch only changes of IDs with these prefixes.
*
* @return array List of array("event" => ..., "cursor" => ..., "id" => ...).
* @throws Dklab_Realplexor_Exception
*/
public function cmdWatch($fromPos, $idPrefixes = null)
{
$idPrefixes = $idPrefixes !== null? (array)$idPrefixes : array();
Expand Down Expand Up @@ -198,15 +205,18 @@ private function _sendCmd($cmd)
return $this->_send(null, "$cmd\n");
}

/**
* Internal method.
* Send specified data to IN channel. Return response data.
* Throw Dklab_Realplexor_Exception in case of error.
*
* @param string $identifier If set, pass this identifier string.
* @param string $data Data to be sent.
* @return string Response from IN line.
*/
/**
* Internal method.
* Send specified data to IN channel. Return response data.
* Throw Dklab_Realplexor_Exception in case of error.
*
* @param string $identifier If set, pass this identifier string.
* @param string $body Data to be sent.
*
* @return string Response from IN line.
* @throws Dklab_Realplexor_Exception
* @throws Exception
*/
private function _send($identifier, $body)
{
// Build HTTP request.
Expand Down