TeamSpeak 3 PHP Framework
Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
TeamSpeak3_Exception Class Reference

Enhanced exception class for TeamSpeak3 objects. More...

+ Inheritance diagram for TeamSpeak3_Exception:

Public Member Functions

 __construct ($mesg, $code=0x00)
 The TeamSpeak3_Exception constructor. More...
 
 getSender ()
 Returns the class from which the exception was thrown. More...
 

Static Public Member Functions

static registerCustomMessage ($code, $mesg)
 Registers a custom error message to $code. More...
 
static unregisterCustomMessage ($code)
 Unregisters a custom error message from $code. More...
 

Protected Member Functions

 prepareCustomMessage (TeamSpeak3_Helper_String $mesg)
 Prepares a custom error message by replacing pre-defined signs with given values. More...
 

Detailed Description

Enhanced exception class for TeamSpeak3 objects.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $mesg,
  $code = 0x00 
)

The TeamSpeak3_Exception constructor.

Parameters
string$mesg
integer$code
Returns
TeamSpeak3_Exception
46  {
47  parent::__construct($mesg, $code);
48 
49  if(array_key_exists((int) $code, self::$messages))
50  {
51  $this->message = $this->prepareCustomMessage(self::$messages[intval($code)]);
52  }
53 
54  TeamSpeak3_Helper_Signal::getInstance()->emit("errorException", $this);
55  }
static getInstance()
Returns a singleton instance of TeamSpeak3_Helper_Signal.
Definition: Signal.php:201
prepareCustomMessage(TeamSpeak3_Helper_String $mesg)
Prepares a custom error message by replacing pre-defined signs with given values. ...
Definition: Exception.php:63

Member Function Documentation

◆ getSender()

getSender ( )

Returns the class from which the exception was thrown.

Returns
string
121  {
122  $trace = $this->getTrace();
123 
124  return (isset($trace[0]["class"])) ? $trace[0]["class"] : "{main}";
125  }

◆ prepareCustomMessage()

prepareCustomMessage ( TeamSpeak3_Helper_String  $mesg)
protected

Prepares a custom error message by replacing pre-defined signs with given values.

Parameters
TeamSpeak3_Helper_String$mesg
Returns
TeamSpeak3_Helper_String
64  {
65  $args = array(
66  "code" => $this->getCode(),
67  "mesg" => $this->getMessage(),
68  "line" => $this->getLine(),
69  "file" => $this->getFile(),
70  );
71 
72  return $mesg->arg($args)->toString();
73  }
arg(array $args, $char="%")
This function replaces indexed or associative signs with given values.
Definition: String.php:94

◆ registerCustomMessage()

static registerCustomMessage (   $code,
  $mesg 
)
static

Registers a custom error message to $code.

Parameters
integer$code
string$mesg
Exceptions
TeamSpeak3_Exception
Returns
void
84  {
85  if(array_key_exists((int) $code, self::$messages))
86  {
87  throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is already registered");
88  }
89 
90  if(!is_string($mesg))
91  {
92  throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " must be a string");
93  }
94 
95  self::$messages[(int) $code] = new TeamSpeak3_Helper_String($mesg);
96  }
Helper class for string handling.
Definition: String.php:29

◆ unregisterCustomMessage()

static unregisterCustomMessage (   $code)
static

Unregisters a custom error message from $code.

Parameters
integer$code
Exceptions
TeamSpeak3_Exception
Returns
void
106  {
107  if(!array_key_exists((int) $code, self::$messages))
108  {
109  throw new self("custom message for code 0x" . strtoupper(dechex($code)) . " is not registered");
110  }
111 
112  unset(self::$messages[(int) $code]);
113  }

The documentation for this class was generated from the following file: