EventsService.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Elgg;
  3. use Elgg\Debug\Inspector;
  4. /**
  5. * Service for Events
  6. *
  7. * @access private
  8. *
  9. * @package Elgg.Core
  10. * @subpackage Hooks
  11. * @since 1.9.0
  12. */
  13. class EventsService extends \Elgg\HooksRegistrationService {
  14. const OPTION_STOPPABLE = 'stoppable';
  15. const OPTION_DEPRECATION_MESSAGE = 'deprecation_message';
  16. const OPTION_DEPRECATION_VERSION = 'deprecation_version';
  17. /**
  18. * Triggers an Elgg event.
  19. *
  20. * @see elgg_trigger_event
  21. * @see elgg_trigger_after_event
  22. * @access private
  23. */
  24. public function trigger($event, $type, $object = null, array $options = array()) {
  25. $options = array_merge(array(
  26. self::OPTION_STOPPABLE => true,
  27. self::OPTION_DEPRECATION_MESSAGE => '',
  28. self::OPTION_DEPRECATION_VERSION => '',
  29. ), $options);
  30. $events = $this->hasHandler($event, $type);
  31. if ($events && $options[self::OPTION_DEPRECATION_MESSAGE]) {
  32. elgg_deprecated_notice(
  33. $options[self::OPTION_DEPRECATION_MESSAGE],
  34. $options[self::OPTION_DEPRECATION_VERSION],
  35. 2
  36. );
  37. }
  38. $events = $this->getOrderedHandlers($event, $type);
  39. $args = array($event, $type, $object);
  40. foreach ($events as $callback) {
  41. if (!is_callable($callback)) {
  42. if ($this->logger) {
  43. $inspector = new Inspector();
  44. $this->logger->warn("handler for event [$event, $type] is not callable: "
  45. . $inspector->describeCallable($callback));
  46. }
  47. continue;
  48. }
  49. $return = call_user_func_array($callback, $args);
  50. if (!empty($options[self::OPTION_STOPPABLE]) && ($return === false)) {
  51. return false;
  52. }
  53. }
  54. return true;
  55. }
  56. }