diff --git a/config/config.sample.php b/config/config.sample.php index 953a47fd19850..b663f0bed471b 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1659,15 +1659,6 @@ */ 'comments.managerFactory' => '\OC\Comments\ManagerFactory', - /** - * Replaces the default System Tags Manager Factory. This can be utilized if an - * own or 3rd-party SystemTagsManager should be used that – for instance – uses the - * filesystem instead of the database to keep the tags. - * - * Defaults to ``\OC\SystemTag\ManagerFactory`` - */ - 'systemtags.managerFactory' => '\OC\SystemTag\ManagerFactory', - /** * Maintenance * diff --git a/lib/private/Activity/EventMerger.php b/lib/private/Activity/EventMerger.php index df2c8e138adf9..0da2c529a684a 100644 --- a/lib/private/Activity/EventMerger.php +++ b/lib/private/Activity/EventMerger.php @@ -10,14 +10,15 @@ use OCP\Activity\IEvent; use OCP\Activity\IEventMerger; use OCP\IL10N; +use OCP\L10N\IFactory; class EventMerger implements IEventMerger { - /** - * @param IL10N $l10n - */ + private readonly IL10N $l10n; + public function __construct( - protected IL10N $l10n, + IFactory $factory, ) { + $this->l10n = $factory->get('lib'); } /** diff --git a/lib/private/App/AppStore/Bundles/BundleFetcher.php b/lib/private/App/AppStore/Bundles/BundleFetcher.php index 798913784e1e8..df99d1ee95cb5 100644 --- a/lib/private/App/AppStore/Bundles/BundleFetcher.php +++ b/lib/private/App/AppStore/Bundles/BundleFetcher.php @@ -8,11 +8,14 @@ namespace OC\App\AppStore\Bundles; use OCP\IL10N; +use OCP\L10N\IFactory; class BundleFetcher { + private IL10N $l10n; public function __construct( - private IL10N $l10n, + IFactory $factory, ) { + $this->l10n = $factory->get('lib'); } /** diff --git a/lib/private/Diagnostics/QueryLogger.php b/lib/private/Diagnostics/QueryLogger.php index cd7cff6338a9b..af660b943cb45 100644 --- a/lib/private/Diagnostics/QueryLogger.php +++ b/lib/private/Diagnostics/QueryLogger.php @@ -8,6 +8,7 @@ namespace OC\Diagnostics; +use OC\SystemConfig; use OCP\Cache\CappedMemoryCache; use OCP\Diagnostics\IQueryLogger; @@ -20,7 +21,11 @@ class QueryLogger implements IQueryLogger { /** * QueryLogger constructor. */ - public function __construct() { + public function __construct(SystemConfig $config) { + if ($config->getValue('debug', false)) { + // In debug mode, module is being activated by default + $this->activate(); + } $this->queries = new CappedMemoryCache(1024); } diff --git a/lib/private/Server.php b/lib/private/Server.php index edbf8c225a6ff..46678cbd5496a 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -12,7 +12,6 @@ use OC\Accounts\AccountManager; use OC\Activity\EventMerger; use OC\App\AppManager; -use OC\App\AppStore\Bundles\BundleFetcher; use OC\AppFramework\Http\Request; use OC\AppFramework\Http\RequestId; use OC\AppFramework\Services\AppConfig; @@ -79,7 +78,6 @@ use OC\FilesMetadata\FilesMetadataManager; use OC\FullTextSearch\FullTextSearchManager; use OC\Http\Client\ClientService; -use OC\Http\Client\NegativeDnsCache; use OC\IntegrityCheck\Checker; use OC\IntegrityCheck\Helpers\EnvironmentHelper; use OC\IntegrityCheck\Helpers\FileAccessHelper; @@ -102,9 +100,7 @@ use OC\OCM\OCMDiscoveryService; use OC\OCS\CoreCapabilities; use OC\OCS\DiscoveryService; -use OC\Preview\Db\PreviewMapper; use OC\Preview\MimeIconProvider; -use OC\Preview\Watcher; use OC\Preview\WatcherConnector; use OC\Profile\ProfileManager; use OC\Profiler\Profiler; @@ -282,6 +278,7 @@ use OCP\SpeechToText\ISpeechToTextManager; use OCP\Support\Subscription\IAssertion; use OCP\SystemTag\ISystemTagManager; +use OCP\SystemTag\ISystemTagManagerFactory; use OCP\SystemTag\ISystemTagObjectMapper; use OCP\Talk\IBroker; use OCP\Teams\ITeamManager; @@ -348,124 +345,64 @@ public function __construct( $this->registerAlias(IPreview::class, PreviewManager::class); $this->registerAlias(IMimeIconProvider::class, MimeIconProvider::class); - - $this->registerService(Watcher::class, function (ContainerInterface $c): Watcher { - return new Watcher( - $c->get(\OC\Preview\Storage\StorageFactory::class), - $c->get(PreviewMapper::class), - $c->get(IDBConnection::class), - ); - }); - - $this->registerService(IProfiler::class, function (Server $c) { - return new Profiler($c->get(SystemConfig::class)); - }); + $this->registerAlias(IProfiler::class, Profiler::class); $this->registerService(Encryption\Manager::class, function (Server $c): Encryption\Manager { - $view = new View(); - $util = new Encryption\Util( - $view, - $c->get(IUserManager::class), - $c->get(IGroupManager::class), - $c->get(IConfig::class) - ); return new Encryption\Manager( $c->get(IConfig::class), $c->get(LoggerInterface::class), - $c->getL10N('core'), - new View(), - $util, + $c->get(IFactory::class)->get('core'), + $c->get(View::class), + $c->get(Encryption\Util::class), new ArrayCache() ); }); $this->registerAlias(\OCP\Encryption\IManager::class, Encryption\Manager::class); - - $this->registerService(IFile::class, function (ContainerInterface $c) { - $util = new Encryption\Util( - new View(), - $c->get(IUserManager::class), - $c->get(IGroupManager::class), - $c->get(IConfig::class) - ); - return new File( - $util, - $c->get(IRootFolder::class), - $c->get(\OCP\Share\IManager::class) - ); - }); - - $this->registerService(IStorage::class, function (ContainerInterface $c) { - $view = new View(); - $util = new Encryption\Util( - $view, - $c->get(IUserManager::class), - $c->get(IGroupManager::class), - $c->get(IConfig::class) - ); - - return new Storage( - $view, - $util, - $c->get(ICrypto::class), - $c->get(IConfig::class) - ); - }); - + $this->registerAlias(IFile::class, File::class); + $this->registerAlias(IStorage::class, Storage::class); $this->registerAlias(ITagManager::class, TagManager::class); - $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) { - /** @var IConfig $config */ - $config = $c->get(IConfig::class); - $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); - return new $factoryClass($this); - }); - $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { - return $c->get('SystemTagManagerFactory')->getManager(); - }); + $this->registerAlias(ISystemTagManagerFactory::class, SystemTagManagerFactory::class); + /** @deprecated 35.0.0 */ + $this->registerDeprecatedAlias('SystemTagManagerFactory', ISystemTagManagerFactory::class); /** @deprecated 19.0.0 */ $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class); + $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) { + return $c->get(ISystemTagManagerFactory::class)->getManager(); + }); $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) { - return $c->get('SystemTagManagerFactory')->getObjectMapper(); + return $c->get(ISystemTagManagerFactory::class)->getObjectMapper(); }); - $this->registerAlias(IFileAccess::class, FileAccess::class); - $this->registerService('RootFolder', function (ContainerInterface $c) { - $view = new View(); - /** @var IUserSession $userSession */ - $userSession = $c->get(IUserSession::class); - $root = new Root( - $c->get(\OC\Files\Mount\Manager::class), - $view, - $userSession->getUser(), - $c->get(IUserMountCache::class), - $this->get(LoggerInterface::class), - $this->get(IUserManager::class), - $this->get(IEventDispatcher::class), - $this->get(ICacheFactory::class), - $this->get(IAppConfig::class), - ); - - $previewConnector = new WatcherConnector( - $root, - $c->get(SystemConfig::class), - $this->get(IEventDispatcher::class) - ); - $previewConnector->connectWatcher(); - return $root; - }); - $this->registerService(HookConnector::class, function (ContainerInterface $c) { - return new HookConnector( - $c->get(IRootFolder::class), - new View(), - $c->get(IEventDispatcher::class), - $c->get(LoggerInterface::class) - ); - }); + $this->registerAlias(IFileAccess::class, FileAccess::class); + /** @deprecated 35.0.0 */ + $this->registerDeprecatedAlias('RootFolder', IRootFolder::class); $this->registerService(IRootFolder::class, function (ContainerInterface $c) { return new LazyRoot(function () use ($c) { - return $c->get('RootFolder'); + $view = new View(); + /** @var IUserSession $userSession */ + $userSession = $c->get(IUserSession::class); + $root = new Root( + $c->get(\OC\Files\Mount\Manager::class), + $view, + $userSession->getUser(), + $c->get(IUserMountCache::class), + $this->get(LoggerInterface::class), + $this->get(IUserManager::class), + $this->get(IEventDispatcher::class), + $this->get(ICacheFactory::class), + $this->get(IAppConfig::class), + ); + + $previewConnector = new WatcherConnector( + $root, + $c->get(SystemConfig::class), + $this->get(IEventDispatcher::class) + ); + $previewConnector->connectWatcher(); + return $root; }); }); @@ -475,16 +412,7 @@ public function __construct( return $c->get(\OC\User\Manager::class)->getDisplayNameCache(); }); - $this->registerService(IGroupManager::class, function (ContainerInterface $c) { - $groupManager = new \OC\Group\Manager( - $this->get(IUserManager::class), - $this->get(IEventDispatcher::class), - $this->get(LoggerInterface::class), - $this->get(ICacheFactory::class), - $this->get(IRemoteAddress::class), - ); - return $groupManager; - }); + $this->registerAlias(IGroupManager::class, \OC\Group\Manager::class); $this->registerService(Store::class, function (ContainerInterface $c) { $session = $c->get(ISession::class); @@ -520,7 +448,7 @@ public function __construct( $provider, $c->get(IConfig::class), $c->get(ISecureRandom::class), - $c->get('LockdownManager'), + $c->get(ILockdownManager::class), $c->get(LoggerInterface::class), $c->get(IEventDispatcher::class), ); @@ -613,16 +541,7 @@ public function __construct( $this->registerAlias(IUserConfig::class, UserConfig::class); $this->registerAlias(IAppManager::class, AppManager::class); - $this->registerService(IFactory::class, function (Server $c) { - return new \OC\L10N\Factory( - $c->get(IConfig::class), - $c->get(IRequest::class), - $c->get(IUserSession::class), - $c->get(ICacheFactory::class), - \OC::$SERVERROOT, - $c->get(IAppManager::class), - ); - }); + $this->registerAlias(IFactory::class, \OC\L10N\Factory::class); $this->registerAlias(IURLGenerator::class, URLGenerator::class); @@ -675,11 +594,7 @@ public function __construct( ); }); - $this->registerService(IEventMerger::class, function (Server $c) { - return new EventMerger( - $c->getL10N('lib') - ); - }); + $this->registerAlias(IEventMerger::class, EventMerger::class); $this->registerAlias(IValidator::class, Validator::class); $this->registerService(AvatarManager::class, function (Server $c) { @@ -713,10 +628,7 @@ public function __construct( // PSR-3 logger $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class); - $this->registerService(ILogFactory::class, function (Server $c) { - return new LogFactory($c, $this->get(SystemConfig::class)); - }); - + $this->registerAlias(ILogFactory::class, LogFactory::class); $this->registerAlias(IJobList::class, JobList::class); $this->registerService(Router::class, function (Server $c) { @@ -730,7 +642,7 @@ public function __construct( }); $this->registerAlias(IRouter::class, Router::class); - $this->registerService(IBackend::class, function ($c) { + $this->registerService(IBackend::class, function ($c): IBackend { $config = $c->get(IConfig::class); if (ltrim($config->getSystemValueString('memcache.distributed', ''), '\\') === Redis::class) { $backend = new MemoryCacheBackend( @@ -773,25 +685,12 @@ public function __construct( $this->registerAlias(ICertificateManager::class, CertificateManager::class); $this->registerAlias(IClientService::class, ClientService::class); - $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) { - return new NegativeDnsCache( - $c->get(ICacheFactory::class), - ); - }); $this->registerDeprecatedAlias('HttpClientService', IClientService::class); $this->registerService(IEventLogger::class, function (ContainerInterface $c) { return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class)); }); - $this->registerService(IQueryLogger::class, function (ContainerInterface $c) { - $queryLogger = new QueryLogger(); - if ($c->get(SystemConfig::class)->getValue('debug', false)) { - // In debug mode, module is being activated by default - $queryLogger->activate(); - } - return $queryLogger; - }); - + $this->registerAlias(IQueryLogger::class, QueryLogger::class); $this->registerAlias(ITempManager::class, TempManager::class); $this->registerAlias(IDateTimeZone::class, DateTimeZone::class); @@ -804,14 +703,14 @@ public function __construct( ); }); - $this->registerService(IUserMountCache::class, function (ContainerInterface $c) { + $this->registerService(IUserMountCache::class, function (ContainerInterface $c): IUserMountCache { $mountCache = $c->get(UserMountCache::class); $listener = new UserMountCacheListener($mountCache); $listener->listen($c->get(IUserManager::class)); return $mountCache; }); - $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) { + $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c): IMountProviderCollection { $loader = $c->get(IStorageFactory::class); $mountCache = $c->get(IUserMountCache::class); $eventLogger = $c->get(IEventLogger::class); @@ -820,7 +719,6 @@ public function __construct( // builtin providers $config = $c->get(IConfig::class); - $logger = $c->get(LoggerInterface::class); $objectStoreConfig = $c->get(PrimaryObjectStoreConfig::class); $manager->registerProvider(new CacheMountProvider($config)); $manager->registerHomeProvider(new LocalHomeMountProvider()); @@ -830,7 +728,7 @@ public function __construct( return $manager; }); - $this->registerService(IBus::class, function (ContainerInterface $c) { + $this->registerService(IBus::class, function (ContainerInterface $c): IBus { $busClass = $c->get(IConfig::class)->getSystemValueString('commandbus'); if ($busClass) { [$app, $class] = explode('::', $busClass, 2); @@ -981,11 +879,8 @@ public function __construct( return new NoopLockingProvider(); }); - $this->registerService(ILockManager::class, function (Server $c): LockManager { - return new LockManager(); - }); + $this->registerAlias(ILockManager::class, LockManager::class); - $this->registerAlias(ILockdownManager::class, 'LockdownManager'); $this->registerService(SetupManager::class, function ($c) { // create the setupmanager through the mount manager to resolve the cyclic dependency return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager(); @@ -1002,9 +897,6 @@ public function __construct( }); $this->registerAlias(IMimeTypeLoader::class, Loader::class); - $this->registerService(BundleFetcher::class, function () { - return new BundleFetcher($this->getL10N('lib')); - }); $this->registerAlias(\OCP\Notification\IManager::class, Manager::class); $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) { @@ -1109,7 +1001,9 @@ public function __construct( }); $this->registerAlias(IEventDispatcher::class, EventDispatcher::class); - $this->registerService('CryptoWrapper', function (ContainerInterface $c) { + /** @deprecated 35.0.0 */ + $this->registerDeprecatedAlias('CryptoWrapper', CryptoWrapper::class); + $this->registerService(CryptoWrapper::class, function (ContainerInterface $c): CryptoWrapper { // FIXME: Instantiated here due to cyclic dependency $request = new Request( [ @@ -1133,9 +1027,6 @@ public function __construct( $request ); }); - $this->registerService(SessionStorage::class, function (ContainerInterface $c) { - return new SessionStorage($c->get(ISession::class)); - }); $this->registerAlias(IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class); $this->registerService(IProviderFactory::class, function (ContainerInterface $c) { @@ -1172,42 +1063,26 @@ public function __construct( $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class); $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class); - $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) { - return new \OC\Files\AppData\Factory( - $c->get(IRootFolder::class), - $c->get(SystemConfig::class) - ); - }); - $this->registerService('LockdownManager', function (ContainerInterface $c) { - return new LockdownManager(function () use ($c) { - return $c->get(ISession::class); - }); - }); - - $this->registerService(IDiscoveryService::class, function (ContainerInterface $c): IDiscoveryService { - return new DiscoveryService( - $c->get(ICacheFactory::class), - $c->get(IClientService::class) + /** @deprecated 35.0.0 */ + $this->registerDeprecatedAlias('LockdownManager', ILockdownManager::class); + $this->registerService(LockdownManager::class, function (ContainerInterface $c): LockdownManager { + return new LockdownManager( + function () use ($c) { + return $c->get(ISession::class); + } ); }); + $this->registerAlias(ILockdownManager::class, LockdownManager::class); + + $this->registerAlias(IDiscoveryService::class, DiscoveryService::class); $this->registerAlias(IOCMDiscoveryService::class, OCMDiscoveryService::class); - $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) { - return new CloudIdManager( - $c->get(ICacheFactory::class), - $c->get(IEventDispatcher::class), - $c->get(\OCP\Contacts\IManager::class), - $c->get(IURLGenerator::class), - $c->get(IUserManager::class), - ); - }); + $this->registerAlias(ICloudIdManager::class, CloudIdManager::class); $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class); $this->registerAlias(ICloudFederationProviderManager::class, CloudFederationProviderManager::class); - $this->registerService(ICloudFederationFactory::class, function (Server $c) { - return new CloudFederationFactory(); - }); + $this->registerAlias(ICloudFederationFactory::class, CloudFederationFactory::class); $this->registerAlias(IControllerMethodReflector::class, ControllerMethodReflector::class); @@ -1226,15 +1101,8 @@ public function __construct( return $session->getSession(); }, false); - $this->registerService(IShareHelper::class, function (ContainerInterface $c) { - return new ShareHelper( - $c->get(\OCP\Share\IManager::class) - ); - }); - - $this->registerService(IApiFactory::class, function (ContainerInterface $c) { - return new ApiFactory($c->get(IClientService::class)); - }); + $this->registerAlias(IShareHelper::class, ShareHelper::class); + $this->registerAlias(IApiFactory::class, ApiFactory::class); $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) { $memcacheFactory = $c->get(ICacheFactory::class); diff --git a/lib/private/legacy/OC_Util.php b/lib/private/legacy/OC_Util.php index b9c91a83aab36..a025105f28cc4 100644 --- a/lib/private/legacy/OC_Util.php +++ b/lib/private/legacy/OC_Util.php @@ -26,6 +26,7 @@ use OCP\IUser; use OCP\IUserManager; use OCP\IUserSession; +use OCP\L10N\IFactory; use OCP\Security\ISecureRandom; use OCP\Server; use OCP\Share\IManager; @@ -260,7 +261,7 @@ public static function addHeader($tag, $attributes, $text = null, $prepend = fal * @return array arrays with error messages and hints */ public static function checkServer(SystemConfig $config) { - $l = \OC::$server->getL10N('lib'); + $l = \OCP\Server::get(IFactory::class)->get('lib'); $errors = []; $CONFIG_DATADIRECTORY = $config->getValue('datadirectory', OC::$SERVERROOT . '/data'); diff --git a/tests/lib/App/AppStore/Bundles/BundleFetcherTest.php b/tests/lib/App/AppStore/Bundles/BundleFetcherTest.php index 9d554dcfeba07..2fcbb78c3ec53 100644 --- a/tests/lib/App/AppStore/Bundles/BundleFetcherTest.php +++ b/tests/lib/App/AppStore/Bundles/BundleFetcherTest.php @@ -17,6 +17,7 @@ use OC\App\AppStore\Bundles\PublicSectorBundle; use OC\App\AppStore\Bundles\SocialSharingBundle; use OCP\IL10N; +use OCP\L10N\IFactory; use PHPUnit\Framework\MockObject\MockObject; use Test\TestCase; @@ -29,10 +30,10 @@ protected function setUp(): void { parent::setUp(); $this->l10n = $this->createMock(IL10N::class); + $factory = $this->createMock(IFactory::class); + $factory->method('get')->willReturn($this->l10n); - $this->bundleFetcher = new BundleFetcher( - $this->l10n - ); + $this->bundleFetcher = new BundleFetcher($factory); } public function testGetBundles(): void { diff --git a/tests/lib/Diagnostics/QueryLoggerTest.php b/tests/lib/Diagnostics/QueryLoggerTest.php index ed806c7c24872..4d01ea79c164c 100644 --- a/tests/lib/Diagnostics/QueryLoggerTest.php +++ b/tests/lib/Diagnostics/QueryLoggerTest.php @@ -9,6 +9,8 @@ namespace Test\Diagnostics; use OC\Diagnostics\QueryLogger; +use OC\SystemConfig; +use OCP\Server; use Test\TestCase; class QueryLoggerTest extends TestCase { @@ -18,7 +20,9 @@ class QueryLoggerTest extends TestCase { protected function setUp(): void { parent::setUp(); - $this->logger = new QueryLogger(); + $this->logger = new QueryLogger( + Server::get(SystemConfig::class) + ); } public function testQueryLogger(): void {