]> source.dussan.org Git - nextcloud-server.git/commitdiff
feat(dav): Emit a typed event to deprecate OCA\DAV\Connector\Sabre::addPlugin 39305/head
authorJoas Schilling <coding@schilljs.com>
Tue, 11 Jul 2023 09:50:07 +0000 (11:50 +0200)
committerJoas Schilling <coding@schilljs.com>
Mon, 17 Jul 2023 14:06:15 +0000 (16:06 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/appinfo/v1/publicwebdav.php
apps/dav/appinfo/v1/webdav.php
apps/dav/composer/composer/autoload_classmap.php
apps/dav/composer/composer/autoload_static.php
apps/dav/lib/Connector/Sabre/ServerFactory.php
apps/dav/lib/Events/SabrePluginAddEvent.php [new file with mode: 0644]
apps/dav/lib/Server.php
apps/dav/tests/unit/Connector/Sabre/RequestTest/RequestTestCase.php

index 5530fc2cc7d31372ff17fb832679a4dffe90baff..8ca9c6c577c9cdee8742d8ae009bedda26ac79a8 100644 (file)
@@ -51,6 +51,9 @@ $authBackend = new OCA\DAV\Connector\PublicAuth(
 );
 $authPlugin = new \Sabre\DAV\Auth\Plugin($authBackend);
 
+/** @var IEventDispatcher $eventDispatcher */
+$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
+
 $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
        \OC::$server->getConfig(),
        \OC::$server->get(LoggerInterface::class),
@@ -60,7 +63,7 @@ $serverFactory = new OCA\DAV\Connector\Sabre\ServerFactory(
        \OC::$server->getTagManager(),
        \OC::$server->getRequest(),
        \OC::$server->getPreviewManager(),
-       \OC::$server->getEventDispatcher(),
+       $eventDispatcher,
        \OC::$server->getL10N('dav')
 );
 
@@ -115,8 +118,6 @@ $server->addPlugin($linkCheckPlugin);
 $server->addPlugin($filesDropPlugin);
 // allow setup of additional plugins
 $event = new BeforeSabrePubliclyLoadedEvent($server);
-/** @var IEventDispatcher $eventDispatcher */
-$eventDispatcher = \OC::$server->get(IEventDispatcher::class);
 $eventDispatcher->dispatchTyped($event);
 
 // And off we go!
index 8dbe846f3ffbd63cba62d82b04e4bedf84de35aa..7c6a3fc77a6e6f02053bb6ecc14050e09159f250 100644 (file)
@@ -39,6 +39,8 @@ ignore_user_abort(true);
 // 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),
@@ -48,7 +50,7 @@ $serverFactory = new \OCA\DAV\Connector\Sabre\ServerFactory(
        \OC::$server->getTagManager(),
        \OC::$server->getRequest(),
        \OC::$server->getPreviewManager(),
-       \OC::$server->getEventDispatcher(),
+       $dispatcher,
        \OC::$server->getL10N('dav')
 );
 
@@ -76,10 +78,11 @@ $server = $serverFactory->createServer($baseuri, $requestUri, $authPlugin, funct
        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();
index 13b9356f587c0b76b7347fa1bdf3e5f5a8c50e6d..6d41801728b5896c736d486f7f36f1013872321a 100644 (file)
@@ -233,6 +233,7 @@ return array(
     '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',
index e2b7e905dfed9149f66a279f807711ccff8aff1a..600397c371e1a92a5c30ee67129e93385ce0767a 100644 (file)
@@ -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',
index 4c57f3412e3f9f0312f9435a0e51ad1349c0666f..d0cc8aab5d01df45316c68b001e6749e1c8f8daa 100644 (file)
@@ -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;
@@ -46,7 +47,6 @@ use OCP\IUserSession;
 use OCP\SabrePluginEvent;
 use Psr\Log\LoggerInterface;
 use Sabre\DAV\Auth\Plugin;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 
 class ServerFactory {
        private IConfig $config;
@@ -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(
@@ -69,7 +69,7 @@ class ServerFactory {
                ITagManager $tagManager,
                IRequest $request,
                IPreview $previewManager,
-               EventDispatcherInterface $eventDispatcher,
+               IEventDispatcher $eventDispatcher,
                IL10N $l10n
        ) {
                $this->config = $config;
@@ -199,7 +199,7 @@ class ServerFactory {
 
                        // 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()
diff --git a/apps/dav/lib/Events/SabrePluginAddEvent.php b/apps/dav/lib/Events/SabrePluginAddEvent.php
new file mode 100644 (file)
index 0000000..3bff756
--- /dev/null
@@ -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;
+       }
+}
index 909bcaa71e8f98ae69beae644395701c60dadb57..47cb9e3ec360aa1ce186556355a0e8ae8542e4b6 100644 (file)
@@ -64,6 +64,7 @@ use OCA\DAV\Connector\Sabre\TagsPlugin;
 use OCA\DAV\DAV\CustomPropertiesBackend;
 use OCA\DAV\DAV\PublicAuth;
 use OCA\DAV\DAV\ViewOnlyPlugin;
+use OCA\DAV\Events\SabrePluginAddEvent;
 use OCA\DAV\Events\SabrePluginAuthInitEvent;
 use OCA\DAV\Files\BrowserErrorPagePlugin;
 use OCA\DAV\Files\LazySearchBackend;
@@ -102,9 +103,8 @@ class Server {
                $this->request = $request;
                $this->baseUri = $baseUri;
                $logger = \OC::$server->get(LoggerInterface::class);
-               $dispatcher = \OC::$server->getEventDispatcher();
-               /** @var IEventDispatcher $newDispatcher */
-               $newDispatcher = \OC::$server->query(IEventDispatcher::class);
+               /** @var IEventDispatcher $dispatcher */
+               $dispatcher = \OC::$server->get(IEventDispatcher::class);
 
                $root = new RootCollection();
                $this->server = new \OCA\DAV\Connector\Sabre\Server(new CachingTree($root));
@@ -139,7 +139,7 @@ class Server {
                $dispatcher->dispatch('OCA\DAV\Connector\Sabre::authInit', $event);
 
                $newAuthEvent = new SabrePluginAuthInitEvent($this->server);
-               $newDispatcher->dispatchTyped($newAuthEvent);
+               $dispatcher->dispatchTyped($newAuthEvent);
 
                $bearerAuthBackend = new BearerAuth(
                        \OC::$server->getUserSession(),
@@ -223,6 +223,8 @@ class Server {
 
                // allow setup of additional plugins
                $dispatcher->dispatch('OCA\DAV\Connector\Sabre::addPlugin', $event);
+               $typedEvent = new SabrePluginAddEvent($this->server);
+               $dispatcher->dispatchTyped($typedEvent);
 
                // Some WebDAV clients do require Class 2 WebDAV support (locking), since
                // we do not provide locking we emulate it using a fake locking plugin.
index f6aa79eb6c4b6ee17cf0c7c219863c8248ef8dcb..c4f8c21eae1861f97810080bc3f063601475dad8 100644 (file)
@@ -31,6 +31,7 @@ namespace OCA\DAV\Tests\unit\Connector\Sabre\RequestTest;
 use OC\Files\View;
 use OCA\DAV\Connector\Sabre\Server;
 use OCA\DAV\Connector\Sabre\ServerFactory;
+use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IRequest;
 use Psr\Log\LoggerInterface;
 use Sabre\HTTP\Request;
@@ -70,7 +71,7 @@ abstract class RequestTestCase extends TestCase {
                                ->disableOriginalConstructor()
                                ->getMock(),
                        \OC::$server->getPreviewManager(),
-                       \OC::$server->getEventDispatcher(),
+                       \OC::$server->get(IEventDispatcher::class),
                        \OC::$server->getL10N('dav')
                );
        }