Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChristoph Wurst <ChristophWurst@users.noreply.github.com>2022-02-09 12:25:03 +0300
committerGitHub <noreply@github.com>2022-02-09 12:25:03 +0300
commitcd7a217c29a38a778aea54827dcecccd254e6f20 (patch)
treef84baaec393b30daa2199a5b2c6fd2b220ec6415 /lib
parentf4c719734a1939b846929a9a8303b26f5b7a3ed6 (diff)
parent9a656e5b35d004b55fbe09d10d51254a8ec4fd67 (diff)
Merge pull request #31007 from nextcloud/enhancement/bootstrap-calendar-resource-room-backend-registration
Move calendar resource/room backend registration to IBootstrap
Diffstat (limited to 'lib')
-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
-rw-r--r--lib/public/AppFramework/Bootstrap/IRegistrationContext.php20
-rw-r--r--lib/public/Calendar/Resource/IManager.php11
-rw-r--r--lib/public/Calendar/Room/IManager.php11
6 files changed, 168 insertions, 26 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);
}
diff --git a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
index 19b5665f547..89583912e00 100644
--- a/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
+++ b/lib/public/AppFramework/Bootstrap/IRegistrationContext.php
@@ -275,4 +275,24 @@ interface IRegistrationContext {
* @since 24.0.0
*/
public function registerTalkBackend(string $backend): void;
+
+ /**
+ * Register a resource backend for the DAV server
+ *
+ * @param string $actionClass
+ * @psalm-param class-string<\OCP\Calendar\Resource\IBackend> $actionClass
+ * @return void
+ * @since 24.0.0
+ */
+ public function registerCalendarResourceBackend(string $class): void;
+
+ /**
+ * Register a room backend for the DAV server
+ *
+ * @param string $actionClass
+ * @psalm-param class-string<\OCP\Calendar\Room\IBackend> $actionClass
+ * @return void
+ * @since 24.0.0
+ */
+ public function registerCalendarRoomBackend(string $class): void;
}
diff --git a/lib/public/Calendar/Resource/IManager.php b/lib/public/Calendar/Resource/IManager.php
index 6910ecb164c..268cf8ec633 100644
--- a/lib/public/Calendar/Resource/IManager.php
+++ b/lib/public/Calendar/Resource/IManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,9 +26,8 @@
namespace OCP\Calendar\Resource;
/**
- * Interface IManager
- *
* @since 14.0.0
+ * @deprecated 24.0.0
*/
interface IManager {
@@ -35,6 +37,7 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0 use \OCP\AppFramework\Bootstrap\IRegistrationContext::registerCalendarResourceBackend
*/
public function registerBackend(string $backendClass);
@@ -44,12 +47,14 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function unregisterBackend(string $backendClass);
/**
* @return IBackend[]
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackends():array;
@@ -57,6 +62,7 @@ interface IManager {
* @param string $backendId
* @return IBackend|null
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackend($backendId);
@@ -64,6 +70,7 @@ interface IManager {
* removes all registered backend instances
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function clear();
}
diff --git a/lib/public/Calendar/Room/IManager.php b/lib/public/Calendar/Room/IManager.php
index 6529ad265b6..c55f3fd4ae4 100644
--- a/lib/public/Calendar/Room/IManager.php
+++ b/lib/public/Calendar/Room/IManager.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2018, Georg Ehrke <oc.list@georgehrke.com>
*
@@ -23,9 +26,8 @@
namespace OCP\Calendar\Room;
/**
- * Interface IManager
- *
* @since 14.0.0
+ * @deprecated 24.0.0
*/
interface IManager {
@@ -35,6 +37,7 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0 use \OC\AppFramework\Bootstrap\::registerCalendarRoomBackend
*/
public function registerBackend(string $backendClass);
@@ -44,12 +47,14 @@ interface IManager {
* @param string $backendClass
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function unregisterBackend(string $backendClass);
/**
* @return IBackend[]
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackends():array;
@@ -57,6 +62,7 @@ interface IManager {
* @param string $backendId
* @return IBackend|null
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function getBackend($backendId);
@@ -64,6 +70,7 @@ interface IManager {
* removes all registered backend instances
* @return void
* @since 14.0.0
+ * @deprecated 24.0.0
*/
public function clear();
}