EventDispatcherInterface.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface as ContractsEventDispatcherInterface;
  12. /**
  13. * The EventDispatcherInterface is the central point of Symfony's event listener system.
  14. * Listeners are registered on the manager and events are dispatched through the
  15. * manager.
  16. *
  17. * @author Bernhard Schussek <bschussek@gmail.com>
  18. */
  19. interface EventDispatcherInterface extends ContractsEventDispatcherInterface
  20. {
  21. /**
  22. * Adds an event listener that listens on the specified events.
  23. *
  24. * @param callable $listener The listener
  25. * @param int $priority The higher this value, the earlier an event
  26. * listener will be triggered in the chain (defaults to 0)
  27. */
  28. public function addListener(string $eventName, $listener, int $priority = 0);
  29. /**
  30. * Adds an event subscriber.
  31. *
  32. * The subscriber is asked for all the events it is
  33. * interested in and added as a listener for these events.
  34. */
  35. public function addSubscriber(EventSubscriberInterface $subscriber);
  36. /**
  37. * Removes an event listener from the specified events.
  38. *
  39. * @param callable $listener The listener to remove
  40. */
  41. public function removeListener(string $eventName, $listener);
  42. public function removeSubscriber(EventSubscriberInterface $subscriber);
  43. /**
  44. * Gets the listeners of a specific event or all listeners sorted by descending priority.
  45. *
  46. * @return array The event listeners for the specified event, or all event listeners by event name
  47. */
  48. public function getListeners(string $eventName = null);
  49. /**
  50. * Gets the listener priority for a specific event.
  51. *
  52. * Returns null if the event or the listener does not exist.
  53. *
  54. * @param callable $listener The listener
  55. *
  56. * @return int|null The event listener priority
  57. */
  58. public function getListenerPriority(string $eventName, $listener);
  59. /**
  60. * Checks whether an event has any registered listeners.
  61. *
  62. * @return bool true if the specified event has any listeners, false otherwise
  63. */
  64. public function hasListeners(string $eventName = null);
  65. }