TeamSpeak 3 PHP Framework  1.1.12
TeamSpeak3_Adapter_ServerQuery Class Reference

Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server. More...

Inheritance diagram for TeamSpeak3_Adapter_ServerQuery:
TeamSpeak3_Adapter_Abstract

List of all members.

Public Member Functions

 __destruct ()
 The TeamSpeak3_Adapter_ServerQuery destructor.
 request ($cmd)
 Sends a prepared command to the server and returns the result.
 wait ()
 Waits for the server to send a notification message and returns the result.
 prepare ($cmd, array $params=array())
 Uses given parameters and returns a prepared ServerQuery command.
 getQueryLastTimestamp ()
 Returns the timestamp of the last command.
 getQueryCount ()
 Returns the number of queries executed on the server.
 getQueryRuntime ()
 Returns the total runtime of all queries.
 getHost ()
 Returns the TeamSpeak3_Node_Host object of the current connection.
 __sleep ()
 Commit pending data.
 __wakeup ()
 Reconnects to the remote server.
 getProfiler ()
 Returns the profiler timer used for this connection adapter.
 getTransport ()
 Returns the transport object used for this connection adapter.
 getTransportHost ()
 Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object is connected to.
 getTransportPort ()
 Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object is connected to.

Protected Member Functions

 syn ()
 Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server.
 initTransport ($options, $transport="TeamSpeak3_Transport_TCP")
 Loads the transport object object used for the connection adapter and passes a given set of options.

Protected Attributes

 $host = null
 $timer = null
 $count = 0
 $block = array("help")
 $options = null
 $transport = null

Detailed Description

Provides low-level methods for ServerQuery communication with a TeamSpeak 3 Server.

Definition at line 32 of file ServerQuery.php.


Constructor & Destructor Documentation

The TeamSpeak3_Adapter_ServerQuery destructor.

Returns:
void

Reimplemented from TeamSpeak3_Adapter_Abstract.

Definition at line 89 of file ServerQuery.php.

References TeamSpeak3_Adapter_Abstract\getTransport(), TeamSpeak3_Transport_Abstract\isConnected(), and request().

  {
    if($this->getTransport() instanceof TeamSpeak3_Transport_Abstract && $this->transport->isConnected())
    {
      try
      {
        $this->request("quit");
      }
      catch(Exception $e)
      {
        return;
      }
    }
  }

Member Function Documentation

Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote server.

Exceptions:
TeamSpeak3_Adapter_Exception
Returns:
void

Reimplemented from TeamSpeak3_Adapter_Abstract.

Definition at line 69 of file ServerQuery.php.

References TeamSpeak3_Helper_Signal\getInstance(), TeamSpeak3_Adapter_Abstract\getTransport(), TeamSpeak3_Helper_Profiler\init(), TeamSpeak3_Adapter_Abstract\initTransport(), and TeamSpeak3\READY.

  {
    $this->initTransport($this->options);
    $this->transport->setAdapter($this);

    TeamSpeak3_Helper_Profiler::init(spl_object_hash($this));

    if(!$this->getTransport()->readLine()->startsWith(TeamSpeak3::READY))
    {
      throw new TeamSpeak3_Adapter_Exception("invalid reply from the server");
    }

    TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryConnected", $this);
  }

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

Parameters:
string$cmd
Exceptions:
TeamSpeak3_Adapter_Exception
Returns:
TeamSpeak3_Adapter_ServerQuery_Reply

Definition at line 111 of file ServerQuery.php.

References TeamSpeak3\ERROR, TeamSpeak3_Helper_String\factory(), getHost(), TeamSpeak3_Helper_Signal\getInstance(), TeamSpeak3_Adapter_Abstract\getProfiler(), TeamSpeak3_Adapter_Abstract\getTransport(), TeamSpeak3_Helper_String\section(), and TeamSpeak3\SEPARATOR_CELL.

Referenced by __destruct().

  {
    $query = TeamSpeak3_Helper_String::factory($cmd)->section(TeamSpeak3::SEPARATOR_CELL);

    if(strstr($cmd, "\r") || strstr($cmd, "\n"))
    {
      throw new TeamSpeak3_Adapter_Exception("illegal characters in command '" . $query . "'");
    }
    elseif(in_array($query, $this->block))
    {
      throw new TeamSpeak3_Adapter_ServerQuery_Exception("command not found", 0x100);
    }

    TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandStarted", $cmd);

    $this->getProfiler()->start();
    $this->getTransport()->sendLine($cmd);
    $this->timer = time();
    $this->count++;

    $rpl = array();

    do {
      $str = $this->getTransport()->readLine();
      $rpl[] = $str;
    } while($str instanceof TeamSpeak3_Helper_String && $str->section(TeamSpeak3::SEPARATOR_CELL) != TeamSpeak3::ERROR);

    $this->getProfiler()->stop();

    $reply = new TeamSpeak3_Adapter_ServerQuery_Reply($rpl, $cmd, $this->getHost());

    TeamSpeak3_Helper_Signal::getInstance()->emit("serverqueryCommandFinished", $cmd, $reply);

    return $reply;
  }

Waits for the server to send a notification message and returns the result.

Exceptions:
TeamSpeak3_Adapter_Exception
Returns:
TeamSpeak3_Adapter_ServerQuery_Event

Definition at line 153 of file ServerQuery.php.

References TeamSpeak3\EVENT, getHost(), TeamSpeak3_Adapter_Abstract\getTransport(), TeamSpeak3_Helper_String\section(), and TeamSpeak3\SEPARATOR_CELL.

  {
    if($this->getTransport()->getConfig("blocking"))
    {
      throw new TeamSpeak3_Adapter_Exception("only available in non-blocking mode");
    }

    do {
      $evt = $this->getTransport()->readLine();
    } while($evt instanceof TeamSpeak3_Helper_String && !$evt->section(TeamSpeak3::SEPARATOR_CELL)->startsWith(TeamSpeak3::EVENT));

    return new TeamSpeak3_Adapter_ServerQuery_Event($evt, $this->getHost());
  }
TeamSpeak3_Adapter_ServerQuery::prepare ( cmd,
array $  params = array() 
)

Uses given parameters and returns a prepared ServerQuery command.

Parameters:
string$cmd
array$params
Returns:
string

Definition at line 174 of file ServerQuery.php.

References TeamSpeak3_Helper_String\factory(), TeamSpeak3\SEPARATOR_CELL, TeamSpeak3\SEPARATOR_LIST, and TeamSpeak3\SEPARATOR_PAIR.

  {
    $args = array();
    $cells = array();

    foreach($params as $ident => $value)
    {
      $ident = is_numeric($ident) ? "" : strtolower($ident) . TeamSpeak3::SEPARATOR_PAIR;

      if(is_array($value))
      {
        $value = array_values($value);

        for($i = 0; $i < count($value); $i++)
        {
          if($value[$i] === null) continue;
          elseif($value[$i] === FALSE) $value[$i] = 0x00;
          elseif($value[$i] === TRUE) $value[$i] = 0x01;
          elseif($value[$i] instanceof TeamSpeak3_Node_Abstract) $value[$i] = $value[$i]->getId();

          $cells[$i][] = $ident . TeamSpeak3_Helper_String::factory($value[$i])->escape()->toUtf8();
        }
      }
      else
      {
        if($value === null) continue;
        elseif($value === FALSE) $value = 0x00;
        elseif($value === TRUE) $value = 0x01;
        elseif($value instanceof TeamSpeak3_Node_Abstract) $value = $value->getId();

        $args[] = $ident . TeamSpeak3_Helper_String::factory($value)->escape()->toUtf8();
      }
    }

    foreach(array_keys($cells) as $ident) $cells[$ident] = implode(TeamSpeak3::SEPARATOR_CELL, $cells[$ident]);

    if(count($args)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_CELL, $args);
    if(count($cells)) $cmd .= " " . implode(TeamSpeak3::SEPARATOR_LIST, $cells);

    return trim($cmd);
  }

Returns the timestamp of the last command.

Returns:
integer

Definition at line 221 of file ServerQuery.php.

  {
    return $this->timer;
  }

Returns the number of queries executed on the server.

Returns:
integer

Definition at line 231 of file ServerQuery.php.

  {
    return $this->count;
  }

Returns the total runtime of all queries.

Returns:
mixed

Definition at line 241 of file ServerQuery.php.

References TeamSpeak3_Adapter_Abstract\getProfiler().

  {
    return $this->getProfiler()->getRuntime();
  }

Returns the TeamSpeak3_Node_Host object of the current connection.

Returns:
TeamSpeak3_Node_Host

Definition at line 251 of file ServerQuery.php.

Referenced by request(), and wait().

  {
    if($this->host === null)
    {
      $this->host = new TeamSpeak3_Node_Host($this);
    }

    return $this->host;
  }

Commit pending data.

Returns:
array

Definition at line 85 of file Abstract.php.

  {
    return array("options");
  }

Reconnects to the remote server.

Returns:
void

Definition at line 95 of file Abstract.php.

References TeamSpeak3_Adapter_Abstract\syn().

  {
    $this->syn();
  }
TeamSpeak3_Adapter_Abstract::initTransport ( options,
transport = "TeamSpeak3_Transport_TCP" 
) [protected, inherited]

Loads the transport object object used for the connection adapter and passes a given set of options.

Parameters:
array$options
string$transport
Exceptions:
TeamSpeak3_Adapter_Exception
Returns:
void

Definition at line 129 of file Abstract.php.

Referenced by TeamSpeak3_Adapter_FileTransfer\syn(), TeamSpeak3_Adapter_TSDNS\syn(), TeamSpeak3_Adapter_Blacklist\syn(), syn(), and TeamSpeak3_Adapter_Update\syn().

  {
    if(!is_array($options))
    {
      throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array");
    }

    $this->transport = new $transport($options);
  }

Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object is connected to.

Returns:
string

Definition at line 145 of file Abstract.php.

References TeamSpeak3_Adapter_Abstract\getTransport().

  {
    return $this->getTransport()->getConfig("host", "0.0.0.0");
  }

Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object is connected to.

Returns:
string

Definition at line 156 of file Abstract.php.

References TeamSpeak3_Adapter_Abstract\getTransport().

  {
    return $this->getTransport()->getConfig("port", "0");
  }

The documentation for this class was generated from the following file:
 All Classes Files Functions Variables