1
0

IEventDispatcher.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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
  69. * @psalm-param string|class-string<T> $eventName
  70. * @param Event $event
  71. * @psalm-param T $event
  72. *
  73. * @since 17.0.0
  74. * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTyped
  75. */
  76. public function dispatch(string $eventName, Event $event): void;
  77. /**
  78. * Dispatch a typed event
  79. *
  80. * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
  81. * The object's class will determine the event name.
  82. *
  83. * @param Event $event
  84. *
  85. * @since 18.0.0
  86. */
  87. public function dispatchTyped(Event $event): void;
  88. }