Manager.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
  4. *
  5. * @author Georg Ehrke <oc.list@georgehrke.com>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  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
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace OC\Calendar\Room;
  24. use OCP\Calendar\Room\IBackend;
  25. class Manager implements \OCP\Calendar\Room\IManager {
  26. /** @var IBackend[] holds all registered resource backends */
  27. private $backends = [];
  28. /**
  29. * Registers a resource backend
  30. *
  31. * @param IBackend $backend
  32. * @return void
  33. * @since 14.0.0
  34. */
  35. public function registerBackend(IBackend $backend) {
  36. $this->backends[$backend->getBackendIdentifier()] = $backend;
  37. }
  38. /**
  39. * Unregisters a resource backend
  40. *
  41. * @param IBackend $backend
  42. * @return void
  43. * @since 14.0.0
  44. */
  45. public function unregisterBackend(IBackend $backend) {
  46. unset($this->backends[$backend->getBackendIdentifier()]);
  47. }
  48. /**
  49. * @return IBackend[]
  50. * @since 14.0.0
  51. */
  52. public function getBackends():array {
  53. return array_values($this->backends);
  54. }
  55. /**
  56. * @param string $backendId
  57. * @return IBackend|null
  58. */
  59. public function getBackend($backendId):IBackend {
  60. if (!isset($this->backends[$backendId])) {
  61. return null;
  62. }
  63. return $this->backends[$backendId];
  64. }
  65. /**
  66. * removes all registered backend instances
  67. * @return void
  68. * @since 14.0.0
  69. */
  70. public function clear() {
  71. $this->backends = [];
  72. }
  73. }