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.

77 lines
2.1 KiB

3 years ago
  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. */
  31. class CommentsEntityEvent extends Event {
  32. public const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
  33. /** @var string */
  34. protected $event;
  35. /** @var \Closure[] */
  36. protected $collections;
  37. /**
  38. * DispatcherEvent constructor.
  39. *
  40. * @param string $event
  41. * @since 9.1.0
  42. */
  43. public function __construct($event) {
  44. $this->event = $event;
  45. $this->collections = [];
  46. }
  47. /**
  48. * @param string $name
  49. * @param \Closure $entityExistsFunction The closure should take one
  50. * argument, which is the id of the entity, that comments
  51. * should be handled for. The return should then be bool,
  52. * depending on whether comments are allowed (true) or not.
  53. * @throws \OutOfBoundsException when the entity name is already taken
  54. * @since 9.1.0
  55. */
  56. public function addEntityCollection($name, \Closure $entityExistsFunction) {
  57. if (isset($this->collections[$name])) {
  58. throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
  59. }
  60. $this->collections[$name] = $entityExistsFunction;
  61. }
  62. /**
  63. * @return \Closure[]
  64. * @since 9.1.0
  65. */
  66. public function getEntityCollections() {
  67. return $this->collections;
  68. }
  69. }