aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
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
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')
-rw-r--r--lib/private/AppFramework/Bootstrap/RegistrationContext.php52
-rw-r--r--lib/private/Calendar/Resource/Manager.php45
-rw-r--r--lib/private/Calendar/Room/Manager.php55
3 files changed, 130 insertions, 22 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
index 401a967c988..b40d3356d1a 100644
--- a/lib/private/AppFramework/Bootstrap/RegistrationContext.php
+++ b/lib/private/AppFramework/Bootstrap/RegistrationContext.php
@@ -30,6 +30,8 @@ declare(strict_types=1);
namespace OC\AppFramework\Bootstrap;
use Closure;
+use OCP\Calendar\Resource\IBackend as IResourceBackend;
+use OCP\Calendar\Room\IBackend as IRoomBackend;
use OCP\Talk\ITalkBackend;
use RuntimeException;
use function array_shift;
@@ -70,6 +72,12 @@ class RegistrationContext {
/** @var null|ServiceRegistration<ITalkBackend> */
private $talkBackendRegistration = null;
+ /** @var ServiceRegistration<IResourceBackend>[] */
+ private $calendarResourceBackendRegistrations = [];
+
+ /** @var ServiceRegistration<IRoomBackend>[] */
+ private $calendarRoomBackendRegistrations = [];
+
/** @var ServiceFactoryRegistration[] */
private $services = [];
@@ -271,6 +279,20 @@ class RegistrationContext {
$backend
);
}
+
+ public function registerCalendarResourceBackend(string $class): void {
+ $this->context->registerCalendarResourceBackend(
+ $this->appId,
+ $class
+ );
+ }
+
+ public function registerCalendarRoomBackend(string $class): void {
+ $this->context->registerCalendarRoomBackend(
+ $this->appId,
+ $class
+ );
+ }
};
}
@@ -376,6 +398,20 @@ class RegistrationContext {
$this->talkBackendRegistration = new ServiceRegistration($appId, $backend);
}
+ public function registerCalendarResourceBackend(string $appId, string $class) {
+ $this->calendarResourceBackendRegistrations[] = new ServiceRegistration(
+ $appId,
+ $class,
+ );
+ }
+
+ public function registerCalendarRoomBackend(string $appId, string $class) {
+ $this->calendarRoomBackendRegistrations[] = new ServiceRegistration(
+ $appId,
+ $class,
+ );
+ }
+
/**
* @param App[] $apps
*/
@@ -635,4 +671,20 @@ class RegistrationContext {
public function getTalkBackendRegistration(): ?ServiceRegistration {
return $this->talkBackendRegistration;
}
+
+ /**
+ * @return ServiceRegistration[]
+ * @psalm-return ServiceRegistration<IResourceBackend>[]
+ */
+ public function getCalendarResourceBackendRegistrations(): array {
+ return $this->calendarResourceBackendRegistrations;
+ }
+
+ /**
+ * @return ServiceRegistration[]
+ * @psalm-return ServiceRegistration<IRoomBackend>[]
+ */
+ public function getCalendarRoomBackendRegistrations(): array {
+ return $this->calendarRoomBackendRegistrations;
+ }
}
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);
}