1
0

CommentsEntityEvent.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCP\Comments;
  8. use OCP\EventDispatcher\Event;
  9. /**
  10. * Class CommentsEntityEvent
  11. *
  12. * @since 9.1.0
  13. * @since 28.0.0 Dispatched as a typed event
  14. */
  15. class CommentsEntityEvent extends Event {
  16. /**
  17. * @since 9.1.0
  18. * @deprecated 22.0.0 - Listen to the typed event instead.
  19. */
  20. public const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
  21. /** @var \Closure[] */
  22. protected $collections;
  23. /**
  24. * DispatcherEvent constructor.
  25. *
  26. * @since 9.1.0
  27. */
  28. public function __construct() {
  29. parent::__construct();
  30. $this->collections = [];
  31. }
  32. /**
  33. * @param string $name
  34. * @param \Closure $entityExistsFunction The closure should take one
  35. * argument, which is the id of the entity, that comments
  36. * should be handled for. The return should then be bool,
  37. * depending on whether comments are allowed (true) or not.
  38. * @throws \OutOfBoundsException when the entity name is already taken
  39. * @since 9.1.0
  40. */
  41. public function addEntityCollection($name, \Closure $entityExistsFunction) {
  42. if (isset($this->collections[$name])) {
  43. throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
  44. }
  45. $this->collections[$name] = $entityExistsFunction;
  46. }
  47. /**
  48. * @return \Closure[]
  49. * @since 9.1.0
  50. */
  51. public function getEntityCollections() {
  52. return $this->collections;
  53. }
  54. }