TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
TeamSpeak3_Node_Abstract Class Reference

Abstract class describing a TeamSpeak 3 node and all it's parameters. More...

+ Inheritance diagram for TeamSpeak3_Node_Abstract:

Public Member Functions

 __call ($name, array $args)
 Called whenever we're using an unknown method. More...
 
 __get ($offset)
 
 __set ($offset, $value)
 
 __sleep ()
 Commit pending data. More...
 
 __toString ()
 Returns a string representation of this node. More...
 
 count ()
 
 current ()
 
 execute ($cmd, array $params=array())
 Prepares and executes a ServerQuery command and returns the result. More...
 
 getChildren ()
 
 getClass ($prefix="ts3_")
 Returns a possible classname for the node which can be used as a HTML property. More...
 
 getIcon ()
 Returns the name of a possible icon to display the node object. More...
 
 getId ()
 Returns the primary ID of the current node. More...
 
 getInfo ($extend=TRUE, $convert=FALSE)
 Returns all information available on this node. More...
 
 getParent ()
 Returns the parent object of the current node. More...
 
 getProperty ($property, $default=null)
 Returns the specified property or a pre-defined default value from the node info array. More...
 
 getSymbol ()
 Returns a symbol representing the node. More...
 
 getUniqueId ()
 Returns a unique identifier for the node which can be used as a HTML property. More...
 
 getViewer (TeamSpeak3_Viewer_Interface $viewer)
 Returns the HTML code to display a TeamSpeak 3 viewer. More...
 
 hasChildren ()
 
 hasNext ()
 
 iconGetName ($key)
 Returns the internal path of the node icon. More...
 
 iconIsLocal ($key)
 Returns TRUE if the node icon has a local source. More...
 
 key ()
 
 next ()
 
 offsetExists ($offset)
 
 offsetGet ($offset)
 
 offsetSet ($offset, $value)
 
 offsetUnset ($offset)
 
 prepare ($cmd, array $params=array())
 Uses given parameters and returns a prepared ServerQuery command. More...
 
 request ($cmd, $throw=TRUE)
 Sends a prepared command to the server and returns the result. More...
 
 rewind ()
 
 toArray ()
 Returns an assoc array filled with current node info properties. More...
 
 toString ()
 Returns a string representation of this node. More...
 
 valid ()
 

Protected Member Functions

 delStorage ($key)
 Deletes data from the internal storage array. More...
 
 fetchNodeInfo ()
 
 fetchNodeList ()
 
 filterList (array $nodes=array(), array $rules=array())
 Filters given node list array using specified filter rules. More...
 
 getStorage ($key, $default=null)
 Returns data from the internal storage array. More...
 
 resetNodeInfo ()
 
 resetNodeList ()
 
 setStorage ($key, $val)
 Writes data to the internal storage array. More...
 
 verifyNodeList ()
 

Protected Attributes

 $nodeId = 0x00
 
 $nodeInfo = array()
 
 $nodeList = null
 
 $parent = null
 
 $server = null
 
 $storage = array()
 

Detailed Description

Abstract class describing a TeamSpeak 3 node and all it's parameters.

Member Function Documentation

◆ __call()

__call (   $name,
array  $args 
)

Called whenever we're using an unknown method.

Parameters
string$name
array$args
Exceptions
TeamSpeak3_Node_Exception
Returns
mixed
372  {
373  if($this->getParent() instanceof TeamSpeak3_Node_Abstract)
374  {
375  return call_user_func_array(array($this->getParent(), $name), $args);
376  }
377 
378  throw new TeamSpeak3_Node_Exception("node method '" . $name . "()' does not exist");
379  }
Enhanced exception class for TeamSpeak3_Node_Abstract objects.
Definition: Exception.php:29
Abstract class describing a TeamSpeak 3 node and all it's parameters.
Definition: Abstract.php:29
getParent()
Returns the parent object of the current node.
Definition: Abstract.php:103

◆ __sleep()

__sleep ( )

Commit pending data.

Returns
array
422  {
423  return array("parent", "storage", "nodeId");
424  }

◆ __toString()

__toString ( )

Returns a string representation of this node.

Returns
string
339  {
340  return get_class($this);
341  }

◆ delStorage()

delStorage (   $key)
protected

Deletes data from the internal storage array.

Parameters
string$key
Returns
void
412  {
413  unset($this->storage[$key]);
414  }

◆ execute()

execute (   $cmd,
array  $params = array() 
)

Prepares and executes a ServerQuery command and returns the result.

Parameters
string$cmd
array$params
Returns
TeamSpeak3_Adapter_ServerQuery_Reply
93  {
94  return $this->request($this->prepare($cmd, $params));
95  }
request($cmd, $throw=TRUE)
Sends a prepared command to the server and returns the result.
Definition: Abstract.php:68
prepare($cmd, array $params=array())
Uses given parameters and returns a prepared ServerQuery command.
Definition: Abstract.php:80

◆ filterList()

filterList ( array  $nodes = array(),
array  $rules = array() 
)
protected

Filters given node list array using specified filter rules.

Parameters
array$nodes
array$rules
Returns
array
220  {
221  if(!empty($rules))
222  {
223  foreach($nodes as $node)
224  {
225  if(!$node instanceof TeamSpeak3_Node_Abstract) continue;
226 
227  $props = $node->getInfo(FALSE);
228  $props = array_intersect_key($props, $rules);
229 
230  foreach($props as $key => $val)
231  {
232  if($val instanceof TeamSpeak3_Helper_String)
233  {
234  $match = $val->contains($rules[$key], TRUE);
235  }
236  else
237  {
238  $match = $val == $rules[$key];
239  }
240 
241  if($match === FALSE)
242  {
243  unset($nodes[$node->getId()]);
244  }
245  }
246  }
247  }
248 
249  return $nodes;
250  }
Helper class for string handling.
Definition: String.php:29
Abstract class describing a TeamSpeak 3 node and all it's parameters.
Definition: Abstract.php:29

◆ getClass()

getClass (   $prefix = "ts3_")

Returns a possible classname for the node which can be used as a HTML property.

Parameters
string$prefix
Returns
string
149  {
150  if($this instanceof TeamSpeak3_Node_Channel && $this->isSpacer())
151  {
152  return $prefix . "spacer";
153  }
154  elseif($this instanceof TeamSpeak3_Node_Client && $this["client_type"])
155  {
156  return $prefix . "query";
157  }
158 
159  return $prefix . TeamSpeak3_Helper_String::factory(get_class($this))->section("_", 2)->toLower();
160  }
Class describing a TeamSpeak 3 client and all it's parameters.
Definition: Client.php:29
Class describing a TeamSpeak 3 channel and all it's parameters.
Definition: Channel.php:29
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60

◆ getIcon()

getIcon ( )
abstract

Returns the name of a possible icon to display the node object.

Returns
string

◆ getId()

getId ( )

Returns the primary ID of the current node.

Returns
integer
114  {
115  return $this->nodeId;
116  }
$nodeId
Definition: Abstract.php:44

◆ getInfo()

getInfo (   $extend = TRUE,
  $convert = FALSE 
)

Returns all information available on this node.

If $convert is enabled, some property values will be converted to human-readable values.

Parameters
boolean$extend
boolean$convert
Returns
array
261  {
262  if($extend)
263  {
264  $this->fetchNodeInfo();
265  }
266 
267  if($convert)
268  {
269  $info = $this->nodeInfo;
270 
271  foreach($info as $key => $val)
272  {
274 
275  if($key->contains("_bytes_"))
276  {
277  $info[$key->toString()] = TeamSpeak3_Helper_Convert::bytes($val);
278  }
279  elseif($key->contains("_bandwidth_"))
280  {
281  $info[$key->toString()] = TeamSpeak3_Helper_Convert::bytes($val) . "/s";
282  }
283  elseif($key->contains("_packets_"))
284  {
285  $info[$key->toString()] = number_format($val, null, null, ".");
286  }
287  elseif($key->contains("_packetloss_"))
288  {
289  $info[$key->toString()] = sprintf("%01.2f", floatval($val instanceof TeamSpeak3_Helper_String ? $val->toString() : strval($val))*100) . "%";
290  }
291  elseif($key->endsWith("_uptime"))
292  {
293  $info[$key->toString()] = TeamSpeak3_Helper_Convert::seconds($val);
294  }
295  elseif($key->endsWith("_version"))
296  {
297  $info[$key->toString()] = TeamSpeak3_Helper_Convert::version($val);
298  }
299  elseif($key->endsWith("_icon_id"))
300  {
301  $info[$key->toString()] = $this->iconGetName($key)->filterDigits();
302  }
303  }
304 
305  return $info;
306  }
307 
308  return $this->nodeInfo;
309  }
fetchNodeInfo()
Definition: Abstract.php:437
iconGetName($key)
Returns the internal path of the node icon.
Definition: Abstract.php:135
Helper class for string handling.
Definition: String.php:29
static bytes($bytes)
Converts bytes to a human readable value.
Definition: Convert.php:37
$nodeInfo
Definition: Abstract.php:54
static version($version, $format="Y-m-d h:i:s")
Returns a client-like formatted version of the TeamSpeak 3 version string.
Definition: Convert.php:312
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60
toString()
Returns the string as a standard string.
Definition: String.php:793
static seconds($seconds, $is_ms=FALSE, $format="%dD %02d:%02d:%02d")
Converts seconds/milliseconds to a human readable value.
Definition: Convert.php:64

◆ getParent()

getParent ( )

Returns the parent object of the current node.

Returns
TeamSpeak3_Adapter_ServerQuery
TeamSpeak3_Node_Abstract
104  {
105  return $this->parent;
106  }
$parent
Definition: Abstract.php:34

◆ getProperty()

getProperty (   $property,
  $default = null 
)

Returns the specified property or a pre-defined default value from the node info array.

Parameters
string$property
mixed$default
Returns
mixed
319  {
320  if(!$this->offsetExists($property))
321  {
322  $this->fetchNodeInfo();
323  }
324 
325  if(!$this->offsetExists($property))
326  {
327  return $default;
328  }
329 
330  return $this->nodeInfo[(string) $property];
331  }
fetchNodeInfo()
Definition: Abstract.php:437
offsetExists($offset)
Definition: Abstract.php:562

◆ getStorage()

getStorage (   $key,
  $default = null 
)
protected

Returns data from the internal storage array.

Parameters
string$key
mixed$default
Returns
mixed
401  {
402  return !empty($this->storage[$key]) ? $this->storage[$key] : $default;
403  }

◆ getSymbol()

getSymbol ( )
abstract

Returns a symbol representing the node.

Returns
string

◆ getUniqueId()

getUniqueId ( )
abstract

Returns a unique identifier for the node which can be used as a HTML property.

Returns
string

◆ getViewer()

getViewer ( TeamSpeak3_Viewer_Interface  $viewer)

Returns the HTML code to display a TeamSpeak 3 viewer.

Parameters
TeamSpeak3_Viewer_Interface$viewer
Returns
string
190  {
191  $html = $viewer->fetchObject($this);
192 
193  $iterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
194 
195  foreach($iterator as $node)
196  {
197  $siblings = array();
198 
199  for($level = 0; $level < $iterator->getDepth(); $level++)
200  {
201  $siblings[] = ($iterator->getSubIterator($level)->hasNext()) ? 1 : 0;
202  }
203 
204  $siblings[] = (!$iterator->getSubIterator($level)->hasNext()) ? 1 : 0;
205 
206  $html .= $viewer->fetchObject($node, $siblings);
207  }
208 
209  return $html;
210  }
fetchObject(TeamSpeak3_Node_Abstract $node, array $siblings=array())
Returns the code needed to display a node in a TeamSpeak 3 viewer.

◆ iconGetName()

iconGetName (   $key)

Returns the internal path of the node icon.

Parameters
string$key
Returns
TeamSpeak3_Helper_String
136  {
137  $iconid = ($this[$key] < 0) ? (pow(2, 32))-($this[$key]*-1) : $this[$key];
138 
139  return new TeamSpeak3_Helper_String("/icon_" . $iconid);
140  }
Helper class for string handling.
Definition: String.php:29

◆ iconIsLocal()

iconIsLocal (   $key)

Returns TRUE if the node icon has a local source.

Parameters
string$key
Returns
boolean
125  {
126  return ($this[$key] > 0 && $this[$key] < 1000) ? TRUE : FALSE;
127  }

◆ prepare()

prepare (   $cmd,
array  $params = array() 
)

Uses given parameters and returns a prepared ServerQuery command.

Parameters
string$cmd
array$params
Returns
TeamSpeak3_Helper_String
81  {
82  return $this->getParent()->prepare($cmd, $params);
83  }
getParent()
Returns the parent object of the current node.
Definition: Abstract.php:103

◆ request()

request (   $cmd,
  $throw = TRUE 
)

Sends a prepared command to the server and returns the result.

Parameters
string$cmd
boolean$throw
Returns
TeamSpeak3_Adapter_ServerQuery_Reply
69  {
70  return $this->getParent()->request($cmd, $throw);
71  }
getParent()
Returns the parent object of the current node.
Definition: Abstract.php:103

◆ setStorage()

setStorage (   $key,
  $val 
)
protected

Writes data to the internal storage array.

Parameters
string$key
mixed$val
Returns
void
389  {
390  $this->storage[$key] = $val;
391  }

◆ toArray()

toArray ( )

Returns an assoc array filled with current node info properties.

Returns
array
359  {
360  return $this->nodeList;
361  }
$nodeList
Definition: Abstract.php:49

◆ toString()

toString ( )

Returns a string representation of this node.

Returns
string
349  {
350  return $this->__toString();
351  }
__toString()
Returns a string representation of this node.
Definition: Abstract.php:338

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