mirror of https://github.com/nextcloud/server
feat(OCM): Dispatch an event so apps can register resources
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
fc445a2eaa
commit
21e7a82e64
|
@ -537,6 +537,7 @@ return array(
|
|||
'OCP\\Notification\\IManager' => $baseDir . '/lib/public/Notification/IManager.php',
|
||||
'OCP\\Notification\\INotification' => $baseDir . '/lib/public/Notification/INotification.php',
|
||||
'OCP\\Notification\\INotifier' => $baseDir . '/lib/public/Notification/INotifier.php',
|
||||
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => $baseDir . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
|
||||
'OCP\\OCM\\Exceptions\\OCMArgumentException' => $baseDir . '/lib/public/OCM/Exceptions/OCMArgumentException.php',
|
||||
'OCP\\OCM\\Exceptions\\OCMProviderException' => $baseDir . '/lib/public/OCM/Exceptions/OCMProviderException.php',
|
||||
'OCP\\OCM\\IOCMDiscoveryService' => $baseDir . '/lib/public/OCM/IOCMDiscoveryService.php',
|
||||
|
|
|
@ -570,6 +570,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'OCP\\Notification\\IManager' => __DIR__ . '/../../..' . '/lib/public/Notification/IManager.php',
|
||||
'OCP\\Notification\\INotification' => __DIR__ . '/../../..' . '/lib/public/Notification/INotification.php',
|
||||
'OCP\\Notification\\INotifier' => __DIR__ . '/../../..' . '/lib/public/Notification/INotifier.php',
|
||||
'OCP\\OCM\\Events\\ResourceTypeRegisterEvent' => __DIR__ . '/../../..' . '/lib/public/OCM/Events/ResourceTypeRegisterEvent.php',
|
||||
'OCP\\OCM\\Exceptions\\OCMArgumentException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMArgumentException.php',
|
||||
'OCP\\OCM\\Exceptions\\OCMProviderException' => __DIR__ . '/../../..' . '/lib/public/OCM/Exceptions/OCMProviderException.php',
|
||||
'OCP\\OCM\\IOCMDiscoveryService' => __DIR__ . '/../../..' . '/lib/public/OCM/IOCMDiscoveryService.php',
|
||||
|
|
|
@ -26,6 +26,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace OC\OCM\Model;
|
||||
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\OCM\Events\ResourceTypeRegisterEvent;
|
||||
use OCP\OCM\Exceptions\OCMArgumentException;
|
||||
use OCP\OCM\Exceptions\OCMProviderException;
|
||||
use OCP\OCM\IOCMProvider;
|
||||
|
@ -41,6 +43,13 @@ class OCMProvider implements IOCMProvider {
|
|||
/** @var IOCMResource[] */
|
||||
private array $resourceTypes = [];
|
||||
|
||||
private bool $emittedEvent = false;
|
||||
|
||||
public function __construct(
|
||||
protected IEventDispatcher $dispatcher,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $enabled
|
||||
*
|
||||
|
@ -129,6 +138,12 @@ class OCMProvider implements IOCMProvider {
|
|||
* @return IOCMResource[]
|
||||
*/
|
||||
public function getResourceTypes(): array {
|
||||
if (!$this->emittedEvent) {
|
||||
$this->emittedEvent = true;
|
||||
$event = new ResourceTypeRegisterEvent($this);
|
||||
$this->dispatcher->dispatchTyped($event);
|
||||
}
|
||||
|
||||
return $this->resourceTypes;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* @copyright Copyright (c) 2023 Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @author Joas Schilling <coding@schilljs.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCP\OCM\Events;
|
||||
|
||||
use OCP\EventDispatcher\Event;
|
||||
use OCP\OCM\IOCMProvider;
|
||||
|
||||
/**
|
||||
* Use this event to register additional OCM resources before the API returns
|
||||
* them in the OCM provider list and capability
|
||||
*
|
||||
* @since 28.0.0
|
||||
*/
|
||||
class ResourceTypeRegisterEvent extends Event {
|
||||
/**
|
||||
* @param IOCMProvider $provider
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function __construct(
|
||||
protected IOCMProvider $provider,
|
||||
) {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param list<string> $shareTypes List of supported share recipients, e.g. 'user', 'group', …
|
||||
* @param array<string, string> $protocols List of supported protocols and their location,
|
||||
* e.g. ['webdav' => '/remote.php/webdav/']
|
||||
* @since 28.0.0
|
||||
*/
|
||||
public function registerResourceType(string $name, array $shareTypes, array $protocols): void {
|
||||
$resourceType = $this->provider->createNewResourceType();
|
||||
$resourceType->setName($name)
|
||||
->setShareTypes($shareTypes)
|
||||
->setProtocols($protocols);
|
||||
$this->provider->addResourceType($resourceType);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue