summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-12-03 15:51:58 +0100
committerJulius Härtl <jus@bitgrid.net>2020-12-09 13:20:23 +0100
commitfdea545415f63c9b3dba8af9badb698f4d23e670 (patch)
treef13c9720192ad112ba295efa8e4a948d4d0eda41 /lib
parentf3184238407d30a95dfb69ab5e68ec68a2d4d3e6 (diff)
downloadnextcloud-server-fdea545415f63c9b3dba8af9badb698f4d23e670.tar.gz
nextcloud-server-fdea545415f63c9b3dba8af9badb698f4d23e670.zip
Allow apps to register their share providers from outside
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Share20/Manager.php4
-rw-r--r--lib/private/Share20/ProviderFactory.php23
-rw-r--r--lib/public/Share/IManager.php6
-rw-r--r--lib/public/Share/IProviderFactory.php6
4 files changed, 39 insertions, 0 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index e9895edf95a..9f2d885f4fb 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -1887,6 +1887,10 @@ class Manager implements IManager {
return true;
}
+ public function registerShareProvider(string $shareProviderClass): void {
+ $this->factory->registerProvider($shareProviderClass);
+ }
+
public function getAllShares(): iterable {
$providers = $this->factory->getAllProviders();
diff --git a/lib/private/Share20/ProviderFactory.php b/lib/private/Share20/ProviderFactory.php
index 2d4c4e6d40a..933125c10b4 100644
--- a/lib/private/Share20/ProviderFactory.php
+++ b/lib/private/Share20/ProviderFactory.php
@@ -44,6 +44,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer;
use OCP\Share\IProviderFactory;
use OCP\Share\IShare;
+use OCP\Share\IShareProvider;
/**
* Class ProviderFactory
@@ -67,6 +68,10 @@ class ProviderFactory implements IProviderFactory {
/** @var \OCA\Talk\Share\RoomShareProvider */
private $roomShareProvider = null;
+ private $registeredShareProviders = [];
+
+ private $shareProviders = [];
+
/**
* IProviderFactory constructor.
*
@@ -76,6 +81,10 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer = $serverContainer;
}
+ public function registerProvider(string $shareProviderClass): void {
+ $this->registeredShareProviders[] = $shareProviderClass;
+ }
+
/**
* Create the default share provider.
*
@@ -257,6 +266,10 @@ class ProviderFactory implements IProviderFactory {
*/
public function getProvider($id) {
$provider = null;
+ if (isset($this->shareProviders[$id])) {
+ return $this->shareProviders[$id];
+ }
+
if ($id === 'ocinternal') {
$provider = $this->defaultShareProvider();
} elseif ($id === 'ocFederatedSharing') {
@@ -269,6 +282,16 @@ class ProviderFactory implements IProviderFactory {
$provider = $this->getRoomShareProvider();
}
+ foreach ($this->registeredShareProviders as $shareProvider) {
+ /** @var IShareProvider $instance */
+ $instance = $this->serverContainer->get($shareProvider);
+ $this->shareProviders[$instance->identifier()] = $instance;
+ }
+
+ if (isset($this->shareProviders[$id])) {
+ $provider = $this->shareProviders[$id];
+ }
+
if ($provider === null) {
throw new ProviderException('No provider with id .' . $id . ' found.');
}
diff --git a/lib/public/Share/IManager.php b/lib/public/Share/IManager.php
index cc2ec45cc9f..635ccc1483d 100644
--- a/lib/public/Share/IManager.php
+++ b/lib/public/Share/IManager.php
@@ -417,6 +417,12 @@ interface IManager {
public function shareProviderExists($shareType);
/**
+ * @param string $shareProviderClass
+ * @since 21.0.0
+ */
+ public function registerShareProvider(string $shareProviderClass): void;
+
+ /**
* @Internal
*
* Get all the shares as iterable to reduce memory overhead
diff --git a/lib/public/Share/IProviderFactory.php b/lib/public/Share/IProviderFactory.php
index 27218497e53..480837404f0 100644
--- a/lib/public/Share/IProviderFactory.php
+++ b/lib/public/Share/IProviderFactory.php
@@ -53,4 +53,10 @@ interface IProviderFactory {
* @since 11.0.0
*/
public function getAllProviders();
+
+ /**
+ * @since 21.0.0
+ * @param string $shareProvier
+ */
+ public function registerProvider(string $shareProvier): void;
}