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.

SystemTagsEntityEvent.php 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2016, ownCloud, Inc.
  5. *
  6. * @author Joas Schilling <coding@schilljs.com>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCP\SystemTag;
  24. use OCP\EventDispatcher\Event;
  25. /**
  26. * Class SystemTagsEntityEvent
  27. *
  28. * @package OCP\SystemTag
  29. * @since 9.1.0
  30. */
  31. class SystemTagsEntityEvent extends Event {
  32. const EVENT_ENTITY = 'OCP\SystemTag\ISystemTagManager::registerEntity';
  33. /** @var string */
  34. protected $event;
  35. /** @var \Closure[] */
  36. protected $collections;
  37. /**
  38. * SystemTagsEntityEvent constructor.
  39. *
  40. * @param string $event
  41. * @since 9.1.0
  42. */
  43. public function __construct(string $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 tags
  51. * should be handled for. The return should then be bool,
  52. * depending on whether tags 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(string $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(): array {
  67. return $this->collections;
  68. }
  69. }