events_dispatcher.class.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. *
  4. * Entry point for every event in the application.
  5. * Fires the functions linked to the events according to the event's conf.
  6. * Every function got its own filter, it's fired inside the functiones fired
  7. * by this class. The filter config is next to the event config, in conf/events.conf.php
  8. *
  9. */
  10. class EventsDispatcher
  11. {
  12. public static function events($event_name, $event_data = array())
  13. {
  14. global $event_config;
  15. // get the config for the event passed in parameter ($event_name)
  16. // and execute every actions with the values
  17. foreach ($event_config[$event_name]["actions"] as $func) {
  18. $execute = true;
  19. if (!function_exists($func)) // if the function doesn't exist, we log
  20. {
  21. error_log("EventsDispatcher warning : ".$func." does not exist.");
  22. $execute = false;
  23. }
  24. // check if the event's got a filter
  25. if (function_exists($event_name."_".$func."_filter_func"))
  26. {
  27. $filter = $event_name."_".$func."_filter_func";
  28. // if it does, we execute the filter (which changes the data
  29. // in-place and returns true on success or false on error)
  30. $execute = $filter($event_data);
  31. }
  32. else // if there's no filter
  33. {
  34. error_log("EventsDispatcher warning : ".$event_name."_".$func."_filter_func does not exist.");
  35. }
  36. if (!$execute) // if the filter says we cannot send the mail, we get out of here
  37. {
  38. return false;
  39. }
  40. // finally, if the filter says yes (or the filter doesn't exist),
  41. // we execute the in-between function that will call the needed
  42. // function
  43. $func($event_name, $event_data);
  44. }
  45. }
  46. }