EventDispatcherInterface.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. public function addSubscriber(EventSubscriberInterface $subscriber);
  48. /**
  49. * Removes an event listener from the specified events.
  50. *
  51. * @param string $eventName The event to remove a listener from
  52. * @param callable $listener The listener to remove
  53. */
  54. public function removeListener($eventName, $listener);
  55. public function removeSubscriber(EventSubscriberInterface $subscriber);
  56. /**
  57. * Gets the listeners of a specific event or all listeners sorted by descending priority.
  58. *
  59. * @param string $eventName The name of the event
  60. *
  61. * @return array The event listeners for the specified event, or all event listeners by event name
  62. */
  63. public function getListeners($eventName = null);
  64. /**
  65. * Checks whether an event has any registered listeners.
  66. *
  67. * @param string $eventName The name of the event
  68. *
  69. * @return bool true if the specified event has any listeners, false otherwise
  70. */
  71. public function hasListeners($eventName = null);
  72. }