From 36f9ebb6776bf41f75599d7ff48826b204e29f6e Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 15 Aug 2023 16:51:35 +0200 Subject: [PATCH] only gather dependencies for trashbin wrapper once Signed-off-by: Robin Appelman --- apps/files_trashbin/lib/Storage.php | 63 +++++++++++------------ apps/files_trashbin/tests/StorageTest.php | 3 +- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/apps/files_trashbin/lib/Storage.php b/apps/files_trashbin/lib/Storage.php index 68d0951b6947c..31304935c26d8 100644 --- a/apps/files_trashbin/lib/Storage.php +++ b/apps/files_trashbin/lib/Storage.php @@ -40,35 +40,24 @@ use OCP\Files\Storage\IStorage; use OCP\ILogger; use OCP\IUserManager; +use Psr\Log\LoggerInterface; class Storage extends Wrapper { - /** @var IMountPoint */ - private $mountPoint; - - /** @var IUserManager */ - private $userManager; - - /** @var ILogger */ - private $logger; - - /** @var IEventDispatcher */ - private $eventDispatcher; - - /** @var IRootFolder */ - private $rootFolder; - - /** @var ITrashManager */ - private $trashManager; - - private $trashEnabled = true; + private string $mountPoint; + private IUserManager$userManager; + private LoggerInterface $logger; + private IEventDispatcher $eventDispatcher; + private IRootFolder $rootFolder; + private ITrashManager $trashManager; + private bool $trashEnabled = true; /** * Storage constructor. * * @param array $parameters - * @param ITrashManager $trashManager + * @param ITrashManager|null $trashManager * @param IUserManager|null $userManager - * @param ILogger|null $logger + * @param LoggerInterface|null $logger * @param IEventDispatcher|null $eventDispatcher * @param IRootFolder|null $rootFolder */ @@ -76,7 +65,7 @@ public function __construct( $parameters, ITrashManager $trashManager = null, IUserManager $userManager = null, - ILogger $logger = null, + LoggerInterface $logger = null, IEventDispatcher $eventDispatcher = null, IRootFolder $rootFolder = null ) { @@ -209,19 +198,27 @@ private function doDelete($path, $method) { } /** - * Setup the storate wrapper callback + * Setup the storage wrapper callback */ public static function setupStorage() { - \OC\Files\Filesystem::addStorageWrapper('oc_trashbin', function ($mountPoint, $storage) { - return new \OCA\Files_Trashbin\Storage( - ['storage' => $storage, 'mountPoint' => $mountPoint], - \OC::$server->query(ITrashManager::class), - \OC::$server->getUserManager(), - \OC::$server->getLogger(), - \OC::$server->get(IEventDispatcher::class), - \OC::$server->getLazyRootFolder() - ); - }, 1); + $trashManager = \OC::$server->get(ITrashManager::class); + $userManager = \OC::$server->get(IUserManager::class); + $logger = \OC::$server->get(LoggerInterface::class); + $eventDispatcher = \OC::$server->get(IEventDispatcher::class); + $rootFolder = \OC::$server->get(IRootFolder::class); + Filesystem::addStorageWrapper( + 'oc_trashbin', + function (string $mountPoint, IStorage $storage) use ($trashManager, $userManager, $logger, $eventDispatcher, $rootFolder) { + return new Storage( + ['storage' => $storage, 'mountPoint' => $mountPoint], + $trashManager, + $userManager, + $logger, + $eventDispatcher, + $rootFolder, + ); + }, + 1); } public function getMountPoint() { diff --git a/apps/files_trashbin/tests/StorageTest.php b/apps/files_trashbin/tests/StorageTest.php index b4b995c3ae590..1b9c23f778d91 100644 --- a/apps/files_trashbin/tests/StorageTest.php +++ b/apps/files_trashbin/tests/StorageTest.php @@ -51,6 +51,7 @@ use OCP\IUserManager; use OCP\Lock\ILockingProvider; use OCP\Share\IShare; +use Psr\Log\LoggerInterface; use Test\Traits\MountProviderTrait; class TemporaryNoCross extends Temporary { @@ -606,7 +607,7 @@ public function testShouldMoveToTrash($mountPoint, $path, $userExists, $appDisab ->disableOriginalConstructor()->getMock(); $userManager->expects($this->any()) ->method('userExists')->willReturn($userExists); - $logger = $this->getMockBuilder(ILogger::class)->getMock(); + $logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); $eventDispatcher = $this->createMock(IEventDispatcher::class); $rootFolder = $this->createMock(IRootFolder::class); $userFolder = $this->createMock(Folder::class);