diff options
author | Christoph Wurst <christoph@winzerhof-wurst.at> | 2021-12-20 17:58:54 +0100 |
---|---|---|
committer | Christoph Wurst <christoph@winzerhof-wurst.at> | 2022-02-04 08:53:18 +0100 |
commit | 2c356d085236ba17367f25998953b61368078fcd (patch) | |
tree | 5dea9ee6937915d06a2e1989009efdda7adb2656 /lib/private/AppFramework/Bootstrap/RegistrationContext.php | |
parent | eb1927040f8e059bd0a291f4a9db41b2ef48acf2 (diff) | |
download | nextcloud-server-2c356d085236ba17367f25998953b61368078fcd.tar.gz nextcloud-server-2c356d085236ba17367f25998953b61368078fcd.zip |
Add a Talk API for OCP
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/AppFramework/Bootstrap/RegistrationContext.php')
-rw-r--r-- | lib/private/AppFramework/Bootstrap/RegistrationContext.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/private/AppFramework/Bootstrap/RegistrationContext.php b/lib/private/AppFramework/Bootstrap/RegistrationContext.php index 6a9073b576b..401a967c988 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\Talk\ITalkBackend; +use RuntimeException; use function array_shift; use OC\Support\CrashReport\Registry; use OCP\AppFramework\App; @@ -65,6 +67,9 @@ class RegistrationContext { /** @var ServiceRegistration<ILinkAction>[] */ private $profileLinkActions = []; + /** @var null|ServiceRegistration<ITalkBackend> */ + private $talkBackendRegistration = null; + /** @var ServiceFactoryRegistration[] */ private $services = []; @@ -259,6 +264,13 @@ class RegistrationContext { $actionClass ); } + + public function registerTalkBackend(string $backend): void { + $this->context->registerTalkBackend( + $this->appId, + $backend + ); + } }; } @@ -350,6 +362,21 @@ class RegistrationContext { } /** + * @psalm-param class-string<ITalkBackend> $backend + */ + public function registerTalkBackend(string $appId, string $backend) { + // Some safeguards for invalid registrations + if ($appId !== 'spreed') { + throw new RuntimeException("Only the Talk app is allowed to register a Talk backend"); + } + if ($this->talkBackendRegistration !== null) { + throw new RuntimeException("There can only be one Talk backend"); + } + + $this->talkBackendRegistration = new ServiceRegistration($appId, $backend); + } + + /** * @param App[] $apps */ public function delegateCapabilityRegistrations(array $apps): void { @@ -600,4 +627,12 @@ class RegistrationContext { public function getProfileLinkActions(): array { return $this->profileLinkActions; } + + /** + * @return ServiceRegistration|null + * @psalm-return ServiceRegistration<ITalkBackend>|null + */ + public function getTalkBackendRegistration(): ?ServiceRegistration { + return $this->talkBackendRegistration; + } } |