EventDispatcherInterface.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 $eventName The event to listen on
  38. * @param callable $listener The listener
  39. * @param integer $priority The higher this value, the earlier an event
  40. * listener will be triggered in the chain (defaults to 0)
  41. *
  42. * @api
  43. */
  44. function addListener($eventName, $listener, $priority = 0);
  45. /**
  46. * Adds an event subscriber. The subscriber is asked for all the events he is
  47. * interested in and added as a listener for these events.
  48. *
  49. * @param EventSubscriberInterface $subscriber The subscriber.
  50. * @param integer $priority The higher this value, the earlier an event
  51. * listener will be triggered in the chain.
  52. * Defaults to 0.
  53. */
  54. function addSubscriber(EventSubscriberInterface $subscriber, $priority = 0);
  55. /**
  56. * Removes an event listener from the specified events.
  57. *
  58. * @param string|array $eventNames The event(s) to remove a listener from.
  59. * @param object $listener The listener object to remove.
  60. */
  61. function removeListener($eventNames, $listener);
  62. /**
  63. * Removes an event subscriber.
  64. *
  65. * @param EventSubscriberInterface $subscriber The subscriber.
  66. */
  67. function removeSubscriber(EventSubscriberInterface $subscriber);
  68. /**
  69. * Gets the listeners of a specific event or all listeners.
  70. *
  71. * @param string $eventName The name of the event.
  72. *
  73. * @return array The event listeners for the specified event, or all event
  74. * listeners by event name.
  75. *
  76. * @api
  77. */
  78. function getListeners($eventName = null);
  79. /**
  80. * Checks whether an event has any registered listeners.
  81. *
  82. * @param string $eventName The name of the event.
  83. *
  84. * @return Boolean TRUE if the specified event has any listeners, FALSE
  85. * otherwise.
  86. *
  87. * @api
  88. */
  89. function hasListeners($eventName = null);
  90. }