Skip to content

Commit

Permalink
feat(dav): Emit a typed event to deprecate OCA\DAV\Connector\Sabre::a…
Browse files Browse the repository at this point in the history
…ddPlugin

Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 11, 2023
1 parent e285d72 commit 8245c21
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 6 deletions.
7 changes: 5 additions & 2 deletions apps/dav/appinfo/v1/webdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
// Turn off output buffering to prevent memory problems
\OC_Util::obEnd();

$dispatcher = \OC::$server->get(\OCP\EventDispatcher\IEventDispatcher::class);

$serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
\OC::$server->getConfig(),
\OC::$server->get(LoggerInterface::class),
Expand All @@ -48,7 +50,7 @@
\OC::$server->getTagManager(),
\OC::$server->getRequest(),
\OC::$server->getPreviewManager(),
\OC::$server->getEventDispatcher(),
$dispatcher,
\OC::$server->getL10N('dav')
);

Expand Down Expand Up @@ -76,10 +78,11 @@
return \OC\Files\Filesystem::getView();
});

$dispatcher = \OC::$server->getEventDispatcher();
// allow setup of additional plugins
$event = new \OCP\SabrePluginEvent($server);
$dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
$event = new \OCA\DAV\Events\SabrePluginAddEvent($server);
$dispatcher->dispatchTyped($event);

// And off we go!
$server->exec();
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@
'OCA\\DAV\\Events\\CardDeletedEvent' => $baseDir . '/../lib/Events/CardDeletedEvent.php',
'OCA\\DAV\\Events\\CardMovedEvent' => $baseDir . '/../lib/Events/CardMovedEvent.php',
'OCA\\DAV\\Events\\CardUpdatedEvent' => $baseDir . '/../lib/Events/CardUpdatedEvent.php',
'OCA\\DAV\\Events\\SabrePluginAddEvent' => $baseDir . '/../lib/Events/SabrePluginAddEvent.php',
'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => $baseDir . '/../lib/Events/SabrePluginAuthInitEvent.php',
'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => $baseDir . '/../lib/Events/SubscriptionCreatedEvent.php',
'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => $baseDir . '/../lib/Events/SubscriptionDeletedEvent.php',
Expand Down
1 change: 1 addition & 0 deletions apps/dav/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\Events\\CardDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/CardDeletedEvent.php',
'OCA\\DAV\\Events\\CardMovedEvent' => __DIR__ . '/..' . '/../lib/Events/CardMovedEvent.php',
'OCA\\DAV\\Events\\CardUpdatedEvent' => __DIR__ . '/..' . '/../lib/Events/CardUpdatedEvent.php',
'OCA\\DAV\\Events\\SabrePluginAddEvent' => __DIR__ . '/..' . '/../lib/Events/SabrePluginAddEvent.php',
'OCA\\DAV\\Events\\SabrePluginAuthInitEvent' => __DIR__ . '/..' . '/../lib/Events/SabrePluginAuthInitEvent.php',
'OCA\\DAV\\Events\\SubscriptionCreatedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionCreatedEvent.php',
'OCA\\DAV\\Events\\SubscriptionDeletedEvent' => __DIR__ . '/..' . '/../lib/Events/SubscriptionDeletedEvent.php',
Expand Down
8 changes: 4 additions & 4 deletions apps/dav/lib/Connector/Sabre/ServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
*/
namespace OCA\DAV\Connector\Sabre;

use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Folder;
use OCA\DAV\AppInfo\PluginManager;
use OCA\DAV\DAV\ViewOnlyPlugin;
Expand All @@ -46,7 +47,6 @@
use OCP\SabrePluginEvent;
use Psr\Log\LoggerInterface;
use Sabre\DAV\Auth\Plugin;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class ServerFactory {
private IConfig $config;
Expand All @@ -57,7 +57,7 @@ class ServerFactory {
private ITagManager $tagManager;
private IRequest $request;
private IPreview $previewManager;
private EventDispatcherInterface $eventDispatcher;
private IEventDispatcher $eventDispatcher;
private IL10N $l10n;

public function __construct(
Expand All @@ -69,7 +69,7 @@ public function __construct(
ITagManager $tagManager,
IRequest $request,
IPreview $previewManager,
EventDispatcherInterface $eventDispatcher,
IEventDispatcher $eventDispatcher,
IL10N $l10n
) {
$this->config = $config;
Expand Down Expand Up @@ -199,7 +199,7 @@ public function createServer(string $baseUri,

// Load dav plugins from apps
$event = new SabrePluginEvent($server);
$this->eventDispatcher->dispatch($event);
$this->eventDispatcher->dispatchTyped($event);
$pluginManager = new PluginManager(
\OC::$server,
\OC::$server->getAppManager()
Expand Down
56 changes: 56 additions & 0 deletions apps/dav/lib/Events/SabrePluginAddEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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 OCA\DAV\Events;

use OCP\EventDispatcher\Event;
use Sabre\DAV\Server;

/**
* This event is triggered during the setup of the SabreDAV server to allow the
* registration of additional plugins.
*
* @since 28.0.0
*/
class SabrePluginAddEvent extends Event {

/** @var Server */
private $server;

/**
* @since 28.0.0
*/
public function __construct(Server $server) {
parent::__construct();
$this->server = $server;
}

/**
* @since 28.0.0
*/
public function getServer(): Server {
return $this->server;
}
}

0 comments on commit 8245c21

Please sign in to comment.