$callable, 'param' => $param, ); } /** * Run triggered actions on specific event * * @param $event string Hook event name * @param $event_data mixed Hook event data (optional, default: null) * * @return boolean True if all triggered actions succefully runned, false otherwise */ public static function trigger($event_name, $event_data=null) { $return = true; if (isset(self :: $hooks[$event_name]) && is_array(self :: $hooks[$event_name])) { if ($event_name == 'all') $event = new HookEvent($event_data['event_name'], $event_data['event_data']); else $event = new HookEvent($event_name, $event_data); foreach (self :: $hooks[$event_name] as $e) { if (is_callable($e['callable'])) { try { call_user_func_array($e['callable'],array($event, &$e['param'])); } catch(Exception $e) { Log :: exception( $e, "An exception occured running hook ".format_callable($e['callable']). " on event $event_name"); $return = false; } } else { Log :: error( "The hook ".format_callable($e['callable'])." on event $event_name is not callable."); $return = false; } } } else Log :: debug("No hook registered for event $event_name."); // Handle 'all' event if ($event_name != 'all') { self :: trigger ( 'all', array ( 'event_name' => $event_name, 'event_data' => $event_data, ) ); } return $return; } } # vim: tabstop=2 shiftwidth=2 softtabstop=2 expandtab