simplify setup of circular SetupManager<->Manager

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2022-03-02 19:38:21 +01:00
parent 6c1d051ecd
commit d81713e5c1
No known key found for this signature in database
GPG key ID: 42B69D8A64526EFB
5 changed files with 68 additions and 29 deletions

View file

@ -25,6 +25,7 @@
namespace OCA\Files_External\Tests;
use OC\Files\Mount\Manager;
use OC\Files\SetupManagerFactory;
use OCA\Files_External\Lib\PersonalMount;
use OCA\Files_External\Lib\StorageConfig;
use OCP\Diagnostics\IEventLogger;
@ -51,12 +52,7 @@ class PersonalMountTest extends TestCase {
$mount = new PersonalMount($storageService, $storageConfig, 10, $storage, '/foo');
$mountManager = new Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$mountManager = new Manager($this->createMock(SetupManagerFactory::class));
$mountManager->addMount($mount);
$this->assertEquals([$mount], $mountManager->findByStorageId('dummy'));

View file

@ -32,6 +32,7 @@ namespace OCA\Files_Sharing\Tests\External;
use OC\Federation\CloudIdManager;
use OC\Files\SetupManager;
use OC\Files\SetupManagerFactory;
use OC\Files\Storage\StorageFactory;
use OCA\Files_Sharing\External\Manager;
use OCA\Files_Sharing\External\MountProvider;
@ -107,12 +108,7 @@ class ManagerTest extends TestCase {
$this->uid = $this->getUniqueID('user');
$this->user = $this->createUser($this->uid, '');
$this->mountManager = new \OC\Files\Mount\Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class)
);
$this->mountManager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
$this->clientService = $this->getMockBuilder(IClientService::class)
->disableOriginalConstructor()->getMock();
$this->cloudFederationProviderManager = $this->createMock(ICloudFederationProviderManager::class);

View file

@ -26,18 +26,16 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
namespace OC\Files\Mount;
use OC\Cache\CappedMemoryCache;
use OC\Files\Filesystem;
use OC\Files\SetupManager;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OC\Files\SetupManagerFactory;
use OCP\Files\Mount\IMountManager;
use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException;
use OCP\IUserManager;
class Manager implements IMountManager {
/** @var MountPoint[] */
@ -48,15 +46,10 @@ class Manager implements IMountManager {
private CappedMemoryCache $inPathCache;
private SetupManager $setupManager;
public function __construct(
IEventLogger $eventLogger,
IMountProviderCollection $mountProviderCollection,
IUserManager $userManager,
IEventDispatcher $eventDispatcher
) {
public function __construct(SetupManagerFactory $setupManagerFactory) {
$this->pathCache = new CappedMemoryCache();
$this->inPathCache = new CappedMemoryCache();
$this->setupManager = new SetupManager($eventLogger, $mountProviderCollection, $this, $userManager, $eventDispatcher);
$this->setupManager = $setupManagerFactory->create($this);
}
/**

View file

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OC\Files;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\Config\IMountProviderCollection;
use OCP\Files\Mount\IMountManager;
use OCP\IUserManager;
class SetupManagerFactory {
private IEventLogger $eventLogger;
private IMountProviderCollection $mountProviderCollection;
private IUserManager $userManager;
private IEventDispatcher $eventDispatcher;
private ?SetupManager $setupManager;
public function __construct(
IEventLogger $eventLogger,
IMountProviderCollection $mountProviderCollection,
IUserManager $userManager,
IEventDispatcher $eventDispatcher
) {
$this->eventLogger = $eventLogger;
$this->mountProviderCollection = $mountProviderCollection;
$this->userManager = $userManager;
$this->eventDispatcher = $eventDispatcher;
$this->setupManager = null;
}
public function create(IMountManager $mountManager): SetupManager {
if (!$this->setupManager) {
$this->setupManager = new SetupManager($this->eventLogger, $this->mountProviderCollection, $mountManager, $this->userManager, $this->eventDispatcher);
}
return $this->setupManager;
}
}

View file

@ -8,6 +8,7 @@
namespace Test\Files\Mount;
use OC\Files\SetupManagerFactory;
use OC\Files\Storage\Temporary;
use OCP\Diagnostics\IEventLogger;
use OCP\EventDispatcher\IEventDispatcher;
@ -28,12 +29,7 @@ class ManagerTest extends \Test\TestCase {
protected function setUp(): void {
parent::setUp();
$this->manager = new \OC\Files\Mount\Manager(
$this->createMock(IEventLogger::class),
$this->createMock(IMountProviderCollection::class),
$this->createMock(IUserManager::class),
$this->createMock(IEventDispatcher::class),
);
$this->manager = new \OC\Files\Mount\Manager($this->createMock(SetupManagerFactory::class));
}
public function testFind() {