diff options
author | Georg Ehrke <developer@georgehrke.com> | 2018-08-24 16:21:04 +0300 |
---|---|---|
committer | Georg Ehrke <developer@georgehrke.com> | 2018-10-08 02:25:20 +0300 |
commit | 1c6f666bbfc46b9092312c81f82a5e0cbe59fc18 (patch) | |
tree | ecb9d6ae2662d28b167574d2533f7917c7c2e20e /lib | |
parent | 4c47ec005f31e10b55af1bec277c6c0d011e4c28 (diff) |
adjust Calendar resource / room interfaces to use class implementation
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Calendar/Resource/Manager.php | 41 | ||||
-rw-r--r-- | lib/private/Calendar/Room/Manager.php | 41 | ||||
-rw-r--r-- | lib/public/Calendar/Resource/IManager.php | 12 | ||||
-rw-r--r-- | lib/public/Calendar/Room/IManager.php | 12 |
4 files changed, 70 insertions, 36 deletions
diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php index baa8117e85a..04ef69d69ea 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -27,49 +27,65 @@ use OCP\Calendar\Resource\IBackend; class Manager implements \OCP\Calendar\Resource\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend) { - $this->backends[$backend->getBackendIdentifier()] = $backend; + public function registerBackend(string $backendClass) { + $this->backends[$backendClass] = $backendClass; } /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend) { - unset($this->backends[$backend->getBackendIdentifier()]); + public function unregisterBackend(string $backendClass) { + unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]); } /** * @return IBackend[] + * @throws \OCP\AppFramework\QueryException * @since 14.0.0 */ public function getBackends():array { - return array_values($this->backends); + foreach($this->backends as $backend) { + if (isset($this->initializedBackends[$backend])) { + continue; + } + + $this->initializedBackends[$backend] = \OC::$server->query($backend); + } + + return array_values($this->initializedBackends); } /** * @param string $backendId + * @throws \OCP\AppFramework\QueryException * @return IBackend|null */ - public function getBackend($backendId):IBackend { - if (!isset($this->backends[$backendId])) { - return null; + public function getBackend($backendId) { + $backends = $this->getBackends(); + foreach($backends as $backend) { + if ($backend->getBackendIdentifier() === $backendId) { + return $backend; + } } - return $this->backends[$backendId]; + return null; } /** @@ -79,5 +95,6 @@ class Manager implements \OCP\Calendar\Resource\IManager { */ public function clear() { $this->backends = []; + $this->initializedBackends = []; } } diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php index aef9f2ed32b..8664149549d 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -27,49 +27,65 @@ use OCP\Calendar\Room\IBackend; class Manager implements \OCP\Calendar\Room\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend) { - $this->backends[$backend->getBackendIdentifier()] = $backend; + public function registerBackend(string $backendClass) { + $this->backends[$backendClass] = $backendClass; } /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend) { - unset($this->backends[$backend->getBackendIdentifier()]); + public function unregisterBackend(string $backendClass) { + unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]); } /** * @return IBackend[] + * @throws \OCP\AppFramework\QueryException * @since 14.0.0 */ public function getBackends():array { - return array_values($this->backends); + foreach($this->backends as $backend) { + if (isset($this->initializedBackends[$backend])) { + continue; + } + + $this->initializedBackends[$backend] = \OC::$server->query($backend); + } + + return array_values($this->initializedBackends); } /** * @param string $backendId + * @throws \OCP\AppFramework\QueryException * @return IBackend|null */ - public function getBackend($backendId):IBackend { - if (!isset($this->backends[$backendId])) { - return null; + public function getBackend($backendId) { + $backends = $this->getBackends(); + foreach($backends as $backend) { + if ($backend->getBackendIdentifier() === $backendId) { + return $backend; + } } - return $this->backends[$backendId]; + return null; } /** @@ -79,5 +95,6 @@ class Manager implements \OCP\Calendar\Room\IManager { */ public function clear() { $this->backends = []; + $this->initializedBackends = []; } } diff --git a/lib/public/Calendar/Resource/IManager.php b/lib/public/Calendar/Resource/IManager.php index 8542e13eba7..b59cb6c797a 100644 --- a/lib/public/Calendar/Resource/IManager.php +++ b/lib/public/Calendar/Resource/IManager.php @@ -34,20 +34,20 @@ interface IManager { /** * Registers a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend); + public function registerBackend(string $backendClass); /** * Unregisters a resource backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend); + public function unregisterBackend(string $backendClass); /** * @return IBackend[] @@ -57,10 +57,10 @@ interface IManager { /** * @param string $backendId - * @return IBackend + * @return IBackend|null * @since 14.0.0 */ - public function getBackend($backendId):IBackend; + public function getBackend($backendId); /** * removes all registered backend instances diff --git a/lib/public/Calendar/Room/IManager.php b/lib/public/Calendar/Room/IManager.php index 39e85c43e45..9aa61aa3f66 100644 --- a/lib/public/Calendar/Room/IManager.php +++ b/lib/public/Calendar/Room/IManager.php @@ -34,20 +34,20 @@ interface IManager { /** * Registers a room backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function registerBackend(IBackend $backend); + public function registerBackend(string $backendClass); /** * Unregisters a room backend * - * @param IBackend $backend + * @param string $backendClass * @return void * @since 14.0.0 */ - public function unregisterBackend(IBackend $backend); + public function unregisterBackend(string $backendClass); /** * @return IBackend[] @@ -57,10 +57,10 @@ interface IManager { /** * @param string $backendId - * @return IBackend + * @return IBackend|null * @since 14.0.0 */ - public function getBackend($backendId):IBackend; + public function getBackend($backendId); /** * removes all registered backend instances |