TeamSpeak 3 PHP Framework  1.1.12
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:
TeamSpeak3_Transport_TCP TeamSpeak3_Transport_UDP

List of all members.

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

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;
  }

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

Commit pending data.

Returns:
array

Definition at line 92 of file Abstract.php.

  {
    return array("config");
  }

Reconnects to the remote server.

Returns:
void

Definition at line 102 of file Abstract.php.

References connect().

  {
    $this->connect();
  }

Connects to a remote server.

Exceptions:
TeamSpeak3_Transport_Exception
Returns:
void

Reimplemented in TeamSpeak3_Transport_TCP, and TeamSpeak3_Transport_UDP.

Referenced by __wakeup().

Disconnects from a remote server.

Returns:
void

Reimplemented in TeamSpeak3_Transport_TCP, and TeamSpeak3_Transport_UDP.

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

Reimplemented in TeamSpeak3_Transport_TCP, and TeamSpeak3_Transport_UDP.

TeamSpeak3_Transport_Abstract::send ( data) [abstract]

Writes data to the stream.

Parameters:
string$data
Returns:
void

Reimplemented in TeamSpeak3_Transport_TCP, and TeamSpeak3_Transport_UDP.

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;
  }

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;
  }

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;
  }

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";
  }

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);
  }

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;
  }

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:
 All Classes Files Functions Variables