You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.2 KiB

3 years ago
  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. * @param int $priority
  38. *
  39. * @since 17.0.0
  40. */
  41. public function addListener(string $eventName, callable $listener, int $priority = 0): void;
  42. /**
  43. * @template T of \OCP\EventDispatcher\Event
  44. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  45. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class
  46. * @param callable $listener the object that is invoked when a matching event is dispatched
  47. *
  48. * @since 19.0.0
  49. */
  50. public function removeListener(string $eventName, callable $listener): void;
  51. /**
  52. * @template T of \OCP\EventDispatcher\Event
  53. * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
  54. * @psalm-param string|class-string<T> $eventName preferably the fully-qualified class name of the Event sub class to listen for
  55. * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
  56. * @psalm-param class-string<\OCP\EventDispatcher\IEventListener<T>> $className fully qualified class name that can be built by the DI container
  57. * @param int $priority
  58. *
  59. * @since 17.0.0
  60. */
  61. public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
  62. /**
  63. * @template T of \OCP\EventDispatcher\Event
  64. * @param string $eventName
  65. * @psalm-param string|class-string<T> $eventName
  66. * @param Event $event
  67. * @psalm-param T $event
  68. *
  69. * @since 17.0.0
  70. */
  71. public function dispatch(string $eventName, Event $event): void;
  72. /**
  73. * Dispatch a typed event
  74. *
  75. * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
  76. * The object's class will determine the event name.
  77. *
  78. * @param Event $event
  79. *
  80. * @since 18.0.0
  81. */
  82. public function dispatchTyped(Event $event): void;
  83. }