TeamSpeak 3 PHP Framework
1.1.12
|
00001 <?php 00002 00003 /** 00004 * @file 00005 * TeamSpeak 3 PHP Framework 00006 * 00007 * $Id: Abstract.php 2/18/2012 12:42:45 scp@orilla $ 00008 * 00009 * This program is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 * @package TeamSpeak3 00023 * @version 1.1.12 00024 * @author Sven 'ScP' Paulsen 00025 * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved. 00026 */ 00027 00028 /** 00029 * @class TeamSpeak3_Adapter_Abstract 00030 * @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server. 00031 */ 00032 abstract class TeamSpeak3_Adapter_Abstract 00033 { 00034 /** 00035 * Stores user-provided options. 00036 * 00037 * @var array 00038 */ 00039 protected $options = null; 00040 00041 /** 00042 * Stores an TeamSpeak3_Transport_Abstract object. 00043 * 00044 * @var TeamSpeak3_Transport_Abstract 00045 */ 00046 protected $transport = null; 00047 00048 /** 00049 * The TeamSpeak3_Adapter_Abstract constructor. 00050 * 00051 * @param array $options 00052 * @return TeamSpeak3_Adapter_Abstract 00053 */ 00054 public function __construct(array $options) 00055 { 00056 $this->options = $options; 00057 00058 if($this->transport === null) 00059 { 00060 $this->syn(); 00061 } 00062 } 00063 00064 /** 00065 * The TeamSpeak3_Adapter_Abstract destructor. 00066 * 00067 * @return void 00068 */ 00069 abstract public function __destruct(); 00070 00071 /** 00072 * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote 00073 * server. 00074 * 00075 * @throws TeamSpeak3_Adapter_Exception 00076 * @return void 00077 */ 00078 abstract protected function syn(); 00079 00080 /** 00081 * Commit pending data. 00082 * 00083 * @return array 00084 */ 00085 public function __sleep() 00086 { 00087 return array("options"); 00088 } 00089 00090 /** 00091 * Reconnects to the remote server. 00092 * 00093 * @return void 00094 */ 00095 public function __wakeup() 00096 { 00097 $this->syn(); 00098 } 00099 00100 /** 00101 * Returns the profiler timer used for this connection adapter. 00102 * 00103 * @return TeamSpeak3_Helper_Profiler_Timer 00104 */ 00105 public function getProfiler() 00106 { 00107 return TeamSpeak3_Helper_Profiler::get(spl_object_hash($this)); 00108 } 00109 00110 /** 00111 * Returns the transport object used for this connection adapter. 00112 * 00113 * @return TeamSpeak3_Transport_Abstract 00114 */ 00115 public function getTransport() 00116 { 00117 return $this->transport; 00118 } 00119 00120 /** 00121 * Loads the transport object object used for the connection adapter and passes a given set 00122 * of options. 00123 * 00124 * @param array $options 00125 * @param string $transport 00126 * @throws TeamSpeak3_Adapter_Exception 00127 * @return void 00128 */ 00129 protected function initTransport($options, $transport = "TeamSpeak3_Transport_TCP") 00130 { 00131 if(!is_array($options)) 00132 { 00133 throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array"); 00134 } 00135 00136 $this->transport = new $transport($options); 00137 } 00138 00139 /** 00140 * Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object 00141 * is connected to. 00142 * 00143 * @return string 00144 */ 00145 public function getTransportHost() 00146 { 00147 return $this->getTransport()->getConfig("host", "0.0.0.0"); 00148 } 00149 00150 /** 00151 * Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object 00152 * is connected to. 00153 * 00154 * @return string 00155 */ 00156 public function getTransportPort() 00157 { 00158 return $this->getTransport()->getConfig("port", "0"); 00159 } 00160 }