0
class CmsEventOperations extends CmsObject
0
private static $handlercache;
0
+ private static $instance = null;
0
+ //arrays to handle "on the fly" event handlers
0
+ //either before or after the actual calls to the stored handlers
0
+ public static $before_temp_calls = null;
0
+ public static $after_temp_calls = null;
0
+ function __construct()
0
+ parent::__construct();
0
+ * Get an instance of this object, though most people should be using
0
+ * the static methods instead. This is more for compatibility than
0
+ * @return CmsUserTagOperations The instance of the singleton object.
0
+ static public function get_instance()
0
+ if (self::$instance == NULL)
0
+ self::$instance = new CmsEventOperations();
0
+ return self::$instance;
0
* Inform the system about a new event that can be generated
0
@@ -100,9 +129,17 @@ class CmsEventOperations extends CmsObject
0
public static function send_event( $modulename, $eventname, $params = array() )
0
- //var_dump("Sending $eventname on $modulename");
0
- //$usertagops =& $gCms->GetUserTagOperations();
0
+ //Send "before" temp handlers
0
+ if (self::$before_temp_calls != null)
0
+ if (isset(self::$before_temp_calls[$modulename][$eventname]))
0
+ foreach (self::$before_temp_calls[$modulename][$eventname] as &$one_method)
0
+ call_user_func_array($one_method, $params);
0
$results = self::list_event_handlers($modulename, $eventname);
0
@@ -125,7 +162,7 @@ class CmsEventOperations extends CmsObject
0
// and call the module event handler.
0
- $obj =
& CmsModule::get_module_instance($row['module_name']);
0
+ $obj =
CmsModule::get_module_instance($row['module_name']);
0
debug_buffer('calling module ' . $row['module_name'] . ' from event ' . $eventname);
0
@@ -134,6 +171,18 @@ class CmsEventOperations extends CmsObject
0
+ //Send "after" temp handlers
0
+ if (self::$after_temp_calls != null)
0
+ if (isset(self::$after_temp_calls[$modulename][$eventname]))
0
+ foreach (self::$after_temp_calls[$modulename][$eventname] as &$one_method)
0
+ call_user_func_array($one_method, $params);
0
@@ -252,6 +301,35 @@ class CmsEventOperations extends CmsObject
0
return self::add_event_handler( $modulename, $eventname, $tag_name, $module_handler, $removable );
0
+ * Add an event handler "on the fly" for a module event. This means that
0
+ * it only lasts for the duration of the request.
0
+ * @param string $module_name The name of the module sending the event
0
+ * @param string $event_name The name of the event
0
+ * @param array $method The callback method. This should be in the standard array($object, $method) structure
0
+ * @param boolean $before_calls Do we call this before or after the stored handlers? Defaults to false (after)
0
+ public static function add_temp_event_handler($module_name, $event_name, $method, $before_calls = false)
0
+ if (self::$before_temp_calls == null)
0
+ self::$before_temp_calls = array();
0
+ self::$before_temp_calls[$module_name][$event_name][] = $method;
0
+ if (self::$after_temp_calls == null)
0
+ self::$after_temp_calls = array();
0
+ self::$after_temp_calls[$module_name][$event_name][] = $method;
0
* Remove an event handler for a particular event
Comments
No one has commented yet.