Allow apps to register their share providers from outside
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
f318423840
commit
fdea545415
|
@ -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();
|
||||
|
||||
|
|
|
@ -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.');
|
||||
}
|
||||
|
|
|
@ -416,6 +416,12 @@ interface IManager {
|
|||
*/
|
||||
public function shareProviderExists($shareType);
|
||||
|
||||
/**
|
||||
* @param string $shareProviderClass
|
||||
* @since 21.0.0
|
||||
*/
|
||||
public function registerShareProvider(string $shareProviderClass): void;
|
||||
|
||||
/**
|
||||
* @Internal
|
||||
*
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue