Skip to content

Commit 6d2edef

Browse files
authored
Merge pull request #736 from nextcloud/carl/modern-event
refactor: Use modern SabrePluginAddEvent
2 parents b5a0244 + c2ae699 commit 6d2edef

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

lib/AppInfo/Application.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use OCA\AppAPI\Notifications\ExAppNotifier;
2525
use OCA\AppAPI\PublicCapabilities;
2626
use OCA\AppAPI\SetupChecks\DaemonCheck;
27+
use OCA\DAV\Events\SabrePluginAddEvent;
2728
use OCA\DAV\Events\SabrePluginAuthInitEvent;
2829
use OCA\Files\Event\LoadAdditionalScriptsEvent;
2930
use OCP\AppFramework\App;
@@ -32,7 +33,6 @@
3233
use OCP\AppFramework\Bootstrap\IRegistrationContext;
3334
use OCP\EventDispatcher\IEventDispatcher;
3435
use OCP\Navigation\Events\LoadAdditionalEntriesEvent;
35-
use OCP\SabrePluginEvent;
3636
use OCP\Settings\Events\DeclarativeSettingsGetValueEvent;
3737
use OCP\Settings\Events\DeclarativeSettingsRegisterFormEvent;
3838
use OCP\Settings\Events\DeclarativeSettingsSetValueEvent;
@@ -77,9 +77,9 @@ public function boot(IBootContext $context): void {
7777
public function registerDavAuth(): void {
7878
$container = $this->getContainer();
7979

80-
$dispatcher = $container->query(IEventDispatcher::class);
81-
$dispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($container) {
82-
$event->getServer()->addPlugin($container->query(DavPlugin::class));
80+
$dispatcher = $container->get(IEventDispatcher::class);
81+
$dispatcher->addListener(SabrePluginAddEvent::class, function (SabrePluginAddEvent $event) use ($container) {
82+
$event->getServer()->addPlugin($container->get(DavPlugin::class));
8383
});
8484
}
8585
}

psalm.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,7 @@
5454
</errorLevel>
5555
</UndefinedDocblockClass>
5656
</issueHandlers>
57+
<stubs>
58+
<file name="tests/stubs/oca_dav_events_sabrepluginaddevent.php"/>
59+
</stubs>
5760
</psalm>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
namespace OCA\DAV\Events;
10+
11+
use OCP\EventDispatcher\Event;
12+
use Sabre\DAV\Server;
13+
14+
/**
15+
* This event is triggered during the setup of the SabreDAV server to allow the
16+
* registration of additional plugins.
17+
*
18+
* @since 28.0.0
19+
*/
20+
class SabrePluginAddEvent extends Event {
21+
22+
/**
23+
* @since 28.0.0
24+
*/
25+
public function __construct(
26+
private Server $server,
27+
) {
28+
}
29+
30+
/**
31+
* @since 28.0.0
32+
*/
33+
public function getServer(): Server {
34+
}
35+
}

0 commit comments

Comments
 (0)