Event.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /**
  3. * @file
  4. * TeamSpeak 3 PHP Framework
  5. *
  6. * $Id: Event.php 06/06/2016 22:27:13 scp@Svens-iMac $
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * @package TeamSpeak3
  22. * @version 1.1.24
  23. * @author Sven 'ScP' Paulsen
  24. * @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
  25. */
  26. /**
  27. * @class TeamSpeak3_Adapter_ServerQuery_Event
  28. * @brief Provides methods to analyze and format a ServerQuery event.
  29. */
  30. class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess
  31. {
  32. /**
  33. * Stores the event type.
  34. *
  35. * @var TeamSpeak3_Helper_String
  36. */
  37. protected $type = null;
  38. /**
  39. * Stores the event data.
  40. *
  41. * @var array
  42. */
  43. protected $data = null;
  44. /**
  45. * Stores the event data as an unparsed string.
  46. *
  47. * @var TeamSpeak3_Helper_String
  48. */
  49. protected $mesg = null;
  50. /**
  51. * Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
  52. *
  53. * @param TeamSpeak3_Helper_String $evt
  54. * @param TeamSpeak3_Node_Host $con
  55. * @throws TeamSpeak3_Adapter_Exception
  56. * @return TeamSpeak3_Adapter_ServerQuery_Event
  57. */
  58. public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null)
  59. {
  60. if(!$evt->startsWith(TeamSpeak3::EVENT))
  61. {
  62. throw new TeamSpeak3_Adapter_Exception("invalid notification event format");
  63. }
  64. list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
  65. if(empty($data))
  66. {
  67. throw new TeamSpeak3_Adapter_Exception("invalid notification event data");
  68. }
  69. $fake = new TeamSpeak3_Helper_String(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok");
  70. $repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type);
  71. $this->type = $type->substr(strlen(TeamSpeak3::EVENT));
  72. $this->data = $repl->toList();
  73. $this->mesg = $data;
  74. TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con);
  75. TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
  76. }
  77. /**
  78. * Returns the event type string.
  79. *
  80. * @return TeamSpeak3_Helper_String
  81. */
  82. public function getType()
  83. {
  84. return $this->type;
  85. }
  86. /**
  87. * Returns the event data array.
  88. *
  89. * @return array
  90. */
  91. public function getData()
  92. {
  93. return $this->data;
  94. }
  95. /**
  96. * Returns the event data as an unparsed string.
  97. *
  98. * @return TeamSpeak3_Helper_String
  99. */
  100. public function getMessage()
  101. {
  102. return $this->mesg;
  103. }
  104. /**
  105. * @ignore
  106. */
  107. public function offsetExists($offset)
  108. {
  109. return array_key_exists($offset, $this->data) ? TRUE : FALSE;
  110. }
  111. /**
  112. * @ignore
  113. */
  114. public function offsetGet($offset)
  115. {
  116. if(!$this->offsetExists($offset))
  117. {
  118. throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
  119. }
  120. return $this->data[$offset];
  121. }
  122. /**
  123. * @ignore
  124. */
  125. public function offsetSet($offset, $value)
  126. {
  127. throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only");
  128. }
  129. /**
  130. * @ignore
  131. */
  132. public function offsetUnset($offset)
  133. {
  134. unset($this->data[$offset]);
  135. }
  136. /**
  137. * @ignore
  138. */
  139. public function __get($offset)
  140. {
  141. return $this->offsetGet($offset);
  142. }
  143. /**
  144. * @ignore
  145. */
  146. public function __set($offset, $value)
  147. {
  148. $this->offsetSet($offset, $value);
  149. }
  150. }