IEventDispatcher.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. namespace OCP\EventDispatcher;
  26. /**
  27. * Event dispatcher service of Nextcloud
  28. *
  29. * @since 17.0.0
  30. */
  31. interface IEventDispatcher {
  32. /**
  33. * @template T of \OCP\EventDispatcher\Event
  34. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  35. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
  36. * @param callable $listener the object that is invoked when a matching event is dispatched
  37. * @psalm-param callable(T):void $listener
  38. * @param int $priority The higher this value, the earlier an event
  39. * listener will be triggered in the chain (defaults to 0)
  40. *
  41. * @since 17.0.0
  42. */
  43. public function addListener(string $eventName, callable $listener, int $priority = 0): void;
  44. /**
  45. * @template T of \OCP\EventDispatcher\Event
  46. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  47. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
  48. * @param callable $listener the object that is invoked when a matching event is dispatched
  49. * @psalm-param callable(T):void $listener
  50. *
  51. * @since 19.0.0
  52. */
  53. public function removeListener(string $eventName, callable $listener): void;
  54. /**
  55. * @template T of \OCP\EventDispatcher\Event
  56. * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
  57. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class to listen for
  58. * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
  59. * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $className fully qualified class name that can be built by the DI container
  60. * @param int $priority The higher this value, the earlier an event
  61. * listener will be triggered in the chain (defaults to 0)
  62. *
  63. * @since 17.0.0
  64. */
  65. public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
  66. /**
  67. * @template T of \OCP\EventDispatcher\Event
  68. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  69. *
  70. * @return bool TRUE if event has registered listeners
  71. * @since 29.0.0
  72. */
  73. public function hasListeners(string $eventName): bool;
  74. /**
  75. * @template T of \OCP\EventDispatcher\Event
  76. * @param string $eventName
  77. * @psalm-param string|class-string<T> $eventName
  78. * @param Event $event
  79. * @psalm-param T $event
  80. *
  81. * @since 17.0.0
  82. * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTyped
  83. */
  84. public function dispatch(string $eventName, Event $event): void;
  85. /**
  86. * Dispatch a typed event
  87. *
  88. * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
  89. * The object's class will determine the event name.
  90. *
  91. * @param Event $event
  92. *
  93. * @since 18.0.0
  94. */
  95. public function dispatchTyped(Event $event): void;
  96. }