EventDispatcherInterface.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. * @return Event
  32. *
  33. * @api
  34. */
  35. public function dispatch($eventName, Event $event = null);
  36. /**
  37. * Adds an event listener that listens on the specified events.
  38. *
  39. * @param string $eventName The event to listen on
  40. * @param callable $listener The listener
  41. * @param integer $priority The higher this value, the earlier an event
  42. * listener will be triggered in the chain (defaults to 0)
  43. *
  44. * @api
  45. */
  46. public function addListener($eventName, $listener, $priority = 0);
  47. /**
  48. * Adds an event subscriber.
  49. *
  50. * The subscriber is asked for all the events he is
  51. * interested in and added as a listener for these events.
  52. *
  53. * @param EventSubscriberInterface $subscriber The subscriber.
  54. *
  55. * @api
  56. */
  57. public function addSubscriber(EventSubscriberInterface $subscriber);
  58. /**
  59. * Removes an event listener from the specified events.
  60. *
  61. * @param string|array $eventName The event(s) to remove a listener from
  62. * @param callable $listener The listener to remove
  63. */
  64. public function removeListener($eventName, $listener);
  65. /**
  66. * Removes an event subscriber.
  67. *
  68. * @param EventSubscriberInterface $subscriber The subscriber
  69. */
  70. public function removeSubscriber(EventSubscriberInterface $subscriber);
  71. /**
  72. * Gets the listeners of a specific event or all listeners.
  73. *
  74. * @param string $eventName The name of the event
  75. *
  76. * @return array The event listeners for the specified event, or all event listeners by event name
  77. */
  78. public 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 otherwise
  85. */
  86. public function hasListeners($eventName = null);
  87. }