TeamSpeak 3 PHP Framework  1.1.12
libraries/TeamSpeak3/Adapter/ServerQuery/Event.php
Go to the documentation of this file.
00001 <?php
00002 
00003 /**
00004  * @file
00005  * TeamSpeak 3 PHP Framework
00006  *
00007  * $Id: Event.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_ServerQuery_Event
00030  * @brief Provides methods to analyze and format a ServerQuery event.
00031  */
00032 class TeamSpeak3_Adapter_ServerQuery_Event implements ArrayAccess
00033 {
00034   /**
00035    * Stores the event type.
00036    *
00037    * @var TeamSpeak3_Helper_String
00038    */
00039   protected $type = null;
00040 
00041   /**
00042    * Stores the event data.
00043    *
00044    * @var array
00045    */
00046   protected $data = null;
00047 
00048   /**
00049    * Stores the event data as an unparsed string.
00050    *
00051    * @var TeamSpeak3_Helper_String
00052    */
00053   protected $mesg = null;
00054 
00055   /**
00056    * Creates a new TeamSpeak3_Adapter_ServerQuery_Event object.
00057    *
00058    * @param  TeamSpeak3_Helper_String $evt
00059    * @param  TeamSpeak3_Node_Host     $con
00060    * @throws TeamSpeak3_Adapter_Exception
00061    * @return TeamSpeak3_Adapter_ServerQuery_Event
00062    */
00063   public function __construct(TeamSpeak3_Helper_String $evt, TeamSpeak3_Node_Host $con = null)
00064   {
00065     if(!$evt->startsWith(TeamSpeak3::EVENT))
00066     {
00067       throw new TeamSpeak3_Adapter_Exception("invalid notification event format");
00068     }
00069 
00070     list($type, $data) = $evt->split(TeamSpeak3::SEPARATOR_CELL, 2);
00071 
00072     if(empty($data))
00073     {
00074       throw new TeamSpeak3_Adapter_Exception("invalid notification event data");
00075     }
00076 
00077     $fake = new TeamSpeak3_Helper_String(TeamSpeak3::ERROR . TeamSpeak3::SEPARATOR_CELL . "id" . TeamSpeak3::SEPARATOR_PAIR . 0 . TeamSpeak3::SEPARATOR_CELL . "msg" . TeamSpeak3::SEPARATOR_PAIR . "ok");
00078     $repl = new TeamSpeak3_Adapter_ServerQuery_Reply(array($data, $fake), $type);
00079 
00080     $this->type = $type->substr(strlen(TeamSpeak3::EVENT));
00081     $this->data = $repl->toList();
00082     $this->mesg = $data;
00083 
00084     TeamSpeak3_Helper_Signal::getInstance()->emit("notifyEvent", $this, $con);
00085     TeamSpeak3_Helper_Signal::getInstance()->emit("notify" . ucfirst($this->type), $this, $con);
00086   }
00087 
00088   /**
00089    * Returns the event type string.
00090    *
00091    * @return TeamSpeak3_Helper_String
00092    */
00093   public function getType()
00094   {
00095     return $this->type;
00096   }
00097 
00098   /**
00099    * Returns the event data array.
00100    *
00101    * @return array
00102    */
00103   public function getData()
00104   {
00105     return $this->data;
00106   }
00107 
00108   /**
00109    * Returns the event data as an unparsed string.
00110    *
00111    * @return TeamSpeak3_Helper_String
00112    */
00113   public function getMessage()
00114   {
00115     return $this->mesg;
00116   }
00117 
00118   /**
00119    * @ignore
00120    */
00121   public function offsetExists($offset)
00122   {
00123     return array_key_exists($offset, $this->data) ? TRUE : FALSE;
00124   }
00125 
00126   /**
00127    * @ignore
00128    */
00129   public function offsetGet($offset)
00130   {
00131     if(!$this->offsetExists($offset))
00132     {
00133       throw new TeamSpeak3_Adapter_ServerQuery_Exception("invalid parameter", 0x602);
00134     }
00135 
00136     return $this->data[$offset];
00137   }
00138 
00139   /**
00140    * @ignore
00141    */
00142   public function offsetSet($offset, $value)
00143   {
00144     throw new TeamSpeak3_Node_Exception("event '" . $this->getType() . "' is read only");
00145   }
00146 
00147   /**
00148    * @ignore
00149    */
00150   public function offsetUnset($offset)
00151   {
00152     unset($this->data[$offset]);
00153   }
00154 
00155   /**
00156    * @ignore
00157    */
00158   public function __get($offset)
00159   {
00160     return $this->offsetGet($offset);
00161   }
00162 
00163   /**
00164    * @ignore
00165    */
00166   public function __set($offset, $value)
00167   {
00168     $this->offsetSet($offset, $value);
00169   }
00170 }
 All Classes Files Functions Variables