release 1.00

This commit is contained in:
Newcomer1989
2016-04-17 14:11:49 +02:00
parent 5429ffb819
commit 916cb41794
112 changed files with 14170 additions and 9797 deletions

View File

@@ -1,5 +1,4 @@
<?php
<?PHP
/**
* @file
* TeamSpeak 3 PHP Framework
@@ -24,106 +23,4 @@
* @author Sven 'ScP' Paulsen
* @copyright Copyright (c) 2010 by Planet TeamSpeak. All rights reserved.
*/
/**
* @class TeamSpeak3_Exception
* @brief Enhanced exception class for TeamSpeak3 objects.
*/
class TeamSpeak3_Exception extends Exception
{
/**
* Stores custom error messages.
*
* @var array
*/
protected static $messages = array();
/**
* The TeamSpeak3_Exception constructor.
*
* @param string $mesg
* @param integer $code
* @return TeamSpeak3_Exception
*/
public function __construct($mesg, $code = 0x00)
{
parent::__construct($mesg, $code);
if(array_key_exists((int) $code, self::$messages))
{
$this->message = $this->prepareCustomMessage(self::$messages[intval($code)]);
}
TeamSpeak3_Helper_Signal::getInstance()->emit("errorException", $this);
}
/**
* Prepares a custom error message by replacing pre-defined signs with given values.
*
* @param TeamSpeak3_Helper_String $mesg
* @return TeamSpeak3_Helper_String
*/
protected function prepareCustomMessage(TeamSpeak3_Helper_String $mesg)
{
$args = array(
"code" => $this->getCode(),
"mesg" => $this->getMessage(),
"line" => $this->getLine(),
"file" => $this->getFile(),
);
return $mesg->arg($args)->toString();
}
/**
* Registers a custom error message to $code.
*
* @param integer $code
* @param string $mesg
* @throws TeamSpeak3_Exception
* @return void
*/
public static function registerCustomMessage($code, $mesg)
{
if(array_key_exists((int) $code, self::$messages))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is already registered");
}
if(!is_string($mesg))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " must be a string");
}
self::$messages[(int) $code] = new TeamSpeak3_Helper_String($mesg);
}
/**
* Unregisters a custom error message from $code.
*
* @param integer $code
* @throws TeamSpeak3_Exception
* @return void
*/
public static function unregisterCustomMessage($code)
{
if(!array_key_exists((int) $code, self::$messages))
{
throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is not registered");
}
unset(self::$messages[intval($code)]);
}
/**
* Returns the class from which the exception was thrown.
*
* @return string
*/
public function getSender()
{
$trace = $this->getTrace();
return (isset($trace[0]["class"])) ? $trace[0]["class"] : "{main}";
}
}
class TeamSpeak3_Exception extends Exception{ protected static $messages=array(); public function __construct($mesg,$code=0x00){parent::__construct($mesg,$code);if(array_key_exists((int)$code,self::$messages)){$this->message=$this->prepareCustomMessage(self::$messages[intval($code)]);}TeamSpeak3_Helper_Signal::getInstance()->emit("errorException",$this);} protected function prepareCustomMessage(TeamSpeak3_Helper_String$mesg){$args=array("code"=>$this->getCode(),"mesg"=>$this->getMessage(),"line"=>$this->getLine(),"file"=>$this->getFile(),);return $mesg->arg($args)->toString();} public static function registerCustomMessage($code,$mesg){if(array_key_exists((int)$code,self::$messages)){ throw new self("custom message for code 0x".strtoupper(dechex($code))." is already registered");}if(!is_string($mesg)){ throw new self("custom message for code 0x".strtoupper(dechex($code))." must be a string");}self::$messages[(int)$code]=new TeamSpeak3_Helper_String($mesg);} public static function unregisterCustomMessage($code){if(!array_key_exists((int)$code,self::$messages)){ throw new self("custom message for code 0x".strtoupper(dechex($code))." is not registered");}unset(self::$messages[intval($code)]);} public function getSender(){$trace=$this->getTrace();return (isset($trace[0]["class"]))?$trace[0]["class"]:"{main}";}}?>