Skip to content

Commit 2301a1e

Browse files
author
Carl Schwan
committed
refactor: Use modern SabrePluginAddEvent
Signed-off-by: Carl Schwan <[email protected]>
1 parent 7ad50e5 commit 2301a1e

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

lib/AppInfo/Application.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Exception;
1111
use OC\Files\Filesystem;
12+
use OCA\DAV\Events\SabrePluginAddEvent;
1213
use OCA\Registration\Events\PassedFormEvent;
1314
use OCA\Registration\Events\ShowFormEvent;
1415
use OCA\Registration\Events\ValidateFormEvent;
@@ -30,7 +31,6 @@
3031
use OCP\IUser;
3132
use OCP\IUserSession;
3233
use OCP\Notification\IManager;
33-
use OCP\SabrePluginEvent;
3434
use OCP\User\Events\UserDeletedEvent;
3535
use OCP\User\Events\UserFirstTimeLoggedInEvent;
3636
use OCP\Util;
@@ -61,16 +61,14 @@ public function boot(IBootContext $context): void {
6161
Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
6262

6363
$eventDispatcher = $context->getServerContainer()->get(IEventDispatcher::class);
64-
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event) use ($context): void {
64+
$eventDispatcher->addListener(SabrePluginAddEvent::class, function (SabrePluginAddEvent $event) use ($context): void {
6565
$eventServer = $event->getServer();
6666

67-
if ($eventServer !== null) {
68-
// We have to register the CheckPlugin here and not info.xml,
69-
// because info.xml plugins are loaded, after the
70-
// beforeMethod:* hook has already been emitted.
71-
$plugin = $context->getAppContainer()->get(CheckPlugin::class);
72-
$eventServer->addPlugin($plugin);
73-
}
67+
// We have to register the CheckPlugin here and not info.xml,
68+
// because info.xml plugins are loaded, after the
69+
// beforeMethod:* hook has already been emitted.
70+
$plugin = $context->getAppContainer()->get(CheckPlugin::class);
71+
$eventServer->addPlugin($plugin);
7472
});
7573

7674
$context->injectFn($this->registerNotifier(...));
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)