2323use OCP \Interaction \Resources \NodeResource ;
2424use OCP \IURLGenerator ;
2525use OCP \L10N \IFactory ;
26- use OCP \Server ;
2726use OCP \Sharing \Icon \ShareIconURL ;
2827use OCP \Sharing \ISharingManager ;
2928use OCP \Sharing \ShareAccessContext ;
3332/**
3433 * @template-implements IEventListener<NodeDeletedEvent|MoveToTrashEvent>
3534 */
36- final class NodeShareSourceType implements IShareSourceType, IEventListener {
37- private ?IRootFolder $ rootFolder = null ;
38-
39- private ?IURLGenerator $ urlGenerator = null ;
40-
35+ final readonly class NodeShareSourceType implements IShareSourceType, IEventListener {
4136 public function __construct (
4237 IEventDispatcher $ eventDispatcher ,
43- private readonly IDBConnection $ dbConnection ,
44- private readonly ISharingManager $ manager ,
38+ private IDBConnection $ dbConnection ,
39+ private IRootFolder $ rootFolder ,
40+ private IURLGenerator $ urlGenerator ,
41+ private ISharingManager $ manager ,
4542 ) {
4643 $ eventDispatcher ->addServiceListener (NodeDeletedEvent::class, self ::class);
4744 $ eventDispatcher ->addServiceListener (MoveToTrashEvent::class, self ::class);
4845 }
4946
50- private function getRootFolder (): IRootFolder {
51- return $ this ->rootFolder ??= Server::get (IRootFolder::class);
52- }
53-
54- private function getUrlGenerator (): IURLGenerator {
55- return $ this ->urlGenerator ??= Server::get (IURLGenerator::class);
56- }
57-
5847 #[\Override]
5948 public function getDisplayName (IFactory $ l10nFactory ): string {
6049 return $ l10nFactory ->get (Application::APP_ID )->t ('File ' );
6150 }
6251
6352 #[\Override]
6453 public function validateSource (string $ source ): bool {
65- return $ this ->getRootFolder () ->getFirstNodeById ((int )$ source ) instanceof Node;
54+ return $ this ->rootFolder ->getFirstNodeById ((int )$ source ) instanceof Node;
6655 }
6756
6857 #[\Override]
6958 public function getSourceDisplayName (string $ source ): ?string {
70- $ displayName = $ this ->getRootFolder () ->getFirstNodeById ((int )$ source )?->getName();
59+ $ displayName = $ this ->rootFolder ->getFirstNodeById ((int )$ source )?->getName();
7160 if ($ displayName === '' ) {
7261 return null ;
7362 }
@@ -77,7 +66,7 @@ public function getSourceDisplayName(string $source): ?string {
7766
7867 #[\Override]
7968 public function getSourceIcon (string $ source ): ShareIconURL {
80- $ url = $ this ->getUrlGenerator () ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , ['fileId ' => $ source , 'x ' => 64 , 'y ' => 64 ]);
69+ $ url = $ this ->urlGenerator ->linkToRouteAbsolute ('core.Preview.getPreviewByFileId ' , ['fileId ' => $ source , 'x ' => 64 , 'y ' => 64 ]);
8170
8271 return new ShareIconURL ($ url , $ url );
8372 }
0 commit comments