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

Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport. More...

+ Inheritance diagram for TeamSpeak3_Transport_Abstract:

Public Member Functions

 __construct (array $config)
 The TeamSpeak3_Transport_Abstract constructor. More...
 
 __destruct ()
 The TeamSpeak3_Transport_Abstract destructor. More...
 
 __sleep ()
 Commit pending data. More...
 
 __wakeup ()
 Reconnects to the remote server. More...
 
 connect ()
 Connects to a remote server. More...
 
 disconnect ()
 Disconnects from a remote server. More...
 
 getAdapter ()
 Returns the TeamSpeak3_Adapter_Abstract object using this transport. More...
 
 getAdapterType ()
 Returns the adapter type. More...
 
 getConfig ($key=null, $default=null)
 Returns the configuration variables in this adapter. More...
 
 getMetaData ()
 Returns header/meta data from stream pointer. More...
 
 getStream ()
 Returns the underlying stream resource. More...
 
 isConnected ()
 Returns TRUE if the transport is connected. More...
 
 read ($length=4096)
 Reads data from the stream. More...
 
 send ($data)
 Writes data to the stream. More...
 
 setAdapter (TeamSpeak3_Adapter_Abstract $adapter)
 Sets the TeamSpeak3_Adapter_Abstract object using this transport. More...
 

Protected Member Functions

 waitForReadyRead ($time=0)
 Blocks a stream until data is available for reading if the stream is connected in non-blocking mode. More...
 

Detailed Description

Abstract class for connecting to a TeamSpeak 3 Server through different ways of transport.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $config)

The TeamSpeak3_Transport_Abstract constructor.

Parameters
array$config
Exceptions
TeamSpeak3_Transport_Exception
Returns
TeamSpeak3_Transport_Abstract
60  {
61  if(!array_key_exists("host", $config))
62  {
63  throw new TeamSpeak3_Transport_Exception("config must have a key for 'host' which specifies the server host name");
64  }
65 
66  if(!array_key_exists("port", $config))
67  {
68  throw new TeamSpeak3_Transport_Exception("config must have a key for 'port' which specifies the server port number");
69  }
70 
71  if(!array_key_exists("timeout", $config))
72  {
73  $config["timeout"] = 10;
74  }
75 
76  if(!array_key_exists("blocking", $config))
77  {
78  $config["blocking"] = 1;
79  }
80 
81  $this->config = $config;
82  }
Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
Definition: Exception.php:29

◆ __destruct()

__destruct ( )

The TeamSpeak3_Transport_Abstract destructor.

Returns
void
110  {
111  if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
112  {
113  $this->adapter->__destruct();
114  }
115 
116  $this->disconnect();
117  }
Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server...
Definition: Abstract.php:29
disconnect()
Disconnects from a remote server.

Member Function Documentation

◆ __sleep()

__sleep ( )

Commit pending data.

Returns
array
90  {
91  return array("config");
92  }

◆ __wakeup()

__wakeup ( )

Reconnects to the remote server.

Returns
void
100  {
101  $this->connect();
102  }
connect()
Connects to a remote server.

◆ connect()

connect ( )
abstract

Connects to a remote server.

Exceptions
TeamSpeak3_Transport_Exception
Returns
void

◆ disconnect()

disconnect ( )
abstract

Disconnects from a remote server.

Returns
void

◆ getAdapter()

getAdapter ( )

Returns the TeamSpeak3_Adapter_Abstract object using this transport.

Returns
TeamSpeak3_Adapter_Abstract
195  {
196  return $this->adapter;
197  }

◆ getAdapterType()

getAdapterType ( )

Returns the adapter type.

Returns
string
205  {
206  if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
207  {
208  $string = TeamSpeak3_Helper_String::factory(get_class($this->adapter));
209 
210  return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString();
211  }
212 
213  return "Unknown";
214  }
Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server...
Definition: Abstract.php:29
static factory($string)
Returns a TeamSpeak3_Helper_String object for thegiven string.
Definition: String.php:60

◆ getConfig()

getConfig (   $key = null,
  $default = null 
)

Returns the configuration variables in this adapter.

Parameters
string$key
mixed$default
Returns
array
169  {
170  if($key !== null)
171  {
172  return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
173  }
174 
175  return $this->config;
176  }

◆ getMetaData()

getMetaData ( )

Returns header/meta data from stream pointer.

Exceptions
TeamSpeak3_Transport_Exception
Returns
array
223  {
224  if($this->stream === null)
225  {
226  throw new TeamSpeak3_Transport_Exception("unable to retrieve header/meta data from stream pointer");
227  }
228 
229  return stream_get_meta_data($this->stream);
230  }
Enhanced exception class for TeamSpeak3_Transport_Abstract objects.
Definition: Exception.php:29

◆ getStream()

getStream ( )

Returns the underlying stream resource.

Returns
resource
157  {
158  return $this->stream;
159  }

◆ isConnected()

isConnected ( )

Returns TRUE if the transport is connected.

Returns
boolean
238  {
239  return (is_resource($this->stream)) ? TRUE : FALSE;
240  }

◆ read()

read (   $length = 4096)
abstract

Reads data from the stream.

Parameters
integer$length
Exceptions
TeamSpeak3_Transport_Exception
Returns
TeamSpeak3_Helper_String

◆ send()

send (   $data)
abstract

Writes data to the stream.

Parameters
string$data
Returns
void

◆ setAdapter()

setAdapter ( TeamSpeak3_Adapter_Abstract  $adapter)

Sets the TeamSpeak3_Adapter_Abstract object using this transport.

Parameters
TeamSpeak3_Adapter_Abstract$adapter
Returns
void
185  {
186  $this->adapter = $adapter;
187  }

◆ waitForReadyRead()

waitForReadyRead (   $time = 0)
protected

Blocks a stream until data is available for reading if the stream is connected in non-blocking mode.

Parameters
integer$time
Returns
void
250  {
251  if(!$this->isConnected() || $this->config["blocking"]) return;
252 
253  do
254  {
255  $read = array($this->stream);
256  $null = null;
257 
258  if($time)
259  {
260  TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
261  }
262 
263  $time = $time+$this->config["timeout"];
264  }
265  while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
266  }
isConnected()
Returns TRUE if the transport is connected.
Definition: Abstract.php:237
getAdapter()
Returns the TeamSpeak3_Adapter_Abstract object using this transport.
Definition: Abstract.php:194
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
getAdapterType()
Returns the adapter type.
Definition: Abstract.php:204

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