HookManager.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\Encryption;
  8. use OCA\Encryption\Hooks\Contracts\IHook;
  9. class HookManager {
  10. /** @var IHook[] */
  11. private $hookInstances = [];
  12. /**
  13. * @param array|IHook $instances
  14. * - This accepts either a single instance of IHook or an array of instances of IHook
  15. * @return bool
  16. */
  17. public function registerHook($instances) {
  18. if (is_array($instances)) {
  19. foreach ($instances as $instance) {
  20. if (!$instance instanceof IHook) {
  21. return false;
  22. }
  23. $this->hookInstances[] = $instance;
  24. }
  25. } elseif ($instances instanceof IHook) {
  26. $this->hookInstances[] = $instances;
  27. }
  28. return true;
  29. }
  30. public function fireHooks() {
  31. foreach ($this->hookInstances as $instance) {
  32. /**
  33. * Fire off the add hooks method of each instance stored in cache
  34. */
  35. $instance->addHooks();
  36. }
  37. }
  38. }