Source for file EventTrigger.abstract.php

Documentation is available at EventTrigger.abstract.php

  1. <?php
  2. /**
  3. * @since Jul 18, 2005
  4. * @package harmoni.architecture.events
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: EventTrigger.abstract.php,v 1.3 2007/09/04 20:25:30 adamfranco Exp $
  10. */
  11.  
  12. require_once(HARMONI."/Primitives/Objects/SObject.class.php");
  13.  
  14. /**
  15. * The event trigger is an abstract class which handles the aggregation of {@link EventListener}s and can trigger events.
  16. *
  17. * @since Jul 18, 2005
  18. * @package harmoni.architecture.events
  19. *
  20. * @copyright Copyright &copy; 2005, Middlebury College
  21. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  22. *
  23. * @version $Id: EventTrigger.abstract.php,v 1.3 2007/09/04 20:25:30 adamfranco Exp $
  24. * @abstract
  25. */
  26. class EventTrigger extends SObject {
  27. /**
  28. * @var array $_eventListeners
  29. * @access private
  30. */
  31. var $_eventListeners = array();
  32. /**
  33. * Adds an {@link EventListener} to be triggered whenever an event is thrown.
  34. * @param string $eventType The string event type for which this {@link EventListener} is listening (example: "edu.middlebury.harmoni.action_executed")
  35. * @param ref object $eventListener the {@link EventListener} object.
  36. * @access public
  37. * @return ref object
  38. */
  39. function addEventListener ($eventListener) {
  40. ArgumentValidator::validate($eventListener, HasMethodsValidatorRule::getRule("handleEvent"), true);
  41. // if (!isset($this->_eventListeners[$eventType]) || !is_array($this->_eventListeners[$eventType])) {
  42. // $this->_eventListeners[$eventType] = array();
  43. // }
  44. // $this->_eventListeners[$eventType][] =$eventListener;
  45. $this->_eventListeners[] =$eventListener;
  46. }
  47. /**
  48. * Notifies all of the {@link EventListener}s that have been added that an event has
  49. * occured.
  50. * @param string $eventType The event type string.
  51. * @param ref object $source The source object of this event.
  52. * @param optional array $context An array of contextual parameters for the specific event. The content of the array will depend on the event.
  53. * @access public
  54. * @return void
  55. */
  56. function triggerEvent ($eventType, $source, $context = null) {
  57. // print "event triggered: $eventType<br/>";
  58. // if (isset($this->_eventListeners[$eventType]) && is_array($this->_eventListeners[$eventType])) {
  59. // $list =$this->_eventListeners[$eventType];
  60. // foreach (array_keys($list) as $key) {
  61. // $list[$key]->handleEvent($eventType, $source, $context);
  62. // }
  63. // }
  64. $list =$this->_eventListeners;
  65. foreach (array_keys($list) as $key) {
  66. $list[$key]->handleEvent($eventType, $source, $context);
  67. }
  68. }
  69. }
  70.  
  71. ?>

Documentation generated on Wed, 19 Sep 2007 10:23:03 -0400 by phpDocumentor 1.3.0RC3