Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CommentsEntityEvent.php 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. *
  7. * @license AGPL-3.0
  8. *
  9. * This code is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License, version 3,
  11. * as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License, version 3,
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>
  20. *
  21. */
  22. namespace OCP\Comments;
  23. use Symfony\Component\EventDispatcher\Event;
  24. /**
  25. * Class CommentsEntityEvent
  26. *
  27. * @package OCP\Comments
  28. * @since 9.1.0
  29. */
  30. class CommentsEntityEvent extends Event {
  31. const EVENT_ENTITY = 'OCP\Comments\ICommentsManager::registerEntity';
  32. /** @var string */
  33. protected $event;
  34. /** @var \Closure[] */
  35. protected $collections;
  36. /**
  37. * DispatcherEvent constructor.
  38. *
  39. * @param string $event
  40. * @since 9.1.0
  41. */
  42. public function __construct($event) {
  43. $this->event = $event;
  44. $this->collections = [];
  45. }
  46. /**
  47. * @param string $name
  48. * @param \Closure $entityExistsFunction The closure should take one
  49. * argument, which is the id of the entity, that comments
  50. * should be handled for. The return should then be bool,
  51. * depending on whether comments are allowed (true) or not.
  52. * @throws \OutOfBoundsException when the entity name is already taken
  53. * @since 9.1.0
  54. */
  55. public function addEntityCollection($name, \Closure $entityExistsFunction) {
  56. if (isset($this->collections[$name])) {
  57. throw new \OutOfBoundsException('Duplicate entity name "' . $name . '"');
  58. }
  59. $this->collections[$name] = $entityExistsFunction;
  60. }
  61. /**
  62. * @return \Closure[]
  63. * @since 9.1.0
  64. */
  65. public function getEntityCollections() {
  66. return $this->collections;
  67. }
  68. }