CommentsEntityEvent.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  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, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCP\Comments;
  25. use OCP\EventDispatcher\Event;
  26. /**
  27. * Class CommentsEntityEvent
  28. *
  29. * @since 9.1.0
  30. * @since 28.0.0 Dispatched as a typed event
  31. */
  32. class CommentsEntityEvent extends Event {
  33. /**
  34. * @since 9.1.0
  35. * @deprecated 22.0.0 - Listen to the typed event instead.
  36. */
  37. public const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
  38. /** @var \Closure[] */
  39. protected $collections;
  40. /**
  41. * DispatcherEvent constructor.
  42. *
  43. * @since 9.1.0
  44. */
  45. public function __construct() {
  46. parent::__construct();
  47. $this->collections = [];
  48. }
  49. /**
  50. * @param string $name
  51. * @param \Closure $entityExistsFunction The closure should take one
  52. * argument, which is the id of the entity, that comments
  53. * should be handled for. The return should then be bool,
  54. * depending on whether comments are allowed (true) or not.
  55. * @throws \OutOfBoundsException when the entity name is already taken
  56. * @since 9.1.0
  57. */
  58. public function addEntityCollection($name, \Closure $entityExistsFunction) {
  59. if (isset($this->collections[$name])) {
  60. throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
  61. }
  62. $this->collections[$name] = $entityExistsFunction;
  63. }
  64. /**
  65. * @return \Closure[]
  66. * @since 9.1.0
  67. */
  68. public function getEntityCollections() {
  69. return $this->collections;
  70. }
  71. }