Skip to content

Commit 9270928

Browse files
author
Carl Schwan
committed
refactor(Application): Use modern SabrePluginAddEvent
Signed-off-by: Carl Schwan <[email protected]>
1 parent 9275a32 commit 9270928

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

lib/AppInfo/Application.php

Lines changed: 8 additions & 7 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;
@@ -23,6 +24,8 @@
2324
use OCP\Files\Events\Node\NodeRenamedEvent;
2425
use OCP\Files\Events\NodeRemovedFromCache;
2526
use OCP\SabrePluginEvent;
27+
use OCP\Share\Events\ShareCreatedEvent;
28+
use OCP\Share\Events\ShareDeletedEvent;
2629

2730
final class Application extends App implements IBootstrap {
2831
public const APP_ID = 'recognize';
@@ -60,15 +63,13 @@ public function register(IRegistrationContext $context): void {
6063
*/
6164
public function boot(IBootContext $context): void {
6265
$eventDispatcher = \OCP\Server::get(IEventDispatcher::class);
63-
$eventDispatcher->addListener('OCA\DAV\Connector\Sabre::addPlugin', function (SabrePluginEvent $event): void {
66+
$eventDispatcher->addListener(SabrePluginAddEvent::class, function (SabrePluginAddEvent $event): void {
6467
$server = $event->getServer();
6568

66-
if ($server !== null) {
67-
// We have to register the PropFindPlugin here and not info.xml,
68-
// because info.xml plugins are loaded, after the
69-
// beforeMethod:* hook has already been emitted.
70-
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
71-
}
69+
// We have to register the PropFindPlugin here and not info.xml,
70+
// because info.xml plugins are loaded, after the
71+
// beforeMethod:* hook has already been emitted.
72+
$server->addPlugin($this->getContainer()->get(PropFindPlugin::class));
7273
});
7374
}
7475
}

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)