SystemTagsEntityEvent.php 2.2 KB

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