EventDispatcherInterface.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. interface EventDispatcherInterface
  19. {
  20. /**
  21. * Dispatches an event to all registered listeners.
  22. *
  23. * @param string $eventName The name of the event to dispatch. The name of
  24. * the event is the name of the method that is
  25. * invoked on listeners.
  26. * @param Event $event The event to pass to the event handlers/listeners
  27. * If not supplied, an empty Event instance is created.
  28. *
  29. * @return Event
  30. */
  31. public function dispatch($eventName, Event $event = null);
  32. /**
  33. * Adds an event listener that listens on the specified events.
  34. *
  35. * @param string $eventName The event to listen on
  36. * @param callable $listener The listener
  37. * @param int $priority The higher this value, the earlier an event
  38. * listener will be triggered in the chain (defaults to 0)
  39. */
  40. public function addListener($eventName, $listener, $priority = 0);
  41. /**
  42. * Adds an event subscriber.
  43. *
  44. * The subscriber is asked for all the events he is
  45. * interested in and added as a listener for these events.
  46. *
  47. * @param EventSubscriberInterface $subscriber The subscriber
  48. */
  49. public function addSubscriber(EventSubscriberInterface $subscriber);
  50. /**
  51. * Removes an event listener from the specified events.
  52. *
  53. * @param string $eventName The event to remove a listener from
  54. * @param callable $listener The listener to remove
  55. */
  56. public function removeListener($eventName, $listener);
  57. /**
  58. * Removes an event subscriber.
  59. *
  60. * @param EventSubscriberInterface $subscriber The subscriber
  61. */
  62. public function removeSubscriber(EventSubscriberInterface $subscriber);
  63. /**
  64. * Gets the listeners of a specific event or all listeners sorted by descending priority.
  65. *
  66. * @param string $eventName The name of the event
  67. *
  68. * @return array The event listeners for the specified event, or all event listeners by event name
  69. */
  70. public function getListeners($eventName = null);
  71. /**
  72. * Gets the listener priority for a specific event.
  73. *
  74. * Returns null if the event or the listener does not exist.
  75. *
  76. * @param string $eventName The name of the event
  77. * @param callable $listener The listener
  78. *
  79. * @return int|null The event listener priority
  80. */
  81. public function getListenerPriority($eventName, $listener);
  82. /**
  83. * Checks whether an event has any registered listeners.
  84. *
  85. * @param string $eventName The name of the event
  86. *
  87. * @return bool true if the specified event has any listeners, false otherwise
  88. */
  89. public function hasListeners($eventName = null);
  90. }