SystemTagsEntityEvent.php 2.3 KB

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