TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
All Classes Namespaces Files Functions Variables Pages
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.
 
 __sleep ()
 Commit pending data.
 
 __wakeup ()
 Reconnects to the remote server.
 
 __destruct ()
 The TeamSpeak3_Transport_Abstract destructor.
 
 connect ()
 Connects to a remote server.
 
 disconnect ()
 Disconnects from a remote server.
 
 read ($length=4096)
 Reads data from the stream.
 
 send ($data)
 Writes data to the stream.
 
 getStream ()
 Returns the underlying stream resource.
 
 getConfig ($key=null, $default=null)
 Returns the configuration variables in this adapter.
 
 setAdapter (TeamSpeak3_Adapter_Abstract $adapter)
 Sets the TeamSpeak3_Adapter_Abstract object using this transport.
 
 getAdapter ()
 Returns the TeamSpeak3_Adapter_Abstract object using this transport.
 
 getAdapterType ()
 Returns the adapter type.
 
 getMetaData ()
 Returns header/meta data from stream pointer.
 
 isConnected ()
 Returns TRUE if the transport is connected.
 

Protected Member Functions

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

Protected Attributes

 $config = null
 
 $stream = null
 
 $adapter = null
 

Detailed Description

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

Definition at line 32 of file Abstract.php.

Constructor & Destructor Documentation

TeamSpeak3_Transport_Abstract::__construct ( array  $config)

The TeamSpeak3_Transport_Abstract constructor.

Parameters
array$config
Exceptions
TeamSpeak3_Transport_Exception
Returns
TeamSpeak3_Transport_Abstract

Definition at line 62 of file Abstract.php.

{
if(!array_key_exists("host", $config))
{
throw new TeamSpeak3_Transport_Exception("config must have a key for 'host' which specifies the server host name");
}
if(!array_key_exists("port", $config))
{
throw new TeamSpeak3_Transport_Exception("config must have a key for 'port' which specifies the server port number");
}
if(!array_key_exists("timeout", $config))
{
$config["timeout"] = 10;
}
if(!array_key_exists("blocking", $config))
{
$config["blocking"] = 1;
}
$this->config = $config;
}
TeamSpeak3_Transport_Abstract::__destruct ( )

The TeamSpeak3_Transport_Abstract destructor.

Returns
void

Definition at line 112 of file Abstract.php.

References disconnect().

{
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
{
$this->adapter->__destruct();
}
$this->disconnect();
}

Member Function Documentation

TeamSpeak3_Transport_Abstract::__sleep ( )

Commit pending data.

Returns
array

Definition at line 92 of file Abstract.php.

{
return array("config");
}
TeamSpeak3_Transport_Abstract::__wakeup ( )

Reconnects to the remote server.

Returns
void

Definition at line 102 of file Abstract.php.

References connect().

{
$this->connect();
}
TeamSpeak3_Transport_Abstract::connect ( )
abstract

Connects to a remote server.

Exceptions
TeamSpeak3_Transport_Exception
Returns
void

Referenced by __wakeup().

TeamSpeak3_Transport_Abstract::disconnect ( )
abstract

Disconnects from a remote server.

Returns
void

Referenced by __destruct().

TeamSpeak3_Transport_Abstract::read (   $length = 4096)
abstract

Reads data from the stream.

Parameters
integer$length
Exceptions
TeamSpeak3_Transport_Exception
Returns
TeamSpeak3_Helper_String
TeamSpeak3_Transport_Abstract::send (   $data)
abstract

Writes data to the stream.

Parameters
string$data
Returns
void
TeamSpeak3_Transport_Abstract::getStream ( )

Returns the underlying stream resource.

Returns
resource

Definition at line 159 of file Abstract.php.

{
return $this->stream;
}
TeamSpeak3_Transport_Abstract::getConfig (   $key = null,
  $default = null 
)

Returns the configuration variables in this adapter.

Parameters
string$key
mixed$default
Returns
array

Definition at line 171 of file Abstract.php.

{
if($key !== null)
{
return array_key_exists($key, $this->config) ? $this->config[$key] : $default;
}
return $this->config;
}
TeamSpeak3_Transport_Abstract::setAdapter ( TeamSpeak3_Adapter_Abstract  $adapter)

Sets the TeamSpeak3_Adapter_Abstract object using this transport.

Parameters
TeamSpeak3_Adapter_Abstract$adapter
Returns
void

Definition at line 187 of file Abstract.php.

{
$this->adapter = $adapter;
}
TeamSpeak3_Transport_Abstract::getAdapter ( )

Returns the TeamSpeak3_Adapter_Abstract object using this transport.

Returns
TeamSpeak3_Adapter_Abstract

Definition at line 197 of file Abstract.php.

Referenced by waitForReadyRead().

{
return $this->adapter;
}
TeamSpeak3_Transport_Abstract::getAdapterType ( )

Returns the adapter type.

Returns
string

Definition at line 207 of file Abstract.php.

References TeamSpeak3_Helper_String\factory().

Referenced by TeamSpeak3_Transport_TCP\disconnect(), TeamSpeak3_Transport_UDP\disconnect(), TeamSpeak3_Transport_UDP\read(), TeamSpeak3_Transport_TCP\read(), TeamSpeak3_Transport_TCP\readLine(), TeamSpeak3_Transport_UDP\send(), TeamSpeak3_Transport_TCP\send(), and waitForReadyRead().

{
if($this->adapter instanceof TeamSpeak3_Adapter_Abstract)
{
$string = TeamSpeak3_Helper_String::factory(get_class($this->adapter));
return $string->substr($string->findLast("_"))->replace(array("_", " "), "")->toString();
}
return "Unknown";
}
TeamSpeak3_Transport_Abstract::getMetaData ( )

Returns header/meta data from stream pointer.

Exceptions
TeamSpeak3_Transport_Exception
Returns
array

Definition at line 225 of file Abstract.php.

{
if($this->stream === null)
{
throw new TeamSpeak3_Transport_Exception("unable to retrieve header/meta data from stream pointer");
}
return stream_get_meta_data($this->stream);
}
TeamSpeak3_Transport_Abstract::isConnected ( )

Returns TRUE if the transport is connected.

Returns
boolean

Definition at line 240 of file Abstract.php.

Referenced by TeamSpeak3_Adapter_ServerQuery\__destruct(), and waitForReadyRead().

{
return (is_resource($this->stream)) ? TRUE : FALSE;
}
TeamSpeak3_Transport_Abstract::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

Definition at line 252 of file Abstract.php.

References getAdapter(), getAdapterType(), TeamSpeak3_Helper_Signal\getInstance(), and isConnected().

Referenced by TeamSpeak3_Transport_TCP\read(), TeamSpeak3_Transport_UDP\read(), and TeamSpeak3_Transport_TCP\readLine().

{
if(!$this->isConnected() || $this->config["blocking"]) return;
do {
$read = array($this->stream);
$null = null;
if($time)
{
TeamSpeak3_Helper_Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "WaitTimeout", $time, $this->getAdapter());
}
$time = $time+$this->config["timeout"];
} while(@stream_select($read, $null, $null, $this->config["timeout"]) == 0);
}

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