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.

EventDispatcher.php 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2019 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. namespace OC\EventDispatcher;
  24. use OCP\EventDispatcher\Event;
  25. use OCP\EventDispatcher\IEventDispatcher;
  26. use OCP\IContainer;
  27. use OCP\ILogger;
  28. use OCP\IServerContainer;
  29. use Symfony\Component\EventDispatcher\EventDispatcher as SymfonyDispatcher;
  30. class EventDispatcher implements IEventDispatcher {
  31. /** @var SymfonyDispatcher */
  32. private $dispatcher;
  33. /** @var IContainer */
  34. private $container;
  35. /** @var ILogger */
  36. private $logger;
  37. public function __construct(SymfonyDispatcher $dispatcher,
  38. IServerContainer $container,
  39. ILogger $logger) {
  40. $this->dispatcher = $dispatcher;
  41. $this->container = $container;
  42. $this->logger = $logger;
  43. }
  44. public function addListener(string $eventName,
  45. callable $listener,
  46. int $priority = 0): void {
  47. $this->dispatcher->addListener($eventName, $listener, $priority);
  48. }
  49. public function addServiceListener(string $eventName,
  50. string $className,
  51. int $priority = 0): void {
  52. $listener = new ServiceEventListener(
  53. $this->container,
  54. $className,
  55. $this->logger
  56. );
  57. $this->addListener($eventName, $listener, $priority);
  58. }
  59. public function dispatch(string $eventName,
  60. Event $event): void {
  61. $this->dispatcher->dispatch($eventName, $event);
  62. }
  63. /**
  64. * @return SymfonyDispatcher
  65. */
  66. public function getSymfonyDispatcher(): SymfonyDispatcher {
  67. return $this->dispatcher;
  68. }
  69. }