hookmanager.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Clark Tomlinson <fallen013@gmail.com>
  5. *
  6. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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 OCA\Encryption;
  23. use OCA\Encryption\Hooks\Contracts\IHook;
  24. class HookManager {
  25. private $hookInstances = [];
  26. /**
  27. * @param array|IHook $instances
  28. * - This accepts either a single instance of IHook or an array of instances of IHook
  29. * @return bool
  30. */
  31. public function registerHook($instances) {
  32. if (is_array($instances)) {
  33. foreach ($instances as $instance) {
  34. if (!$instance instanceof IHook) {
  35. return false;
  36. }
  37. $this->hookInstances[] = $instance;
  38. }
  39. } elseif ($instances instanceof IHook) {
  40. $this->hookInstances[] = $instances;
  41. }
  42. return true;
  43. }
  44. /**
  45. *
  46. */
  47. public function fireHooks() {
  48. foreach ($this->hookInstances as $instance) {
  49. /**
  50. * Fire off the add hooks method of each instance stored in cache
  51. *
  52. * @var $instance IHook
  53. */
  54. $instance->addHooks();
  55. }
  56. }
  57. }