diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-10-08 17:00:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-08 17:00:50 +0200 |
commit | fe2a60082334f53d75411bd8c05928778afadc04 (patch) | |
tree | 0a4bcffd54c1f37ffb1a127e4a1314dc20fc1287 /lib | |
parent | 8110a3be699bbdea96df30472dce7862e0964901 (diff) | |
parent | 970242b6ca79a0dbb1ac1a868c7b82c7aa49bd8a (diff) | |
download | nextcloud-server-fe2a60082334f53d75411bd8c05928778afadc04.tar.gz nextcloud-server-fe2a60082334f53d75411bd8c05928778afadc04.zip |
Merge pull request #10839 from nextcloud/bugfix/10212/use_class_implementation
adjust Calendar resource / room interfaces to use class implementation
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Calendar/Resource/Manager.php | 54 | ||||
-rw-r--r-- | lib/private/Calendar/Room/Manager.php | 54 | ||||
-rw-r--r-- | lib/public/Calendar/Resource/IManager.php | 12 | ||||
-rw-r--r-- | lib/public/Calendar/Room/IManager.php | 12 |
4 files changed, 96 insertions, 36 deletions
diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php index baa8117e85a..224ca2a4390 100644 --- a/lib/private/Calendar/Resource/Manager.php +++ b/lib/private/Calendar/Resource/Manager.php @@ -24,52 +24,81 @@ namespace OC\Calendar\Resource; use OCP\Calendar\Resource\IBackend; +use OCP\IServerContainer; class Manager implements \OCP\Calendar\Resource\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var IServerContainer */ + private $server; + + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + + /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + /** * 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] = $this->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 +108,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..d73b52cfb16 100644 --- a/lib/private/Calendar/Room/Manager.php +++ b/lib/private/Calendar/Room/Manager.php @@ -24,52 +24,81 @@ namespace OC\Calendar\Room; use OCP\Calendar\Room\IBackend; +use OCP\IServerContainer; class Manager implements \OCP\Calendar\Room\IManager { - /** @var IBackend[] holds all registered resource backends */ + /** @var IServerContainer */ + private $server; + + /** @var string[] holds all registered resource backends */ private $backends = []; + /** @var IBackend[] holds all backends that have been initialized already */ + private $initializedBackends = []; + + /** + * Manager constructor. + * + * @param IServerContainer $server + */ + public function __construct(IServerContainer $server) { + $this->server = $server; + } + /** * 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] = $this->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 +108,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 |