summaryrefslogtreecommitdiffstats
path: root/lib/private/Calendar
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2022-02-04 11:13:50 +0100
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-02-07 12:51:42 +0100
commit9a656e5b35d004b55fbe09d10d51254a8ec4fd67 (patch)
treeed1dd47a11822744820866ef2b5a5fc3e7dedeb9 /lib/private/Calendar
parentbb55b79837a677074473e980a6b88d358a118621 (diff)
downloadnextcloud-server-9a656e5b35d004b55fbe09d10d51254a8ec4fd67.tar.gz
nextcloud-server-9a656e5b35d004b55fbe09d10d51254a8ec4fd67.zip
Move calendar resource/room backend registration to IBootstrap
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Calendar')
-rw-r--r--lib/private/Calendar/Resource/Manager.php45
-rw-r--r--lib/private/Calendar/Room/Manager.php55
2 files changed, 78 insertions, 22 deletions
diff --git a/lib/private/Calendar/Resource/Manager.php b/lib/private/Calendar/Resource/Manager.php
index 935541d9c87..ebde4ac5eb5 100644
--- a/lib/private/Calendar/Resource/Manager.php
+++ b/lib/private/Calendar/Resource/Manager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -24,26 +27,30 @@
*/
namespace OC\Calendar\Resource;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Calendar\Resource\IBackend;
+use OCP\Calendar\Resource\IManager;
use OCP\IServerContainer;
-class Manager implements \OCP\Calendar\Resource\IManager {
+class Manager implements IManager {
+ private Coordinator $bootstrapCoordinator;
- /** @var IServerContainer */
- private $server;
+ private IServerContainer $server;
- /** @var string[] holds all registered resource backends */
+ private bool $bootstrapBackendsLoaded = false;
+
+ /**
+ * @var string[] holds all registered resource backends
+ * @psalm-var class-string<IBackend>[]
+ */
private $backends = [];
/** @var IBackend[] holds all backends that have been initialized already */
private $initializedBackends = [];
- /**
- * Manager constructor.
- *
- * @param IServerContainer $server
- */
- public function __construct(IServerContainer $server) {
+ public function __construct(Coordinator $bootstrapCoordinator,
+ IServerContainer $server) {
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
$this->server = $server;
}
@@ -69,12 +76,30 @@ class Manager implements \OCP\Calendar\Resource\IManager {
unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
}
+ private function fetchBootstrapBackends(): void {
+ if ($this->bootstrapBackendsLoaded) {
+ return;
+ }
+
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+ if ($context === null) {
+ // Too soon
+ return;
+ }
+
+ foreach ($context->getCalendarResourceBackendRegistrations() as $registration) {
+ $this->backends[] = $registration->getService();
+ }
+ }
+
/**
* @return IBackend[]
* @throws \OCP\AppFramework\QueryException
* @since 14.0.0
*/
public function getBackends():array {
+ $this->fetchBootstrapBackends();
+
foreach ($this->backends as $backend) {
if (isset($this->initializedBackends[$backend])) {
continue;
diff --git a/lib/private/Calendar/Room/Manager.php b/lib/private/Calendar/Room/Manager.php
index 25db5197ef2..7e6af2823a3 100644
--- a/lib/private/Calendar/Room/Manager.php
+++ b/lib/private/Calendar/Room/Manager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -24,26 +27,30 @@
*/
namespace OC\Calendar\Room;
+use OC\AppFramework\Bootstrap\Coordinator;
use OCP\Calendar\Room\IBackend;
+use OCP\Calendar\Room\IManager;
use OCP\IServerContainer;
-class Manager implements \OCP\Calendar\Room\IManager {
+class Manager implements IManager {
+ private Coordinator $bootstrapCoordinator;
- /** @var IServerContainer */
- private $server;
+ private IServerContainer $server;
- /** @var string[] holds all registered resource backends */
- private $backends = [];
-
- /** @var IBackend[] holds all backends that have been initialized already */
- private $initializedBackends = [];
+ private bool $bootstrapBackendsLoaded = false;
/**
- * Manager constructor.
- *
- * @param IServerContainer $server
+ * @var string[] holds all registered resource backends
+ * @psalm-var class-string<IBackend>[]
*/
- public function __construct(IServerContainer $server) {
+ private array $backends = [];
+
+ /** @var IBackend[] holds all backends that have been initialized already */
+ private array $initializedBackends = [];
+
+ public function __construct(Coordinator $bootstrapCoordinator,
+ IServerContainer $server) {
+ $this->bootstrapCoordinator = $bootstrapCoordinator;
$this->server = $server;
}
@@ -69,17 +76,41 @@ class Manager implements \OCP\Calendar\Room\IManager {
unset($this->backends[$backendClass], $this->initializedBackends[$backendClass]);
}
+ private function fetchBootstrapBackends(): void {
+ if ($this->bootstrapBackendsLoaded) {
+ return;
+ }
+
+ $context = $this->bootstrapCoordinator->getRegistrationContext();
+ if ($context === null) {
+ // Too soon
+ return;
+ }
+
+ foreach ($context->getCalendarRoomBackendRegistrations() as $registration) {
+ $this->backends[] = $registration->getService();
+ }
+ }
+
/**
* @return IBackend[]
* @throws \OCP\AppFramework\QueryException
* @since 14.0.0
*/
public function getBackends():array {
+ $this->fetchBootstrapBackends();
+
foreach ($this->backends as $backend) {
if (isset($this->initializedBackends[$backend])) {
continue;
}
+ /**
+ * @todo fetch from the app container
+ *
+ * The backend might have services injected that can't be build from the
+ * server container.
+ */
$this->initializedBackends[$backend] = $this->server->query($backend);
}