TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
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, $exp=TRUE)
 Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object. More...
 
 getCommandString ()
 Returns the command used to get this reply. More...
 
 getErrorProperty ($ident, $default=null)
 Returns the value for a specified error property. More...
 
 getNotifyEvents ()
 Returns an array of events that occured before or during this reply. More...
 
 toArray ()
 Returns a multi-dimensional array containing the reply splitted in multiple rows and columns. More...
 
 toAssocArray ($ident)
 Returns a multi-dimensional assoc array containing the reply splitted in multiple rows and columns. More...
 
 toLines ()
 Returns the reply as a standard PHP array where each element represents one item. More...
 
 toList ()
 Returns an array containing the reply splitted in multiple rows and columns. More...
 
 toObjectArray ()
 Returns an array containing stdClass objects. More...
 
 toString ()
 Returns the reply as an TeamSpeak3_Helper_String object. More...
 
 toTable ()
 Returns the reply as a standard PHP array where each element represents one item in table format. More...
 

Protected Member Functions

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

Detailed Description

Provides methods to analyze and format a ServerQuery reply.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $rpl,
  $cmd = null,
TeamSpeak3_Node_Host  $con = null,
  $exp = TRUE 
)

Creates a new TeamSpeak3_Adapter_ServerQuery_Reply object.

Parameters
array$rpl
string$cmd
boolean$exp
TeamSpeak3_Node_Host$con
Returns
TeamSpeak3_Adapter_ServerQuery_Reply
83  {
84  $this->cmd = new TeamSpeak3_Helper_String($cmd);
85  $this->con = $con;
86  $this->exp = (bool) $exp;
87 
88  $this->fetchError(array_pop($rpl));
89  $this->fetchReply($rpl);
90  }
fetchError($err)
Parses a ServerQuery error and throws a TeamSpeak3_Adapter_ServerQuery_Exception object if there's an...
Definition: Reply.php:281
Helper class for string handling.
Definition: String.php:29
fetchReply($rpl)
Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.
Definition: Reply.php:326

Member Function Documentation

◆ fetchError()

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
282  {
283  $cells = $err->section(TeamSpeak3::SEPARATOR_CELL, 1, 3);
284 
285  foreach($cells->split(TeamSpeak3::SEPARATOR_CELL) as $pair)
286  {
287  list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR);
288 
289  $this->err[$ident->toString()] = $value->isInt() ? $value->toInt() : $value->unescape();
290  }
291 
292  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyError", $this);
293 
294  if($this->getErrorProperty("id", 0x00) != 0x00 && $this->exp)
295  {
296  if($permid = $this->getErrorProperty("failed_permid"))
297  {
298  if($permsid = key($this->con->request("permget permid=" . $permid, FALSE)->toAssocArray("permsid")))
299  {
300  $suffix = " (failed on " . $permsid . ")";
301  }
302  else
303  {
304  $suffix = " (failed on " . $this->cmd->section(TeamSpeak3::SEPARATOR_CELL) . " " . $permid . "/0x" . strtoupper(dechex($permid)) . ")";
305  }
306  }
307  elseif($details = $this->getErrorProperty("extra_msg"))
308  {
309  $suffix = " (" . trim($details) . ")";
310  }
311  else
312  {
313  $suffix = "";
314  }
315 
316  throw new TeamSpeak3_Adapter_ServerQuery_Exception($this->getErrorProperty("msg") . $suffix, $this->getErrorProperty("id"));
317  }
318  }
getErrorProperty($ident, $default=null)
Returns the value for a specified error property.
Definition: Reply.php:268
const SEPARATOR_CELL
protocol cell separator
Definition: TeamSpeak3.php:76
Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects.
Definition: Exception.php:29
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
const SEPARATOR_PAIR
protocol pair separator
Definition: TeamSpeak3.php:77

◆ fetchReply()

fetchReply (   $rpl)
protected

Parses a ServerQuery reply and creates a TeamSpeak3_Helper_String object.

Parameters
string$rpl
Returns
void
327  {
328  foreach($rpl as $key => $val)
329  {
330  if($val->startsWith(TeamSpeak3::GREET))
331  {
332  unset($rpl[$key]);
333  }
334  elseif($val->startsWith(TeamSpeak3::EVENT))
335  {
336  $this->evt[] = new TeamSpeak3_Adapter_ServerQuery_Event($rpl[$key], $this->con);
337  unset($rpl[$key]);
338  }
339  }
340 
341  $this->rpl = new TeamSpeak3_Helper_String(implode(TeamSpeak3::SEPARATOR_LIST, $rpl));
342  }
Helper class for string handling.
Definition: String.php:29
Provides methods to analyze and format a ServerQuery event.
Definition: Event.php:29
const GREET
TeamSpeak 3 protocol greeting message prefix.
Definition: TeamSpeak3.php:39
const EVENT
TeamSpeak 3 protocol event message prefix.
Definition: TeamSpeak3.php:49
const SEPARATOR_LIST
protocol list separator
Definition: TeamSpeak3.php:75

◆ getCommandString()

getCommandString ( )

Returns the command used to get this reply.

Returns
TeamSpeak3_Helper_String
247  {
248  return new TeamSpeak3_Helper_String($this->cmd);
249  }
Helper class for string handling.
Definition: String.php:29

◆ getErrorProperty()

getErrorProperty (   $ident,
  $default = null 
)

Returns the value for a specified error property.

Parameters
string$ident
mixed$default
Returns
mixed
269  {
270  return (array_key_exists($ident, $this->err)) ? $this->err[$ident] : $default;
271  }

◆ getNotifyEvents()

getNotifyEvents ( )

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

Returns
array
257  {
258  return $this->evt;
259  }

◆ toArray()

toArray ( )

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

Returns
array
151  {
152  $array = array();
153  $table = $this->toTable(1);
154 
155  for($i = 0; $i < count($table); $i++)
156  {
157  foreach($table[$i] as $pair)
158  {
159  if(!count($pair))
160  {
161  continue;
162  }
163 
164  if(!$pair->contains(TeamSpeak3::SEPARATOR_PAIR))
165  {
166  $array[$i][$pair->toString()] = null;
167  }
168  else
169  {
170  list($ident, $value) = $pair->split(TeamSpeak3::SEPARATOR_PAIR, 2);
171 
172  $array[$i][$ident->toString()] = $value->isInt() ? $value->toInt() : (!func_num_args() ? $value->unescape() : $value);
173  }
174  }
175  }
176 
177  return $array;
178  }
toTable()
Returns the reply as a standard PHP array where each element represents one item in table format...
Definition: Reply.php:126
const SEPARATOR_PAIR
protocol pair separator
Definition: TeamSpeak3.php:77

◆ toAssocArray()

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
188  {
189  $nodes = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
190  $array = array();
191 
192  foreach($nodes as $node)
193  {
194  if(isset($node[$ident]))
195  {
196  $array[(is_object($node[$ident])) ? $node[$ident]->toString() : $node[$ident]] = $node;
197  }
198  else
199  {
200  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
201  }
202  }
203 
204  return $array;
205  }
Enhanced exception class for TeamSpeak3_Adapter_ServerQuery objects.
Definition: Exception.php:29
toString()
Returns the reply as an TeamSpeak3_Helper_String object.
Definition: Reply.php:97
toArray()
Returns a multi-dimensional array containing the reply splitted in multiple rows and columns...
Definition: Reply.php:150

◆ toLines()

toLines ( )

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

Returns
array
108  {
109  if(!count($this->rpl)) return array();
110 
111  $list = $this->toString(0)->split(TeamSpeak3::SEPARATOR_LIST);
112 
113  if(!func_num_args())
114  {
115  for($i = 0; $i < count($list); $i++) $list[$i]->unescape();
116  }
117 
118  return $list;
119  }
toString()
Returns the reply as an TeamSpeak3_Helper_String object.
Definition: Reply.php:97
const SEPARATOR_LIST
protocol list separator
Definition: TeamSpeak3.php:75

◆ toList()

toList ( )

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

Returns
array
213  {
214  $array = func_num_args() ? $this->toArray(1) : $this->toArray();
215 
216  if(count($array) == 1)
217  {
218  return array_shift($array);
219  }
220 
221  return $array;
222  }
toArray()
Returns a multi-dimensional array containing the reply splitted in multiple rows and columns...
Definition: Reply.php:150

◆ toObjectArray()

toObjectArray ( )

Returns an array containing stdClass objects.

Returns
ArrayObject
230  {
231  $array = (func_num_args() > 1) ? $this->toArray(1) : $this->toArray();
232 
233  for($i = 0; $i < count($array); $i++)
234  {
235  $array[$i] = (object) $array[$i];
236  }
237 
238  return $array;
239  }
toArray()
Returns a multi-dimensional array containing the reply splitted in multiple rows and columns...
Definition: Reply.php:150

◆ toString()

toString ( )

Returns the reply as an TeamSpeak3_Helper_String object.

Returns
TeamSpeak3_Helper_String
98  {
99  return (!func_num_args()) ? $this->rpl->unescape() : $this->rpl;
100  }

◆ toTable()

toTable ( )

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

Returns
array
127  {
128  $table = array();
129 
130  foreach($this->toLines(0) as $cells)
131  {
132  $pairs = $cells->split(TeamSpeak3::SEPARATOR_CELL);
133 
134  if(!func_num_args())
135  {
136  for($i = 0; $i < count($pairs); $i++) $pairs[$i]->unescape();
137  }
138 
139  $table[] = $pairs;
140  }
141 
142  return $table;
143  }
const SEPARATOR_CELL
protocol cell separator
Definition: TeamSpeak3.php:76
toLines()
Returns the reply as a standard PHP array where each element represents one item. ...
Definition: Reply.php:107

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