1
0

CommentsEntityEvent.php 2.2 KB

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