TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
TeamSpeak3_Adapter_ServerQuery_Reply Class Reference

Provides methods to analyze and format a ServerQuery reply. More...

Public Member Functions

 __construct (array $rpl, $cmd=null, TeamSpeak3_Node_Host $con=null)
 Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object.
 
 toString ()
 Returns the reply as an TeamSpeak3_Helper_String object.
 
 toLines ()
 Returns the reply as a standard PHP array where each element represents one item.
 
 toTable ()
 Returns the reply as a standard PHP array where each element represents one item in table format.
 
 toArray ()
 Returns a multi-dimensional array containing the reply splitted in multiple rows and columns.
 
 toAssocArray ($ident)
 Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns.
 
 toList ()
 Returns an array containing the reply splitted in multiple rows and columns.
 
 toObjectArray ()
 Returns an array containing stdClass objects.
 
 getCommandString ()
 Returns the command used to get this reply.
 
 getNotifyEvents ()
 Returns an array of events that occured before or during this reply.
 
 getErrorProperty ($ident, $default=null)
 Returns the value for a specified error property.
 

Protected Member Functions

 fetchError ($err)
 Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if there's an error.
 
 fetchReply ($rpl)
 Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.
 

Protected Attributes

 $cmd = null
 
 $rpl = null
 
 $con = null
 
 $err = array()
 
 $evt = array()
 

Detailed Description

Provides methods to analyze and format a ServerQuery reply.

Definition at line 32 of file Reply.php.

Constructor & Destructor Documentation

TeamSpeak3_Adapter_ServerQuery_Reply::__construct ( array  $rpl,
  $cmd = null,
TeamSpeak3_Node_Host  $con = null 
)

Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object.

Parameters
array$rpl
string$cmd
TeamSpeak3_Node_Host$con
Returns
TeamSpeak3_Adapter_ServerQuery_Reply

Definition at line 77 of file Reply.php.

References fetchError(), and fetchReply().

{
$this->cmd = new TeamSpeak3_Helper_String($cmd);
$this->con = $con;
$this->fetchError(array_pop($rpl));
$this->fetchReply($rpl);
}

Member Function Documentation

TeamSpeak3_Adapter_ServerQuery_Reply::toString ( )

Returns the reply as an TeamSpeak3_Helper_String object.

Returns
TeamSpeak3_Helper_String

Definition at line 91 of file Reply.php.

Referenced by toAssocArray(), and toLines().

{
return (!func_num_args()) ? $this->rpl->unescape() : $this->rpl;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toLines ( )

Returns the reply as a standard PHP array where each element represents one item.

Returns
array

Definition at line 101 of file Reply.php.

References TeamSpeak3\SEPARATOR_LIST, and toString().

Referenced by toTable().

{
if(!count($this->rpl)) return array();
$list = $this->toString(0)->split(TeamSpeak3::SEPARATOR_LIST);
if(!func_num_args())
{
for($i = 0; $i < count($list); $i++) $list[$i]->unescape();
}
return $list;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toTable ( )

Returns the reply as a standard PHP array where each element represents one item in table format.

Returns
array

Definition at line 120 of file Reply.php.

References TeamSpeak3\SEPARATOR_CELL, and toLines().

Referenced by toArray().

{
$table = array();
foreach($this->toLines(0) as $cells)
{
$pairs = $cells->split(TeamSpeak3::SEPARATOR_CELL);
if(!func_num_args())
{
for($i = 0; $i < count($pairs); $i++) $pairs[$i]->unescape();
}
$table[] = $pairs;
}
return $table;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toArray ( )

Returns a multi-dimensional array containing the reply splitted in multiple rows and columns.

Returns
array

Definition at line 144 of file Reply.php.

References TeamSpeak3\SEPARATOR_PAIR, and toTable().

Referenced by toAssocArray(), toList(), and toObjectArray().

{
$array = array();
$table = $this->toTable(1);
for($i = 0; $i < count($table); $i++)
{
foreach($table[$i] as $pair)
{
if(!$pair->contains(TeamSpeak3::SEPARATOR_PAIR))
{
$array[$i][$pair->toString()] = null;
}
else
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR, 2);
$array[$i][$ident->toString()] = $value->isInt() ? $value->toInt() : (!func_num_args() ? $value->unescape() : $value);
}
}
}
return $array;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toAssocArray (   $ident)

Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns.

The identifier specified by key will be used while indexing the array.

Parameters
$key
Returns
array

Definition at line 176 of file Reply.php.

References toArray(), and toString().

{
$nodes = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
$array = array();
foreach($nodes as $node)
{
if(array_key_exists($ident, $node))
{
$array[(is_object($node[$ident])) ? $node[$ident]->toString() : $node[$ident]] = $node;
}
else
{
throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
}
}
return $array;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toList ( )

Returns an array containing the reply splitted in multiple rows and columns.

Returns
array

Definition at line 201 of file Reply.php.

References toArray().

{
$array = func_num_args() ? $this->toArray(1) : $this->toArray();
if(count($array) == 1)
{
return array_shift($array);
}
return $array;
}
TeamSpeak3_Adapter_ServerQuery_Reply::toObjectArray ( )

Returns an array containing stdClass objects.

Returns
ArrayObject

Definition at line 218 of file Reply.php.

References toArray().

{
$array = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
for($i = 0; $i < count($array); $i++)
{
$array[$i] = (object) $array[$i];
}
return $array;
}
TeamSpeak3_Adapter_ServerQuery_Reply::getCommandString ( )

Returns the command used to get this reply.

Returns
TeamSpeak3_Helper_String

Definition at line 235 of file Reply.php.

{
return new TeamSpeak3_Helper_String($this->cmd);
}
TeamSpeak3_Adapter_ServerQuery_Reply::getNotifyEvents ( )

Returns an array of events that occured before or during this reply.

Returns
array

Definition at line 245 of file Reply.php.

{
return $this->evt;
}
TeamSpeak3_Adapter_ServerQuery_Reply::getErrorProperty (   $ident,
  $default = null 
)

Returns the value for a specified error property.

Parameters
string$ident
mixed$default
Returns
mixed

Definition at line 257 of file Reply.php.

Referenced by fetchError().

{
return (array_key_exists($ident, $this->err)) ? $this->err[$ident] : $default;
}
TeamSpeak3_Adapter_ServerQuery_Reply::fetchError (   $err)
protected

Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if there's an error.

Parameters
string$err
Exceptions
TeamSpeak3_Adapter_ServerQuery_Exception
Returns
void

Definition at line 270 of file Reply.php.

References getErrorProperty(), TeamSpeak3_Helper_Signal\getInstance(), TeamSpeak3\SEPARATOR_CELL, and TeamSpeak3\SEPARATOR_PAIR.

Referenced by __construct().

{
$cells = $err->section(TeamSpeak3::SEPARATOR_CELL, 1, 3);
foreach($cells->split(TeamSpeak3::SEPARATOR_CELL) as $pair)
{
list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR);
$this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
}
TeamSpeak3_Helper_Signal::getInstance()->emit("notifyError", $this);
if($this->getErrorProperty("id", 0x00) != 0x00)
{
if($permid = $this->getErrorProperty("failed_permid"))
{
try
{
$suffix = " (failed on " . key($this->con->selfPermCheck($permid)) . ")";
}
{
$suffix = " (failed on " . $this->cmd->section(TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
}
}
elseif($details = $this->getErrorProperty("extra_msg"))
{
$suffix = " (" . trim($details) . ")";
}
else
{
$suffix = "";
}
throw new TeamSpeak3_Adapter_ServerQuery_Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
}
}
TeamSpeak3_Adapter_ServerQuery_Reply::fetchReply (   $rpl)
protected

Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.

Parameters
string$rpl
Returns
void

Definition at line 315 of file Reply.php.

References TeamSpeak3\EVENT, TeamSpeak3\GREET, and TeamSpeak3\SEPARATOR_LIST.

Referenced by __construct().

{
foreach($rpl as $key => $val)
{
if($val->startsWith(TeamSpeak3::GREET))
{
unset($rpl[$key]);
}
elseif($val->startsWith(TeamSpeak3::EVENT))
{
$this->evt[] = new TeamSpeak3_Adapter_ServerQuery_Event($rpl[$key], $this->con);
unset($rpl[$key]);
}
}
$this->rpl = new TeamSpeak3_Helper_String(implode(TeamSpeak3::SEPARATOR_LIST, $rpl));
}

The documentation for this class was generated from the following file: