TeamSpeak 3 PHP Framework  1.1.16
Copyright © Planet TeamSpeak. All rights reserved.
 All Classes Namespaces Files Functions Variables Pages
Event.php
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * TeamSpeak 3 PHP Framework
6  *
7  * $Id: Event.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_ServerQuery_Event
30  * @brief Provides methods to analyze and format a ServerQuery event.
31  */
32 class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess
33 {
34  /**
35  * Stores the event type.
36  *
37  * @var TeamSpeak3_Helper_String
38  */
39  protected $type = null;
40 
41  /**
42  * Stores the event data.
43  *
44  * @var array
45  */
46  protected $data = null;
47 
48  /**
49  * Stores the event data as an unparsed string.
50  *
51  * @var TeamSpeak3_Helper_String
52  */
53  protected $mesg = null;
54 
55  /**
56  * Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
57  *
58  * @param TeamSpeak3_Helper_String $evt
59  * @param TeamSpeak3_Node_Host $con
60  * @throws TeamSpeak3_Adapter_Exception
61  * @return TeamSpeak3_Adapter_ServerQuery_Event
62  */
63  public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null)
64  {
65  if(!$evt->startsWith(TeamSpeak3::EVENT))
66  {
67  throw new TeamSpeak3_Adapter_Exception("invalid notification event format");
68  }
69 
70  list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
71 
72  if(empty($data))
73  {
74  throw new TeamSpeak3_Adapter_Exception("invalid notification event data");
75  }
76 
78  $repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type);
79 
80  $this->type = $type->substr(strlen(TeamSpeak3::EVENT));
81  $this->data = $repl->toList();
82  $this->mesg = $data;
83 
84  TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con);
85  TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
86  }
87 
88  /**
89  * Returns the event type string.
90  *
91  * @return TeamSpeak3_Helper_String
92  */
93  public function getType()
94  {
95  return $this->type;
96  }
97 
98  /**
99  * Returns the event data array.
100  *
101  * @return array
102  */
103  public function getData()
104  {
105  return $this->data;
106  }
107 
108  /**
109  * Returns the event data as an unparsed string.
110  *
111  * @return TeamSpeak3_Helper_String
112  */
113  public function getMessage()
114  {
115  return $this->mesg;
116  }
117 
118  /**
119  * @ignore
120  */
121  public function offsetExists($offset)
122  {
123  return array_key_exists($offset, $this->data) ? TRUE : FALSE;
124  }
125 
126  /**
127  * @ignore
128  */
129  public function offsetGet($offset)
130  {
131  if(!$this->offsetExists($offset))
132  {
133  throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
134  }
135 
136  return $this->data[$offset];
137  }
138 
139  /**
140  * @ignore
141  */
142  public function offsetSet($offset, $value)
143  {
144  throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only");
145  }
146 
147  /**
148  * @ignore
149  */
150  public function offsetUnset($offset)
151  {
152  unset($this->data[$offset]);
153  }
154 
155  /**
156  * @ignore
157  */
158  public function __get($offset)
159  {
160  return $this->offsetGet($offset);
161  }
162 
163  /**
164  * @ignore
165  */
166  public function __set($offset, $value)
167  {
168  $this->offsetSet($offset, $value);
169  }
170 }