return self::$eventHandler;
}
+ public static function bind($bot, $type, $method) {
+ if(is_a($bot, "Bot") && method_exists($bot, $method)) {
+ if(array_key_exists($type, self::$bindings)) {
+ foreach(self::$bindings[$type] as $binding) {
+ if($binding->match($bot, $method))
+ return;
+ }
+ } else
+ self::$bindings[$type] = array();
+ self::$bindings[$type][] = new Binding($bot, $method);
+ }
+ }
+
+ public static function unbind($bot, $type, $method) {
+ if(is_a($bot, "Bot")) {
+ if(array_key_exists($type, self::$bindings)) {
+ foreach(self::$bindings[$type] as $id => $binding) {
+ if($binding->match($bot, $method)) {
+ unset(self::$bindings[$type][$id]);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ public static function unbindBot($bot) {
+ if(is_a($bot, "Bot")) {
+ foreach(self::$bindings as $type => $bindings) {
+ foreach($bindings as $id => $binding) {
+ if($binding->match($bot, null)) {
+ unset(self::$bindings[$type][$id]);
+ }
+ }
+ }
+ }
+ }
+
/********************************************************************************************
* EVENT HANDLER *
********************************************************************************************/
private function event($type, $parameters) {
if(array_key_exists($type, self::$bindings)) {
- foreach(self::$bindings as $binding) {
- $binding->trigger();
+ foreach(self::$bindings[$type] as $binding) {
+ $binding->trigger($parameters);
}
}
}