TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Abstract.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Abstract.php 8/31/2012 11:06:09 scp@orilla $
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @package TeamSpeak3
23  * @version 1.1.16
24  * @author Sven 'ScP' Paulsen
25  * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
26  */
27 
28 /**
29  * @class TeamSpeak3_Adapter_Abstract
30  * @brief Provides low-level methods for concrete adapters to communicate with a TeamSpeak 3 Server.
31  */
33 {
34  /**
35  * Stores user-provided options.
36  *
37  * @var array
38  */
39  protected $options = null;
40 
41  /**
42  * Stores an TeamSpeak3_Transport_Abstract object.
43  *
44  * @var TeamSpeak3_Transport_Abstract
45  */
46  protected $transport = null;
47 
48  /**
49  * The TeamSpeak3_Adapter_Abstract constructor.
50  *
51  * @param array $options
52  * @return TeamSpeak3_Adapter_Abstract
53  */
54  public function __construct(array $options)
55  {
56  $this->options = $options;
57 
58  if($this->transport === null)
59  {
60  $this->syn();
61  }
62  }
63 
64  /**
65  * The TeamSpeak3_Adapter_Abstract destructor.
66  *
67  * @return void
68  */
69  abstract public function __destruct();
70 
71  /**
72  * Connects the TeamSpeak3_Transport_Abstract object and performs initial actions on the remote
73  * server.
74  *
75  * @throws TeamSpeak3_Adapter_Exception
76  * @return void
77  */
78  abstract protected function syn();
79 
80  /**
81  * Commit pending data.
82  *
83  * @return array
84  */
85  public function __sleep()
86  {
87  return array("options");
88  }
89 
90  /**
91  * Reconnects to the remote server.
92  *
93  * @return void
94  */
95  public function __wakeup()
96  {
97  $this->syn();
98  }
99 
100  /**
101  * Returns the profiler timer used for this connection adapter.
102  *
103  * @return TeamSpeak3_Helper_Profiler_Timer
104  */
105  public function getProfiler()
106  {
107  return TeamSpeak3_Helper_Profiler::get(spl_object_hash($this));
108  }
109 
110  /**
111  * Returns the transport object used for this connection adapter.
112  *
113  * @return TeamSpeak3_Transport_Abstract
114  */
115  public function getTransport()
116  {
117  return $this->transport;
118  }
119 
120  /**
121  * Loads the transport object object used for the connection adapter and passes a given set
122  * of options.
123  *
124  * @param array $options
125  * @param string $transport
126  * @throws TeamSpeak3_Adapter_Exception
127  * @return void
128  */
129  protected function initTransport($options, $transport = "TeamSpeak3_Transport_TCP")
130  {
131  if(!is_array($options))
132  {
133  throw new TeamSpeak3_Adapter_Exception("transport parameters must provided in an array");
134  }
135 
136  $this->transport = new $transport($options);
137  }
138 
139  /**
140  * Returns the hostname or IPv4 address the underlying TeamSpeak3_Transport_Abstract object
141  * is connected to.
142  *
143  * @return string
144  */
145  public function getTransportHost()
146  {
147  return $this->getTransport()->getConfig("host", "0.0.0.0");
148  }
149 
150  /**
151  * Returns the port number of the server the underlying TeamSpeak3_Transport_Abstract object
152  * is connected to.
153  *
154  * @return string
155  */
156  public function getTransportPort()
157  {
158  return $this->getTransport()->getConfig("port", "0");
159  }
160 }