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

Helper class for signal slots. More...

Public Member Functions

 clearHandlers ($signal)
 Clears all slots for a specified signal. More...
 
 emit ($signal, $params=null)
 Emits a signal with a given set of parameters. More...
 
 getCallbackHash ($callback)
 Generates a MD5 hash based on a given callback. More...
 
 getHandlers ($signal)
 Returns all slots for a specified signal. More...
 
 getSignals ()
 Returns all registered signals. More...
 
 hasHandlers ($signal)
 Returns TRUE there are slots subscribed for a specified signal. More...
 
 subscribe ($signal, $callback)
 Subscribes to a signal and returns the signal handler. More...
 
 unsubscribe ($signal, $callback=null)
 Unsubscribes from a signal. More...
 

Static Public Member Functions

static getInstance ()
 Returns a singleton instance of TeamSpeak3_Helper_Signal. More...
 

Detailed Description

Helper class for signal slots.

Member Function Documentation

◆ clearHandlers()

clearHandlers (   $signal)

Clears all slots for a specified signal.

Parameters
string$signal
Returns
void
189  {
190  if(!$this->hasHandlers($signal))
191  {
192  unset($this->sigslots[$signal]);
193  }
194  }
hasHandlers($signal)
Returns TRUE there are slots subscribed for a specified signal.
Definition: Signal.php:161

◆ emit()

emit (   $signal,
  $params = null 
)

Emits a signal with a given set of parameters.

Parameters
string$signal
mixed$params
Returns
mixed
53  {
54  if(!$this->hasHandlers($signal))
55  {
56  return;
57  }
58 
59  if(!is_array($params))
60  {
61  $params = func_get_args();
62  $params = array_slice($params, 1);
63  }
64 
65  foreach($this->sigslots[$signal] as $slot)
66  {
67  $return = $slot->call($params);
68  }
69 
70  return $return;
71  }
hasHandlers($signal)
Returns TRUE there are slots subscribed for a specified signal.
Definition: Signal.php:161

◆ getCallbackHash()

getCallbackHash (   $callback)

Generates a MD5 hash based on a given callback.

Parameters
mixed$callback
string
Returns
void
81  {
82  if(!is_callable($callback, TRUE, $callable_name))
83  {
84  throw new TeamSpeak3_Helper_Signal_Exception("invalid callback specified");
85  }
86 
87  return md5($callable_name);
88  }
Enhanced exception class for TeamSpeak3_Helper_Signal objects.
Definition: Exception.php:29

◆ getHandlers()

getHandlers (   $signal)

Returns all slots for a specified signal.

Parameters
string$signal
Returns
array
173  {
174  if(!$this->hasHandlers($signal))
175  {
176  return $this->sigslots[$signal];
177  }
178 
179  return array();
180  }
hasHandlers($signal)
Returns TRUE there are slots subscribed for a specified signal.
Definition: Signal.php:161

◆ getInstance()

static getInstance ( )
static

Returns a singleton instance of TeamSpeak3_Helper_Signal.

Returns
TeamSpeak3_Helper_Signal
202  {
203  if(self::$instance === null)
204  {
205  self::$instance = new self();
206  }
207 
208  return self::$instance;
209  }

◆ getSignals()

getSignals ( )

Returns all registered signals.

Returns
array
151  {
152  return array_keys($this->sigslots);
153  }

◆ hasHandlers()

hasHandlers (   $signal)

Returns TRUE there are slots subscribed for a specified signal.

Parameters
string$signal
Returns
boolean
162  {
163  return empty($this->sigslots[$signal]) ? FALSE : TRUE;
164  }

◆ subscribe()

subscribe (   $signal,
  $callback 
)

Subscribes to a signal and returns the signal handler.

Parameters
string$signal
mixed$callback
Returns
TeamSpeak3_Helper_Signal_Handler
98  {
99  if(empty($this->sigslots[$signal]))
100  {
101  $this->sigslots[$signal] = array();
102  }
103 
104  $index = $this->getCallbackHash($callback);
105 
106  if(!array_key_exists($index, $this->sigslots[$signal]))
107  {
108  $this->sigslots[$signal][$index] = new TeamSpeak3_Helper_Signal_Handler($signal, $callback);
109  }
110 
111  return $this->sigslots[$signal][$index];
112  }
Helper class providing handler functions for signals.
Definition: Handler.php:29
getCallbackHash($callback)
Generates a MD5 hash based on a given callback.
Definition: Signal.php:80

◆ unsubscribe()

unsubscribe (   $signal,
  $callback = null 
)

Unsubscribes from a signal.

Parameters
string$signal
mixed$callback
Returns
void
122  {
123  if(!$this->hasHandlers($signal))
124  {
125  return;
126  }
127 
128  if($callback !== null)
129  {
130  $index = $this->getCallbackHash($callback);
131 
132  if(!array_key_exists($index, $this->sigslots[$signal]))
133  {
134  return;
135  }
136 
137  unset($this->sigslots[$signal][$index]);
138  }
139  else
140  {
141  unset($this->sigslots[$signal]);
142  }
143  }
hasHandlers($signal)
Returns TRUE there are slots subscribed for a specified signal.
Definition: Signal.php:161
getCallbackHash($callback)
Generates a MD5 hash based on a given callback.
Definition: Signal.php:80

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