1
0

IEventDispatcher.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCP\EventDispatcher;
  25. /**
  26. * Event dispatcher service of Nextcloud
  27. *
  28. * @since 17.0.0
  29. */
  30. interface IEventDispatcher {
  31. /**
  32. * @param string $eventName preferably the fully-qualified class name of the Event sub class
  33. * @param callable $listener the object that is invoked when a matching event is dispatched
  34. * @param int $priority
  35. *
  36. * @since 17.0.0
  37. */
  38. public function addListener(string $eventName, callable $listener, int $priority = 0): void;
  39. /**
  40. * @param string $eventName preferably the fully-qualified class name of the Event sub class to listen for
  41. * @param string $className fully qualified class name (or ::class notation) of a \OCP\EventDispatcher\IEventListener that can be built by the DI container
  42. * @param int $priority
  43. *
  44. * @since 17.0.0
  45. */
  46. public function addServiceListener(string $eventName, string $className, int $priority = 0): void;
  47. /**
  48. * @param string $eventName
  49. * @param Event $event
  50. *
  51. * @since 17.0.0
  52. */
  53. public function dispatch(string $eventName, Event $event): void;
  54. /**
  55. * Dispatch a typed event
  56. *
  57. * Only use this with subclasses of ``\OCP\EventDispatcher\Event``.
  58. * The object's class will determine the event name.
  59. *
  60. * @param Event $event
  61. *
  62. * @since 18.0.0
  63. */
  64. public function dispatchTyped(Event $event): void;
  65. }