IEventDispatcher.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\EventDispatcher;
  8. /**
  9. * Event dispatcher service of Nextcloud
  10. *
  11. * @since 17.0.0
  12. */
  13. interface IEventDispatcher {
  14. /**
  15. * @template T of \OCP\EventDispatcher\Event
  16. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  17. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
  18. * @param callable $listener the object that is invoked when a matching event is dispatched
  19. * @psalm-param callable(T):void $listener
  20. * @param int $priority The higher this value, the earlier an event
  21. * listener will be triggered in the chain (defaults to 0)
  22. *
  23. * @since 17.0.0
  24. */
  25. public function addListener(string $eventName, callable $listener, int $priority = 0): void;
  26. /**
  27. * @template T of \OCP\EventDispatcher\Event
  28. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  29. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
  30. * @param callable $listener the object that is invoked when a matching event is dispatched
  31. * @psalm-param callable(T):void $listener
  32. *
  33. * @since 19.0.0
  34. */
  35. public function removeListener(string $eventName, callable $listener): void;
  36. /**
  37. * @template T of \OCP\EventDispatcher\Event
  38. * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
  39. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class to listen for
  40. * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
  41. * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $className fully qualified class name that can be built by the DI container
  42. * @param int $priority The higher this value, the earlier an event
  43. * listener will be triggered in the chain (defaults to 0)
  44. *
  45. * @since 17.0.0
  46. */
  47. public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
  48. /**
  49. * @template T of \OCP\EventDispatcher\Event
  50. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  51. *
  52. * @return bool TRUE if event has registered listeners
  53. * @since 29.0.0
  54. */
  55. public function hasListeners(string $eventName): bool;
  56. /**
  57. * @template T of \OCP\EventDispatcher\Event
  58. * @param string $eventName
  59. * @psalm-param string|class-string<T> $eventName
  60. * @param Event $event
  61. * @psalm-param T $event
  62. *
  63. * @since 17.0.0
  64. * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTyped
  65. */
  66. public function dispatch(string $eventName, Event $event): void;
  67. /**
  68. * Dispatch a typed event
  69. *
  70. * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
  71. * The object's class will determine the event name.
  72. *
  73. * @param Event $event
  74. *
  75. * @since 18.0.0
  76. */
  77. public function dispatchTyped(Event $event): void;
  78. }