EventDispatcherInterface.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\EventDispatcher;
  11. /**
  12. * The EventDispatcherInterface is the central point of Symfony's event listener system.
  13. * Listeners are registered on the manager and events are dispatched through the
  14. * manager.
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. *
  18. * @api
  19. */
  20. interface EventDispatcherInterface
  21. {
  22. /**
  23. * Dispatches an event to all registered listeners.
  24. *
  25. * @param string $eventName The name of the event to dispatch. The name of
  26. * the event is the name of the method that is
  27. * invoked on listeners.
  28. * @param Event $event The event to pass to the event handlers/listeners.
  29. * If not supplied, an empty Event instance is created.
  30. *
  31. * @api
  32. */
  33. function dispatch($eventName, Event $event = null);
  34. /**
  35. * Adds an event listener that listens on the specified events.
  36. *
  37. * @param string|array $eventNames The event(s) to listen on.
  38. * @param object $listener The listener object.
  39. * @param integer $priority The higher this value, the earlier an event
  40. * listener will be triggered in the chain.
  41. * Defaults to 0.
  42. *
  43. * @api
  44. */
  45. function addListener($eventNames, $listener, $priority = 0);
  46. /**
  47. * Adds an event subscriber. The subscriber is asked for all the events he is
  48. * interested in and added as a listener for these events.
  49. *
  50. * @param EventSubscriberInterface $subscriber The subscriber.
  51. * @param integer $priority The higher this value, the earlier an event
  52. * listener will be triggered in the chain.
  53. * Defaults to 0.
  54. */
  55. function addSubscriber(EventSubscriberInterface $subscriber, $priority = 0);
  56. /**
  57. * Removes an event listener from the specified events.
  58. *
  59. * @param string|array $eventNames The event(s) to remove a listener from.
  60. * @param object $listener The listener object to remove.
  61. */
  62. function removeListener($eventNames, $listener);
  63. /**
  64. * Removes an event subscriber.
  65. *
  66. * @param EventSubscriberInterface $subscriber The subscriber.
  67. */
  68. function removeSubscriber(EventSubscriberInterface $subscriber);
  69. /**
  70. * Gets the listeners of a specific event or all listeners.
  71. *
  72. * @param string $eventName The name of the event.
  73. *
  74. * @return array The event listeners for the specified event, or all event
  75. * listeners by event name.
  76. *
  77. * @api
  78. */
  79. function getListeners($eventName = null);
  80. /**
  81. * Checks whether an event has any registered listeners.
  82. *
  83. * @param string $eventName The name of the event.
  84. *
  85. * @return Boolean TRUE if the specified event has any listeners, FALSE
  86. * otherwise.
  87. *
  88. * @api
  89. */
  90. function hasListeners($eventName = null);
  91. }