Allow apps to register their share providers from outside

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-12-03 15:51:58 +01:00
parent f318423840
commit fdea545415
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
4 changed files with 39 additions and 0 deletions

View File

@ -1887,6 +1887,10 @@ class Manager implements IManager {
return true; return true;
} }
public function registerShareProvider(string $shareProviderClass): void {
$this->factory->registerProvider($shareProviderClass);
}
public function getAllShares(): iterable { public function getAllShares(): iterable {
$providers = $this->factory->getAllProviders(); $providers = $this->factory->getAllProviders();

View File

@ -44,6 +44,7 @@ use OCP\EventDispatcher\IEventDispatcher;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\Share\IProviderFactory; use OCP\Share\IProviderFactory;
use OCP\Share\IShare; use OCP\Share\IShare;
use OCP\Share\IShareProvider;
/** /**
* Class ProviderFactory * Class ProviderFactory
@ -67,6 +68,10 @@ class ProviderFactory implements IProviderFactory {
/** @var \OCA\Talk\Share\RoomShareProvider */ /** @var \OCA\Talk\Share\RoomShareProvider */
private $roomShareProvider = null; private $roomShareProvider = null;
private $registeredShareProviders = [];
private $shareProviders = [];
/** /**
* IProviderFactory constructor. * IProviderFactory constructor.
* *
@ -76,6 +81,10 @@ class ProviderFactory implements IProviderFactory {
$this->serverContainer = $serverContainer; $this->serverContainer = $serverContainer;
} }
public function registerProvider(string $shareProviderClass): void {
$this->registeredShareProviders[] = $shareProviderClass;
}
/** /**
* Create the default share provider. * Create the default share provider.
* *
@ -257,6 +266,10 @@ class ProviderFactory implements IProviderFactory {
*/ */
public function getProvider($id) { public function getProvider($id) {
$provider = null; $provider = null;
if (isset($this->shareProviders[$id])) {
return $this->shareProviders[$id];
}
if ($id === 'ocinternal') { if ($id === 'ocinternal') {
$provider = $this->defaultShareProvider(); $provider = $this->defaultShareProvider();
} elseif ($id === 'ocFederatedSharing') { } elseif ($id === 'ocFederatedSharing') {
@ -269,6 +282,16 @@ class ProviderFactory implements IProviderFactory {
$provider = $this->getRoomShareProvider(); $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) { if ($provider === null) {
throw new ProviderException('No provider with id .' . $id . ' found.'); throw new ProviderException('No provider with id .' . $id . ' found.');
} }

View File

@ -416,6 +416,12 @@ interface IManager {
*/ */
public function shareProviderExists($shareType); public function shareProviderExists($shareType);
/**
* @param string $shareProviderClass
* @since 21.0.0
*/
public function registerShareProvider(string $shareProviderClass): void;
/** /**
* @Internal * @Internal
* *

View File

@ -53,4 +53,10 @@ interface IProviderFactory {
* @since 11.0.0 * @since 11.0.0
*/ */
public function getAllProviders(); public function getAllProviders();
/**
* @since 21.0.0
* @param string $shareProvier
*/
public function registerProvider(string $shareProvier): void;
} }