EventDispatcherInterface.php 2.2 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 int $priority The higher this value, the earlier an event
  25. * listener will be triggered in the chain (defaults to 0)
  26. *
  27. * @return void
  28. */
  29. public function addListener(string $eventName, callable $listener, int $priority = 0);
  30. /**
  31. * Adds an event subscriber.
  32. *
  33. * The subscriber is asked for all the events it is
  34. * interested in and added as a listener for these events.
  35. *
  36. * @return void
  37. */
  38. public function addSubscriber(EventSubscriberInterface $subscriber);
  39. /**
  40. * Removes an event listener from the specified events.
  41. *
  42. * @return void
  43. */
  44. public function removeListener(string $eventName, callable $listener);
  45. /**
  46. * @return void
  47. */
  48. public function removeSubscriber(EventSubscriberInterface $subscriber);
  49. /**
  50. * Gets the listeners of a specific event or all listeners sorted by descending priority.
  51. *
  52. * @return array<callable[]|callable>
  53. */
  54. public function getListeners(?string $eventName = null): array;
  55. /**
  56. * Gets the listener priority for a specific event.
  57. *
  58. * Returns null if the event or the listener does not exist.
  59. */
  60. public function getListenerPriority(string $eventName, callable $listener): ?int;
  61. /**
  62. * Checks whether an event has any registered listeners.
  63. */
  64. public function hasListeners(?string $eventName = null): bool;
  65. }