Skip to content

Commit 63cfe60

Browse files
author
Carl Schwan
committed
refactor(Application): Use modern SabrePluginAddEvent
Signed-off-by: Carl Schwan <[email protected]>
1 parent 2080e17 commit 63cfe60

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

lib/AppInfo/Application.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace OCA\Recognize\AppInfo;
99

1010
use OCA\DAV\Connector\Sabre\Principal;
11+
use OCA\DAV\Events\SabrePluginAddEvent;
1112
use OCA\Recognize\Dav\Faces\PropFindPlugin;
1213
use OCA\Recognize\Hooks\FileListener;
1314
use OCP\AppFramework\App;
@@ -22,7 +23,6 @@
2223
use OCP\Files\Events\Node\NodeDeletedEvent;
2324
use OCP\Files\Events\Node\NodeRenamedEvent;
2425
use OCP\Files\Events\NodeRemovedFromCache;
25-
use OCP\SabrePluginEvent;
2626
use OCP\Share\Events\ShareCreatedEvent;
2727
use OCP\Share\Events\ShareDeletedEvent;
2828

@@ -68,15 +68,13 @@ public function register(IRegistrationContext $context): void {
6868
*/
6969
public function boot(IBootContext $context): void {
7070
$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
71-
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event): void {
71+
$eventDispatcher->addListener(SabrePluginAddEvent::class, function (SabrePluginAddEvent $event): void {
7272
$server = $event->getServer();
7373

74-
if ($server !== null) {
75-
// We have to register the PropFindPlugin here and not info.xml,
76-
// because info.xml plugins are loaded, after the
77-
// beforeMethod:* hook has already been emitted.
78-
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
79-
}
74+
// We have to register the PropFindPlugin here and not info.xml,
75+
// because info.xml plugins are loaded, after the
76+
// beforeMethod:* hook has already been emitted.
77+
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
8078
});
8179
}
8280
}

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
>
1313
<stubs>
1414
<file name="tests/stub.phpstub" preloadClasses="true"/>
15+
<file name="tests/stubs/oca_dav_events_sabrepluginaddevent.php"/>
1516
</stubs>
1617
<projectFiles>
1718
<directory name="lib" />
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)