Passed
Push — master ( e0b2c9...936f63 )
by Robin
30:56 queued 14:22
created
lib/private/Server.php 2 patches
Indentation   +2088 added lines, -2088 removed lines patch added patch discarded remove patch
@@ -276,2097 +276,2097 @@
 block discarded – undo
276 276
  * TODO: hookup all manager classes
277 277
  */
278 278
 class Server extends ServerContainer implements IServerContainer {
279
-	/** @var string */
280
-	private $webRoot;
281
-
282
-	/**
283
-	 * @param string $webRoot
284
-	 * @param \OC\Config $config
285
-	 */
286
-	public function __construct($webRoot, \OC\Config $config) {
287
-		parent::__construct();
288
-		$this->webRoot = $webRoot;
289
-
290
-		// To find out if we are running from CLI or not
291
-		$this->registerParameter('isCLI', \OC::$CLI);
292
-		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
293
-
294
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
295
-			return $c;
296
-		});
297
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
298
-			return $c;
299
-		});
300
-
301
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
302
-		/** @deprecated 19.0.0 */
303
-		$this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
304
-
305
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
306
-		/** @deprecated 19.0.0 */
307
-		$this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
308
-
309
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
310
-		/** @deprecated 19.0.0 */
311
-		$this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
312
-
313
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
314
-		/** @deprecated 19.0.0 */
315
-		$this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
316
-
317
-		$this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
318
-		$this->registerAlias(ITemplateManager::class, TemplateManager::class);
319
-
320
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
321
-
322
-		$this->registerService(View::class, function (Server $c) {
323
-			return new View();
324
-		}, false);
325
-
326
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
327
-			return new PreviewManager(
328
-				$c->get(\OCP\IConfig::class),
329
-				$c->get(IRootFolder::class),
330
-				new \OC\Preview\Storage\Root(
331
-					$c->get(IRootFolder::class),
332
-					$c->get(SystemConfig::class)
333
-				),
334
-				$c->get(IEventDispatcher::class),
335
-				$c->get(SymfonyAdapter::class),
336
-				$c->get(GeneratorHelper::class),
337
-				$c->get(ISession::class)->get('user_id'),
338
-				$c->get(Coordinator::class),
339
-				$c->get(IServerContainer::class),
340
-				$c->get(IBinaryFinder::class)
341
-			);
342
-		});
343
-		/** @deprecated 19.0.0 */
344
-		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
345
-
346
-		$this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
347
-			return new \OC\Preview\Watcher(
348
-				new \OC\Preview\Storage\Root(
349
-					$c->get(IRootFolder::class),
350
-					$c->get(SystemConfig::class)
351
-				)
352
-			);
353
-		});
354
-
355
-		$this->registerService(IProfiler::class, function (Server $c) {
356
-			return new Profiler($c->get(SystemConfig::class));
357
-		});
358
-
359
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
360
-			$view = new View();
361
-			$util = new Encryption\Util(
362
-				$view,
363
-				$c->get(IUserManager::class),
364
-				$c->get(IGroupManager::class),
365
-				$c->get(\OCP\IConfig::class)
366
-			);
367
-			return new Encryption\Manager(
368
-				$c->get(\OCP\IConfig::class),
369
-				$c->get(LoggerInterface::class),
370
-				$c->getL10N('core'),
371
-				new View(),
372
-				$util,
373
-				new ArrayCache()
374
-			);
375
-		});
376
-		/** @deprecated 19.0.0 */
377
-		$this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
378
-
379
-		/** @deprecated 21.0.0 */
380
-		$this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
381
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
382
-			$util = new Encryption\Util(
383
-				new View(),
384
-				$c->get(IUserManager::class),
385
-				$c->get(IGroupManager::class),
386
-				$c->get(\OCP\IConfig::class)
387
-			);
388
-			return new Encryption\File(
389
-				$util,
390
-				$c->get(IRootFolder::class),
391
-				$c->get(\OCP\Share\IManager::class)
392
-			);
393
-		});
394
-
395
-		/** @deprecated 21.0.0 */
396
-		$this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
397
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
398
-			$view = new View();
399
-			$util = new Encryption\Util(
400
-				$view,
401
-				$c->get(IUserManager::class),
402
-				$c->get(IGroupManager::class),
403
-				$c->get(\OCP\IConfig::class)
404
-			);
405
-
406
-			return new Encryption\Keys\Storage(
407
-				$view,
408
-				$util,
409
-				$c->get(ICrypto::class),
410
-				$c->get(\OCP\IConfig::class)
411
-			);
412
-		});
413
-		/** @deprecated 20.0.0 */
414
-		$this->registerDeprecatedAlias('TagMapper', TagMapper::class);
415
-
416
-		$this->registerAlias(\OCP\ITagManager::class, TagManager::class);
417
-		/** @deprecated 19.0.0 */
418
-		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
419
-
420
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
421
-			/** @var \OCP\IConfig $config */
422
-			$config = $c->get(\OCP\IConfig::class);
423
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
424
-			return new $factoryClass($this);
425
-		});
426
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
427
-			return $c->get('SystemTagManagerFactory')->getManager();
428
-		});
429
-		/** @deprecated 19.0.0 */
430
-		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
431
-
432
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
433
-			return $c->get('SystemTagManagerFactory')->getObjectMapper();
434
-		});
435
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
436
-			$manager = \OC\Files\Filesystem::getMountManager(null);
437
-			$view = new View();
438
-			$root = new Root(
439
-				$manager,
440
-				$view,
441
-				null,
442
-				$c->get(IUserMountCache::class),
443
-				$this->get(LoggerInterface::class),
444
-				$this->get(IUserManager::class),
445
-				$this->get(IEventDispatcher::class),
446
-			);
447
-
448
-			$previewConnector = new \OC\Preview\WatcherConnector(
449
-				$root,
450
-				$c->get(SystemConfig::class)
451
-			);
452
-			$previewConnector->connectWatcher();
453
-
454
-			return $root;
455
-		});
456
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
457
-			return new HookConnector(
458
-				$c->get(IRootFolder::class),
459
-				new View(),
460
-				$c->get(\OC\EventDispatcher\SymfonyAdapter::class),
461
-				$c->get(IEventDispatcher::class)
462
-			);
463
-		});
464
-
465
-		/** @deprecated 19.0.0 */
466
-		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
467
-
468
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
469
-			return new LazyRoot(function () use ($c) {
470
-				return $c->get('RootFolder');
471
-			});
472
-		});
473
-		/** @deprecated 19.0.0 */
474
-		$this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
475
-
476
-		/** @deprecated 19.0.0 */
477
-		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
478
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
479
-
480
-		$this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
481
-			return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
482
-		});
483
-
484
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
485
-			$groupManager = new \OC\Group\Manager(
486
-				$this->get(IUserManager::class),
487
-				$c->get(SymfonyAdapter::class),
488
-				$this->get(LoggerInterface::class),
489
-				$this->get(ICacheFactory::class)
490
-			);
491
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
492
-				/** @var IEventDispatcher $dispatcher */
493
-				$dispatcher = $this->get(IEventDispatcher::class);
494
-				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
495
-			});
496
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
497
-				/** @var IEventDispatcher $dispatcher */
498
-				$dispatcher = $this->get(IEventDispatcher::class);
499
-				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
500
-			});
501
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
502
-				/** @var IEventDispatcher $dispatcher */
503
-				$dispatcher = $this->get(IEventDispatcher::class);
504
-				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
505
-			});
506
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
507
-				/** @var IEventDispatcher $dispatcher */
508
-				$dispatcher = $this->get(IEventDispatcher::class);
509
-				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
510
-			});
511
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
512
-				/** @var IEventDispatcher $dispatcher */
513
-				$dispatcher = $this->get(IEventDispatcher::class);
514
-				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
515
-			});
516
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
517
-				/** @var IEventDispatcher $dispatcher */
518
-				$dispatcher = $this->get(IEventDispatcher::class);
519
-				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
520
-			});
521
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
522
-				/** @var IEventDispatcher $dispatcher */
523
-				$dispatcher = $this->get(IEventDispatcher::class);
524
-				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
525
-			});
526
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
527
-				/** @var IEventDispatcher $dispatcher */
528
-				$dispatcher = $this->get(IEventDispatcher::class);
529
-				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
530
-			});
531
-			return $groupManager;
532
-		});
533
-		/** @deprecated 19.0.0 */
534
-		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
535
-
536
-		$this->registerService(Store::class, function (ContainerInterface $c) {
537
-			$session = $c->get(ISession::class);
538
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
539
-				$tokenProvider = $c->get(IProvider::class);
540
-			} else {
541
-				$tokenProvider = null;
542
-			}
543
-			$logger = $c->get(LoggerInterface::class);
544
-			return new Store($session, $logger, $tokenProvider);
545
-		});
546
-		$this->registerAlias(IStore::class, Store::class);
547
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
548
-
549
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
550
-			$manager = $c->get(IUserManager::class);
551
-			$session = new \OC\Session\Memory('');
552
-			$timeFactory = new TimeFactory();
553
-			// Token providers might require a working database. This code
554
-			// might however be called when Nextcloud is not yet setup.
555
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
556
-				$provider = $c->get(IProvider::class);
557
-			} else {
558
-				$provider = null;
559
-			}
560
-
561
-			$legacyDispatcher = $c->get(SymfonyAdapter::class);
562
-
563
-			$userSession = new \OC\User\Session(
564
-				$manager,
565
-				$session,
566
-				$timeFactory,
567
-				$provider,
568
-				$c->get(\OCP\IConfig::class),
569
-				$c->get(ISecureRandom::class),
570
-				$c->getLockdownManager(),
571
-				$c->get(LoggerInterface::class),
572
-				$c->get(IEventDispatcher::class)
573
-			);
574
-			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
575
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
576
-				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
577
-			});
578
-			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
579
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
580
-				/** @var \OC\User\User $user */
581
-				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
582
-			});
583
-			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
584
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
585
-				/** @var \OC\User\User $user */
586
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
587
-				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
588
-			});
589
-			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
590
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
591
-				/** @var \OC\User\User $user */
592
-				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
593
-			});
594
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
595
-				/** @var \OC\User\User $user */
596
-				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
597
-
598
-				/** @var IEventDispatcher $dispatcher */
599
-				$dispatcher = $this->get(IEventDispatcher::class);
600
-				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
601
-			});
602
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
603
-				/** @var \OC\User\User $user */
604
-				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
605
-
606
-				/** @var IEventDispatcher $dispatcher */
607
-				$dispatcher = $this->get(IEventDispatcher::class);
608
-				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
609
-			});
610
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
611
-				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
612
-
613
-				/** @var IEventDispatcher $dispatcher */
614
-				$dispatcher = $this->get(IEventDispatcher::class);
615
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
616
-			});
617
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
618
-				/** @var \OC\User\User $user */
619
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
620
-
621
-				/** @var IEventDispatcher $dispatcher */
622
-				$dispatcher = $this->get(IEventDispatcher::class);
623
-				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
624
-			});
625
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
626
-				/** @var IEventDispatcher $dispatcher */
627
-				$dispatcher = $this->get(IEventDispatcher::class);
628
-				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
629
-			});
630
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
631
-				/** @var \OC\User\User $user */
632
-				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
633
-
634
-				/** @var IEventDispatcher $dispatcher */
635
-				$dispatcher = $this->get(IEventDispatcher::class);
636
-				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
637
-			});
638
-			$userSession->listen('\OC\User', 'logout', function ($user) {
639
-				\OC_Hook::emit('OC_User', 'logout', []);
640
-
641
-				/** @var IEventDispatcher $dispatcher */
642
-				$dispatcher = $this->get(IEventDispatcher::class);
643
-				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
644
-			});
645
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
646
-				/** @var IEventDispatcher $dispatcher */
647
-				$dispatcher = $this->get(IEventDispatcher::class);
648
-				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
649
-			});
650
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
651
-				/** @var \OC\User\User $user */
652
-				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
653
-
654
-				/** @var IEventDispatcher $dispatcher */
655
-				$dispatcher = $this->get(IEventDispatcher::class);
656
-				$dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
657
-			});
658
-			return $userSession;
659
-		});
660
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
661
-		/** @deprecated 19.0.0 */
662
-		$this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
663
-
664
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
665
-
666
-		$this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
667
-		/** @deprecated 19.0.0 */
668
-		$this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
669
-
670
-		/** @deprecated 19.0.0 */
671
-		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
672
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
673
-
674
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
675
-			return new \OC\SystemConfig($config);
676
-		});
677
-		/** @deprecated 19.0.0 */
678
-		$this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
679
-
680
-		/** @deprecated 19.0.0 */
681
-		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
682
-		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
683
-
684
-		$this->registerService(IFactory::class, function (Server $c) {
685
-			return new \OC\L10N\Factory(
686
-				$c->get(\OCP\IConfig::class),
687
-				$c->getRequest(),
688
-				$c->get(IUserSession::class),
689
-				$c->get(ICacheFactory::class),
690
-				\OC::$SERVERROOT
691
-			);
692
-		});
693
-		/** @deprecated 19.0.0 */
694
-		$this->registerDeprecatedAlias('L10NFactory', IFactory::class);
695
-
696
-		$this->registerAlias(IURLGenerator::class, URLGenerator::class);
697
-		/** @deprecated 19.0.0 */
698
-		$this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
699
-
700
-		/** @deprecated 19.0.0 */
701
-		$this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
702
-		/** @deprecated 19.0.0 */
703
-		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
704
-
705
-		$this->registerService(ICache::class, function ($c) {
706
-			return new Cache\File();
707
-		});
708
-		/** @deprecated 19.0.0 */
709
-		$this->registerDeprecatedAlias('UserCache', ICache::class);
710
-
711
-		$this->registerService(Factory::class, function (Server $c) {
712
-			$profiler = $c->get(IProfiler::class);
713
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class),
714
-				$profiler,
715
-				ArrayCache::class,
716
-				ArrayCache::class,
717
-				ArrayCache::class
718
-			);
719
-			/** @var \OCP\IConfig $config */
720
-			$config = $c->get(\OCP\IConfig::class);
721
-
722
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
723
-				if (!$config->getSystemValueBool('log_query')) {
724
-					$v = \OC_App::getAppVersions();
725
-				} else {
726
-					// If the log_query is enabled, we can not get the app versions
727
-					// as that does a query, which will be logged and the logging
728
-					// depends on redis and here we are back again in the same function.
729
-					$v = [
730
-						'log_query' => 'enabled',
731
-					];
732
-				}
733
-				$v['core'] = implode(',', \OC_Util::getVersion());
734
-				$version = implode(',', $v);
735
-				$instanceId = \OC_Util::getInstanceId();
736
-				$path = \OC::$SERVERROOT;
737
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
738
-				return new \OC\Memcache\Factory($prefix,
739
-					$c->get(LoggerInterface::class),
740
-					$profiler,
741
-					$config->getSystemValue('memcache.local', null),
742
-					$config->getSystemValue('memcache.distributed', null),
743
-					$config->getSystemValue('memcache.locking', null),
744
-					$config->getSystemValueString('redis_log_file')
745
-				);
746
-			}
747
-			return $arrayCacheFactory;
748
-		});
749
-		/** @deprecated 19.0.0 */
750
-		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
751
-		$this->registerAlias(ICacheFactory::class, Factory::class);
752
-
753
-		$this->registerService('RedisFactory', function (Server $c) {
754
-			$systemConfig = $c->get(SystemConfig::class);
755
-			return new RedisFactory($systemConfig, $c->getEventLogger());
756
-		});
757
-
758
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
759
-			$l10n = $this->get(IFactory::class)->get('lib');
760
-			return new \OC\Activity\Manager(
761
-				$c->getRequest(),
762
-				$c->get(IUserSession::class),
763
-				$c->get(\OCP\IConfig::class),
764
-				$c->get(IValidator::class),
765
-				$l10n
766
-			);
767
-		});
768
-		/** @deprecated 19.0.0 */
769
-		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
770
-
771
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
772
-			return new \OC\Activity\EventMerger(
773
-				$c->getL10N('lib')
774
-			);
775
-		});
776
-		$this->registerAlias(IValidator::class, Validator::class);
777
-
778
-		$this->registerService(AvatarManager::class, function (Server $c) {
779
-			return new AvatarManager(
780
-				$c->get(IUserSession::class),
781
-				$c->get(\OC\User\Manager::class),
782
-				$c->getAppDataDir('avatar'),
783
-				$c->getL10N('lib'),
784
-				$c->get(LoggerInterface::class),
785
-				$c->get(\OCP\IConfig::class),
786
-				$c->get(IAccountManager::class),
787
-				$c->get(KnownUserService::class)
788
-			);
789
-		});
790
-
791
-		$this->registerAlias(IAvatarManager::class, AvatarManager::class);
792
-		/** @deprecated 19.0.0 */
793
-		$this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
794
-
795
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
796
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
797
-		$this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
798
-
799
-		$this->registerService(\OC\Log::class, function (Server $c) {
800
-			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
801
-			$factory = new LogFactory($c, $this->get(SystemConfig::class));
802
-			$logger = $factory->get($logType);
803
-			$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
804
-
805
-			return new Log($logger, $this->get(SystemConfig::class), null, $registry);
806
-		});
807
-		$this->registerAlias(ILogger::class, \OC\Log::class);
808
-		/** @deprecated 19.0.0 */
809
-		$this->registerDeprecatedAlias('Logger', \OC\Log::class);
810
-		// PSR-3 logger
811
-		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
812
-
813
-		$this->registerService(ILogFactory::class, function (Server $c) {
814
-			return new LogFactory($c, $this->get(SystemConfig::class));
815
-		});
816
-
817
-		$this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
818
-		/** @deprecated 19.0.0 */
819
-		$this->registerDeprecatedAlias('JobList', IJobList::class);
820
-
821
-		$this->registerService(Router::class, function (Server $c) {
822
-			$cacheFactory = $c->get(ICacheFactory::class);
823
-			$logger = $c->get(LoggerInterface::class);
824
-			if ($cacheFactory->isLocalCacheAvailable()) {
825
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
826
-			} else {
827
-				$router = new \OC\Route\Router($logger);
828
-			}
829
-			return $router;
830
-		});
831
-		$this->registerAlias(IRouter::class, Router::class);
832
-		/** @deprecated 19.0.0 */
833
-		$this->registerDeprecatedAlias('Router', IRouter::class);
834
-
835
-		$this->registerAlias(ISearch::class, Search::class);
836
-		/** @deprecated 19.0.0 */
837
-		$this->registerDeprecatedAlias('Search', ISearch::class);
838
-
839
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
840
-			$cacheFactory = $c->get(ICacheFactory::class);
841
-			if ($cacheFactory->isAvailable()) {
842
-				$backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
843
-					$this->get(ICacheFactory::class),
844
-					new \OC\AppFramework\Utility\TimeFactory()
845
-				);
846
-			} else {
847
-				$backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
848
-					$c->get(IDBConnection::class),
849
-					new \OC\AppFramework\Utility\TimeFactory()
850
-				);
851
-			}
852
-
853
-			return $backend;
854
-		});
855
-
856
-		$this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
857
-		/** @deprecated 19.0.0 */
858
-		$this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
859
-		$this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class);
860
-		$this->registerAlias(IVerificationToken::class, VerificationToken::class);
861
-
862
-		$this->registerAlias(ICrypto::class, Crypto::class);
863
-		/** @deprecated 19.0.0 */
864
-		$this->registerDeprecatedAlias('Crypto', ICrypto::class);
865
-
866
-		$this->registerAlias(IHasher::class, Hasher::class);
867
-		/** @deprecated 19.0.0 */
868
-		$this->registerDeprecatedAlias('Hasher', IHasher::class);
869
-
870
-		$this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
871
-		/** @deprecated 19.0.0 */
872
-		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
873
-
874
-		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
875
-		$this->registerService(Connection::class, function (Server $c) {
876
-			$systemConfig = $c->get(SystemConfig::class);
877
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
878
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
879
-			if (!$factory->isValidType($type)) {
880
-				throw new \OC\DatabaseException('Invalid database type');
881
-			}
882
-			$connectionParams = $factory->createConnectionParams();
883
-			$connection = $factory->getConnection($type, $connectionParams);
884
-			return $connection;
885
-		});
886
-		/** @deprecated 19.0.0 */
887
-		$this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
888
-
889
-		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
890
-		$this->registerAlias(IClientService::class, ClientService::class);
891
-		$this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
892
-			return new NegativeDnsCache(
893
-				$c->get(ICacheFactory::class),
894
-			);
895
-		});
896
-		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
897
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
898
-			return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
899
-		});
900
-		/** @deprecated 19.0.0 */
901
-		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
902
-
903
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
904
-			$queryLogger = new QueryLogger();
905
-			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
906
-				// In debug mode, module is being activated by default
907
-				$queryLogger->activate();
908
-			}
909
-			return $queryLogger;
910
-		});
911
-		/** @deprecated 19.0.0 */
912
-		$this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
913
-
914
-		/** @deprecated 19.0.0 */
915
-		$this->registerDeprecatedAlias('TempManager', TempManager::class);
916
-		$this->registerAlias(ITempManager::class, TempManager::class);
917
-
918
-		$this->registerService(AppManager::class, function (ContainerInterface $c) {
919
-			// TODO: use auto-wiring
920
-			return new \OC\App\AppManager(
921
-				$c->get(IUserSession::class),
922
-				$c->get(\OCP\IConfig::class),
923
-				$c->get(\OC\AppConfig::class),
924
-				$c->get(IGroupManager::class),
925
-				$c->get(ICacheFactory::class),
926
-				$c->get(SymfonyAdapter::class),
927
-				$c->get(LoggerInterface::class)
928
-			);
929
-		});
930
-		/** @deprecated 19.0.0 */
931
-		$this->registerDeprecatedAlias('AppManager', AppManager::class);
932
-		$this->registerAlias(IAppManager::class, AppManager::class);
933
-
934
-		$this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
935
-		/** @deprecated 19.0.0 */
936
-		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
937
-
938
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
939
-			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
940
-
941
-			return new DateTimeFormatter(
942
-				$c->get(IDateTimeZone::class)->getTimeZone(),
943
-				$c->getL10N('lib', $language)
944
-			);
945
-		});
946
-		/** @deprecated 19.0.0 */
947
-		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
948
-
949
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
950
-			$mountCache = $c->get(UserMountCache::class);
951
-			$listener = new UserMountCacheListener($mountCache);
952
-			$listener->listen($c->get(IUserManager::class));
953
-			return $mountCache;
954
-		});
955
-		/** @deprecated 19.0.0 */
956
-		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
957
-
958
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
959
-			$loader = $c->get(IStorageFactory::class);
960
-			$mountCache = $c->get(IUserMountCache::class);
961
-			$eventLogger = $c->get(IEventLogger::class);
962
-			$manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
963
-
964
-			// builtin providers
965
-
966
-			$config = $c->get(\OCP\IConfig::class);
967
-			$logger = $c->get(LoggerInterface::class);
968
-			$manager->registerProvider(new CacheMountProvider($config));
969
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
970
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
971
-			$manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class)));
972
-			$manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
973
-
974
-			return $manager;
975
-		});
976
-		/** @deprecated 19.0.0 */
977
-		$this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
978
-
979
-		/** @deprecated 20.0.0 */
980
-		$this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
981
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
982
-			$busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
983
-			if ($busClass) {
984
-				[$app, $class] = explode('::', $busClass, 2);
985
-				if ($c->get(IAppManager::class)->isInstalled($app)) {
986
-					\OC_App::loadApp($app);
987
-					return $c->get($class);
988
-				} else {
989
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
990
-				}
991
-			} else {
992
-				$jobList = $c->get(IJobList::class);
993
-				return new CronBus($jobList);
994
-			}
995
-		});
996
-		$this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
997
-		/** @deprecated 20.0.0 */
998
-		$this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
999
-		$this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
1000
-		/** @deprecated 19.0.0 */
1001
-		$this->registerDeprecatedAlias('Throttler', Throttler::class);
1002
-		$this->registerAlias(IThrottler::class, Throttler::class);
1003
-		$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
1004
-			// IConfig and IAppManager requires a working database. This code
1005
-			// might however be called when ownCloud is not yet setup.
1006
-			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
1007
-				$config = $c->get(\OCP\IConfig::class);
1008
-				$appManager = $c->get(IAppManager::class);
1009
-			} else {
1010
-				$config = null;
1011
-				$appManager = null;
1012
-			}
1013
-
1014
-			return new Checker(
1015
-				new EnvironmentHelper(),
1016
-				new FileAccessHelper(),
1017
-				new AppLocator(),
1018
-				$config,
1019
-				$c->get(ICacheFactory::class),
1020
-				$appManager,
1021
-				$c->get(IMimeTypeDetector::class)
1022
-			);
1023
-		});
1024
-		$this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
1025
-			if (isset($this['urlParams'])) {
1026
-				$urlParams = $this['urlParams'];
1027
-			} else {
1028
-				$urlParams = [];
1029
-			}
1030
-
1031
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
1032
-				&& in_array('fakeinput', stream_get_wrappers())
1033
-			) {
1034
-				$stream = 'fakeinput://data';
1035
-			} else {
1036
-				$stream = 'php://input';
1037
-			}
1038
-
1039
-			return new Request(
1040
-				[
1041
-					'get' => $_GET,
1042
-					'post' => $_POST,
1043
-					'files' => $_FILES,
1044
-					'server' => $_SERVER,
1045
-					'env' => $_ENV,
1046
-					'cookies' => $_COOKIE,
1047
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1048
-						? $_SERVER['REQUEST_METHOD']
1049
-						: '',
1050
-					'urlParams' => $urlParams,
1051
-				],
1052
-				$this->get(IRequestId::class),
1053
-				$this->get(\OCP\IConfig::class),
1054
-				$this->get(CsrfTokenManager::class),
1055
-				$stream
1056
-			);
1057
-		});
1058
-		/** @deprecated 19.0.0 */
1059
-		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
1060
-
1061
-		$this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
1062
-			return new RequestId(
1063
-				$_SERVER['UNIQUE_ID'] ?? '',
1064
-				$this->get(ISecureRandom::class)
1065
-			);
1066
-		});
1067
-
1068
-		$this->registerService(IMailer::class, function (Server $c) {
1069
-			return new Mailer(
1070
-				$c->get(\OCP\IConfig::class),
1071
-				$c->get(LoggerInterface::class),
1072
-				$c->get(Defaults::class),
1073
-				$c->get(IURLGenerator::class),
1074
-				$c->getL10N('lib'),
1075
-				$c->get(IEventDispatcher::class),
1076
-				$c->get(IFactory::class)
1077
-			);
1078
-		});
1079
-		/** @deprecated 19.0.0 */
1080
-		$this->registerDeprecatedAlias('Mailer', IMailer::class);
1081
-
1082
-		/** @deprecated 21.0.0 */
1083
-		$this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
1084
-
1085
-		$this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
1086
-			$config = $c->get(\OCP\IConfig::class);
1087
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1088
-			if (is_null($factoryClass) || !class_exists($factoryClass)) {
1089
-				return new NullLDAPProviderFactory($this);
1090
-			}
1091
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1092
-			return new $factoryClass($this);
1093
-		});
1094
-		$this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
1095
-			$factory = $c->get(ILDAPProviderFactory::class);
1096
-			return $factory->getLDAPProvider();
1097
-		});
1098
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1099
-			$ini = $c->get(IniGetWrapper::class);
1100
-			$config = $c->get(\OCP\IConfig::class);
1101
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1102
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1103
-				/** @var \OC\Memcache\Factory $memcacheFactory */
1104
-				$memcacheFactory = $c->get(ICacheFactory::class);
1105
-				$memcache = $memcacheFactory->createLocking('lock');
1106
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
1107
-					return new MemcacheLockingProvider($memcache, $ttl);
1108
-				}
1109
-				return new DBLockingProvider(
1110
-					$c->get(IDBConnection::class),
1111
-					new TimeFactory(),
1112
-					$ttl,
1113
-					!\OC::$CLI
1114
-				);
1115
-			}
1116
-			return new NoopLockingProvider();
1117
-		});
1118
-		/** @deprecated 19.0.0 */
1119
-		$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1120
-
1121
-		$this->registerService(ILockManager::class, function (Server $c): LockManager {
1122
-			return new LockManager();
1123
-		});
1124
-
1125
-		$this->registerAlias(ILockdownManager::class, 'LockdownManager');
1126
-		$this->registerService(SetupManager::class, function ($c) {
1127
-			// create the setupmanager through the mount manager to resolve the cyclic dependency
1128
-			return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
1129
-		});
1130
-		$this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1131
-		/** @deprecated 19.0.0 */
1132
-		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1133
-
1134
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1135
-			return new \OC\Files\Type\Detection(
1136
-				$c->get(IURLGenerator::class),
1137
-				$c->get(LoggerInterface::class),
1138
-				\OC::$configDir,
1139
-				\OC::$SERVERROOT . '/resources/config/'
1140
-			);
1141
-		});
1142
-		/** @deprecated 19.0.0 */
1143
-		$this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1144
-
1145
-		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
1146
-		/** @deprecated 19.0.0 */
1147
-		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1148
-		$this->registerService(BundleFetcher::class, function () {
1149
-			return new BundleFetcher($this->getL10N('lib'));
1150
-		});
1151
-		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1152
-		/** @deprecated 19.0.0 */
1153
-		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1154
-
1155
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1156
-			$manager = new CapabilitiesManager($c->get(LoggerInterface::class));
1157
-			$manager->registerCapability(function () use ($c) {
1158
-				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1159
-			});
1160
-			$manager->registerCapability(function () use ($c) {
1161
-				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1162
-			});
1163
-			$manager->registerCapability(function () use ($c) {
1164
-				return $c->get(MetadataCapabilities::class);
1165
-			});
1166
-			return $manager;
1167
-		});
1168
-		/** @deprecated 19.0.0 */
1169
-		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1170
-
1171
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1172
-			$config = $c->get(\OCP\IConfig::class);
1173
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1174
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1175
-			$factory = new $factoryClass($this);
1176
-			$manager = $factory->getManager();
1177
-
1178
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1179
-				$manager = $c->get(IUserManager::class);
1180
-				$userDisplayName = $manager->getDisplayName($id);
1181
-				if ($userDisplayName === null) {
1182
-					$l = $c->get(IFactory::class)->get('core');
1183
-					return $l->t('Unknown user');
1184
-				}
1185
-				return $userDisplayName;
1186
-			});
1187
-
1188
-			return $manager;
1189
-		});
1190
-		/** @deprecated 19.0.0 */
1191
-		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1192
-
1193
-		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1194
-		$this->registerService('ThemingDefaults', function (Server $c) {
1195
-			/*
279
+    /** @var string */
280
+    private $webRoot;
281
+
282
+    /**
283
+     * @param string $webRoot
284
+     * @param \OC\Config $config
285
+     */
286
+    public function __construct($webRoot, \OC\Config $config) {
287
+        parent::__construct();
288
+        $this->webRoot = $webRoot;
289
+
290
+        // To find out if we are running from CLI or not
291
+        $this->registerParameter('isCLI', \OC::$CLI);
292
+        $this->registerParameter('serverRoot', \OC::$SERVERROOT);
293
+
294
+        $this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
295
+            return $c;
296
+        });
297
+        $this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
298
+            return $c;
299
+        });
300
+
301
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
302
+        /** @deprecated 19.0.0 */
303
+        $this->registerDeprecatedAlias('CalendarManager', \OC\Calendar\Manager::class);
304
+
305
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
306
+        /** @deprecated 19.0.0 */
307
+        $this->registerDeprecatedAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
308
+
309
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
310
+        /** @deprecated 19.0.0 */
311
+        $this->registerDeprecatedAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
312
+
313
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
314
+        /** @deprecated 19.0.0 */
315
+        $this->registerDeprecatedAlias('ContactsManager', \OCP\Contacts\IManager::class);
316
+
317
+        $this->registerAlias(\OCP\DirectEditing\IManager::class, \OC\DirectEditing\Manager::class);
318
+        $this->registerAlias(ITemplateManager::class, TemplateManager::class);
319
+
320
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
321
+
322
+        $this->registerService(View::class, function (Server $c) {
323
+            return new View();
324
+        }, false);
325
+
326
+        $this->registerService(IPreview::class, function (ContainerInterface $c) {
327
+            return new PreviewManager(
328
+                $c->get(\OCP\IConfig::class),
329
+                $c->get(IRootFolder::class),
330
+                new \OC\Preview\Storage\Root(
331
+                    $c->get(IRootFolder::class),
332
+                    $c->get(SystemConfig::class)
333
+                ),
334
+                $c->get(IEventDispatcher::class),
335
+                $c->get(SymfonyAdapter::class),
336
+                $c->get(GeneratorHelper::class),
337
+                $c->get(ISession::class)->get('user_id'),
338
+                $c->get(Coordinator::class),
339
+                $c->get(IServerContainer::class),
340
+                $c->get(IBinaryFinder::class)
341
+            );
342
+        });
343
+        /** @deprecated 19.0.0 */
344
+        $this->registerDeprecatedAlias('PreviewManager', IPreview::class);
345
+
346
+        $this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
347
+            return new \OC\Preview\Watcher(
348
+                new \OC\Preview\Storage\Root(
349
+                    $c->get(IRootFolder::class),
350
+                    $c->get(SystemConfig::class)
351
+                )
352
+            );
353
+        });
354
+
355
+        $this->registerService(IProfiler::class, function (Server $c) {
356
+            return new Profiler($c->get(SystemConfig::class));
357
+        });
358
+
359
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
360
+            $view = new View();
361
+            $util = new Encryption\Util(
362
+                $view,
363
+                $c->get(IUserManager::class),
364
+                $c->get(IGroupManager::class),
365
+                $c->get(\OCP\IConfig::class)
366
+            );
367
+            return new Encryption\Manager(
368
+                $c->get(\OCP\IConfig::class),
369
+                $c->get(LoggerInterface::class),
370
+                $c->getL10N('core'),
371
+                new View(),
372
+                $util,
373
+                new ArrayCache()
374
+            );
375
+        });
376
+        /** @deprecated 19.0.0 */
377
+        $this->registerDeprecatedAlias('EncryptionManager', \OCP\Encryption\IManager::class);
378
+
379
+        /** @deprecated 21.0.0 */
380
+        $this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
381
+        $this->registerService(IFile::class, function (ContainerInterface $c) {
382
+            $util = new Encryption\Util(
383
+                new View(),
384
+                $c->get(IUserManager::class),
385
+                $c->get(IGroupManager::class),
386
+                $c->get(\OCP\IConfig::class)
387
+            );
388
+            return new Encryption\File(
389
+                $util,
390
+                $c->get(IRootFolder::class),
391
+                $c->get(\OCP\Share\IManager::class)
392
+            );
393
+        });
394
+
395
+        /** @deprecated 21.0.0 */
396
+        $this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
397
+        $this->registerService(IStorage::class, function (ContainerInterface $c) {
398
+            $view = new View();
399
+            $util = new Encryption\Util(
400
+                $view,
401
+                $c->get(IUserManager::class),
402
+                $c->get(IGroupManager::class),
403
+                $c->get(\OCP\IConfig::class)
404
+            );
405
+
406
+            return new Encryption\Keys\Storage(
407
+                $view,
408
+                $util,
409
+                $c->get(ICrypto::class),
410
+                $c->get(\OCP\IConfig::class)
411
+            );
412
+        });
413
+        /** @deprecated 20.0.0 */
414
+        $this->registerDeprecatedAlias('TagMapper', TagMapper::class);
415
+
416
+        $this->registerAlias(\OCP\ITagManager::class, TagManager::class);
417
+        /** @deprecated 19.0.0 */
418
+        $this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
419
+
420
+        $this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
421
+            /** @var \OCP\IConfig $config */
422
+            $config = $c->get(\OCP\IConfig::class);
423
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
424
+            return new $factoryClass($this);
425
+        });
426
+        $this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
427
+            return $c->get('SystemTagManagerFactory')->getManager();
428
+        });
429
+        /** @deprecated 19.0.0 */
430
+        $this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
431
+
432
+        $this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
433
+            return $c->get('SystemTagManagerFactory')->getObjectMapper();
434
+        });
435
+        $this->registerService('RootFolder', function (ContainerInterface $c) {
436
+            $manager = \OC\Files\Filesystem::getMountManager(null);
437
+            $view = new View();
438
+            $root = new Root(
439
+                $manager,
440
+                $view,
441
+                null,
442
+                $c->get(IUserMountCache::class),
443
+                $this->get(LoggerInterface::class),
444
+                $this->get(IUserManager::class),
445
+                $this->get(IEventDispatcher::class),
446
+            );
447
+
448
+            $previewConnector = new \OC\Preview\WatcherConnector(
449
+                $root,
450
+                $c->get(SystemConfig::class)
451
+            );
452
+            $previewConnector->connectWatcher();
453
+
454
+            return $root;
455
+        });
456
+        $this->registerService(HookConnector::class, function (ContainerInterface $c) {
457
+            return new HookConnector(
458
+                $c->get(IRootFolder::class),
459
+                new View(),
460
+                $c->get(\OC\EventDispatcher\SymfonyAdapter::class),
461
+                $c->get(IEventDispatcher::class)
462
+            );
463
+        });
464
+
465
+        /** @deprecated 19.0.0 */
466
+        $this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
467
+
468
+        $this->registerService(IRootFolder::class, function (ContainerInterface $c) {
469
+            return new LazyRoot(function () use ($c) {
470
+                return $c->get('RootFolder');
471
+            });
472
+        });
473
+        /** @deprecated 19.0.0 */
474
+        $this->registerDeprecatedAlias('LazyRootFolder', IRootFolder::class);
475
+
476
+        /** @deprecated 19.0.0 */
477
+        $this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
478
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
479
+
480
+        $this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
481
+            return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
482
+        });
483
+
484
+        $this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
485
+            $groupManager = new \OC\Group\Manager(
486
+                $this->get(IUserManager::class),
487
+                $c->get(SymfonyAdapter::class),
488
+                $this->get(LoggerInterface::class),
489
+                $this->get(ICacheFactory::class)
490
+            );
491
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
492
+                /** @var IEventDispatcher $dispatcher */
493
+                $dispatcher = $this->get(IEventDispatcher::class);
494
+                $dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
495
+            });
496
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
497
+                /** @var IEventDispatcher $dispatcher */
498
+                $dispatcher = $this->get(IEventDispatcher::class);
499
+                $dispatcher->dispatchTyped(new GroupCreatedEvent($group));
500
+            });
501
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
502
+                /** @var IEventDispatcher $dispatcher */
503
+                $dispatcher = $this->get(IEventDispatcher::class);
504
+                $dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
505
+            });
506
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
507
+                /** @var IEventDispatcher $dispatcher */
508
+                $dispatcher = $this->get(IEventDispatcher::class);
509
+                $dispatcher->dispatchTyped(new GroupDeletedEvent($group));
510
+            });
511
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
512
+                /** @var IEventDispatcher $dispatcher */
513
+                $dispatcher = $this->get(IEventDispatcher::class);
514
+                $dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
515
+            });
516
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
517
+                /** @var IEventDispatcher $dispatcher */
518
+                $dispatcher = $this->get(IEventDispatcher::class);
519
+                $dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
520
+            });
521
+            $groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
522
+                /** @var IEventDispatcher $dispatcher */
523
+                $dispatcher = $this->get(IEventDispatcher::class);
524
+                $dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
525
+            });
526
+            $groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
527
+                /** @var IEventDispatcher $dispatcher */
528
+                $dispatcher = $this->get(IEventDispatcher::class);
529
+                $dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
530
+            });
531
+            return $groupManager;
532
+        });
533
+        /** @deprecated 19.0.0 */
534
+        $this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
535
+
536
+        $this->registerService(Store::class, function (ContainerInterface $c) {
537
+            $session = $c->get(ISession::class);
538
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
539
+                $tokenProvider = $c->get(IProvider::class);
540
+            } else {
541
+                $tokenProvider = null;
542
+            }
543
+            $logger = $c->get(LoggerInterface::class);
544
+            return new Store($session, $logger, $tokenProvider);
545
+        });
546
+        $this->registerAlias(IStore::class, Store::class);
547
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
548
+
549
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
550
+            $manager = $c->get(IUserManager::class);
551
+            $session = new \OC\Session\Memory('');
552
+            $timeFactory = new TimeFactory();
553
+            // Token providers might require a working database. This code
554
+            // might however be called when Nextcloud is not yet setup.
555
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
556
+                $provider = $c->get(IProvider::class);
557
+            } else {
558
+                $provider = null;
559
+            }
560
+
561
+            $legacyDispatcher = $c->get(SymfonyAdapter::class);
562
+
563
+            $userSession = new \OC\User\Session(
564
+                $manager,
565
+                $session,
566
+                $timeFactory,
567
+                $provider,
568
+                $c->get(\OCP\IConfig::class),
569
+                $c->get(ISecureRandom::class),
570
+                $c->getLockdownManager(),
571
+                $c->get(LoggerInterface::class),
572
+                $c->get(IEventDispatcher::class)
573
+            );
574
+            /** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
575
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
576
+                \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
577
+            });
578
+            /** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
579
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
580
+                /** @var \OC\User\User $user */
581
+                \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
582
+            });
583
+            /** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
584
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
585
+                /** @var \OC\User\User $user */
586
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
587
+                $legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
588
+            });
589
+            /** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
590
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
591
+                /** @var \OC\User\User $user */
592
+                \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
593
+            });
594
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
595
+                /** @var \OC\User\User $user */
596
+                \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
597
+
598
+                /** @var IEventDispatcher $dispatcher */
599
+                $dispatcher = $this->get(IEventDispatcher::class);
600
+                $dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
601
+            });
602
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
603
+                /** @var \OC\User\User $user */
604
+                \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
605
+
606
+                /** @var IEventDispatcher $dispatcher */
607
+                $dispatcher = $this->get(IEventDispatcher::class);
608
+                $dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
609
+            });
610
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
611
+                \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
612
+
613
+                /** @var IEventDispatcher $dispatcher */
614
+                $dispatcher = $this->get(IEventDispatcher::class);
615
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
616
+            });
617
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
618
+                /** @var \OC\User\User $user */
619
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
620
+
621
+                /** @var IEventDispatcher $dispatcher */
622
+                $dispatcher = $this->get(IEventDispatcher::class);
623
+                $dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
624
+            });
625
+            $userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
626
+                /** @var IEventDispatcher $dispatcher */
627
+                $dispatcher = $this->get(IEventDispatcher::class);
628
+                $dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
629
+            });
630
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
631
+                /** @var \OC\User\User $user */
632
+                \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
633
+
634
+                /** @var IEventDispatcher $dispatcher */
635
+                $dispatcher = $this->get(IEventDispatcher::class);
636
+                $dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
637
+            });
638
+            $userSession->listen('\OC\User', 'logout', function ($user) {
639
+                \OC_Hook::emit('OC_User', 'logout', []);
640
+
641
+                /** @var IEventDispatcher $dispatcher */
642
+                $dispatcher = $this->get(IEventDispatcher::class);
643
+                $dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
644
+            });
645
+            $userSession->listen('\OC\User', 'postLogout', function ($user) {
646
+                /** @var IEventDispatcher $dispatcher */
647
+                $dispatcher = $this->get(IEventDispatcher::class);
648
+                $dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
649
+            });
650
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
651
+                /** @var \OC\User\User $user */
652
+                \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
653
+
654
+                /** @var IEventDispatcher $dispatcher */
655
+                $dispatcher = $this->get(IEventDispatcher::class);
656
+                $dispatcher->dispatchTyped(new UserChangedEvent($user, $feature, $value, $oldValue));
657
+            });
658
+            return $userSession;
659
+        });
660
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
661
+        /** @deprecated 19.0.0 */
662
+        $this->registerDeprecatedAlias('UserSession', \OC\User\Session::class);
663
+
664
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
665
+
666
+        $this->registerAlias(INavigationManager::class, \OC\NavigationManager::class);
667
+        /** @deprecated 19.0.0 */
668
+        $this->registerDeprecatedAlias('NavigationManager', INavigationManager::class);
669
+
670
+        /** @deprecated 19.0.0 */
671
+        $this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
672
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
673
+
674
+        $this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
675
+            return new \OC\SystemConfig($config);
676
+        });
677
+        /** @deprecated 19.0.0 */
678
+        $this->registerDeprecatedAlias('SystemConfig', \OC\SystemConfig::class);
679
+
680
+        /** @deprecated 19.0.0 */
681
+        $this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
682
+        $this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
683
+
684
+        $this->registerService(IFactory::class, function (Server $c) {
685
+            return new \OC\L10N\Factory(
686
+                $c->get(\OCP\IConfig::class),
687
+                $c->getRequest(),
688
+                $c->get(IUserSession::class),
689
+                $c->get(ICacheFactory::class),
690
+                \OC::$SERVERROOT
691
+            );
692
+        });
693
+        /** @deprecated 19.0.0 */
694
+        $this->registerDeprecatedAlias('L10NFactory', IFactory::class);
695
+
696
+        $this->registerAlias(IURLGenerator::class, URLGenerator::class);
697
+        /** @deprecated 19.0.0 */
698
+        $this->registerDeprecatedAlias('URLGenerator', IURLGenerator::class);
699
+
700
+        /** @deprecated 19.0.0 */
701
+        $this->registerDeprecatedAlias('AppFetcher', AppFetcher::class);
702
+        /** @deprecated 19.0.0 */
703
+        $this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
704
+
705
+        $this->registerService(ICache::class, function ($c) {
706
+            return new Cache\File();
707
+        });
708
+        /** @deprecated 19.0.0 */
709
+        $this->registerDeprecatedAlias('UserCache', ICache::class);
710
+
711
+        $this->registerService(Factory::class, function (Server $c) {
712
+            $profiler = $c->get(IProfiler::class);
713
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class),
714
+                $profiler,
715
+                ArrayCache::class,
716
+                ArrayCache::class,
717
+                ArrayCache::class
718
+            );
719
+            /** @var \OCP\IConfig $config */
720
+            $config = $c->get(\OCP\IConfig::class);
721
+
722
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
723
+                if (!$config->getSystemValueBool('log_query')) {
724
+                    $v = \OC_App::getAppVersions();
725
+                } else {
726
+                    // If the log_query is enabled, we can not get the app versions
727
+                    // as that does a query, which will be logged and the logging
728
+                    // depends on redis and here we are back again in the same function.
729
+                    $v = [
730
+                        'log_query' => 'enabled',
731
+                    ];
732
+                }
733
+                $v['core'] = implode(',', \OC_Util::getVersion());
734
+                $version = implode(',', $v);
735
+                $instanceId = \OC_Util::getInstanceId();
736
+                $path = \OC::$SERVERROOT;
737
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
738
+                return new \OC\Memcache\Factory($prefix,
739
+                    $c->get(LoggerInterface::class),
740
+                    $profiler,
741
+                    $config->getSystemValue('memcache.local', null),
742
+                    $config->getSystemValue('memcache.distributed', null),
743
+                    $config->getSystemValue('memcache.locking', null),
744
+                    $config->getSystemValueString('redis_log_file')
745
+                );
746
+            }
747
+            return $arrayCacheFactory;
748
+        });
749
+        /** @deprecated 19.0.0 */
750
+        $this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
751
+        $this->registerAlias(ICacheFactory::class, Factory::class);
752
+
753
+        $this->registerService('RedisFactory', function (Server $c) {
754
+            $systemConfig = $c->get(SystemConfig::class);
755
+            return new RedisFactory($systemConfig, $c->getEventLogger());
756
+        });
757
+
758
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
759
+            $l10n = $this->get(IFactory::class)->get('lib');
760
+            return new \OC\Activity\Manager(
761
+                $c->getRequest(),
762
+                $c->get(IUserSession::class),
763
+                $c->get(\OCP\IConfig::class),
764
+                $c->get(IValidator::class),
765
+                $l10n
766
+            );
767
+        });
768
+        /** @deprecated 19.0.0 */
769
+        $this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
770
+
771
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
772
+            return new \OC\Activity\EventMerger(
773
+                $c->getL10N('lib')
774
+            );
775
+        });
776
+        $this->registerAlias(IValidator::class, Validator::class);
777
+
778
+        $this->registerService(AvatarManager::class, function (Server $c) {
779
+            return new AvatarManager(
780
+                $c->get(IUserSession::class),
781
+                $c->get(\OC\User\Manager::class),
782
+                $c->getAppDataDir('avatar'),
783
+                $c->getL10N('lib'),
784
+                $c->get(LoggerInterface::class),
785
+                $c->get(\OCP\IConfig::class),
786
+                $c->get(IAccountManager::class),
787
+                $c->get(KnownUserService::class)
788
+            );
789
+        });
790
+
791
+        $this->registerAlias(IAvatarManager::class, AvatarManager::class);
792
+        /** @deprecated 19.0.0 */
793
+        $this->registerDeprecatedAlias('AvatarManager', AvatarManager::class);
794
+
795
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
796
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
797
+        $this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
798
+
799
+        $this->registerService(\OC\Log::class, function (Server $c) {
800
+            $logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
801
+            $factory = new LogFactory($c, $this->get(SystemConfig::class));
802
+            $logger = $factory->get($logType);
803
+            $registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
804
+
805
+            return new Log($logger, $this->get(SystemConfig::class), null, $registry);
806
+        });
807
+        $this->registerAlias(ILogger::class, \OC\Log::class);
808
+        /** @deprecated 19.0.0 */
809
+        $this->registerDeprecatedAlias('Logger', \OC\Log::class);
810
+        // PSR-3 logger
811
+        $this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
812
+
813
+        $this->registerService(ILogFactory::class, function (Server $c) {
814
+            return new LogFactory($c, $this->get(SystemConfig::class));
815
+        });
816
+
817
+        $this->registerAlias(IJobList::class, \OC\BackgroundJob\JobList::class);
818
+        /** @deprecated 19.0.0 */
819
+        $this->registerDeprecatedAlias('JobList', IJobList::class);
820
+
821
+        $this->registerService(Router::class, function (Server $c) {
822
+            $cacheFactory = $c->get(ICacheFactory::class);
823
+            $logger = $c->get(LoggerInterface::class);
824
+            if ($cacheFactory->isLocalCacheAvailable()) {
825
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
826
+            } else {
827
+                $router = new \OC\Route\Router($logger);
828
+            }
829
+            return $router;
830
+        });
831
+        $this->registerAlias(IRouter::class, Router::class);
832
+        /** @deprecated 19.0.0 */
833
+        $this->registerDeprecatedAlias('Router', IRouter::class);
834
+
835
+        $this->registerAlias(ISearch::class, Search::class);
836
+        /** @deprecated 19.0.0 */
837
+        $this->registerDeprecatedAlias('Search', ISearch::class);
838
+
839
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
840
+            $cacheFactory = $c->get(ICacheFactory::class);
841
+            if ($cacheFactory->isAvailable()) {
842
+                $backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
843
+                    $this->get(ICacheFactory::class),
844
+                    new \OC\AppFramework\Utility\TimeFactory()
845
+                );
846
+            } else {
847
+                $backend = new \OC\Security\RateLimiting\Backend\DatabaseBackend(
848
+                    $c->get(IDBConnection::class),
849
+                    new \OC\AppFramework\Utility\TimeFactory()
850
+                );
851
+            }
852
+
853
+            return $backend;
854
+        });
855
+
856
+        $this->registerAlias(\OCP\Security\ISecureRandom::class, SecureRandom::class);
857
+        /** @deprecated 19.0.0 */
858
+        $this->registerDeprecatedAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
859
+        $this->registerAlias(\OCP\Security\IRemoteHostValidator::class, \OC\Security\RemoteHostValidator::class);
860
+        $this->registerAlias(IVerificationToken::class, VerificationToken::class);
861
+
862
+        $this->registerAlias(ICrypto::class, Crypto::class);
863
+        /** @deprecated 19.0.0 */
864
+        $this->registerDeprecatedAlias('Crypto', ICrypto::class);
865
+
866
+        $this->registerAlias(IHasher::class, Hasher::class);
867
+        /** @deprecated 19.0.0 */
868
+        $this->registerDeprecatedAlias('Hasher', IHasher::class);
869
+
870
+        $this->registerAlias(ICredentialsManager::class, CredentialsManager::class);
871
+        /** @deprecated 19.0.0 */
872
+        $this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
873
+
874
+        $this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
875
+        $this->registerService(Connection::class, function (Server $c) {
876
+            $systemConfig = $c->get(SystemConfig::class);
877
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
878
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
879
+            if (!$factory->isValidType($type)) {
880
+                throw new \OC\DatabaseException('Invalid database type');
881
+            }
882
+            $connectionParams = $factory->createConnectionParams();
883
+            $connection = $factory->getConnection($type, $connectionParams);
884
+            return $connection;
885
+        });
886
+        /** @deprecated 19.0.0 */
887
+        $this->registerDeprecatedAlias('DatabaseConnection', IDBConnection::class);
888
+
889
+        $this->registerAlias(ICertificateManager::class, CertificateManager::class);
890
+        $this->registerAlias(IClientService::class, ClientService::class);
891
+        $this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
892
+            return new NegativeDnsCache(
893
+                $c->get(ICacheFactory::class),
894
+            );
895
+        });
896
+        $this->registerDeprecatedAlias('HttpClientService', IClientService::class);
897
+        $this->registerService(IEventLogger::class, function (ContainerInterface $c) {
898
+            return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
899
+        });
900
+        /** @deprecated 19.0.0 */
901
+        $this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
902
+
903
+        $this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
904
+            $queryLogger = new QueryLogger();
905
+            if ($c->get(SystemConfig::class)->getValue('debug', false)) {
906
+                // In debug mode, module is being activated by default
907
+                $queryLogger->activate();
908
+            }
909
+            return $queryLogger;
910
+        });
911
+        /** @deprecated 19.0.0 */
912
+        $this->registerDeprecatedAlias('QueryLogger', IQueryLogger::class);
913
+
914
+        /** @deprecated 19.0.0 */
915
+        $this->registerDeprecatedAlias('TempManager', TempManager::class);
916
+        $this->registerAlias(ITempManager::class, TempManager::class);
917
+
918
+        $this->registerService(AppManager::class, function (ContainerInterface $c) {
919
+            // TODO: use auto-wiring
920
+            return new \OC\App\AppManager(
921
+                $c->get(IUserSession::class),
922
+                $c->get(\OCP\IConfig::class),
923
+                $c->get(\OC\AppConfig::class),
924
+                $c->get(IGroupManager::class),
925
+                $c->get(ICacheFactory::class),
926
+                $c->get(SymfonyAdapter::class),
927
+                $c->get(LoggerInterface::class)
928
+            );
929
+        });
930
+        /** @deprecated 19.0.0 */
931
+        $this->registerDeprecatedAlias('AppManager', AppManager::class);
932
+        $this->registerAlias(IAppManager::class, AppManager::class);
933
+
934
+        $this->registerAlias(IDateTimeZone::class, DateTimeZone::class);
935
+        /** @deprecated 19.0.0 */
936
+        $this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
937
+
938
+        $this->registerService(IDateTimeFormatter::class, function (Server $c) {
939
+            $language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
940
+
941
+            return new DateTimeFormatter(
942
+                $c->get(IDateTimeZone::class)->getTimeZone(),
943
+                $c->getL10N('lib', $language)
944
+            );
945
+        });
946
+        /** @deprecated 19.0.0 */
947
+        $this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
948
+
949
+        $this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
950
+            $mountCache = $c->get(UserMountCache::class);
951
+            $listener = new UserMountCacheListener($mountCache);
952
+            $listener->listen($c->get(IUserManager::class));
953
+            return $mountCache;
954
+        });
955
+        /** @deprecated 19.0.0 */
956
+        $this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
957
+
958
+        $this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
959
+            $loader = $c->get(IStorageFactory::class);
960
+            $mountCache = $c->get(IUserMountCache::class);
961
+            $eventLogger = $c->get(IEventLogger::class);
962
+            $manager = new MountProviderCollection($loader, $mountCache, $eventLogger);
963
+
964
+            // builtin providers
965
+
966
+            $config = $c->get(\OCP\IConfig::class);
967
+            $logger = $c->get(LoggerInterface::class);
968
+            $manager->registerProvider(new CacheMountProvider($config));
969
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
970
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
971
+            $manager->registerRootProvider(new RootMountProvider($config, $c->get(LoggerInterface::class)));
972
+            $manager->registerRootProvider(new ObjectStorePreviewCacheMountProvider($logger, $config));
973
+
974
+            return $manager;
975
+        });
976
+        /** @deprecated 19.0.0 */
977
+        $this->registerDeprecatedAlias('MountConfigManager', IMountProviderCollection::class);
978
+
979
+        /** @deprecated 20.0.0 */
980
+        $this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
981
+        $this->registerService(IBus::class, function (ContainerInterface $c) {
982
+            $busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
983
+            if ($busClass) {
984
+                [$app, $class] = explode('::', $busClass, 2);
985
+                if ($c->get(IAppManager::class)->isInstalled($app)) {
986
+                    \OC_App::loadApp($app);
987
+                    return $c->get($class);
988
+                } else {
989
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
990
+                }
991
+            } else {
992
+                $jobList = $c->get(IJobList::class);
993
+                return new CronBus($jobList);
994
+            }
995
+        });
996
+        $this->registerDeprecatedAlias('AsyncCommandBus', IBus::class);
997
+        /** @deprecated 20.0.0 */
998
+        $this->registerDeprecatedAlias('TrustedDomainHelper', TrustedDomainHelper::class);
999
+        $this->registerAlias(ITrustedDomainHelper::class, TrustedDomainHelper::class);
1000
+        /** @deprecated 19.0.0 */
1001
+        $this->registerDeprecatedAlias('Throttler', Throttler::class);
1002
+        $this->registerAlias(IThrottler::class, Throttler::class);
1003
+        $this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
1004
+            // IConfig and IAppManager requires a working database. This code
1005
+            // might however be called when ownCloud is not yet setup.
1006
+            if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
1007
+                $config = $c->get(\OCP\IConfig::class);
1008
+                $appManager = $c->get(IAppManager::class);
1009
+            } else {
1010
+                $config = null;
1011
+                $appManager = null;
1012
+            }
1013
+
1014
+            return new Checker(
1015
+                new EnvironmentHelper(),
1016
+                new FileAccessHelper(),
1017
+                new AppLocator(),
1018
+                $config,
1019
+                $c->get(ICacheFactory::class),
1020
+                $appManager,
1021
+                $c->get(IMimeTypeDetector::class)
1022
+            );
1023
+        });
1024
+        $this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
1025
+            if (isset($this['urlParams'])) {
1026
+                $urlParams = $this['urlParams'];
1027
+            } else {
1028
+                $urlParams = [];
1029
+            }
1030
+
1031
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
1032
+                && in_array('fakeinput', stream_get_wrappers())
1033
+            ) {
1034
+                $stream = 'fakeinput://data';
1035
+            } else {
1036
+                $stream = 'php://input';
1037
+            }
1038
+
1039
+            return new Request(
1040
+                [
1041
+                    'get' => $_GET,
1042
+                    'post' => $_POST,
1043
+                    'files' => $_FILES,
1044
+                    'server' => $_SERVER,
1045
+                    'env' => $_ENV,
1046
+                    'cookies' => $_COOKIE,
1047
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1048
+                        ? $_SERVER['REQUEST_METHOD']
1049
+                        : '',
1050
+                    'urlParams' => $urlParams,
1051
+                ],
1052
+                $this->get(IRequestId::class),
1053
+                $this->get(\OCP\IConfig::class),
1054
+                $this->get(CsrfTokenManager::class),
1055
+                $stream
1056
+            );
1057
+        });
1058
+        /** @deprecated 19.0.0 */
1059
+        $this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
1060
+
1061
+        $this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
1062
+            return new RequestId(
1063
+                $_SERVER['UNIQUE_ID'] ?? '',
1064
+                $this->get(ISecureRandom::class)
1065
+            );
1066
+        });
1067
+
1068
+        $this->registerService(IMailer::class, function (Server $c) {
1069
+            return new Mailer(
1070
+                $c->get(\OCP\IConfig::class),
1071
+                $c->get(LoggerInterface::class),
1072
+                $c->get(Defaults::class),
1073
+                $c->get(IURLGenerator::class),
1074
+                $c->getL10N('lib'),
1075
+                $c->get(IEventDispatcher::class),
1076
+                $c->get(IFactory::class)
1077
+            );
1078
+        });
1079
+        /** @deprecated 19.0.0 */
1080
+        $this->registerDeprecatedAlias('Mailer', IMailer::class);
1081
+
1082
+        /** @deprecated 21.0.0 */
1083
+        $this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
1084
+
1085
+        $this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
1086
+            $config = $c->get(\OCP\IConfig::class);
1087
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1088
+            if (is_null($factoryClass) || !class_exists($factoryClass)) {
1089
+                return new NullLDAPProviderFactory($this);
1090
+            }
1091
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1092
+            return new $factoryClass($this);
1093
+        });
1094
+        $this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
1095
+            $factory = $c->get(ILDAPProviderFactory::class);
1096
+            return $factory->getLDAPProvider();
1097
+        });
1098
+        $this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1099
+            $ini = $c->get(IniGetWrapper::class);
1100
+            $config = $c->get(\OCP\IConfig::class);
1101
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
1102
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
1103
+                /** @var \OC\Memcache\Factory $memcacheFactory */
1104
+                $memcacheFactory = $c->get(ICacheFactory::class);
1105
+                $memcache = $memcacheFactory->createLocking('lock');
1106
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
1107
+                    return new MemcacheLockingProvider($memcache, $ttl);
1108
+                }
1109
+                return new DBLockingProvider(
1110
+                    $c->get(IDBConnection::class),
1111
+                    new TimeFactory(),
1112
+                    $ttl,
1113
+                    !\OC::$CLI
1114
+                );
1115
+            }
1116
+            return new NoopLockingProvider();
1117
+        });
1118
+        /** @deprecated 19.0.0 */
1119
+        $this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1120
+
1121
+        $this->registerService(ILockManager::class, function (Server $c): LockManager {
1122
+            return new LockManager();
1123
+        });
1124
+
1125
+        $this->registerAlias(ILockdownManager::class, 'LockdownManager');
1126
+        $this->registerService(SetupManager::class, function ($c) {
1127
+            // create the setupmanager through the mount manager to resolve the cyclic dependency
1128
+            return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
1129
+        });
1130
+        $this->registerAlias(IMountManager::class, \OC\Files\Mount\Manager::class);
1131
+        /** @deprecated 19.0.0 */
1132
+        $this->registerDeprecatedAlias('MountManager', IMountManager::class);
1133
+
1134
+        $this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1135
+            return new \OC\Files\Type\Detection(
1136
+                $c->get(IURLGenerator::class),
1137
+                $c->get(LoggerInterface::class),
1138
+                \OC::$configDir,
1139
+                \OC::$SERVERROOT . '/resources/config/'
1140
+            );
1141
+        });
1142
+        /** @deprecated 19.0.0 */
1143
+        $this->registerDeprecatedAlias('MimeTypeDetector', IMimeTypeDetector::class);
1144
+
1145
+        $this->registerAlias(IMimeTypeLoader::class, Loader::class);
1146
+        /** @deprecated 19.0.0 */
1147
+        $this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1148
+        $this->registerService(BundleFetcher::class, function () {
1149
+            return new BundleFetcher($this->getL10N('lib'));
1150
+        });
1151
+        $this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1152
+        /** @deprecated 19.0.0 */
1153
+        $this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1154
+
1155
+        $this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1156
+            $manager = new CapabilitiesManager($c->get(LoggerInterface::class));
1157
+            $manager->registerCapability(function () use ($c) {
1158
+                return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1159
+            });
1160
+            $manager->registerCapability(function () use ($c) {
1161
+                return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1162
+            });
1163
+            $manager->registerCapability(function () use ($c) {
1164
+                return $c->get(MetadataCapabilities::class);
1165
+            });
1166
+            return $manager;
1167
+        });
1168
+        /** @deprecated 19.0.0 */
1169
+        $this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1170
+
1171
+        $this->registerService(ICommentsManager::class, function (Server $c) {
1172
+            $config = $c->get(\OCP\IConfig::class);
1173
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1174
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
1175
+            $factory = new $factoryClass($this);
1176
+            $manager = $factory->getManager();
1177
+
1178
+            $manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1179
+                $manager = $c->get(IUserManager::class);
1180
+                $userDisplayName = $manager->getDisplayName($id);
1181
+                if ($userDisplayName === null) {
1182
+                    $l = $c->get(IFactory::class)->get('core');
1183
+                    return $l->t('Unknown user');
1184
+                }
1185
+                return $userDisplayName;
1186
+            });
1187
+
1188
+            return $manager;
1189
+        });
1190
+        /** @deprecated 19.0.0 */
1191
+        $this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1192
+
1193
+        $this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1194
+        $this->registerService('ThemingDefaults', function (Server $c) {
1195
+            /*
1196 1196
 			 * Dark magic for autoloader.
1197 1197
 			 * If we do a class_exists it will try to load the class which will
1198 1198
 			 * make composer cache the result. Resulting in errors when enabling
1199 1199
 			 * the theming app.
1200 1200
 			 */
1201
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1202
-			if (isset($prefixes['OCA\\Theming\\'])) {
1203
-				$classExists = true;
1204
-			} else {
1205
-				$classExists = false;
1206
-			}
1207
-
1208
-			if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1209
-				$imageManager = new ImageManager(
1210
-					$c->get(\OCP\IConfig::class),
1211
-					$c->getAppDataDir('theming'),
1212
-					$c->get(IURLGenerator::class),
1213
-					$this->get(ICacheFactory::class),
1214
-					$this->get(ILogger::class),
1215
-					$this->get(ITempManager::class)
1216
-				);
1217
-				return new ThemingDefaults(
1218
-					$c->get(\OCP\IConfig::class),
1219
-					$c->getL10N('theming'),
1220
-					$c->get(IUserSession::class),
1221
-					$c->get(IURLGenerator::class),
1222
-					$c->get(ICacheFactory::class),
1223
-					new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager),
1224
-					$imageManager,
1225
-					$c->get(IAppManager::class),
1226
-					$c->get(INavigationManager::class)
1227
-				);
1228
-			}
1229
-			return new \OC_Defaults();
1230
-		});
1231
-		$this->registerService(JSCombiner::class, function (Server $c) {
1232
-			return new JSCombiner(
1233
-				$c->getAppDataDir('js'),
1234
-				$c->get(IURLGenerator::class),
1235
-				$this->get(ICacheFactory::class),
1236
-				$c->get(SystemConfig::class),
1237
-				$c->get(LoggerInterface::class)
1238
-			);
1239
-		});
1240
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1241
-		/** @deprecated 19.0.0 */
1242
-		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1243
-		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1244
-
1245
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1246
-			// FIXME: Instantiated here due to cyclic dependency
1247
-			$request = new Request(
1248
-				[
1249
-					'get' => $_GET,
1250
-					'post' => $_POST,
1251
-					'files' => $_FILES,
1252
-					'server' => $_SERVER,
1253
-					'env' => $_ENV,
1254
-					'cookies' => $_COOKIE,
1255
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1256
-						? $_SERVER['REQUEST_METHOD']
1257
-						: null,
1258
-				],
1259
-				$c->get(IRequestId::class),
1260
-				$c->get(\OCP\IConfig::class)
1261
-			);
1262
-
1263
-			return new CryptoWrapper(
1264
-				$c->get(\OCP\IConfig::class),
1265
-				$c->get(ICrypto::class),
1266
-				$c->get(ISecureRandom::class),
1267
-				$request
1268
-			);
1269
-		});
1270
-		/** @deprecated 19.0.0 */
1271
-		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1272
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1273
-			return new SessionStorage($c->get(ISession::class));
1274
-		});
1275
-		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1276
-		/** @deprecated 19.0.0 */
1277
-		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1278
-
1279
-		$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1280
-			$config = $c->get(\OCP\IConfig::class);
1281
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1282
-			/** @var \OCP\Share\IProviderFactory $factory */
1283
-			$factory = new $factoryClass($this);
1284
-
1285
-			$manager = new \OC\Share20\Manager(
1286
-				$c->get(LoggerInterface::class),
1287
-				$c->get(\OCP\IConfig::class),
1288
-				$c->get(ISecureRandom::class),
1289
-				$c->get(IHasher::class),
1290
-				$c->get(IMountManager::class),
1291
-				$c->get(IGroupManager::class),
1292
-				$c->getL10N('lib'),
1293
-				$c->get(IFactory::class),
1294
-				$factory,
1295
-				$c->get(IUserManager::class),
1296
-				$c->get(IRootFolder::class),
1297
-				$c->get(SymfonyAdapter::class),
1298
-				$c->get(IMailer::class),
1299
-				$c->get(IURLGenerator::class),
1300
-				$c->get('ThemingDefaults'),
1301
-				$c->get(IEventDispatcher::class),
1302
-				$c->get(IUserSession::class),
1303
-				$c->get(KnownUserService::class)
1304
-			);
1305
-
1306
-			return $manager;
1307
-		});
1308
-		/** @deprecated 19.0.0 */
1309
-		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1310
-
1311
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1312
-			$instance = new Collaboration\Collaborators\Search($c);
1313
-
1314
-			// register default plugins
1315
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1316
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1317
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1318
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1319
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1320
-
1321
-			return $instance;
1322
-		});
1323
-		/** @deprecated 19.0.0 */
1324
-		$this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1325
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1326
-
1327
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1328
-
1329
-		$this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1330
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1331
-
1332
-		$this->registerAlias(IReferenceManager::class, ReferenceManager::class);
1333
-
1334
-		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1335
-		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1336
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1337
-			return new \OC\Files\AppData\Factory(
1338
-				$c->get(IRootFolder::class),
1339
-				$c->get(SystemConfig::class)
1340
-			);
1341
-		});
1342
-
1343
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1344
-			return new LockdownManager(function () use ($c) {
1345
-				return $c->get(ISession::class);
1346
-			});
1347
-		});
1348
-
1349
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1350
-			return new DiscoveryService(
1351
-				$c->get(ICacheFactory::class),
1352
-				$c->get(IClientService::class)
1353
-			);
1354
-		});
1355
-
1356
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1357
-			return new CloudIdManager(
1358
-				$c->get(\OCP\Contacts\IManager::class),
1359
-				$c->get(IURLGenerator::class),
1360
-				$c->get(IUserManager::class),
1361
-				$c->get(ICacheFactory::class),
1362
-				$c->get(IEventDispatcher::class),
1363
-			);
1364
-		});
1365
-
1366
-		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1367
-
1368
-		$this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1369
-			return new CloudFederationProviderManager(
1370
-				$c->get(IAppManager::class),
1371
-				$c->get(IClientService::class),
1372
-				$c->get(ICloudIdManager::class),
1373
-				$c->get(LoggerInterface::class)
1374
-			);
1375
-		});
1376
-
1377
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1378
-			return new CloudFederationFactory();
1379
-		});
1380
-
1381
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1382
-		/** @deprecated 19.0.0 */
1383
-		$this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1384
-
1385
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1386
-		/** @deprecated 19.0.0 */
1387
-		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1388
-
1389
-		$this->registerService(Defaults::class, function (Server $c) {
1390
-			return new Defaults(
1391
-				$c->getThemingDefaults()
1392
-			);
1393
-		});
1394
-		/** @deprecated 19.0.0 */
1395
-		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1396
-
1397
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1398
-			return $c->get(\OCP\IUserSession::class)->getSession();
1399
-		}, false);
1400
-
1401
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1402
-			return new ShareHelper(
1403
-				$c->get(\OCP\Share\IManager::class)
1404
-			);
1405
-		});
1406
-
1407
-		$this->registerService(Installer::class, function (ContainerInterface $c) {
1408
-			return new Installer(
1409
-				$c->get(AppFetcher::class),
1410
-				$c->get(IClientService::class),
1411
-				$c->get(ITempManager::class),
1412
-				$c->get(LoggerInterface::class),
1413
-				$c->get(\OCP\IConfig::class),
1414
-				\OC::$CLI
1415
-			);
1416
-		});
1417
-
1418
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1419
-			return new ApiFactory($c->get(IClientService::class));
1420
-		});
1421
-
1422
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1423
-			$memcacheFactory = $c->get(ICacheFactory::class);
1424
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1425
-		});
1426
-
1427
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1428
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1429
-
1430
-		$this->registerAlias(IStorageFactory::class, StorageFactory::class);
1431
-
1432
-		$this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1433
-
1434
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1435
-
1436
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1437
-
1438
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1439
-
1440
-		$this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
1441
-
1442
-		$this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1443
-
1444
-		$this->registerAlias(IBroker::class, Broker::class);
1445
-
1446
-		$this->registerAlias(IMetadataManager::class, MetadataManager::class);
1447
-
1448
-		$this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
1449
-
1450
-		$this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
1451
-
1452
-		$this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class);
1453
-
1454
-		$this->connectDispatcher();
1455
-	}
1456
-
1457
-	public function boot() {
1458
-		/** @var HookConnector $hookConnector */
1459
-		$hookConnector = $this->get(HookConnector::class);
1460
-		$hookConnector->viewToNode();
1461
-	}
1462
-
1463
-	/**
1464
-	 * @return \OCP\Calendar\IManager
1465
-	 * @deprecated 20.0.0
1466
-	 */
1467
-	public function getCalendarManager() {
1468
-		return $this->get(\OC\Calendar\Manager::class);
1469
-	}
1470
-
1471
-	/**
1472
-	 * @return \OCP\Calendar\Resource\IManager
1473
-	 * @deprecated 20.0.0
1474
-	 */
1475
-	public function getCalendarResourceBackendManager() {
1476
-		return $this->get(\OC\Calendar\Resource\Manager::class);
1477
-	}
1478
-
1479
-	/**
1480
-	 * @return \OCP\Calendar\Room\IManager
1481
-	 * @deprecated 20.0.0
1482
-	 */
1483
-	public function getCalendarRoomBackendManager() {
1484
-		return $this->get(\OC\Calendar\Room\Manager::class);
1485
-	}
1486
-
1487
-	private function connectDispatcher(): void {
1488
-		/** @var IEventDispatcher $eventDispatcher */
1489
-		$eventDispatcher = $this->get(IEventDispatcher::class);
1490
-		$eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1491
-		$eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1492
-		$eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
1493
-		$eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
1494
-	}
1495
-
1496
-	/**
1497
-	 * @return \OCP\Contacts\IManager
1498
-	 * @deprecated 20.0.0
1499
-	 */
1500
-	public function getContactsManager() {
1501
-		return $this->get(\OCP\Contacts\IManager::class);
1502
-	}
1503
-
1504
-	/**
1505
-	 * @return \OC\Encryption\Manager
1506
-	 * @deprecated 20.0.0
1507
-	 */
1508
-	public function getEncryptionManager() {
1509
-		return $this->get(\OCP\Encryption\IManager::class);
1510
-	}
1511
-
1512
-	/**
1513
-	 * @return \OC\Encryption\File
1514
-	 * @deprecated 20.0.0
1515
-	 */
1516
-	public function getEncryptionFilesHelper() {
1517
-		return $this->get(IFile::class);
1518
-	}
1519
-
1520
-	/**
1521
-	 * @return \OCP\Encryption\Keys\IStorage
1522
-	 * @deprecated 20.0.0
1523
-	 */
1524
-	public function getEncryptionKeyStorage() {
1525
-		return $this->get(IStorage::class);
1526
-	}
1527
-
1528
-	/**
1529
-	 * The current request object holding all information about the request
1530
-	 * currently being processed is returned from this method.
1531
-	 * In case the current execution was not initiated by a web request null is returned
1532
-	 *
1533
-	 * @return \OCP\IRequest
1534
-	 * @deprecated 20.0.0
1535
-	 */
1536
-	public function getRequest() {
1537
-		return $this->get(IRequest::class);
1538
-	}
1539
-
1540
-	/**
1541
-	 * Returns the preview manager which can create preview images for a given file
1542
-	 *
1543
-	 * @return IPreview
1544
-	 * @deprecated 20.0.0
1545
-	 */
1546
-	public function getPreviewManager() {
1547
-		return $this->get(IPreview::class);
1548
-	}
1549
-
1550
-	/**
1551
-	 * Returns the tag manager which can get and set tags for different object types
1552
-	 *
1553
-	 * @see \OCP\ITagManager::load()
1554
-	 * @return ITagManager
1555
-	 * @deprecated 20.0.0
1556
-	 */
1557
-	public function getTagManager() {
1558
-		return $this->get(ITagManager::class);
1559
-	}
1560
-
1561
-	/**
1562
-	 * Returns the system-tag manager
1563
-	 *
1564
-	 * @return ISystemTagManager
1565
-	 *
1566
-	 * @since 9.0.0
1567
-	 * @deprecated 20.0.0
1568
-	 */
1569
-	public function getSystemTagManager() {
1570
-		return $this->get(ISystemTagManager::class);
1571
-	}
1572
-
1573
-	/**
1574
-	 * Returns the system-tag object mapper
1575
-	 *
1576
-	 * @return ISystemTagObjectMapper
1577
-	 *
1578
-	 * @since 9.0.0
1579
-	 * @deprecated 20.0.0
1580
-	 */
1581
-	public function getSystemTagObjectMapper() {
1582
-		return $this->get(ISystemTagObjectMapper::class);
1583
-	}
1584
-
1585
-	/**
1586
-	 * Returns the avatar manager, used for avatar functionality
1587
-	 *
1588
-	 * @return IAvatarManager
1589
-	 * @deprecated 20.0.0
1590
-	 */
1591
-	public function getAvatarManager() {
1592
-		return $this->get(IAvatarManager::class);
1593
-	}
1594
-
1595
-	/**
1596
-	 * Returns the root folder of ownCloud's data directory
1597
-	 *
1598
-	 * @return IRootFolder
1599
-	 * @deprecated 20.0.0
1600
-	 */
1601
-	public function getRootFolder() {
1602
-		return $this->get(IRootFolder::class);
1603
-	}
1604
-
1605
-	/**
1606
-	 * Returns the root folder of ownCloud's data directory
1607
-	 * This is the lazy variant so this gets only initialized once it
1608
-	 * is actually used.
1609
-	 *
1610
-	 * @return IRootFolder
1611
-	 * @deprecated 20.0.0
1612
-	 */
1613
-	public function getLazyRootFolder() {
1614
-		return $this->get(IRootFolder::class);
1615
-	}
1616
-
1617
-	/**
1618
-	 * Returns a view to ownCloud's files folder
1619
-	 *
1620
-	 * @param string $userId user ID
1621
-	 * @return \OCP\Files\Folder|null
1622
-	 * @deprecated 20.0.0
1623
-	 */
1624
-	public function getUserFolder($userId = null) {
1625
-		if ($userId === null) {
1626
-			$user = $this->get(IUserSession::class)->getUser();
1627
-			if (!$user) {
1628
-				return null;
1629
-			}
1630
-			$userId = $user->getUID();
1631
-		}
1632
-		$root = $this->get(IRootFolder::class);
1633
-		return $root->getUserFolder($userId);
1634
-	}
1635
-
1636
-	/**
1637
-	 * @return \OC\User\Manager
1638
-	 * @deprecated 20.0.0
1639
-	 */
1640
-	public function getUserManager() {
1641
-		return $this->get(IUserManager::class);
1642
-	}
1643
-
1644
-	/**
1645
-	 * @return \OC\Group\Manager
1646
-	 * @deprecated 20.0.0
1647
-	 */
1648
-	public function getGroupManager() {
1649
-		return $this->get(IGroupManager::class);
1650
-	}
1651
-
1652
-	/**
1653
-	 * @return \OC\User\Session
1654
-	 * @deprecated 20.0.0
1655
-	 */
1656
-	public function getUserSession() {
1657
-		return $this->get(IUserSession::class);
1658
-	}
1659
-
1660
-	/**
1661
-	 * @return \OCP\ISession
1662
-	 * @deprecated 20.0.0
1663
-	 */
1664
-	public function getSession() {
1665
-		return $this->get(Session::class)->getSession();
1666
-	}
1667
-
1668
-	/**
1669
-	 * @param \OCP\ISession $session
1670
-	 */
1671
-	public function setSession(\OCP\ISession $session) {
1672
-		$this->get(SessionStorage::class)->setSession($session);
1673
-		$this->get(Session::class)->setSession($session);
1674
-		$this->get(Store::class)->setSession($session);
1675
-	}
1676
-
1677
-	/**
1678
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1679
-	 * @deprecated 20.0.0
1680
-	 */
1681
-	public function getTwoFactorAuthManager() {
1682
-		return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1683
-	}
1684
-
1685
-	/**
1686
-	 * @return \OC\NavigationManager
1687
-	 * @deprecated 20.0.0
1688
-	 */
1689
-	public function getNavigationManager() {
1690
-		return $this->get(INavigationManager::class);
1691
-	}
1692
-
1693
-	/**
1694
-	 * @return \OCP\IConfig
1695
-	 * @deprecated 20.0.0
1696
-	 */
1697
-	public function getConfig() {
1698
-		return $this->get(AllConfig::class);
1699
-	}
1700
-
1701
-	/**
1702
-	 * @return \OC\SystemConfig
1703
-	 * @deprecated 20.0.0
1704
-	 */
1705
-	public function getSystemConfig() {
1706
-		return $this->get(SystemConfig::class);
1707
-	}
1708
-
1709
-	/**
1710
-	 * Returns the app config manager
1711
-	 *
1712
-	 * @return IAppConfig
1713
-	 * @deprecated 20.0.0
1714
-	 */
1715
-	public function getAppConfig() {
1716
-		return $this->get(IAppConfig::class);
1717
-	}
1718
-
1719
-	/**
1720
-	 * @return IFactory
1721
-	 * @deprecated 20.0.0
1722
-	 */
1723
-	public function getL10NFactory() {
1724
-		return $this->get(IFactory::class);
1725
-	}
1726
-
1727
-	/**
1728
-	 * get an L10N instance
1729
-	 *
1730
-	 * @param string $app appid
1731
-	 * @param string $lang
1732
-	 * @return IL10N
1733
-	 * @deprecated 20.0.0
1734
-	 */
1735
-	public function getL10N($app, $lang = null) {
1736
-		return $this->get(IFactory::class)->get($app, $lang);
1737
-	}
1738
-
1739
-	/**
1740
-	 * @return IURLGenerator
1741
-	 * @deprecated 20.0.0
1742
-	 */
1743
-	public function getURLGenerator() {
1744
-		return $this->get(IURLGenerator::class);
1745
-	}
1746
-
1747
-	/**
1748
-	 * @return AppFetcher
1749
-	 * @deprecated 20.0.0
1750
-	 */
1751
-	public function getAppFetcher() {
1752
-		return $this->get(AppFetcher::class);
1753
-	}
1754
-
1755
-	/**
1756
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1757
-	 * getMemCacheFactory() instead.
1758
-	 *
1759
-	 * @return ICache
1760
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1761
-	 */
1762
-	public function getCache() {
1763
-		return $this->get(ICache::class);
1764
-	}
1765
-
1766
-	/**
1767
-	 * Returns an \OCP\CacheFactory instance
1768
-	 *
1769
-	 * @return \OCP\ICacheFactory
1770
-	 * @deprecated 20.0.0
1771
-	 */
1772
-	public function getMemCacheFactory() {
1773
-		return $this->get(ICacheFactory::class);
1774
-	}
1775
-
1776
-	/**
1777
-	 * Returns an \OC\RedisFactory instance
1778
-	 *
1779
-	 * @return \OC\RedisFactory
1780
-	 * @deprecated 20.0.0
1781
-	 */
1782
-	public function getGetRedisFactory() {
1783
-		return $this->get('RedisFactory');
1784
-	}
1785
-
1786
-
1787
-	/**
1788
-	 * Returns the current session
1789
-	 *
1790
-	 * @return \OCP\IDBConnection
1791
-	 * @deprecated 20.0.0
1792
-	 */
1793
-	public function getDatabaseConnection() {
1794
-		return $this->get(IDBConnection::class);
1795
-	}
1796
-
1797
-	/**
1798
-	 * Returns the activity manager
1799
-	 *
1800
-	 * @return \OCP\Activity\IManager
1801
-	 * @deprecated 20.0.0
1802
-	 */
1803
-	public function getActivityManager() {
1804
-		return $this->get(\OCP\Activity\IManager::class);
1805
-	}
1806
-
1807
-	/**
1808
-	 * Returns an job list for controlling background jobs
1809
-	 *
1810
-	 * @return IJobList
1811
-	 * @deprecated 20.0.0
1812
-	 */
1813
-	public function getJobList() {
1814
-		return $this->get(IJobList::class);
1815
-	}
1816
-
1817
-	/**
1818
-	 * Returns a logger instance
1819
-	 *
1820
-	 * @return ILogger
1821
-	 * @deprecated 20.0.0
1822
-	 */
1823
-	public function getLogger() {
1824
-		return $this->get(ILogger::class);
1825
-	}
1826
-
1827
-	/**
1828
-	 * @return ILogFactory
1829
-	 * @throws \OCP\AppFramework\QueryException
1830
-	 * @deprecated 20.0.0
1831
-	 */
1832
-	public function getLogFactory() {
1833
-		return $this->get(ILogFactory::class);
1834
-	}
1835
-
1836
-	/**
1837
-	 * Returns a router for generating and matching urls
1838
-	 *
1839
-	 * @return IRouter
1840
-	 * @deprecated 20.0.0
1841
-	 */
1842
-	public function getRouter() {
1843
-		return $this->get(IRouter::class);
1844
-	}
1845
-
1846
-	/**
1847
-	 * Returns a search instance
1848
-	 *
1849
-	 * @return ISearch
1850
-	 * @deprecated 20.0.0
1851
-	 */
1852
-	public function getSearch() {
1853
-		return $this->get(ISearch::class);
1854
-	}
1855
-
1856
-	/**
1857
-	 * Returns a SecureRandom instance
1858
-	 *
1859
-	 * @return \OCP\Security\ISecureRandom
1860
-	 * @deprecated 20.0.0
1861
-	 */
1862
-	public function getSecureRandom() {
1863
-		return $this->get(ISecureRandom::class);
1864
-	}
1865
-
1866
-	/**
1867
-	 * Returns a Crypto instance
1868
-	 *
1869
-	 * @return ICrypto
1870
-	 * @deprecated 20.0.0
1871
-	 */
1872
-	public function getCrypto() {
1873
-		return $this->get(ICrypto::class);
1874
-	}
1875
-
1876
-	/**
1877
-	 * Returns a Hasher instance
1878
-	 *
1879
-	 * @return IHasher
1880
-	 * @deprecated 20.0.0
1881
-	 */
1882
-	public function getHasher() {
1883
-		return $this->get(IHasher::class);
1884
-	}
1885
-
1886
-	/**
1887
-	 * Returns a CredentialsManager instance
1888
-	 *
1889
-	 * @return ICredentialsManager
1890
-	 * @deprecated 20.0.0
1891
-	 */
1892
-	public function getCredentialsManager() {
1893
-		return $this->get(ICredentialsManager::class);
1894
-	}
1895
-
1896
-	/**
1897
-	 * Get the certificate manager
1898
-	 *
1899
-	 * @return \OCP\ICertificateManager
1900
-	 */
1901
-	public function getCertificateManager() {
1902
-		return $this->get(ICertificateManager::class);
1903
-	}
1904
-
1905
-	/**
1906
-	 * Returns an instance of the HTTP client service
1907
-	 *
1908
-	 * @return IClientService
1909
-	 * @deprecated 20.0.0
1910
-	 */
1911
-	public function getHTTPClientService() {
1912
-		return $this->get(IClientService::class);
1913
-	}
1914
-
1915
-	/**
1916
-	 * Create a new event source
1917
-	 *
1918
-	 * @return \OCP\IEventSource
1919
-	 * @deprecated 20.0.0
1920
-	 */
1921
-	public function createEventSource() {
1922
-		return new \OC_EventSource();
1923
-	}
1924
-
1925
-	/**
1926
-	 * Get the active event logger
1927
-	 *
1928
-	 * The returned logger only logs data when debug mode is enabled
1929
-	 *
1930
-	 * @return IEventLogger
1931
-	 * @deprecated 20.0.0
1932
-	 */
1933
-	public function getEventLogger() {
1934
-		return $this->get(IEventLogger::class);
1935
-	}
1936
-
1937
-	/**
1938
-	 * Get the active query logger
1939
-	 *
1940
-	 * The returned logger only logs data when debug mode is enabled
1941
-	 *
1942
-	 * @return IQueryLogger
1943
-	 * @deprecated 20.0.0
1944
-	 */
1945
-	public function getQueryLogger() {
1946
-		return $this->get(IQueryLogger::class);
1947
-	}
1948
-
1949
-	/**
1950
-	 * Get the manager for temporary files and folders
1951
-	 *
1952
-	 * @return \OCP\ITempManager
1953
-	 * @deprecated 20.0.0
1954
-	 */
1955
-	public function getTempManager() {
1956
-		return $this->get(ITempManager::class);
1957
-	}
1958
-
1959
-	/**
1960
-	 * Get the app manager
1961
-	 *
1962
-	 * @return \OCP\App\IAppManager
1963
-	 * @deprecated 20.0.0
1964
-	 */
1965
-	public function getAppManager() {
1966
-		return $this->get(IAppManager::class);
1967
-	}
1968
-
1969
-	/**
1970
-	 * Creates a new mailer
1971
-	 *
1972
-	 * @return IMailer
1973
-	 * @deprecated 20.0.0
1974
-	 */
1975
-	public function getMailer() {
1976
-		return $this->get(IMailer::class);
1977
-	}
1978
-
1979
-	/**
1980
-	 * Get the webroot
1981
-	 *
1982
-	 * @return string
1983
-	 * @deprecated 20.0.0
1984
-	 */
1985
-	public function getWebRoot() {
1986
-		return $this->webRoot;
1987
-	}
1988
-
1989
-	/**
1990
-	 * @return \OC\OCSClient
1991
-	 * @deprecated 20.0.0
1992
-	 */
1993
-	public function getOcsClient() {
1994
-		return $this->get('OcsClient');
1995
-	}
1996
-
1997
-	/**
1998
-	 * @return IDateTimeZone
1999
-	 * @deprecated 20.0.0
2000
-	 */
2001
-	public function getDateTimeZone() {
2002
-		return $this->get(IDateTimeZone::class);
2003
-	}
2004
-
2005
-	/**
2006
-	 * @return IDateTimeFormatter
2007
-	 * @deprecated 20.0.0
2008
-	 */
2009
-	public function getDateTimeFormatter() {
2010
-		return $this->get(IDateTimeFormatter::class);
2011
-	}
2012
-
2013
-	/**
2014
-	 * @return IMountProviderCollection
2015
-	 * @deprecated 20.0.0
2016
-	 */
2017
-	public function getMountProviderCollection() {
2018
-		return $this->get(IMountProviderCollection::class);
2019
-	}
2020
-
2021
-	/**
2022
-	 * Get the IniWrapper
2023
-	 *
2024
-	 * @return IniGetWrapper
2025
-	 * @deprecated 20.0.0
2026
-	 */
2027
-	public function getIniWrapper() {
2028
-		return $this->get(IniGetWrapper::class);
2029
-	}
2030
-
2031
-	/**
2032
-	 * @return \OCP\Command\IBus
2033
-	 * @deprecated 20.0.0
2034
-	 */
2035
-	public function getCommandBus() {
2036
-		return $this->get(IBus::class);
2037
-	}
2038
-
2039
-	/**
2040
-	 * Get the trusted domain helper
2041
-	 *
2042
-	 * @return TrustedDomainHelper
2043
-	 * @deprecated 20.0.0
2044
-	 */
2045
-	public function getTrustedDomainHelper() {
2046
-		return $this->get(TrustedDomainHelper::class);
2047
-	}
2048
-
2049
-	/**
2050
-	 * Get the locking provider
2051
-	 *
2052
-	 * @return ILockingProvider
2053
-	 * @since 8.1.0
2054
-	 * @deprecated 20.0.0
2055
-	 */
2056
-	public function getLockingProvider() {
2057
-		return $this->get(ILockingProvider::class);
2058
-	}
2059
-
2060
-	/**
2061
-	 * @return IMountManager
2062
-	 * @deprecated 20.0.0
2063
-	 **/
2064
-	public function getMountManager() {
2065
-		return $this->get(IMountManager::class);
2066
-	}
2067
-
2068
-	/**
2069
-	 * @return IUserMountCache
2070
-	 * @deprecated 20.0.0
2071
-	 */
2072
-	public function getUserMountCache() {
2073
-		return $this->get(IUserMountCache::class);
2074
-	}
2075
-
2076
-	/**
2077
-	 * Get the MimeTypeDetector
2078
-	 *
2079
-	 * @return IMimeTypeDetector
2080
-	 * @deprecated 20.0.0
2081
-	 */
2082
-	public function getMimeTypeDetector() {
2083
-		return $this->get(IMimeTypeDetector::class);
2084
-	}
2085
-
2086
-	/**
2087
-	 * Get the MimeTypeLoader
2088
-	 *
2089
-	 * @return IMimeTypeLoader
2090
-	 * @deprecated 20.0.0
2091
-	 */
2092
-	public function getMimeTypeLoader() {
2093
-		return $this->get(IMimeTypeLoader::class);
2094
-	}
2095
-
2096
-	/**
2097
-	 * Get the manager of all the capabilities
2098
-	 *
2099
-	 * @return CapabilitiesManager
2100
-	 * @deprecated 20.0.0
2101
-	 */
2102
-	public function getCapabilitiesManager() {
2103
-		return $this->get(CapabilitiesManager::class);
2104
-	}
2105
-
2106
-	/**
2107
-	 * Get the EventDispatcher
2108
-	 *
2109
-	 * @return EventDispatcherInterface
2110
-	 * @since 8.2.0
2111
-	 * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2112
-	 */
2113
-	public function getEventDispatcher() {
2114
-		return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2115
-	}
2116
-
2117
-	/**
2118
-	 * Get the Notification Manager
2119
-	 *
2120
-	 * @return \OCP\Notification\IManager
2121
-	 * @since 8.2.0
2122
-	 * @deprecated 20.0.0
2123
-	 */
2124
-	public function getNotificationManager() {
2125
-		return $this->get(\OCP\Notification\IManager::class);
2126
-	}
2127
-
2128
-	/**
2129
-	 * @return ICommentsManager
2130
-	 * @deprecated 20.0.0
2131
-	 */
2132
-	public function getCommentsManager() {
2133
-		return $this->get(ICommentsManager::class);
2134
-	}
2135
-
2136
-	/**
2137
-	 * @return \OCA\Theming\ThemingDefaults
2138
-	 * @deprecated 20.0.0
2139
-	 */
2140
-	public function getThemingDefaults() {
2141
-		return $this->get('ThemingDefaults');
2142
-	}
2143
-
2144
-	/**
2145
-	 * @return \OC\IntegrityCheck\Checker
2146
-	 * @deprecated 20.0.0
2147
-	 */
2148
-	public function getIntegrityCodeChecker() {
2149
-		return $this->get('IntegrityCodeChecker');
2150
-	}
2151
-
2152
-	/**
2153
-	 * @return \OC\Session\CryptoWrapper
2154
-	 * @deprecated 20.0.0
2155
-	 */
2156
-	public function getSessionCryptoWrapper() {
2157
-		return $this->get('CryptoWrapper');
2158
-	}
2159
-
2160
-	/**
2161
-	 * @return CsrfTokenManager
2162
-	 * @deprecated 20.0.0
2163
-	 */
2164
-	public function getCsrfTokenManager() {
2165
-		return $this->get(CsrfTokenManager::class);
2166
-	}
2167
-
2168
-	/**
2169
-	 * @return Throttler
2170
-	 * @deprecated 20.0.0
2171
-	 */
2172
-	public function getBruteForceThrottler() {
2173
-		return $this->get(Throttler::class);
2174
-	}
2175
-
2176
-	/**
2177
-	 * @return IContentSecurityPolicyManager
2178
-	 * @deprecated 20.0.0
2179
-	 */
2180
-	public function getContentSecurityPolicyManager() {
2181
-		return $this->get(ContentSecurityPolicyManager::class);
2182
-	}
2183
-
2184
-	/**
2185
-	 * @return ContentSecurityPolicyNonceManager
2186
-	 * @deprecated 20.0.0
2187
-	 */
2188
-	public function getContentSecurityPolicyNonceManager() {
2189
-		return $this->get(ContentSecurityPolicyNonceManager::class);
2190
-	}
2191
-
2192
-	/**
2193
-	 * Not a public API as of 8.2, wait for 9.0
2194
-	 *
2195
-	 * @return \OCA\Files_External\Service\BackendService
2196
-	 * @deprecated 20.0.0
2197
-	 */
2198
-	public function getStoragesBackendService() {
2199
-		return $this->get(BackendService::class);
2200
-	}
2201
-
2202
-	/**
2203
-	 * Not a public API as of 8.2, wait for 9.0
2204
-	 *
2205
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
2206
-	 * @deprecated 20.0.0
2207
-	 */
2208
-	public function getGlobalStoragesService() {
2209
-		return $this->get(GlobalStoragesService::class);
2210
-	}
2211
-
2212
-	/**
2213
-	 * Not a public API as of 8.2, wait for 9.0
2214
-	 *
2215
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
2216
-	 * @deprecated 20.0.0
2217
-	 */
2218
-	public function getUserGlobalStoragesService() {
2219
-		return $this->get(UserGlobalStoragesService::class);
2220
-	}
2221
-
2222
-	/**
2223
-	 * Not a public API as of 8.2, wait for 9.0
2224
-	 *
2225
-	 * @return \OCA\Files_External\Service\UserStoragesService
2226
-	 * @deprecated 20.0.0
2227
-	 */
2228
-	public function getUserStoragesService() {
2229
-		return $this->get(UserStoragesService::class);
2230
-	}
2231
-
2232
-	/**
2233
-	 * @return \OCP\Share\IManager
2234
-	 * @deprecated 20.0.0
2235
-	 */
2236
-	public function getShareManager() {
2237
-		return $this->get(\OCP\Share\IManager::class);
2238
-	}
2239
-
2240
-	/**
2241
-	 * @return \OCP\Collaboration\Collaborators\ISearch
2242
-	 * @deprecated 20.0.0
2243
-	 */
2244
-	public function getCollaboratorSearch() {
2245
-		return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2246
-	}
2247
-
2248
-	/**
2249
-	 * @return \OCP\Collaboration\AutoComplete\IManager
2250
-	 * @deprecated 20.0.0
2251
-	 */
2252
-	public function getAutoCompleteManager() {
2253
-		return $this->get(IManager::class);
2254
-	}
2255
-
2256
-	/**
2257
-	 * Returns the LDAP Provider
2258
-	 *
2259
-	 * @return \OCP\LDAP\ILDAPProvider
2260
-	 * @deprecated 20.0.0
2261
-	 */
2262
-	public function getLDAPProvider() {
2263
-		return $this->get('LDAPProvider');
2264
-	}
2265
-
2266
-	/**
2267
-	 * @return \OCP\Settings\IManager
2268
-	 * @deprecated 20.0.0
2269
-	 */
2270
-	public function getSettingsManager() {
2271
-		return $this->get(\OC\Settings\Manager::class);
2272
-	}
2273
-
2274
-	/**
2275
-	 * @return \OCP\Files\IAppData
2276
-	 * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
2277
-	 */
2278
-	public function getAppDataDir($app) {
2279
-		/** @var \OC\Files\AppData\Factory $factory */
2280
-		$factory = $this->get(\OC\Files\AppData\Factory::class);
2281
-		return $factory->get($app);
2282
-	}
2283
-
2284
-	/**
2285
-	 * @return \OCP\Lockdown\ILockdownManager
2286
-	 * @deprecated 20.0.0
2287
-	 */
2288
-	public function getLockdownManager() {
2289
-		return $this->get('LockdownManager');
2290
-	}
2291
-
2292
-	/**
2293
-	 * @return \OCP\Federation\ICloudIdManager
2294
-	 * @deprecated 20.0.0
2295
-	 */
2296
-	public function getCloudIdManager() {
2297
-		return $this->get(ICloudIdManager::class);
2298
-	}
2299
-
2300
-	/**
2301
-	 * @return \OCP\GlobalScale\IConfig
2302
-	 * @deprecated 20.0.0
2303
-	 */
2304
-	public function getGlobalScaleConfig() {
2305
-		return $this->get(IConfig::class);
2306
-	}
2307
-
2308
-	/**
2309
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2310
-	 * @deprecated 20.0.0
2311
-	 */
2312
-	public function getCloudFederationProviderManager() {
2313
-		return $this->get(ICloudFederationProviderManager::class);
2314
-	}
2315
-
2316
-	/**
2317
-	 * @return \OCP\Remote\Api\IApiFactory
2318
-	 * @deprecated 20.0.0
2319
-	 */
2320
-	public function getRemoteApiFactory() {
2321
-		return $this->get(IApiFactory::class);
2322
-	}
2323
-
2324
-	/**
2325
-	 * @return \OCP\Federation\ICloudFederationFactory
2326
-	 * @deprecated 20.0.0
2327
-	 */
2328
-	public function getCloudFederationFactory() {
2329
-		return $this->get(ICloudFederationFactory::class);
2330
-	}
2331
-
2332
-	/**
2333
-	 * @return \OCP\Remote\IInstanceFactory
2334
-	 * @deprecated 20.0.0
2335
-	 */
2336
-	public function getRemoteInstanceFactory() {
2337
-		return $this->get(IInstanceFactory::class);
2338
-	}
2339
-
2340
-	/**
2341
-	 * @return IStorageFactory
2342
-	 * @deprecated 20.0.0
2343
-	 */
2344
-	public function getStorageFactory() {
2345
-		return $this->get(IStorageFactory::class);
2346
-	}
2347
-
2348
-	/**
2349
-	 * Get the Preview GeneratorHelper
2350
-	 *
2351
-	 * @return GeneratorHelper
2352
-	 * @since 17.0.0
2353
-	 * @deprecated 20.0.0
2354
-	 */
2355
-	public function getGeneratorHelper() {
2356
-		return $this->get(\OC\Preview\GeneratorHelper::class);
2357
-	}
2358
-
2359
-	private function registerDeprecatedAlias(string $alias, string $target) {
2360
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2361
-			try {
2362
-				/** @var LoggerInterface $logger */
2363
-				$logger = $container->get(LoggerInterface::class);
2364
-				$logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2365
-			} catch (ContainerExceptionInterface $e) {
2366
-				// Could not get logger. Continue
2367
-			}
2368
-
2369
-			return $container->get($target);
2370
-		}, false);
2371
-	}
1201
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
1202
+            if (isset($prefixes['OCA\\Theming\\'])) {
1203
+                $classExists = true;
1204
+            } else {
1205
+                $classExists = false;
1206
+            }
1207
+
1208
+            if ($classExists && $c->get(\OCP\IConfig::class)->getSystemValue('installed', false) && $c->get(IAppManager::class)->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
1209
+                $imageManager = new ImageManager(
1210
+                    $c->get(\OCP\IConfig::class),
1211
+                    $c->getAppDataDir('theming'),
1212
+                    $c->get(IURLGenerator::class),
1213
+                    $this->get(ICacheFactory::class),
1214
+                    $this->get(ILogger::class),
1215
+                    $this->get(ITempManager::class)
1216
+                );
1217
+                return new ThemingDefaults(
1218
+                    $c->get(\OCP\IConfig::class),
1219
+                    $c->getL10N('theming'),
1220
+                    $c->get(IUserSession::class),
1221
+                    $c->get(IURLGenerator::class),
1222
+                    $c->get(ICacheFactory::class),
1223
+                    new Util($c->get(\OCP\IConfig::class), $this->get(IAppManager::class), $c->getAppDataDir('theming'), $imageManager),
1224
+                    $imageManager,
1225
+                    $c->get(IAppManager::class),
1226
+                    $c->get(INavigationManager::class)
1227
+                );
1228
+            }
1229
+            return new \OC_Defaults();
1230
+        });
1231
+        $this->registerService(JSCombiner::class, function (Server $c) {
1232
+            return new JSCombiner(
1233
+                $c->getAppDataDir('js'),
1234
+                $c->get(IURLGenerator::class),
1235
+                $this->get(ICacheFactory::class),
1236
+                $c->get(SystemConfig::class),
1237
+                $c->get(LoggerInterface::class)
1238
+            );
1239
+        });
1240
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
1241
+        /** @deprecated 19.0.0 */
1242
+        $this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1243
+        $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1244
+
1245
+        $this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1246
+            // FIXME: Instantiated here due to cyclic dependency
1247
+            $request = new Request(
1248
+                [
1249
+                    'get' => $_GET,
1250
+                    'post' => $_POST,
1251
+                    'files' => $_FILES,
1252
+                    'server' => $_SERVER,
1253
+                    'env' => $_ENV,
1254
+                    'cookies' => $_COOKIE,
1255
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1256
+                        ? $_SERVER['REQUEST_METHOD']
1257
+                        : null,
1258
+                ],
1259
+                $c->get(IRequestId::class),
1260
+                $c->get(\OCP\IConfig::class)
1261
+            );
1262
+
1263
+            return new CryptoWrapper(
1264
+                $c->get(\OCP\IConfig::class),
1265
+                $c->get(ICrypto::class),
1266
+                $c->get(ISecureRandom::class),
1267
+                $request
1268
+            );
1269
+        });
1270
+        /** @deprecated 19.0.0 */
1271
+        $this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1272
+        $this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1273
+            return new SessionStorage($c->get(ISession::class));
1274
+        });
1275
+        $this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1276
+        /** @deprecated 19.0.0 */
1277
+        $this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1278
+
1279
+        $this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1280
+            $config = $c->get(\OCP\IConfig::class);
1281
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1282
+            /** @var \OCP\Share\IProviderFactory $factory */
1283
+            $factory = new $factoryClass($this);
1284
+
1285
+            $manager = new \OC\Share20\Manager(
1286
+                $c->get(LoggerInterface::class),
1287
+                $c->get(\OCP\IConfig::class),
1288
+                $c->get(ISecureRandom::class),
1289
+                $c->get(IHasher::class),
1290
+                $c->get(IMountManager::class),
1291
+                $c->get(IGroupManager::class),
1292
+                $c->getL10N('lib'),
1293
+                $c->get(IFactory::class),
1294
+                $factory,
1295
+                $c->get(IUserManager::class),
1296
+                $c->get(IRootFolder::class),
1297
+                $c->get(SymfonyAdapter::class),
1298
+                $c->get(IMailer::class),
1299
+                $c->get(IURLGenerator::class),
1300
+                $c->get('ThemingDefaults'),
1301
+                $c->get(IEventDispatcher::class),
1302
+                $c->get(IUserSession::class),
1303
+                $c->get(KnownUserService::class)
1304
+            );
1305
+
1306
+            return $manager;
1307
+        });
1308
+        /** @deprecated 19.0.0 */
1309
+        $this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1310
+
1311
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1312
+            $instance = new Collaboration\Collaborators\Search($c);
1313
+
1314
+            // register default plugins
1315
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1316
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1317
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1318
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1319
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1320
+
1321
+            return $instance;
1322
+        });
1323
+        /** @deprecated 19.0.0 */
1324
+        $this->registerDeprecatedAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1325
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1326
+
1327
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1328
+
1329
+        $this->registerAlias(\OCP\Collaboration\Resources\IProviderManager::class, \OC\Collaboration\Resources\ProviderManager::class);
1330
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1331
+
1332
+        $this->registerAlias(IReferenceManager::class, ReferenceManager::class);
1333
+
1334
+        $this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1335
+        $this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1336
+        $this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1337
+            return new \OC\Files\AppData\Factory(
1338
+                $c->get(IRootFolder::class),
1339
+                $c->get(SystemConfig::class)
1340
+            );
1341
+        });
1342
+
1343
+        $this->registerService('LockdownManager', function (ContainerInterface $c) {
1344
+            return new LockdownManager(function () use ($c) {
1345
+                return $c->get(ISession::class);
1346
+            });
1347
+        });
1348
+
1349
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1350
+            return new DiscoveryService(
1351
+                $c->get(ICacheFactory::class),
1352
+                $c->get(IClientService::class)
1353
+            );
1354
+        });
1355
+
1356
+        $this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1357
+            return new CloudIdManager(
1358
+                $c->get(\OCP\Contacts\IManager::class),
1359
+                $c->get(IURLGenerator::class),
1360
+                $c->get(IUserManager::class),
1361
+                $c->get(ICacheFactory::class),
1362
+                $c->get(IEventDispatcher::class),
1363
+            );
1364
+        });
1365
+
1366
+        $this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1367
+
1368
+        $this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1369
+            return new CloudFederationProviderManager(
1370
+                $c->get(IAppManager::class),
1371
+                $c->get(IClientService::class),
1372
+                $c->get(ICloudIdManager::class),
1373
+                $c->get(LoggerInterface::class)
1374
+            );
1375
+        });
1376
+
1377
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1378
+            return new CloudFederationFactory();
1379
+        });
1380
+
1381
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1382
+        /** @deprecated 19.0.0 */
1383
+        $this->registerDeprecatedAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1384
+
1385
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1386
+        /** @deprecated 19.0.0 */
1387
+        $this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1388
+
1389
+        $this->registerService(Defaults::class, function (Server $c) {
1390
+            return new Defaults(
1391
+                $c->getThemingDefaults()
1392
+            );
1393
+        });
1394
+        /** @deprecated 19.0.0 */
1395
+        $this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1396
+
1397
+        $this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1398
+            return $c->get(\OCP\IUserSession::class)->getSession();
1399
+        }, false);
1400
+
1401
+        $this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1402
+            return new ShareHelper(
1403
+                $c->get(\OCP\Share\IManager::class)
1404
+            );
1405
+        });
1406
+
1407
+        $this->registerService(Installer::class, function (ContainerInterface $c) {
1408
+            return new Installer(
1409
+                $c->get(AppFetcher::class),
1410
+                $c->get(IClientService::class),
1411
+                $c->get(ITempManager::class),
1412
+                $c->get(LoggerInterface::class),
1413
+                $c->get(\OCP\IConfig::class),
1414
+                \OC::$CLI
1415
+            );
1416
+        });
1417
+
1418
+        $this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1419
+            return new ApiFactory($c->get(IClientService::class));
1420
+        });
1421
+
1422
+        $this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1423
+            $memcacheFactory = $c->get(ICacheFactory::class);
1424
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1425
+        });
1426
+
1427
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1428
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1429
+
1430
+        $this->registerAlias(IStorageFactory::class, StorageFactory::class);
1431
+
1432
+        $this->registerAlias(\OCP\Dashboard\IManager::class, \OC\Dashboard\Manager::class);
1433
+
1434
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1435
+
1436
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1437
+
1438
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1439
+
1440
+        $this->registerAlias(\OCP\IEmojiHelper::class, \OC\EmojiHelper::class);
1441
+
1442
+        $this->registerAlias(\OCP\UserStatus\IManager::class, \OC\UserStatus\Manager::class);
1443
+
1444
+        $this->registerAlias(IBroker::class, Broker::class);
1445
+
1446
+        $this->registerAlias(IMetadataManager::class, MetadataManager::class);
1447
+
1448
+        $this->registerAlias(\OCP\Files\AppData\IAppDataFactory::class, \OC\Files\AppData\Factory::class);
1449
+
1450
+        $this->registerAlias(IBinaryFinder::class, BinaryFinder::class);
1451
+
1452
+        $this->registerAlias(\OCP\Share\IPublicShareTemplateFactory::class, \OC\Share20\PublicShareTemplateFactory::class);
1453
+
1454
+        $this->connectDispatcher();
1455
+    }
1456
+
1457
+    public function boot() {
1458
+        /** @var HookConnector $hookConnector */
1459
+        $hookConnector = $this->get(HookConnector::class);
1460
+        $hookConnector->viewToNode();
1461
+    }
1462
+
1463
+    /**
1464
+     * @return \OCP\Calendar\IManager
1465
+     * @deprecated 20.0.0
1466
+     */
1467
+    public function getCalendarManager() {
1468
+        return $this->get(\OC\Calendar\Manager::class);
1469
+    }
1470
+
1471
+    /**
1472
+     * @return \OCP\Calendar\Resource\IManager
1473
+     * @deprecated 20.0.0
1474
+     */
1475
+    public function getCalendarResourceBackendManager() {
1476
+        return $this->get(\OC\Calendar\Resource\Manager::class);
1477
+    }
1478
+
1479
+    /**
1480
+     * @return \OCP\Calendar\Room\IManager
1481
+     * @deprecated 20.0.0
1482
+     */
1483
+    public function getCalendarRoomBackendManager() {
1484
+        return $this->get(\OC\Calendar\Room\Manager::class);
1485
+    }
1486
+
1487
+    private function connectDispatcher(): void {
1488
+        /** @var IEventDispatcher $eventDispatcher */
1489
+        $eventDispatcher = $this->get(IEventDispatcher::class);
1490
+        $eventDispatcher->addServiceListener(LoginFailed::class, LoginFailedListener::class);
1491
+        $eventDispatcher->addServiceListener(PostLoginEvent::class, UserLoggedInListener::class);
1492
+        $eventDispatcher->addServiceListener(UserChangedEvent::class, UserChangedListener::class);
1493
+        $eventDispatcher->addServiceListener(BeforeUserDeletedEvent::class, BeforeUserDeletedListener::class);
1494
+    }
1495
+
1496
+    /**
1497
+     * @return \OCP\Contacts\IManager
1498
+     * @deprecated 20.0.0
1499
+     */
1500
+    public function getContactsManager() {
1501
+        return $this->get(\OCP\Contacts\IManager::class);
1502
+    }
1503
+
1504
+    /**
1505
+     * @return \OC\Encryption\Manager
1506
+     * @deprecated 20.0.0
1507
+     */
1508
+    public function getEncryptionManager() {
1509
+        return $this->get(\OCP\Encryption\IManager::class);
1510
+    }
1511
+
1512
+    /**
1513
+     * @return \OC\Encryption\File
1514
+     * @deprecated 20.0.0
1515
+     */
1516
+    public function getEncryptionFilesHelper() {
1517
+        return $this->get(IFile::class);
1518
+    }
1519
+
1520
+    /**
1521
+     * @return \OCP\Encryption\Keys\IStorage
1522
+     * @deprecated 20.0.0
1523
+     */
1524
+    public function getEncryptionKeyStorage() {
1525
+        return $this->get(IStorage::class);
1526
+    }
1527
+
1528
+    /**
1529
+     * The current request object holding all information about the request
1530
+     * currently being processed is returned from this method.
1531
+     * In case the current execution was not initiated by a web request null is returned
1532
+     *
1533
+     * @return \OCP\IRequest
1534
+     * @deprecated 20.0.0
1535
+     */
1536
+    public function getRequest() {
1537
+        return $this->get(IRequest::class);
1538
+    }
1539
+
1540
+    /**
1541
+     * Returns the preview manager which can create preview images for a given file
1542
+     *
1543
+     * @return IPreview
1544
+     * @deprecated 20.0.0
1545
+     */
1546
+    public function getPreviewManager() {
1547
+        return $this->get(IPreview::class);
1548
+    }
1549
+
1550
+    /**
1551
+     * Returns the tag manager which can get and set tags for different object types
1552
+     *
1553
+     * @see \OCP\ITagManager::load()
1554
+     * @return ITagManager
1555
+     * @deprecated 20.0.0
1556
+     */
1557
+    public function getTagManager() {
1558
+        return $this->get(ITagManager::class);
1559
+    }
1560
+
1561
+    /**
1562
+     * Returns the system-tag manager
1563
+     *
1564
+     * @return ISystemTagManager
1565
+     *
1566
+     * @since 9.0.0
1567
+     * @deprecated 20.0.0
1568
+     */
1569
+    public function getSystemTagManager() {
1570
+        return $this->get(ISystemTagManager::class);
1571
+    }
1572
+
1573
+    /**
1574
+     * Returns the system-tag object mapper
1575
+     *
1576
+     * @return ISystemTagObjectMapper
1577
+     *
1578
+     * @since 9.0.0
1579
+     * @deprecated 20.0.0
1580
+     */
1581
+    public function getSystemTagObjectMapper() {
1582
+        return $this->get(ISystemTagObjectMapper::class);
1583
+    }
1584
+
1585
+    /**
1586
+     * Returns the avatar manager, used for avatar functionality
1587
+     *
1588
+     * @return IAvatarManager
1589
+     * @deprecated 20.0.0
1590
+     */
1591
+    public function getAvatarManager() {
1592
+        return $this->get(IAvatarManager::class);
1593
+    }
1594
+
1595
+    /**
1596
+     * Returns the root folder of ownCloud's data directory
1597
+     *
1598
+     * @return IRootFolder
1599
+     * @deprecated 20.0.0
1600
+     */
1601
+    public function getRootFolder() {
1602
+        return $this->get(IRootFolder::class);
1603
+    }
1604
+
1605
+    /**
1606
+     * Returns the root folder of ownCloud's data directory
1607
+     * This is the lazy variant so this gets only initialized once it
1608
+     * is actually used.
1609
+     *
1610
+     * @return IRootFolder
1611
+     * @deprecated 20.0.0
1612
+     */
1613
+    public function getLazyRootFolder() {
1614
+        return $this->get(IRootFolder::class);
1615
+    }
1616
+
1617
+    /**
1618
+     * Returns a view to ownCloud's files folder
1619
+     *
1620
+     * @param string $userId user ID
1621
+     * @return \OCP\Files\Folder|null
1622
+     * @deprecated 20.0.0
1623
+     */
1624
+    public function getUserFolder($userId = null) {
1625
+        if ($userId === null) {
1626
+            $user = $this->get(IUserSession::class)->getUser();
1627
+            if (!$user) {
1628
+                return null;
1629
+            }
1630
+            $userId = $user->getUID();
1631
+        }
1632
+        $root = $this->get(IRootFolder::class);
1633
+        return $root->getUserFolder($userId);
1634
+    }
1635
+
1636
+    /**
1637
+     * @return \OC\User\Manager
1638
+     * @deprecated 20.0.0
1639
+     */
1640
+    public function getUserManager() {
1641
+        return $this->get(IUserManager::class);
1642
+    }
1643
+
1644
+    /**
1645
+     * @return \OC\Group\Manager
1646
+     * @deprecated 20.0.0
1647
+     */
1648
+    public function getGroupManager() {
1649
+        return $this->get(IGroupManager::class);
1650
+    }
1651
+
1652
+    /**
1653
+     * @return \OC\User\Session
1654
+     * @deprecated 20.0.0
1655
+     */
1656
+    public function getUserSession() {
1657
+        return $this->get(IUserSession::class);
1658
+    }
1659
+
1660
+    /**
1661
+     * @return \OCP\ISession
1662
+     * @deprecated 20.0.0
1663
+     */
1664
+    public function getSession() {
1665
+        return $this->get(Session::class)->getSession();
1666
+    }
1667
+
1668
+    /**
1669
+     * @param \OCP\ISession $session
1670
+     */
1671
+    public function setSession(\OCP\ISession $session) {
1672
+        $this->get(SessionStorage::class)->setSession($session);
1673
+        $this->get(Session::class)->setSession($session);
1674
+        $this->get(Store::class)->setSession($session);
1675
+    }
1676
+
1677
+    /**
1678
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1679
+     * @deprecated 20.0.0
1680
+     */
1681
+    public function getTwoFactorAuthManager() {
1682
+        return $this->get(\OC\Authentication\TwoFactorAuth\Manager::class);
1683
+    }
1684
+
1685
+    /**
1686
+     * @return \OC\NavigationManager
1687
+     * @deprecated 20.0.0
1688
+     */
1689
+    public function getNavigationManager() {
1690
+        return $this->get(INavigationManager::class);
1691
+    }
1692
+
1693
+    /**
1694
+     * @return \OCP\IConfig
1695
+     * @deprecated 20.0.0
1696
+     */
1697
+    public function getConfig() {
1698
+        return $this->get(AllConfig::class);
1699
+    }
1700
+
1701
+    /**
1702
+     * @return \OC\SystemConfig
1703
+     * @deprecated 20.0.0
1704
+     */
1705
+    public function getSystemConfig() {
1706
+        return $this->get(SystemConfig::class);
1707
+    }
1708
+
1709
+    /**
1710
+     * Returns the app config manager
1711
+     *
1712
+     * @return IAppConfig
1713
+     * @deprecated 20.0.0
1714
+     */
1715
+    public function getAppConfig() {
1716
+        return $this->get(IAppConfig::class);
1717
+    }
1718
+
1719
+    /**
1720
+     * @return IFactory
1721
+     * @deprecated 20.0.0
1722
+     */
1723
+    public function getL10NFactory() {
1724
+        return $this->get(IFactory::class);
1725
+    }
1726
+
1727
+    /**
1728
+     * get an L10N instance
1729
+     *
1730
+     * @param string $app appid
1731
+     * @param string $lang
1732
+     * @return IL10N
1733
+     * @deprecated 20.0.0
1734
+     */
1735
+    public function getL10N($app, $lang = null) {
1736
+        return $this->get(IFactory::class)->get($app, $lang);
1737
+    }
1738
+
1739
+    /**
1740
+     * @return IURLGenerator
1741
+     * @deprecated 20.0.0
1742
+     */
1743
+    public function getURLGenerator() {
1744
+        return $this->get(IURLGenerator::class);
1745
+    }
1746
+
1747
+    /**
1748
+     * @return AppFetcher
1749
+     * @deprecated 20.0.0
1750
+     */
1751
+    public function getAppFetcher() {
1752
+        return $this->get(AppFetcher::class);
1753
+    }
1754
+
1755
+    /**
1756
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1757
+     * getMemCacheFactory() instead.
1758
+     *
1759
+     * @return ICache
1760
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1761
+     */
1762
+    public function getCache() {
1763
+        return $this->get(ICache::class);
1764
+    }
1765
+
1766
+    /**
1767
+     * Returns an \OCP\CacheFactory instance
1768
+     *
1769
+     * @return \OCP\ICacheFactory
1770
+     * @deprecated 20.0.0
1771
+     */
1772
+    public function getMemCacheFactory() {
1773
+        return $this->get(ICacheFactory::class);
1774
+    }
1775
+
1776
+    /**
1777
+     * Returns an \OC\RedisFactory instance
1778
+     *
1779
+     * @return \OC\RedisFactory
1780
+     * @deprecated 20.0.0
1781
+     */
1782
+    public function getGetRedisFactory() {
1783
+        return $this->get('RedisFactory');
1784
+    }
1785
+
1786
+
1787
+    /**
1788
+     * Returns the current session
1789
+     *
1790
+     * @return \OCP\IDBConnection
1791
+     * @deprecated 20.0.0
1792
+     */
1793
+    public function getDatabaseConnection() {
1794
+        return $this->get(IDBConnection::class);
1795
+    }
1796
+
1797
+    /**
1798
+     * Returns the activity manager
1799
+     *
1800
+     * @return \OCP\Activity\IManager
1801
+     * @deprecated 20.0.0
1802
+     */
1803
+    public function getActivityManager() {
1804
+        return $this->get(\OCP\Activity\IManager::class);
1805
+    }
1806
+
1807
+    /**
1808
+     * Returns an job list for controlling background jobs
1809
+     *
1810
+     * @return IJobList
1811
+     * @deprecated 20.0.0
1812
+     */
1813
+    public function getJobList() {
1814
+        return $this->get(IJobList::class);
1815
+    }
1816
+
1817
+    /**
1818
+     * Returns a logger instance
1819
+     *
1820
+     * @return ILogger
1821
+     * @deprecated 20.0.0
1822
+     */
1823
+    public function getLogger() {
1824
+        return $this->get(ILogger::class);
1825
+    }
1826
+
1827
+    /**
1828
+     * @return ILogFactory
1829
+     * @throws \OCP\AppFramework\QueryException
1830
+     * @deprecated 20.0.0
1831
+     */
1832
+    public function getLogFactory() {
1833
+        return $this->get(ILogFactory::class);
1834
+    }
1835
+
1836
+    /**
1837
+     * Returns a router for generating and matching urls
1838
+     *
1839
+     * @return IRouter
1840
+     * @deprecated 20.0.0
1841
+     */
1842
+    public function getRouter() {
1843
+        return $this->get(IRouter::class);
1844
+    }
1845
+
1846
+    /**
1847
+     * Returns a search instance
1848
+     *
1849
+     * @return ISearch
1850
+     * @deprecated 20.0.0
1851
+     */
1852
+    public function getSearch() {
1853
+        return $this->get(ISearch::class);
1854
+    }
1855
+
1856
+    /**
1857
+     * Returns a SecureRandom instance
1858
+     *
1859
+     * @return \OCP\Security\ISecureRandom
1860
+     * @deprecated 20.0.0
1861
+     */
1862
+    public function getSecureRandom() {
1863
+        return $this->get(ISecureRandom::class);
1864
+    }
1865
+
1866
+    /**
1867
+     * Returns a Crypto instance
1868
+     *
1869
+     * @return ICrypto
1870
+     * @deprecated 20.0.0
1871
+     */
1872
+    public function getCrypto() {
1873
+        return $this->get(ICrypto::class);
1874
+    }
1875
+
1876
+    /**
1877
+     * Returns a Hasher instance
1878
+     *
1879
+     * @return IHasher
1880
+     * @deprecated 20.0.0
1881
+     */
1882
+    public function getHasher() {
1883
+        return $this->get(IHasher::class);
1884
+    }
1885
+
1886
+    /**
1887
+     * Returns a CredentialsManager instance
1888
+     *
1889
+     * @return ICredentialsManager
1890
+     * @deprecated 20.0.0
1891
+     */
1892
+    public function getCredentialsManager() {
1893
+        return $this->get(ICredentialsManager::class);
1894
+    }
1895
+
1896
+    /**
1897
+     * Get the certificate manager
1898
+     *
1899
+     * @return \OCP\ICertificateManager
1900
+     */
1901
+    public function getCertificateManager() {
1902
+        return $this->get(ICertificateManager::class);
1903
+    }
1904
+
1905
+    /**
1906
+     * Returns an instance of the HTTP client service
1907
+     *
1908
+     * @return IClientService
1909
+     * @deprecated 20.0.0
1910
+     */
1911
+    public function getHTTPClientService() {
1912
+        return $this->get(IClientService::class);
1913
+    }
1914
+
1915
+    /**
1916
+     * Create a new event source
1917
+     *
1918
+     * @return \OCP\IEventSource
1919
+     * @deprecated 20.0.0
1920
+     */
1921
+    public function createEventSource() {
1922
+        return new \OC_EventSource();
1923
+    }
1924
+
1925
+    /**
1926
+     * Get the active event logger
1927
+     *
1928
+     * The returned logger only logs data when debug mode is enabled
1929
+     *
1930
+     * @return IEventLogger
1931
+     * @deprecated 20.0.0
1932
+     */
1933
+    public function getEventLogger() {
1934
+        return $this->get(IEventLogger::class);
1935
+    }
1936
+
1937
+    /**
1938
+     * Get the active query logger
1939
+     *
1940
+     * The returned logger only logs data when debug mode is enabled
1941
+     *
1942
+     * @return IQueryLogger
1943
+     * @deprecated 20.0.0
1944
+     */
1945
+    public function getQueryLogger() {
1946
+        return $this->get(IQueryLogger::class);
1947
+    }
1948
+
1949
+    /**
1950
+     * Get the manager for temporary files and folders
1951
+     *
1952
+     * @return \OCP\ITempManager
1953
+     * @deprecated 20.0.0
1954
+     */
1955
+    public function getTempManager() {
1956
+        return $this->get(ITempManager::class);
1957
+    }
1958
+
1959
+    /**
1960
+     * Get the app manager
1961
+     *
1962
+     * @return \OCP\App\IAppManager
1963
+     * @deprecated 20.0.0
1964
+     */
1965
+    public function getAppManager() {
1966
+        return $this->get(IAppManager::class);
1967
+    }
1968
+
1969
+    /**
1970
+     * Creates a new mailer
1971
+     *
1972
+     * @return IMailer
1973
+     * @deprecated 20.0.0
1974
+     */
1975
+    public function getMailer() {
1976
+        return $this->get(IMailer::class);
1977
+    }
1978
+
1979
+    /**
1980
+     * Get the webroot
1981
+     *
1982
+     * @return string
1983
+     * @deprecated 20.0.0
1984
+     */
1985
+    public function getWebRoot() {
1986
+        return $this->webRoot;
1987
+    }
1988
+
1989
+    /**
1990
+     * @return \OC\OCSClient
1991
+     * @deprecated 20.0.0
1992
+     */
1993
+    public function getOcsClient() {
1994
+        return $this->get('OcsClient');
1995
+    }
1996
+
1997
+    /**
1998
+     * @return IDateTimeZone
1999
+     * @deprecated 20.0.0
2000
+     */
2001
+    public function getDateTimeZone() {
2002
+        return $this->get(IDateTimeZone::class);
2003
+    }
2004
+
2005
+    /**
2006
+     * @return IDateTimeFormatter
2007
+     * @deprecated 20.0.0
2008
+     */
2009
+    public function getDateTimeFormatter() {
2010
+        return $this->get(IDateTimeFormatter::class);
2011
+    }
2012
+
2013
+    /**
2014
+     * @return IMountProviderCollection
2015
+     * @deprecated 20.0.0
2016
+     */
2017
+    public function getMountProviderCollection() {
2018
+        return $this->get(IMountProviderCollection::class);
2019
+    }
2020
+
2021
+    /**
2022
+     * Get the IniWrapper
2023
+     *
2024
+     * @return IniGetWrapper
2025
+     * @deprecated 20.0.0
2026
+     */
2027
+    public function getIniWrapper() {
2028
+        return $this->get(IniGetWrapper::class);
2029
+    }
2030
+
2031
+    /**
2032
+     * @return \OCP\Command\IBus
2033
+     * @deprecated 20.0.0
2034
+     */
2035
+    public function getCommandBus() {
2036
+        return $this->get(IBus::class);
2037
+    }
2038
+
2039
+    /**
2040
+     * Get the trusted domain helper
2041
+     *
2042
+     * @return TrustedDomainHelper
2043
+     * @deprecated 20.0.0
2044
+     */
2045
+    public function getTrustedDomainHelper() {
2046
+        return $this->get(TrustedDomainHelper::class);
2047
+    }
2048
+
2049
+    /**
2050
+     * Get the locking provider
2051
+     *
2052
+     * @return ILockingProvider
2053
+     * @since 8.1.0
2054
+     * @deprecated 20.0.0
2055
+     */
2056
+    public function getLockingProvider() {
2057
+        return $this->get(ILockingProvider::class);
2058
+    }
2059
+
2060
+    /**
2061
+     * @return IMountManager
2062
+     * @deprecated 20.0.0
2063
+     **/
2064
+    public function getMountManager() {
2065
+        return $this->get(IMountManager::class);
2066
+    }
2067
+
2068
+    /**
2069
+     * @return IUserMountCache
2070
+     * @deprecated 20.0.0
2071
+     */
2072
+    public function getUserMountCache() {
2073
+        return $this->get(IUserMountCache::class);
2074
+    }
2075
+
2076
+    /**
2077
+     * Get the MimeTypeDetector
2078
+     *
2079
+     * @return IMimeTypeDetector
2080
+     * @deprecated 20.0.0
2081
+     */
2082
+    public function getMimeTypeDetector() {
2083
+        return $this->get(IMimeTypeDetector::class);
2084
+    }
2085
+
2086
+    /**
2087
+     * Get the MimeTypeLoader
2088
+     *
2089
+     * @return IMimeTypeLoader
2090
+     * @deprecated 20.0.0
2091
+     */
2092
+    public function getMimeTypeLoader() {
2093
+        return $this->get(IMimeTypeLoader::class);
2094
+    }
2095
+
2096
+    /**
2097
+     * Get the manager of all the capabilities
2098
+     *
2099
+     * @return CapabilitiesManager
2100
+     * @deprecated 20.0.0
2101
+     */
2102
+    public function getCapabilitiesManager() {
2103
+        return $this->get(CapabilitiesManager::class);
2104
+    }
2105
+
2106
+    /**
2107
+     * Get the EventDispatcher
2108
+     *
2109
+     * @return EventDispatcherInterface
2110
+     * @since 8.2.0
2111
+     * @deprecated 18.0.0 use \OCP\EventDispatcher\IEventDispatcher
2112
+     */
2113
+    public function getEventDispatcher() {
2114
+        return $this->get(\OC\EventDispatcher\SymfonyAdapter::class);
2115
+    }
2116
+
2117
+    /**
2118
+     * Get the Notification Manager
2119
+     *
2120
+     * @return \OCP\Notification\IManager
2121
+     * @since 8.2.0
2122
+     * @deprecated 20.0.0
2123
+     */
2124
+    public function getNotificationManager() {
2125
+        return $this->get(\OCP\Notification\IManager::class);
2126
+    }
2127
+
2128
+    /**
2129
+     * @return ICommentsManager
2130
+     * @deprecated 20.0.0
2131
+     */
2132
+    public function getCommentsManager() {
2133
+        return $this->get(ICommentsManager::class);
2134
+    }
2135
+
2136
+    /**
2137
+     * @return \OCA\Theming\ThemingDefaults
2138
+     * @deprecated 20.0.0
2139
+     */
2140
+    public function getThemingDefaults() {
2141
+        return $this->get('ThemingDefaults');
2142
+    }
2143
+
2144
+    /**
2145
+     * @return \OC\IntegrityCheck\Checker
2146
+     * @deprecated 20.0.0
2147
+     */
2148
+    public function getIntegrityCodeChecker() {
2149
+        return $this->get('IntegrityCodeChecker');
2150
+    }
2151
+
2152
+    /**
2153
+     * @return \OC\Session\CryptoWrapper
2154
+     * @deprecated 20.0.0
2155
+     */
2156
+    public function getSessionCryptoWrapper() {
2157
+        return $this->get('CryptoWrapper');
2158
+    }
2159
+
2160
+    /**
2161
+     * @return CsrfTokenManager
2162
+     * @deprecated 20.0.0
2163
+     */
2164
+    public function getCsrfTokenManager() {
2165
+        return $this->get(CsrfTokenManager::class);
2166
+    }
2167
+
2168
+    /**
2169
+     * @return Throttler
2170
+     * @deprecated 20.0.0
2171
+     */
2172
+    public function getBruteForceThrottler() {
2173
+        return $this->get(Throttler::class);
2174
+    }
2175
+
2176
+    /**
2177
+     * @return IContentSecurityPolicyManager
2178
+     * @deprecated 20.0.0
2179
+     */
2180
+    public function getContentSecurityPolicyManager() {
2181
+        return $this->get(ContentSecurityPolicyManager::class);
2182
+    }
2183
+
2184
+    /**
2185
+     * @return ContentSecurityPolicyNonceManager
2186
+     * @deprecated 20.0.0
2187
+     */
2188
+    public function getContentSecurityPolicyNonceManager() {
2189
+        return $this->get(ContentSecurityPolicyNonceManager::class);
2190
+    }
2191
+
2192
+    /**
2193
+     * Not a public API as of 8.2, wait for 9.0
2194
+     *
2195
+     * @return \OCA\Files_External\Service\BackendService
2196
+     * @deprecated 20.0.0
2197
+     */
2198
+    public function getStoragesBackendService() {
2199
+        return $this->get(BackendService::class);
2200
+    }
2201
+
2202
+    /**
2203
+     * Not a public API as of 8.2, wait for 9.0
2204
+     *
2205
+     * @return \OCA\Files_External\Service\GlobalStoragesService
2206
+     * @deprecated 20.0.0
2207
+     */
2208
+    public function getGlobalStoragesService() {
2209
+        return $this->get(GlobalStoragesService::class);
2210
+    }
2211
+
2212
+    /**
2213
+     * Not a public API as of 8.2, wait for 9.0
2214
+     *
2215
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
2216
+     * @deprecated 20.0.0
2217
+     */
2218
+    public function getUserGlobalStoragesService() {
2219
+        return $this->get(UserGlobalStoragesService::class);
2220
+    }
2221
+
2222
+    /**
2223
+     * Not a public API as of 8.2, wait for 9.0
2224
+     *
2225
+     * @return \OCA\Files_External\Service\UserStoragesService
2226
+     * @deprecated 20.0.0
2227
+     */
2228
+    public function getUserStoragesService() {
2229
+        return $this->get(UserStoragesService::class);
2230
+    }
2231
+
2232
+    /**
2233
+     * @return \OCP\Share\IManager
2234
+     * @deprecated 20.0.0
2235
+     */
2236
+    public function getShareManager() {
2237
+        return $this->get(\OCP\Share\IManager::class);
2238
+    }
2239
+
2240
+    /**
2241
+     * @return \OCP\Collaboration\Collaborators\ISearch
2242
+     * @deprecated 20.0.0
2243
+     */
2244
+    public function getCollaboratorSearch() {
2245
+        return $this->get(\OCP\Collaboration\Collaborators\ISearch::class);
2246
+    }
2247
+
2248
+    /**
2249
+     * @return \OCP\Collaboration\AutoComplete\IManager
2250
+     * @deprecated 20.0.0
2251
+     */
2252
+    public function getAutoCompleteManager() {
2253
+        return $this->get(IManager::class);
2254
+    }
2255
+
2256
+    /**
2257
+     * Returns the LDAP Provider
2258
+     *
2259
+     * @return \OCP\LDAP\ILDAPProvider
2260
+     * @deprecated 20.0.0
2261
+     */
2262
+    public function getLDAPProvider() {
2263
+        return $this->get('LDAPProvider');
2264
+    }
2265
+
2266
+    /**
2267
+     * @return \OCP\Settings\IManager
2268
+     * @deprecated 20.0.0
2269
+     */
2270
+    public function getSettingsManager() {
2271
+        return $this->get(\OC\Settings\Manager::class);
2272
+    }
2273
+
2274
+    /**
2275
+     * @return \OCP\Files\IAppData
2276
+     * @deprecated 20.0.0 Use get(\OCP\Files\AppData\IAppDataFactory::class)->get($app) instead
2277
+     */
2278
+    public function getAppDataDir($app) {
2279
+        /** @var \OC\Files\AppData\Factory $factory */
2280
+        $factory = $this->get(\OC\Files\AppData\Factory::class);
2281
+        return $factory->get($app);
2282
+    }
2283
+
2284
+    /**
2285
+     * @return \OCP\Lockdown\ILockdownManager
2286
+     * @deprecated 20.0.0
2287
+     */
2288
+    public function getLockdownManager() {
2289
+        return $this->get('LockdownManager');
2290
+    }
2291
+
2292
+    /**
2293
+     * @return \OCP\Federation\ICloudIdManager
2294
+     * @deprecated 20.0.0
2295
+     */
2296
+    public function getCloudIdManager() {
2297
+        return $this->get(ICloudIdManager::class);
2298
+    }
2299
+
2300
+    /**
2301
+     * @return \OCP\GlobalScale\IConfig
2302
+     * @deprecated 20.0.0
2303
+     */
2304
+    public function getGlobalScaleConfig() {
2305
+        return $this->get(IConfig::class);
2306
+    }
2307
+
2308
+    /**
2309
+     * @return \OCP\Federation\ICloudFederationProviderManager
2310
+     * @deprecated 20.0.0
2311
+     */
2312
+    public function getCloudFederationProviderManager() {
2313
+        return $this->get(ICloudFederationProviderManager::class);
2314
+    }
2315
+
2316
+    /**
2317
+     * @return \OCP\Remote\Api\IApiFactory
2318
+     * @deprecated 20.0.0
2319
+     */
2320
+    public function getRemoteApiFactory() {
2321
+        return $this->get(IApiFactory::class);
2322
+    }
2323
+
2324
+    /**
2325
+     * @return \OCP\Federation\ICloudFederationFactory
2326
+     * @deprecated 20.0.0
2327
+     */
2328
+    public function getCloudFederationFactory() {
2329
+        return $this->get(ICloudFederationFactory::class);
2330
+    }
2331
+
2332
+    /**
2333
+     * @return \OCP\Remote\IInstanceFactory
2334
+     * @deprecated 20.0.0
2335
+     */
2336
+    public function getRemoteInstanceFactory() {
2337
+        return $this->get(IInstanceFactory::class);
2338
+    }
2339
+
2340
+    /**
2341
+     * @return IStorageFactory
2342
+     * @deprecated 20.0.0
2343
+     */
2344
+    public function getStorageFactory() {
2345
+        return $this->get(IStorageFactory::class);
2346
+    }
2347
+
2348
+    /**
2349
+     * Get the Preview GeneratorHelper
2350
+     *
2351
+     * @return GeneratorHelper
2352
+     * @since 17.0.0
2353
+     * @deprecated 20.0.0
2354
+     */
2355
+    public function getGeneratorHelper() {
2356
+        return $this->get(\OC\Preview\GeneratorHelper::class);
2357
+    }
2358
+
2359
+    private function registerDeprecatedAlias(string $alias, string $target) {
2360
+        $this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2361
+            try {
2362
+                /** @var LoggerInterface $logger */
2363
+                $logger = $container->get(LoggerInterface::class);
2364
+                $logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2365
+            } catch (ContainerExceptionInterface $e) {
2366
+                // Could not get logger. Continue
2367
+            }
2368
+
2369
+            return $container->get($target);
2370
+        }, false);
2371
+    }
2372 2372
 }
Please login to merge, or discard this patch.
Spacing   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
 		$this->registerParameter('isCLI', \OC::$CLI);
292 292
 		$this->registerParameter('serverRoot', \OC::$SERVERROOT);
293 293
 
294
-		$this->registerService(ContainerInterface::class, function (ContainerInterface $c) {
294
+		$this->registerService(ContainerInterface::class, function(ContainerInterface $c) {
295 295
 			return $c;
296 296
 		});
297
-		$this->registerService(\OCP\IServerContainer::class, function (ContainerInterface $c) {
297
+		$this->registerService(\OCP\IServerContainer::class, function(ContainerInterface $c) {
298 298
 			return $c;
299 299
 		});
300 300
 
@@ -319,11 +319,11 @@  discard block
 block discarded – undo
319 319
 
320 320
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
321 321
 
322
-		$this->registerService(View::class, function (Server $c) {
322
+		$this->registerService(View::class, function(Server $c) {
323 323
 			return new View();
324 324
 		}, false);
325 325
 
326
-		$this->registerService(IPreview::class, function (ContainerInterface $c) {
326
+		$this->registerService(IPreview::class, function(ContainerInterface $c) {
327 327
 			return new PreviewManager(
328 328
 				$c->get(\OCP\IConfig::class),
329 329
 				$c->get(IRootFolder::class),
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 		/** @deprecated 19.0.0 */
344 344
 		$this->registerDeprecatedAlias('PreviewManager', IPreview::class);
345 345
 
346
-		$this->registerService(\OC\Preview\Watcher::class, function (ContainerInterface $c) {
346
+		$this->registerService(\OC\Preview\Watcher::class, function(ContainerInterface $c) {
347 347
 			return new \OC\Preview\Watcher(
348 348
 				new \OC\Preview\Storage\Root(
349 349
 					$c->get(IRootFolder::class),
@@ -352,11 +352,11 @@  discard block
 block discarded – undo
352 352
 			);
353 353
 		});
354 354
 
355
-		$this->registerService(IProfiler::class, function (Server $c) {
355
+		$this->registerService(IProfiler::class, function(Server $c) {
356 356
 			return new Profiler($c->get(SystemConfig::class));
357 357
 		});
358 358
 
359
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c): Encryption\Manager {
359
+		$this->registerService(\OCP\Encryption\IManager::class, function(Server $c): Encryption\Manager {
360 360
 			$view = new View();
361 361
 			$util = new Encryption\Util(
362 362
 				$view,
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 
379 379
 		/** @deprecated 21.0.0 */
380 380
 		$this->registerDeprecatedAlias('EncryptionFileHelper', IFile::class);
381
-		$this->registerService(IFile::class, function (ContainerInterface $c) {
381
+		$this->registerService(IFile::class, function(ContainerInterface $c) {
382 382
 			$util = new Encryption\Util(
383 383
 				new View(),
384 384
 				$c->get(IUserManager::class),
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 
395 395
 		/** @deprecated 21.0.0 */
396 396
 		$this->registerDeprecatedAlias('EncryptionKeyStorage', IStorage::class);
397
-		$this->registerService(IStorage::class, function (ContainerInterface $c) {
397
+		$this->registerService(IStorage::class, function(ContainerInterface $c) {
398 398
 			$view = new View();
399 399
 			$util = new Encryption\Util(
400 400
 				$view,
@@ -417,22 +417,22 @@  discard block
 block discarded – undo
417 417
 		/** @deprecated 19.0.0 */
418 418
 		$this->registerDeprecatedAlias('TagManager', \OCP\ITagManager::class);
419 419
 
420
-		$this->registerService('SystemTagManagerFactory', function (ContainerInterface $c) {
420
+		$this->registerService('SystemTagManagerFactory', function(ContainerInterface $c) {
421 421
 			/** @var \OCP\IConfig $config */
422 422
 			$config = $c->get(\OCP\IConfig::class);
423 423
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
424 424
 			return new $factoryClass($this);
425 425
 		});
426
-		$this->registerService(ISystemTagManager::class, function (ContainerInterface $c) {
426
+		$this->registerService(ISystemTagManager::class, function(ContainerInterface $c) {
427 427
 			return $c->get('SystemTagManagerFactory')->getManager();
428 428
 		});
429 429
 		/** @deprecated 19.0.0 */
430 430
 		$this->registerDeprecatedAlias('SystemTagManager', ISystemTagManager::class);
431 431
 
432
-		$this->registerService(ISystemTagObjectMapper::class, function (ContainerInterface $c) {
432
+		$this->registerService(ISystemTagObjectMapper::class, function(ContainerInterface $c) {
433 433
 			return $c->get('SystemTagManagerFactory')->getObjectMapper();
434 434
 		});
435
-		$this->registerService('RootFolder', function (ContainerInterface $c) {
435
+		$this->registerService('RootFolder', function(ContainerInterface $c) {
436 436
 			$manager = \OC\Files\Filesystem::getMountManager(null);
437 437
 			$view = new View();
438 438
 			$root = new Root(
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
 
454 454
 			return $root;
455 455
 		});
456
-		$this->registerService(HookConnector::class, function (ContainerInterface $c) {
456
+		$this->registerService(HookConnector::class, function(ContainerInterface $c) {
457 457
 			return new HookConnector(
458 458
 				$c->get(IRootFolder::class),
459 459
 				new View(),
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
 		/** @deprecated 19.0.0 */
466 466
 		$this->registerDeprecatedAlias('SystemTagObjectMapper', ISystemTagObjectMapper::class);
467 467
 
468
-		$this->registerService(IRootFolder::class, function (ContainerInterface $c) {
469
-			return new LazyRoot(function () use ($c) {
468
+		$this->registerService(IRootFolder::class, function(ContainerInterface $c) {
469
+			return new LazyRoot(function() use ($c) {
470 470
 				return $c->get('RootFolder');
471 471
 			});
472 472
 		});
@@ -477,53 +477,53 @@  discard block
 block discarded – undo
477 477
 		$this->registerDeprecatedAlias('UserManager', \OC\User\Manager::class);
478 478
 		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
479 479
 
480
-		$this->registerService(DisplayNameCache::class, function (ContainerInterface $c) {
480
+		$this->registerService(DisplayNameCache::class, function(ContainerInterface $c) {
481 481
 			return $c->get(\OC\User\Manager::class)->getDisplayNameCache();
482 482
 		});
483 483
 
484
-		$this->registerService(\OCP\IGroupManager::class, function (ContainerInterface $c) {
484
+		$this->registerService(\OCP\IGroupManager::class, function(ContainerInterface $c) {
485 485
 			$groupManager = new \OC\Group\Manager(
486 486
 				$this->get(IUserManager::class),
487 487
 				$c->get(SymfonyAdapter::class),
488 488
 				$this->get(LoggerInterface::class),
489 489
 				$this->get(ICacheFactory::class)
490 490
 			);
491
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
491
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
492 492
 				/** @var IEventDispatcher $dispatcher */
493 493
 				$dispatcher = $this->get(IEventDispatcher::class);
494 494
 				$dispatcher->dispatchTyped(new BeforeGroupCreatedEvent($gid));
495 495
 			});
496
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $group) {
496
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $group) {
497 497
 				/** @var IEventDispatcher $dispatcher */
498 498
 				$dispatcher = $this->get(IEventDispatcher::class);
499 499
 				$dispatcher->dispatchTyped(new GroupCreatedEvent($group));
500 500
 			});
501
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
501
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
502 502
 				/** @var IEventDispatcher $dispatcher */
503 503
 				$dispatcher = $this->get(IEventDispatcher::class);
504 504
 				$dispatcher->dispatchTyped(new BeforeGroupDeletedEvent($group));
505 505
 			});
506
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
506
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
507 507
 				/** @var IEventDispatcher $dispatcher */
508 508
 				$dispatcher = $this->get(IEventDispatcher::class);
509 509
 				$dispatcher->dispatchTyped(new GroupDeletedEvent($group));
510 510
 			});
511
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
511
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
512 512
 				/** @var IEventDispatcher $dispatcher */
513 513
 				$dispatcher = $this->get(IEventDispatcher::class);
514 514
 				$dispatcher->dispatchTyped(new BeforeUserAddedEvent($group, $user));
515 515
 			});
516
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
516
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
517 517
 				/** @var IEventDispatcher $dispatcher */
518 518
 				$dispatcher = $this->get(IEventDispatcher::class);
519 519
 				$dispatcher->dispatchTyped(new UserAddedEvent($group, $user));
520 520
 			});
521
-			$groupManager->listen('\OC\Group', 'preRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
521
+			$groupManager->listen('\OC\Group', 'preRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) {
522 522
 				/** @var IEventDispatcher $dispatcher */
523 523
 				$dispatcher = $this->get(IEventDispatcher::class);
524 524
 				$dispatcher->dispatchTyped(new BeforeUserRemovedEvent($group, $user));
525 525
 			});
526
-			$groupManager->listen('\OC\Group', 'postRemoveUser', function (\OC\Group\Group $group, \OC\User\User $user) {
526
+			$groupManager->listen('\OC\Group', 'postRemoveUser', function(\OC\Group\Group $group, \OC\User\User $user) {
527 527
 				/** @var IEventDispatcher $dispatcher */
528 528
 				$dispatcher = $this->get(IEventDispatcher::class);
529 529
 				$dispatcher->dispatchTyped(new UserRemovedEvent($group, $user));
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 		/** @deprecated 19.0.0 */
534 534
 		$this->registerDeprecatedAlias('GroupManager', \OCP\IGroupManager::class);
535 535
 
536
-		$this->registerService(Store::class, function (ContainerInterface $c) {
536
+		$this->registerService(Store::class, function(ContainerInterface $c) {
537 537
 			$session = $c->get(ISession::class);
538 538
 			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
539 539
 				$tokenProvider = $c->get(IProvider::class);
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 		$this->registerAlias(IStore::class, Store::class);
547 547
 		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
548 548
 
549
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
549
+		$this->registerService(\OC\User\Session::class, function(Server $c) {
550 550
 			$manager = $c->get(IUserManager::class);
551 551
 			$session = new \OC\Session\Memory('');
552 552
 			$timeFactory = new TimeFactory();
@@ -572,26 +572,26 @@  discard block
 block discarded – undo
572 572
 				$c->get(IEventDispatcher::class)
573 573
 			);
574 574
 			/** @deprecated 21.0.0 use BeforeUserCreatedEvent event with the IEventDispatcher instead */
575
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
575
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
576 576
 				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
577 577
 			});
578 578
 			/** @deprecated 21.0.0 use UserCreatedEvent event with the IEventDispatcher instead */
579
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
579
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
580 580
 				/** @var \OC\User\User $user */
581 581
 				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
582 582
 			});
583 583
 			/** @deprecated 21.0.0 use BeforeUserDeletedEvent event with the IEventDispatcher instead */
584
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($legacyDispatcher) {
584
+			$userSession->listen('\OC\User', 'preDelete', function($user) use ($legacyDispatcher) {
585 585
 				/** @var \OC\User\User $user */
586 586
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
587 587
 				$legacyDispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
588 588
 			});
589 589
 			/** @deprecated 21.0.0 use UserDeletedEvent event with the IEventDispatcher instead */
590
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
590
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
591 591
 				/** @var \OC\User\User $user */
592 592
 				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
593 593
 			});
594
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
594
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
595 595
 				/** @var \OC\User\User $user */
596 596
 				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
597 597
 
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 				$dispatcher = $this->get(IEventDispatcher::class);
600 600
 				$dispatcher->dispatchTyped(new BeforePasswordUpdatedEvent($user, $password, $recoveryPassword));
601 601
 			});
602
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
602
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
603 603
 				/** @var \OC\User\User $user */
604 604
 				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
605 605
 
@@ -607,14 +607,14 @@  discard block
 block discarded – undo
607 607
 				$dispatcher = $this->get(IEventDispatcher::class);
608 608
 				$dispatcher->dispatchTyped(new PasswordUpdatedEvent($user, $password, $recoveryPassword));
609 609
 			});
610
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
610
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
611 611
 				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
612 612
 
613 613
 				/** @var IEventDispatcher $dispatcher */
614 614
 				$dispatcher = $this->get(IEventDispatcher::class);
615 615
 				$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
616 616
 			});
617
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
617
+			$userSession->listen('\OC\User', 'postLogin', function($user, $loginName, $password, $isTokenLogin) {
618 618
 				/** @var \OC\User\User $user */
619 619
 				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
620 620
 
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
 				$dispatcher = $this->get(IEventDispatcher::class);
623 623
 				$dispatcher->dispatchTyped(new UserLoggedInEvent($user, $loginName, $password, $isTokenLogin));
624 624
 			});
625
-			$userSession->listen('\OC\User', 'preRememberedLogin', function ($uid) {
625
+			$userSession->listen('\OC\User', 'preRememberedLogin', function($uid) {
626 626
 				/** @var IEventDispatcher $dispatcher */
627 627
 				$dispatcher = $this->get(IEventDispatcher::class);
628 628
 				$dispatcher->dispatchTyped(new BeforeUserLoggedInWithCookieEvent($uid));
629 629
 			});
630
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
630
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
631 631
 				/** @var \OC\User\User $user */
632 632
 				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
633 633
 
@@ -635,19 +635,19 @@  discard block
 block discarded – undo
635 635
 				$dispatcher = $this->get(IEventDispatcher::class);
636 636
 				$dispatcher->dispatchTyped(new UserLoggedInWithCookieEvent($user, $password));
637 637
 			});
638
-			$userSession->listen('\OC\User', 'logout', function ($user) {
638
+			$userSession->listen('\OC\User', 'logout', function($user) {
639 639
 				\OC_Hook::emit('OC_User', 'logout', []);
640 640
 
641 641
 				/** @var IEventDispatcher $dispatcher */
642 642
 				$dispatcher = $this->get(IEventDispatcher::class);
643 643
 				$dispatcher->dispatchTyped(new BeforeUserLoggedOutEvent($user));
644 644
 			});
645
-			$userSession->listen('\OC\User', 'postLogout', function ($user) {
645
+			$userSession->listen('\OC\User', 'postLogout', function($user) {
646 646
 				/** @var IEventDispatcher $dispatcher */
647 647
 				$dispatcher = $this->get(IEventDispatcher::class);
648 648
 				$dispatcher->dispatchTyped(new UserLoggedOutEvent($user));
649 649
 			});
650
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
650
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
651 651
 				/** @var \OC\User\User $user */
652 652
 				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue]);
653 653
 
@@ -671,7 +671,7 @@  discard block
 block discarded – undo
671 671
 		$this->registerDeprecatedAlias('AllConfig', \OC\AllConfig::class);
672 672
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
673 673
 
674
-		$this->registerService(\OC\SystemConfig::class, function ($c) use ($config) {
674
+		$this->registerService(\OC\SystemConfig::class, function($c) use ($config) {
675 675
 			return new \OC\SystemConfig($config);
676 676
 		});
677 677
 		/** @deprecated 19.0.0 */
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		$this->registerDeprecatedAlias('AppConfig', \OC\AppConfig::class);
682 682
 		$this->registerAlias(IAppConfig::class, \OC\AppConfig::class);
683 683
 
684
-		$this->registerService(IFactory::class, function (Server $c) {
684
+		$this->registerService(IFactory::class, function(Server $c) {
685 685
 			return new \OC\L10N\Factory(
686 686
 				$c->get(\OCP\IConfig::class),
687 687
 				$c->getRequest(),
@@ -702,13 +702,13 @@  discard block
 block discarded – undo
702 702
 		/** @deprecated 19.0.0 */
703 703
 		$this->registerDeprecatedAlias('CategoryFetcher', CategoryFetcher::class);
704 704
 
705
-		$this->registerService(ICache::class, function ($c) {
705
+		$this->registerService(ICache::class, function($c) {
706 706
 			return new Cache\File();
707 707
 		});
708 708
 		/** @deprecated 19.0.0 */
709 709
 		$this->registerDeprecatedAlias('UserCache', ICache::class);
710 710
 
711
-		$this->registerService(Factory::class, function (Server $c) {
711
+		$this->registerService(Factory::class, function(Server $c) {
712 712
 			$profiler = $c->get(IProfiler::class);
713 713
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->get(LoggerInterface::class),
714 714
 				$profiler,
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 				$version = implode(',', $v);
735 735
 				$instanceId = \OC_Util::getInstanceId();
736 736
 				$path = \OC::$SERVERROOT;
737
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
737
+				$prefix = md5($instanceId.'-'.$version.'-'.$path);
738 738
 				return new \OC\Memcache\Factory($prefix,
739 739
 					$c->get(LoggerInterface::class),
740 740
 					$profiler,
@@ -750,12 +750,12 @@  discard block
 block discarded – undo
750 750
 		$this->registerDeprecatedAlias('MemCacheFactory', Factory::class);
751 751
 		$this->registerAlias(ICacheFactory::class, Factory::class);
752 752
 
753
-		$this->registerService('RedisFactory', function (Server $c) {
753
+		$this->registerService('RedisFactory', function(Server $c) {
754 754
 			$systemConfig = $c->get(SystemConfig::class);
755 755
 			return new RedisFactory($systemConfig, $c->getEventLogger());
756 756
 		});
757 757
 
758
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
758
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
759 759
 			$l10n = $this->get(IFactory::class)->get('lib');
760 760
 			return new \OC\Activity\Manager(
761 761
 				$c->getRequest(),
@@ -768,14 +768,14 @@  discard block
 block discarded – undo
768 768
 		/** @deprecated 19.0.0 */
769 769
 		$this->registerDeprecatedAlias('ActivityManager', \OCP\Activity\IManager::class);
770 770
 
771
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
771
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
772 772
 			return new \OC\Activity\EventMerger(
773 773
 				$c->getL10N('lib')
774 774
 			);
775 775
 		});
776 776
 		$this->registerAlias(IValidator::class, Validator::class);
777 777
 
778
-		$this->registerService(AvatarManager::class, function (Server $c) {
778
+		$this->registerService(AvatarManager::class, function(Server $c) {
779 779
 			return new AvatarManager(
780 780
 				$c->get(IUserSession::class),
781 781
 				$c->get(\OC\User\Manager::class),
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
797 797
 		$this->registerAlias(\OCP\Support\Subscription\IAssertion::class, \OC\Support\Subscription\Assertion::class);
798 798
 
799
-		$this->registerService(\OC\Log::class, function (Server $c) {
799
+		$this->registerService(\OC\Log::class, function(Server $c) {
800 800
 			$logType = $c->get(AllConfig::class)->getSystemValue('log_type', 'file');
801 801
 			$factory = new LogFactory($c, $this->get(SystemConfig::class));
802 802
 			$logger = $factory->get($logType);
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 		// PSR-3 logger
811 811
 		$this->registerAlias(LoggerInterface::class, PsrLoggerAdapter::class);
812 812
 
813
-		$this->registerService(ILogFactory::class, function (Server $c) {
813
+		$this->registerService(ILogFactory::class, function(Server $c) {
814 814
 			return new LogFactory($c, $this->get(SystemConfig::class));
815 815
 		});
816 816
 
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 		/** @deprecated 19.0.0 */
819 819
 		$this->registerDeprecatedAlias('JobList', IJobList::class);
820 820
 
821
-		$this->registerService(Router::class, function (Server $c) {
821
+		$this->registerService(Router::class, function(Server $c) {
822 822
 			$cacheFactory = $c->get(ICacheFactory::class);
823 823
 			$logger = $c->get(LoggerInterface::class);
824 824
 			if ($cacheFactory->isLocalCacheAvailable()) {
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
 		/** @deprecated 19.0.0 */
837 837
 		$this->registerDeprecatedAlias('Search', ISearch::class);
838 838
 
839
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
839
+		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
840 840
 			$cacheFactory = $c->get(ICacheFactory::class);
841 841
 			if ($cacheFactory->isAvailable()) {
842 842
 				$backend = new \OC\Security\RateLimiting\Backend\MemoryCacheBackend(
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
 		$this->registerDeprecatedAlias('CredentialsManager', ICredentialsManager::class);
873 873
 
874 874
 		$this->registerAlias(IDBConnection::class, ConnectionAdapter::class);
875
-		$this->registerService(Connection::class, function (Server $c) {
875
+		$this->registerService(Connection::class, function(Server $c) {
876 876
 			$systemConfig = $c->get(SystemConfig::class);
877 877
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
878 878
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -888,19 +888,19 @@  discard block
 block discarded – undo
888 888
 
889 889
 		$this->registerAlias(ICertificateManager::class, CertificateManager::class);
890 890
 		$this->registerAlias(IClientService::class, ClientService::class);
891
-		$this->registerService(NegativeDnsCache::class, function (ContainerInterface $c) {
891
+		$this->registerService(NegativeDnsCache::class, function(ContainerInterface $c) {
892 892
 			return new NegativeDnsCache(
893 893
 				$c->get(ICacheFactory::class),
894 894
 			);
895 895
 		});
896 896
 		$this->registerDeprecatedAlias('HttpClientService', IClientService::class);
897
-		$this->registerService(IEventLogger::class, function (ContainerInterface $c) {
897
+		$this->registerService(IEventLogger::class, function(ContainerInterface $c) {
898 898
 			return new EventLogger($c->get(SystemConfig::class), $c->get(LoggerInterface::class), $c->get(Log::class));
899 899
 		});
900 900
 		/** @deprecated 19.0.0 */
901 901
 		$this->registerDeprecatedAlias('EventLogger', IEventLogger::class);
902 902
 
903
-		$this->registerService(IQueryLogger::class, function (ContainerInterface $c) {
903
+		$this->registerService(IQueryLogger::class, function(ContainerInterface $c) {
904 904
 			$queryLogger = new QueryLogger();
905 905
 			if ($c->get(SystemConfig::class)->getValue('debug', false)) {
906 906
 				// In debug mode, module is being activated by default
@@ -915,7 +915,7 @@  discard block
 block discarded – undo
915 915
 		$this->registerDeprecatedAlias('TempManager', TempManager::class);
916 916
 		$this->registerAlias(ITempManager::class, TempManager::class);
917 917
 
918
-		$this->registerService(AppManager::class, function (ContainerInterface $c) {
918
+		$this->registerService(AppManager::class, function(ContainerInterface $c) {
919 919
 			// TODO: use auto-wiring
920 920
 			return new \OC\App\AppManager(
921 921
 				$c->get(IUserSession::class),
@@ -935,7 +935,7 @@  discard block
 block discarded – undo
935 935
 		/** @deprecated 19.0.0 */
936 936
 		$this->registerDeprecatedAlias('DateTimeZone', IDateTimeZone::class);
937 937
 
938
-		$this->registerService(IDateTimeFormatter::class, function (Server $c) {
938
+		$this->registerService(IDateTimeFormatter::class, function(Server $c) {
939 939
 			$language = $c->get(\OCP\IConfig::class)->getUserValue($c->get(ISession::class)->get('user_id'), 'core', 'lang', null);
940 940
 
941 941
 			return new DateTimeFormatter(
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 		/** @deprecated 19.0.0 */
947 947
 		$this->registerDeprecatedAlias('DateTimeFormatter', IDateTimeFormatter::class);
948 948
 
949
-		$this->registerService(IUserMountCache::class, function (ContainerInterface $c) {
949
+		$this->registerService(IUserMountCache::class, function(ContainerInterface $c) {
950 950
 			$mountCache = $c->get(UserMountCache::class);
951 951
 			$listener = new UserMountCacheListener($mountCache);
952 952
 			$listener->listen($c->get(IUserManager::class));
@@ -955,7 +955,7 @@  discard block
 block discarded – undo
955 955
 		/** @deprecated 19.0.0 */
956 956
 		$this->registerDeprecatedAlias('UserMountCache', IUserMountCache::class);
957 957
 
958
-		$this->registerService(IMountProviderCollection::class, function (ContainerInterface $c) {
958
+		$this->registerService(IMountProviderCollection::class, function(ContainerInterface $c) {
959 959
 			$loader = $c->get(IStorageFactory::class);
960 960
 			$mountCache = $c->get(IUserMountCache::class);
961 961
 			$eventLogger = $c->get(IEventLogger::class);
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 
979 979
 		/** @deprecated 20.0.0 */
980 980
 		$this->registerDeprecatedAlias('IniWrapper', IniGetWrapper::class);
981
-		$this->registerService(IBus::class, function (ContainerInterface $c) {
981
+		$this->registerService(IBus::class, function(ContainerInterface $c) {
982 982
 			$busClass = $c->get(\OCP\IConfig::class)->getSystemValue('commandbus');
983 983
 			if ($busClass) {
984 984
 				[$app, $class] = explode('::', $busClass, 2);
@@ -1000,7 +1000,7 @@  discard block
 block discarded – undo
1000 1000
 		/** @deprecated 19.0.0 */
1001 1001
 		$this->registerDeprecatedAlias('Throttler', Throttler::class);
1002 1002
 		$this->registerAlias(IThrottler::class, Throttler::class);
1003
-		$this->registerService('IntegrityCodeChecker', function (ContainerInterface $c) {
1003
+		$this->registerService('IntegrityCodeChecker', function(ContainerInterface $c) {
1004 1004
 			// IConfig and IAppManager requires a working database. This code
1005 1005
 			// might however be called when ownCloud is not yet setup.
1006 1006
 			if (\OC::$server->get(SystemConfig::class)->getValue('installed', false)) {
@@ -1021,7 +1021,7 @@  discard block
 block discarded – undo
1021 1021
 				$c->get(IMimeTypeDetector::class)
1022 1022
 			);
1023 1023
 		});
1024
-		$this->registerService(\OCP\IRequest::class, function (ContainerInterface $c) {
1024
+		$this->registerService(\OCP\IRequest::class, function(ContainerInterface $c) {
1025 1025
 			if (isset($this['urlParams'])) {
1026 1026
 				$urlParams = $this['urlParams'];
1027 1027
 			} else {
@@ -1058,14 +1058,14 @@  discard block
 block discarded – undo
1058 1058
 		/** @deprecated 19.0.0 */
1059 1059
 		$this->registerDeprecatedAlias('Request', \OCP\IRequest::class);
1060 1060
 
1061
-		$this->registerService(IRequestId::class, function (ContainerInterface $c): IRequestId {
1061
+		$this->registerService(IRequestId::class, function(ContainerInterface $c): IRequestId {
1062 1062
 			return new RequestId(
1063 1063
 				$_SERVER['UNIQUE_ID'] ?? '',
1064 1064
 				$this->get(ISecureRandom::class)
1065 1065
 			);
1066 1066
 		});
1067 1067
 
1068
-		$this->registerService(IMailer::class, function (Server $c) {
1068
+		$this->registerService(IMailer::class, function(Server $c) {
1069 1069
 			return new Mailer(
1070 1070
 				$c->get(\OCP\IConfig::class),
1071 1071
 				$c->get(LoggerInterface::class),
@@ -1082,7 +1082,7 @@  discard block
 block discarded – undo
1082 1082
 		/** @deprecated 21.0.0 */
1083 1083
 		$this->registerDeprecatedAlias('LDAPProvider', ILDAPProvider::class);
1084 1084
 
1085
-		$this->registerService(ILDAPProviderFactory::class, function (ContainerInterface $c) {
1085
+		$this->registerService(ILDAPProviderFactory::class, function(ContainerInterface $c) {
1086 1086
 			$config = $c->get(\OCP\IConfig::class);
1087 1087
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
1088 1088
 			if (is_null($factoryClass) || !class_exists($factoryClass)) {
@@ -1091,11 +1091,11 @@  discard block
 block discarded – undo
1091 1091
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
1092 1092
 			return new $factoryClass($this);
1093 1093
 		});
1094
-		$this->registerService(ILDAPProvider::class, function (ContainerInterface $c) {
1094
+		$this->registerService(ILDAPProvider::class, function(ContainerInterface $c) {
1095 1095
 			$factory = $c->get(ILDAPProviderFactory::class);
1096 1096
 			return $factory->getLDAPProvider();
1097 1097
 		});
1098
-		$this->registerService(ILockingProvider::class, function (ContainerInterface $c) {
1098
+		$this->registerService(ILockingProvider::class, function(ContainerInterface $c) {
1099 1099
 			$ini = $c->get(IniGetWrapper::class);
1100 1100
 			$config = $c->get(\OCP\IConfig::class);
1101 1101
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -1118,12 +1118,12 @@  discard block
 block discarded – undo
1118 1118
 		/** @deprecated 19.0.0 */
1119 1119
 		$this->registerDeprecatedAlias('LockingProvider', ILockingProvider::class);
1120 1120
 
1121
-		$this->registerService(ILockManager::class, function (Server $c): LockManager {
1121
+		$this->registerService(ILockManager::class, function(Server $c): LockManager {
1122 1122
 			return new LockManager();
1123 1123
 		});
1124 1124
 
1125 1125
 		$this->registerAlias(ILockdownManager::class, 'LockdownManager');
1126
-		$this->registerService(SetupManager::class, function ($c) {
1126
+		$this->registerService(SetupManager::class, function($c) {
1127 1127
 			// create the setupmanager through the mount manager to resolve the cyclic dependency
1128 1128
 			return $c->get(\OC\Files\Mount\Manager::class)->getSetupManager();
1129 1129
 		});
@@ -1131,12 +1131,12 @@  discard block
 block discarded – undo
1131 1131
 		/** @deprecated 19.0.0 */
1132 1132
 		$this->registerDeprecatedAlias('MountManager', IMountManager::class);
1133 1133
 
1134
-		$this->registerService(IMimeTypeDetector::class, function (ContainerInterface $c) {
1134
+		$this->registerService(IMimeTypeDetector::class, function(ContainerInterface $c) {
1135 1135
 			return new \OC\Files\Type\Detection(
1136 1136
 				$c->get(IURLGenerator::class),
1137 1137
 				$c->get(LoggerInterface::class),
1138 1138
 				\OC::$configDir,
1139
-				\OC::$SERVERROOT . '/resources/config/'
1139
+				\OC::$SERVERROOT.'/resources/config/'
1140 1140
 			);
1141 1141
 		});
1142 1142
 		/** @deprecated 19.0.0 */
@@ -1145,22 +1145,22 @@  discard block
 block discarded – undo
1145 1145
 		$this->registerAlias(IMimeTypeLoader::class, Loader::class);
1146 1146
 		/** @deprecated 19.0.0 */
1147 1147
 		$this->registerDeprecatedAlias('MimeTypeLoader', IMimeTypeLoader::class);
1148
-		$this->registerService(BundleFetcher::class, function () {
1148
+		$this->registerService(BundleFetcher::class, function() {
1149 1149
 			return new BundleFetcher($this->getL10N('lib'));
1150 1150
 		});
1151 1151
 		$this->registerAlias(\OCP\Notification\IManager::class, Manager::class);
1152 1152
 		/** @deprecated 19.0.0 */
1153 1153
 		$this->registerDeprecatedAlias('NotificationManager', \OCP\Notification\IManager::class);
1154 1154
 
1155
-		$this->registerService(CapabilitiesManager::class, function (ContainerInterface $c) {
1155
+		$this->registerService(CapabilitiesManager::class, function(ContainerInterface $c) {
1156 1156
 			$manager = new CapabilitiesManager($c->get(LoggerInterface::class));
1157
-			$manager->registerCapability(function () use ($c) {
1157
+			$manager->registerCapability(function() use ($c) {
1158 1158
 				return new \OC\OCS\CoreCapabilities($c->get(\OCP\IConfig::class));
1159 1159
 			});
1160
-			$manager->registerCapability(function () use ($c) {
1160
+			$manager->registerCapability(function() use ($c) {
1161 1161
 				return $c->get(\OC\Security\Bruteforce\Capabilities::class);
1162 1162
 			});
1163
-			$manager->registerCapability(function () use ($c) {
1163
+			$manager->registerCapability(function() use ($c) {
1164 1164
 				return $c->get(MetadataCapabilities::class);
1165 1165
 			});
1166 1166
 			return $manager;
@@ -1168,14 +1168,14 @@  discard block
 block discarded – undo
1168 1168
 		/** @deprecated 19.0.0 */
1169 1169
 		$this->registerDeprecatedAlias('CapabilitiesManager', CapabilitiesManager::class);
1170 1170
 
1171
-		$this->registerService(ICommentsManager::class, function (Server $c) {
1171
+		$this->registerService(ICommentsManager::class, function(Server $c) {
1172 1172
 			$config = $c->get(\OCP\IConfig::class);
1173 1173
 			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
1174 1174
 			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
1175 1175
 			$factory = new $factoryClass($this);
1176 1176
 			$manager = $factory->getManager();
1177 1177
 
1178
-			$manager->registerDisplayNameResolver('user', function ($id) use ($c) {
1178
+			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
1179 1179
 				$manager = $c->get(IUserManager::class);
1180 1180
 				$userDisplayName = $manager->getDisplayName($id);
1181 1181
 				if ($userDisplayName === null) {
@@ -1191,7 +1191,7 @@  discard block
 block discarded – undo
1191 1191
 		$this->registerDeprecatedAlias('CommentsManager', ICommentsManager::class);
1192 1192
 
1193 1193
 		$this->registerAlias(\OC_Defaults::class, 'ThemingDefaults');
1194
-		$this->registerService('ThemingDefaults', function (Server $c) {
1194
+		$this->registerService('ThemingDefaults', function(Server $c) {
1195 1195
 			/*
1196 1196
 			 * Dark magic for autoloader.
1197 1197
 			 * If we do a class_exists it will try to load the class which will
@@ -1228,7 +1228,7 @@  discard block
 block discarded – undo
1228 1228
 			}
1229 1229
 			return new \OC_Defaults();
1230 1230
 		});
1231
-		$this->registerService(JSCombiner::class, function (Server $c) {
1231
+		$this->registerService(JSCombiner::class, function(Server $c) {
1232 1232
 			return new JSCombiner(
1233 1233
 				$c->getAppDataDir('js'),
1234 1234
 				$c->get(IURLGenerator::class),
@@ -1242,7 +1242,7 @@  discard block
 block discarded – undo
1242 1242
 		$this->registerDeprecatedAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
1243 1243
 		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
1244 1244
 
1245
-		$this->registerService('CryptoWrapper', function (ContainerInterface $c) {
1245
+		$this->registerService('CryptoWrapper', function(ContainerInterface $c) {
1246 1246
 			// FIXME: Instantiated here due to cyclic dependency
1247 1247
 			$request = new Request(
1248 1248
 				[
@@ -1269,14 +1269,14 @@  discard block
 block discarded – undo
1269 1269
 		});
1270 1270
 		/** @deprecated 19.0.0 */
1271 1271
 		$this->registerDeprecatedAlias('CsrfTokenManager', CsrfTokenManager::class);
1272
-		$this->registerService(SessionStorage::class, function (ContainerInterface $c) {
1272
+		$this->registerService(SessionStorage::class, function(ContainerInterface $c) {
1273 1273
 			return new SessionStorage($c->get(ISession::class));
1274 1274
 		});
1275 1275
 		$this->registerAlias(\OCP\Security\IContentSecurityPolicyManager::class, ContentSecurityPolicyManager::class);
1276 1276
 		/** @deprecated 19.0.0 */
1277 1277
 		$this->registerDeprecatedAlias('ContentSecurityPolicyManager', ContentSecurityPolicyManager::class);
1278 1278
 
1279
-		$this->registerService(\OCP\Share\IManager::class, function (IServerContainer $c) {
1279
+		$this->registerService(\OCP\Share\IManager::class, function(IServerContainer $c) {
1280 1280
 			$config = $c->get(\OCP\IConfig::class);
1281 1281
 			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1282 1282
 			/** @var \OCP\Share\IProviderFactory $factory */
@@ -1308,7 +1308,7 @@  discard block
 block discarded – undo
1308 1308
 		/** @deprecated 19.0.0 */
1309 1309
 		$this->registerDeprecatedAlias('ShareManager', \OCP\Share\IManager::class);
1310 1310
 
1311
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function (Server $c) {
1311
+		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1312 1312
 			$instance = new Collaboration\Collaborators\Search($c);
1313 1313
 
1314 1314
 			// register default plugins
@@ -1333,27 +1333,27 @@  discard block
 block discarded – undo
1333 1333
 
1334 1334
 		$this->registerDeprecatedAlias('SettingsManager', \OC\Settings\Manager::class);
1335 1335
 		$this->registerAlias(\OCP\Settings\IManager::class, \OC\Settings\Manager::class);
1336
-		$this->registerService(\OC\Files\AppData\Factory::class, function (ContainerInterface $c) {
1336
+		$this->registerService(\OC\Files\AppData\Factory::class, function(ContainerInterface $c) {
1337 1337
 			return new \OC\Files\AppData\Factory(
1338 1338
 				$c->get(IRootFolder::class),
1339 1339
 				$c->get(SystemConfig::class)
1340 1340
 			);
1341 1341
 		});
1342 1342
 
1343
-		$this->registerService('LockdownManager', function (ContainerInterface $c) {
1344
-			return new LockdownManager(function () use ($c) {
1343
+		$this->registerService('LockdownManager', function(ContainerInterface $c) {
1344
+			return new LockdownManager(function() use ($c) {
1345 1345
 				return $c->get(ISession::class);
1346 1346
 			});
1347 1347
 		});
1348 1348
 
1349
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (ContainerInterface $c) {
1349
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(ContainerInterface $c) {
1350 1350
 			return new DiscoveryService(
1351 1351
 				$c->get(ICacheFactory::class),
1352 1352
 				$c->get(IClientService::class)
1353 1353
 			);
1354 1354
 		});
1355 1355
 
1356
-		$this->registerService(ICloudIdManager::class, function (ContainerInterface $c) {
1356
+		$this->registerService(ICloudIdManager::class, function(ContainerInterface $c) {
1357 1357
 			return new CloudIdManager(
1358 1358
 				$c->get(\OCP\Contacts\IManager::class),
1359 1359
 				$c->get(IURLGenerator::class),
@@ -1365,7 +1365,7 @@  discard block
 block discarded – undo
1365 1365
 
1366 1366
 		$this->registerAlias(\OCP\GlobalScale\IConfig::class, \OC\GlobalScale\Config::class);
1367 1367
 
1368
-		$this->registerService(ICloudFederationProviderManager::class, function (ContainerInterface $c) {
1368
+		$this->registerService(ICloudFederationProviderManager::class, function(ContainerInterface $c) {
1369 1369
 			return new CloudFederationProviderManager(
1370 1370
 				$c->get(IAppManager::class),
1371 1371
 				$c->get(IClientService::class),
@@ -1374,7 +1374,7 @@  discard block
 block discarded – undo
1374 1374
 			);
1375 1375
 		});
1376 1376
 
1377
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1377
+		$this->registerService(ICloudFederationFactory::class, function(Server $c) {
1378 1378
 			return new CloudFederationFactory();
1379 1379
 		});
1380 1380
 
@@ -1386,7 +1386,7 @@  discard block
 block discarded – undo
1386 1386
 		/** @deprecated 19.0.0 */
1387 1387
 		$this->registerDeprecatedAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1388 1388
 
1389
-		$this->registerService(Defaults::class, function (Server $c) {
1389
+		$this->registerService(Defaults::class, function(Server $c) {
1390 1390
 			return new Defaults(
1391 1391
 				$c->getThemingDefaults()
1392 1392
 			);
@@ -1394,17 +1394,17 @@  discard block
 block discarded – undo
1394 1394
 		/** @deprecated 19.0.0 */
1395 1395
 		$this->registerDeprecatedAlias('Defaults', \OCP\Defaults::class);
1396 1396
 
1397
-		$this->registerService(\OCP\ISession::class, function (ContainerInterface $c) {
1397
+		$this->registerService(\OCP\ISession::class, function(ContainerInterface $c) {
1398 1398
 			return $c->get(\OCP\IUserSession::class)->getSession();
1399 1399
 		}, false);
1400 1400
 
1401
-		$this->registerService(IShareHelper::class, function (ContainerInterface $c) {
1401
+		$this->registerService(IShareHelper::class, function(ContainerInterface $c) {
1402 1402
 			return new ShareHelper(
1403 1403
 				$c->get(\OCP\Share\IManager::class)
1404 1404
 			);
1405 1405
 		});
1406 1406
 
1407
-		$this->registerService(Installer::class, function (ContainerInterface $c) {
1407
+		$this->registerService(Installer::class, function(ContainerInterface $c) {
1408 1408
 			return new Installer(
1409 1409
 				$c->get(AppFetcher::class),
1410 1410
 				$c->get(IClientService::class),
@@ -1415,11 +1415,11 @@  discard block
 block discarded – undo
1415 1415
 			);
1416 1416
 		});
1417 1417
 
1418
-		$this->registerService(IApiFactory::class, function (ContainerInterface $c) {
1418
+		$this->registerService(IApiFactory::class, function(ContainerInterface $c) {
1419 1419
 			return new ApiFactory($c->get(IClientService::class));
1420 1420
 		});
1421 1421
 
1422
-		$this->registerService(IInstanceFactory::class, function (ContainerInterface $c) {
1422
+		$this->registerService(IInstanceFactory::class, function(ContainerInterface $c) {
1423 1423
 			$memcacheFactory = $c->get(ICacheFactory::class);
1424 1424
 			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->get(IClientService::class));
1425 1425
 		});
@@ -2357,11 +2357,11 @@  discard block
 block discarded – undo
2357 2357
 	}
2358 2358
 
2359 2359
 	private function registerDeprecatedAlias(string $alias, string $target) {
2360
-		$this->registerService($alias, function (ContainerInterface $container) use ($target, $alias) {
2360
+		$this->registerService($alias, function(ContainerInterface $container) use ($target, $alias) {
2361 2361
 			try {
2362 2362
 				/** @var LoggerInterface $logger */
2363 2363
 				$logger = $container->get(LoggerInterface::class);
2364
-				$logger->debug('The requested alias "' . $alias . '" is deprecated. Please request "' . $target . '" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2364
+				$logger->debug('The requested alias "'.$alias.'" is deprecated. Please request "'.$target.'" directly. This alias will be removed in a future Nextcloud version.', ['app' => 'serverDI']);
2365 2365
 			} catch (ContainerExceptionInterface $e) {
2366 2366
 				// Could not get logger. Continue
2367 2367
 			}
Please login to merge, or discard this patch.
lib/private/Files/SetupManager.php 2 patches
Indentation   +543 added lines, -543 removed lines patch added patch discarded remove patch
@@ -63,549 +63,549 @@
 block discarded – undo
63 63
 use Psr\Log\LoggerInterface;
64 64
 
65 65
 class SetupManager {
66
-	private bool $rootSetup = false;
67
-	private IEventLogger $eventLogger;
68
-	private MountProviderCollection $mountProviderCollection;
69
-	private IMountManager $mountManager;
70
-	private IUserManager $userManager;
71
-	// List of users for which at least one mount is setup
72
-	private array $setupUsers = [];
73
-	// List of users for which all mounts are setup
74
-	private array $setupUsersComplete = [];
75
-	/** @var array<string, string[]> */
76
-	private array $setupUserMountProviders = [];
77
-	private IEventDispatcher $eventDispatcher;
78
-	private IUserMountCache $userMountCache;
79
-	private ILockdownManager $lockdownManager;
80
-	private IUserSession $userSession;
81
-	private ICache $cache;
82
-	private LoggerInterface $logger;
83
-	private IConfig $config;
84
-	private bool $listeningForProviders;
85
-	private array $fullSetupRequired = [];
86
-	private bool $setupBuiltinWrappersDone = false;
87
-
88
-	public function __construct(
89
-		IEventLogger $eventLogger,
90
-		MountProviderCollection $mountProviderCollection,
91
-		IMountManager $mountManager,
92
-		IUserManager $userManager,
93
-		IEventDispatcher $eventDispatcher,
94
-		IUserMountCache $userMountCache,
95
-		ILockdownManager $lockdownManager,
96
-		IUserSession $userSession,
97
-		ICacheFactory $cacheFactory,
98
-		LoggerInterface $logger,
99
-		IConfig $config
100
-	) {
101
-		$this->eventLogger = $eventLogger;
102
-		$this->mountProviderCollection = $mountProviderCollection;
103
-		$this->mountManager = $mountManager;
104
-		$this->userManager = $userManager;
105
-		$this->eventDispatcher = $eventDispatcher;
106
-		$this->userMountCache = $userMountCache;
107
-		$this->lockdownManager = $lockdownManager;
108
-		$this->logger = $logger;
109
-		$this->userSession = $userSession;
110
-		$this->cache = $cacheFactory->createDistributed('setupmanager::');
111
-		$this->listeningForProviders = false;
112
-		$this->config = $config;
113
-
114
-		$this->setupListeners();
115
-	}
116
-
117
-	private function isSetupStarted(IUser $user): bool {
118
-		return in_array($user->getUID(), $this->setupUsers, true);
119
-	}
120
-
121
-	public function isSetupComplete(IUser $user): bool {
122
-		return in_array($user->getUID(), $this->setupUsersComplete, true);
123
-	}
124
-
125
-	private function setupBuiltinWrappers() {
126
-		if ($this->setupBuiltinWrappersDone) {
127
-			return;
128
-		}
129
-		$this->setupBuiltinWrappersDone = true;
130
-
131
-		// load all filesystem apps before, so no setup-hook gets lost
132
-		OC_App::loadApps(['filesystem']);
133
-		$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
134
-
135
-		Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
136
-			if ($storage->instanceOfStorage(Common::class)) {
137
-				$storage->setMountOptions($mount->getOptions());
138
-			}
139
-			return $storage;
140
-		});
141
-
142
-		Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
143
-			if (!$mount->getOption('enable_sharing', true)) {
144
-				return new PermissionsMask([
145
-					'storage' => $storage,
146
-					'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
147
-				]);
148
-			}
149
-			return $storage;
150
-		});
151
-
152
-		// install storage availability wrapper, before most other wrappers
153
-		Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
154
-			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
155
-				return new Availability(['storage' => $storage]);
156
-			}
157
-			return $storage;
158
-		});
159
-
160
-		Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
161
-			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
162
-				return new Encoding(['storage' => $storage]);
163
-			}
164
-			return $storage;
165
-		});
166
-
167
-		Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
168
-			// set up quota for home storages, even for other users
169
-			// which can happen when using sharing
170
-
171
-			/**
172
-			 * @var Storage $storage
173
-			 */
174
-			if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
175
-				if (is_object($storage->getUser())) {
176
-					$user = $storage->getUser();
177
-					return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
178
-						return OC_Util::getUserQuota($user);
179
-					}, 'root' => 'files']);
180
-				}
181
-			}
182
-
183
-			return $storage;
184
-		});
185
-
186
-		Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
187
-			/*
66
+    private bool $rootSetup = false;
67
+    private IEventLogger $eventLogger;
68
+    private MountProviderCollection $mountProviderCollection;
69
+    private IMountManager $mountManager;
70
+    private IUserManager $userManager;
71
+    // List of users for which at least one mount is setup
72
+    private array $setupUsers = [];
73
+    // List of users for which all mounts are setup
74
+    private array $setupUsersComplete = [];
75
+    /** @var array<string, string[]> */
76
+    private array $setupUserMountProviders = [];
77
+    private IEventDispatcher $eventDispatcher;
78
+    private IUserMountCache $userMountCache;
79
+    private ILockdownManager $lockdownManager;
80
+    private IUserSession $userSession;
81
+    private ICache $cache;
82
+    private LoggerInterface $logger;
83
+    private IConfig $config;
84
+    private bool $listeningForProviders;
85
+    private array $fullSetupRequired = [];
86
+    private bool $setupBuiltinWrappersDone = false;
87
+
88
+    public function __construct(
89
+        IEventLogger $eventLogger,
90
+        MountProviderCollection $mountProviderCollection,
91
+        IMountManager $mountManager,
92
+        IUserManager $userManager,
93
+        IEventDispatcher $eventDispatcher,
94
+        IUserMountCache $userMountCache,
95
+        ILockdownManager $lockdownManager,
96
+        IUserSession $userSession,
97
+        ICacheFactory $cacheFactory,
98
+        LoggerInterface $logger,
99
+        IConfig $config
100
+    ) {
101
+        $this->eventLogger = $eventLogger;
102
+        $this->mountProviderCollection = $mountProviderCollection;
103
+        $this->mountManager = $mountManager;
104
+        $this->userManager = $userManager;
105
+        $this->eventDispatcher = $eventDispatcher;
106
+        $this->userMountCache = $userMountCache;
107
+        $this->lockdownManager = $lockdownManager;
108
+        $this->logger = $logger;
109
+        $this->userSession = $userSession;
110
+        $this->cache = $cacheFactory->createDistributed('setupmanager::');
111
+        $this->listeningForProviders = false;
112
+        $this->config = $config;
113
+
114
+        $this->setupListeners();
115
+    }
116
+
117
+    private function isSetupStarted(IUser $user): bool {
118
+        return in_array($user->getUID(), $this->setupUsers, true);
119
+    }
120
+
121
+    public function isSetupComplete(IUser $user): bool {
122
+        return in_array($user->getUID(), $this->setupUsersComplete, true);
123
+    }
124
+
125
+    private function setupBuiltinWrappers() {
126
+        if ($this->setupBuiltinWrappersDone) {
127
+            return;
128
+        }
129
+        $this->setupBuiltinWrappersDone = true;
130
+
131
+        // load all filesystem apps before, so no setup-hook gets lost
132
+        OC_App::loadApps(['filesystem']);
133
+        $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
134
+
135
+        Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
136
+            if ($storage->instanceOfStorage(Common::class)) {
137
+                $storage->setMountOptions($mount->getOptions());
138
+            }
139
+            return $storage;
140
+        });
141
+
142
+        Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
143
+            if (!$mount->getOption('enable_sharing', true)) {
144
+                return new PermissionsMask([
145
+                    'storage' => $storage,
146
+                    'mask' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
147
+                ]);
148
+            }
149
+            return $storage;
150
+        });
151
+
152
+        // install storage availability wrapper, before most other wrappers
153
+        Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
154
+            if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
155
+                return new Availability(['storage' => $storage]);
156
+            }
157
+            return $storage;
158
+        });
159
+
160
+        Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
161
+            if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
162
+                return new Encoding(['storage' => $storage]);
163
+            }
164
+            return $storage;
165
+        });
166
+
167
+        Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
168
+            // set up quota for home storages, even for other users
169
+            // which can happen when using sharing
170
+
171
+            /**
172
+             * @var Storage $storage
173
+             */
174
+            if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
175
+                if (is_object($storage->getUser())) {
176
+                    $user = $storage->getUser();
177
+                    return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
178
+                        return OC_Util::getUserQuota($user);
179
+                    }, 'root' => 'files']);
180
+                }
181
+            }
182
+
183
+            return $storage;
184
+        });
185
+
186
+        Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
187
+            /*
188 188
 			 * Do not allow any operations that modify the storage
189 189
 			 */
190
-			if ($mount->getOption('readonly', false)) {
191
-				return new PermissionsMask([
192
-					'storage' => $storage,
193
-					'mask' => Constants::PERMISSION_ALL & ~(
194
-						Constants::PERMISSION_UPDATE |
195
-						Constants::PERMISSION_CREATE |
196
-						Constants::PERMISSION_DELETE
197
-					),
198
-				]);
199
-			}
200
-			return $storage;
201
-		});
202
-
203
-		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
204
-	}
205
-
206
-	/**
207
-	 * Setup the full filesystem for the specified user
208
-	 */
209
-	public function setupForUser(IUser $user): void {
210
-		if ($this->isSetupComplete($user)) {
211
-			return;
212
-		}
213
-		$this->setupUsersComplete[] = $user->getUID();
214
-
215
-		$this->eventLogger->start('fs:setup:user:full', 'Setup full filesystem for user');
216
-
217
-		if (!isset($this->setupUserMountProviders[$user->getUID()])) {
218
-			$this->setupUserMountProviders[$user->getUID()] = [];
219
-		}
220
-
221
-		$previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
222
-
223
-		$this->setupForUserWith($user, function () use ($user) {
224
-			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
225
-				IMountProvider $provider
226
-			) use ($user) {
227
-				return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
228
-			});
229
-		});
230
-		$this->afterUserFullySetup($user, $previouslySetupProviders);
231
-		$this->eventLogger->end('fs:setup:user:full');
232
-	}
233
-
234
-	/**
235
-	 * part of the user setup that is run only once per user
236
-	 */
237
-	private function oneTimeUserSetup(IUser $user) {
238
-		if (in_array($user->getUID(), $this->setupUsers, true)) {
239
-			return;
240
-		}
241
-		$this->setupUsers[] = $user->getUID();
242
-
243
-		$this->eventLogger->start('fs:setup:user:onetime', 'Onetime filesystem for user');
244
-
245
-		$this->setupBuiltinWrappers();
246
-
247
-		$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
248
-
249
-		OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
250
-
251
-		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
252
-
253
-		$userDir = '/' . $user->getUID() . '/files';
254
-
255
-		Filesystem::initInternal($userDir);
256
-
257
-		if ($this->lockdownManager->canAccessFilesystem()) {
258
-			$this->eventLogger->start('fs:setup:user:home', 'Setup home filesystem for user');
259
-			// home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
260
-			$homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
261
-			$this->mountManager->addMount($homeMount);
262
-
263
-			if ($homeMount->getStorageRootId() === -1) {
264
-				$this->eventLogger->start('fs:setup:user:home:scan', 'Scan home filesystem for user');
265
-				$homeMount->getStorage()->mkdir('');
266
-				$homeMount->getStorage()->getScanner()->scan('');
267
-				$this->eventLogger->end('fs:setup:user:home:scan');
268
-			}
269
-			$this->eventLogger->end('fs:setup:user:home');
270
-		} else {
271
-			$this->mountManager->addMount(new MountPoint(
272
-				new NullStorage([]),
273
-				'/' . $user->getUID()
274
-			));
275
-			$this->mountManager->addMount(new MountPoint(
276
-				new NullStorage([]),
277
-				'/' . $user->getUID() . '/files'
278
-			));
279
-			$this->setupUsersComplete[] = $user->getUID();
280
-		}
281
-
282
-		$this->listenForNewMountProviders();
283
-
284
-		$this->eventLogger->end('fs:setup:user:onetime');
285
-	}
286
-
287
-	/**
288
-	 * Final housekeeping after a user has been fully setup
289
-	 */
290
-	private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
291
-		$this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
292
-		$userRoot = '/' . $user->getUID() . '/';
293
-		$mounts = $this->mountManager->getAll();
294
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
295
-			return strpos($mount->getMountPoint(), $userRoot) === 0;
296
-		});
297
-		$allProviders = array_map(function (IMountProvider $provider) {
298
-			return get_class($provider);
299
-		}, $this->mountProviderCollection->getProviders());
300
-		$newProviders = array_diff($allProviders, $previouslySetupProviders);
301
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
302
-			return !in_array($mount->getMountProvider(), $previouslySetupProviders);
303
-		});
304
-		$this->userMountCache->registerMounts($user, $mounts, $newProviders);
305
-
306
-		$cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
307
-		if ($cacheDuration > 0) {
308
-			$this->cache->set($user->getUID(), true, $cacheDuration);
309
-			$this->fullSetupRequired[$user->getUID()] = false;
310
-		}
311
-		$this->eventLogger->end('fs:setup:user:full:post');
312
-	}
313
-
314
-	/**
315
-	 * @param IUser $user
316
-	 * @param IMountPoint $mounts
317
-	 * @return void
318
-	 * @throws \OCP\HintException
319
-	 * @throws \OC\ServerNotAvailableException
320
-	 */
321
-	private function setupForUserWith(IUser $user, callable $mountCallback): void {
322
-		$this->setupRoot();
323
-
324
-		if (!$this->isSetupStarted($user)) {
325
-			$this->oneTimeUserSetup($user);
326
-		}
327
-
328
-		if ($this->lockdownManager->canAccessFilesystem()) {
329
-			$mountCallback();
330
-		}
331
-		$this->eventLogger->start('fs:setup:user:post-init-mountpoint', 'post_initMountPoints legacy hook');
332
-		\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
333
-		$this->eventLogger->end('fs:setup:user:post-init-mountpoint');
334
-
335
-		$userDir = '/' . $user->getUID() . '/files';
336
-		$this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
337
-		OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
338
-		$this->eventLogger->end('fs:setup:user:setup-hook');
339
-	}
340
-
341
-	/**
342
-	 * Set up the root filesystem
343
-	 */
344
-	public function setupRoot(): void {
345
-		//setting up the filesystem twice can only lead to trouble
346
-		if ($this->rootSetup) {
347
-			return;
348
-		}
349
-		$this->rootSetup = true;
350
-
351
-		$this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
352
-
353
-		$this->setupBuiltinWrappers();
354
-
355
-		$rootMounts = $this->mountProviderCollection->getRootMounts();
356
-		foreach ($rootMounts as $rootMountProvider) {
357
-			$this->mountManager->addMount($rootMountProvider);
358
-		}
359
-
360
-		$this->eventLogger->end('fs:setup:root');
361
-	}
362
-
363
-	/**
364
-	 * Get the user to setup for a path or `null` if the root needs to be setup
365
-	 *
366
-	 * @param string $path
367
-	 * @return IUser|null
368
-	 */
369
-	private function getUserForPath(string $path) {
370
-		if (strpos($path, '/__groupfolders') === 0) {
371
-			return null;
372
-		} elseif (substr_count($path, '/') < 2) {
373
-			if ($user = $this->userSession->getUser()) {
374
-				return $user;
375
-			} else {
376
-				return null;
377
-			}
378
-		} elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
379
-			return null;
380
-		} else {
381
-			[, $userId] = explode('/', $path);
382
-		}
383
-
384
-		return $this->userManager->get($userId);
385
-	}
386
-
387
-	/**
388
-	 * Set up the filesystem for the specified path
389
-	 */
390
-	public function setupForPath(string $path, bool $includeChildren = false): void {
391
-		$user = $this->getUserForPath($path);
392
-		if (!$user) {
393
-			$this->setupRoot();
394
-			return;
395
-		}
396
-
397
-		if ($this->isSetupComplete($user)) {
398
-			return;
399
-		}
400
-
401
-		if ($this->fullSetupRequired($user)) {
402
-			$this->setupForUser($user);
403
-			return;
404
-		}
405
-
406
-		// for the user's home folder, and includes children we need everything always
407
-		if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
408
-			$this->setupForUser($user);
409
-			return;
410
-		}
411
-
412
-		if (!isset($this->setupUserMountProviders[$user->getUID()])) {
413
-			$this->setupUserMountProviders[$user->getUID()] = [];
414
-		}
415
-		$setupProviders = &$this->setupUserMountProviders[$user->getUID()];
416
-		$currentProviders = [];
417
-
418
-		try {
419
-			$cachedMount = $this->userMountCache->getMountForPath($user, $path);
420
-		} catch (NotFoundException $e) {
421
-			$this->setupForUser($user);
422
-			return;
423
-		}
424
-
425
-		if (!$this->isSetupStarted($user)) {
426
-			$this->oneTimeUserSetup($user);
427
-		}
428
-
429
-		$this->eventLogger->start('fs:setup:user:path', "Setup $path filesystem for user");
430
-		$this->eventLogger->start('fs:setup:user:path:find', "Find mountpoint for $path");
431
-
432
-		$mounts = [];
433
-		if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
434
-			$currentProviders[] = $cachedMount->getMountProvider();
435
-			if ($cachedMount->getMountProvider()) {
436
-				$setupProviders[] = $cachedMount->getMountProvider();
437
-				$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
438
-			} else {
439
-				$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
440
-				$this->eventLogger->end('fs:setup:user:path:find');
441
-				$this->setupForUser($user);
442
-				$this->eventLogger->end('fs:setup:user:path');
443
-				return;
444
-			}
445
-		}
446
-
447
-		if ($includeChildren) {
448
-			$subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
449
-			$this->eventLogger->end('fs:setup:user:path:find');
450
-
451
-			$needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
452
-				return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
453
-			}, false);
454
-
455
-			if ($needsFullSetup) {
456
-				$this->logger->debug("mount has no provider set, performing full setup");
457
-				$this->setupForUser($user);
458
-				$this->eventLogger->end('fs:setup:user:path');
459
-				return;
460
-			} else {
461
-				foreach ($subCachedMounts as $cachedMount) {
462
-					if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
463
-						$currentProviders[] = $cachedMount->getMountProvider();
464
-						$setupProviders[] = $cachedMount->getMountProvider();
465
-						$mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
466
-					}
467
-				}
468
-			}
469
-		} else {
470
-			$this->eventLogger->end('fs:setup:user:path:find');
471
-		}
472
-
473
-		if (count($mounts)) {
474
-			$this->userMountCache->registerMounts($user, $mounts, $currentProviders);
475
-			$this->setupForUserWith($user, function () use ($mounts) {
476
-				array_walk($mounts, [$this->mountManager, 'addMount']);
477
-			});
478
-		} elseif (!$this->isSetupStarted($user)) {
479
-			$this->oneTimeUserSetup($user);
480
-		}
481
-		$this->eventLogger->end('fs:setup:user:path');
482
-	}
483
-
484
-	private function fullSetupRequired(IUser $user): bool {
485
-		// we perform a "cached" setup only after having done the full setup recently
486
-		// this is also used to trigger a full setup after handling events that are likely
487
-		// to change the available mounts
488
-		if (!isset($this->fullSetupRequired[$user->getUID()])) {
489
-			$this->fullSetupRequired[$user->getUID()] = !$this->cache->get($user->getUID());
490
-		}
491
-		return $this->fullSetupRequired[$user->getUID()];
492
-	}
493
-
494
-	/**
495
-	 * @param string $path
496
-	 * @param string[] $providers
497
-	 */
498
-	public function setupForProvider(string $path, array $providers): void {
499
-		$user = $this->getUserForPath($path);
500
-		if (!$user) {
501
-			$this->setupRoot();
502
-			return;
503
-		}
504
-
505
-		if ($this->isSetupComplete($user)) {
506
-			return;
507
-		}
508
-
509
-		if ($this->fullSetupRequired($user)) {
510
-			$this->setupForUser($user);
511
-			return;
512
-		}
513
-
514
-		$this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
515
-
516
-		// home providers are always used
517
-		$providers = array_filter($providers, function (string $provider) {
518
-			return !is_subclass_of($provider, IHomeMountProvider::class);
519
-		});
520
-
521
-		if (in_array('', $providers)) {
522
-			$this->setupForUser($user);
523
-			return;
524
-		}
525
-		$setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
526
-
527
-		$providers = array_diff($providers, $setupProviders);
528
-		if (count($providers) === 0) {
529
-			if (!$this->isSetupStarted($user)) {
530
-				$this->oneTimeUserSetup($user);
531
-			}
532
-			$this->eventLogger->end('fs:setup:user:providers');
533
-			return;
534
-		} else {
535
-			$this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
536
-			$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
537
-		}
538
-
539
-		$this->userMountCache->registerMounts($user, $mounts, $providers);
540
-		$this->setupForUserWith($user, function () use ($mounts) {
541
-			array_walk($mounts, [$this->mountManager, 'addMount']);
542
-		});
543
-		$this->eventLogger->end('fs:setup:user:providers');
544
-	}
545
-
546
-	public function tearDown() {
547
-		$this->setupUsers = [];
548
-		$this->setupUsersComplete = [];
549
-		$this->setupUserMountProviders = [];
550
-		$this->fullSetupRequired = [];
551
-		$this->rootSetup = false;
552
-		$this->mountManager->clear();
553
-		$this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
554
-	}
555
-
556
-	/**
557
-	 * Get mounts from mount providers that are registered after setup
558
-	 */
559
-	private function listenForNewMountProviders() {
560
-		if (!$this->listeningForProviders) {
561
-			$this->listeningForProviders = true;
562
-			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
563
-				IMountProvider $provider
564
-			) {
565
-				foreach ($this->setupUsers as $userId) {
566
-					$user = $this->userManager->get($userId);
567
-					if ($user) {
568
-						$mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
569
-						array_walk($mounts, [$this->mountManager, 'addMount']);
570
-					}
571
-				}
572
-			});
573
-		}
574
-	}
575
-
576
-	private function setupListeners() {
577
-		// note that this event handling is intentionally pessimistic
578
-		// clearing the cache to often is better than not enough
579
-
580
-		$this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
581
-			$this->cache->remove($event->getUser()->getUID());
582
-		});
583
-		$this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
584
-			$this->cache->remove($event->getUser()->getUID());
585
-		});
586
-		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
587
-			$this->cache->remove($event->getShare()->getSharedWith());
588
-		});
589
-		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
590
-		) {
591
-			if ($user = $event->getUser()) {
592
-				$this->cache->remove($user->getUID());
593
-			} else {
594
-				$this->cache->clear();
595
-			}
596
-		});
597
-
598
-		$genericEvents = [
599
-			'OCA\Circles\Events\CreatingCircleEvent',
600
-			'OCA\Circles\Events\DestroyingCircleEvent',
601
-			'OCA\Circles\Events\AddingCircleMemberEvent',
602
-			'OCA\Circles\Events\RemovingCircleMemberEvent',
603
-		];
604
-
605
-		foreach ($genericEvents as $genericEvent) {
606
-			$this->eventDispatcher->addListener($genericEvent, function ($event) {
607
-				$this->cache->clear();
608
-			});
609
-		}
610
-	}
190
+            if ($mount->getOption('readonly', false)) {
191
+                return new PermissionsMask([
192
+                    'storage' => $storage,
193
+                    'mask' => Constants::PERMISSION_ALL & ~(
194
+                        Constants::PERMISSION_UPDATE |
195
+                        Constants::PERMISSION_CREATE |
196
+                        Constants::PERMISSION_DELETE
197
+                    ),
198
+                ]);
199
+            }
200
+            return $storage;
201
+        });
202
+
203
+        Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
204
+    }
205
+
206
+    /**
207
+     * Setup the full filesystem for the specified user
208
+     */
209
+    public function setupForUser(IUser $user): void {
210
+        if ($this->isSetupComplete($user)) {
211
+            return;
212
+        }
213
+        $this->setupUsersComplete[] = $user->getUID();
214
+
215
+        $this->eventLogger->start('fs:setup:user:full', 'Setup full filesystem for user');
216
+
217
+        if (!isset($this->setupUserMountProviders[$user->getUID()])) {
218
+            $this->setupUserMountProviders[$user->getUID()] = [];
219
+        }
220
+
221
+        $previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
222
+
223
+        $this->setupForUserWith($user, function () use ($user) {
224
+            $this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
225
+                IMountProvider $provider
226
+            ) use ($user) {
227
+                return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
228
+            });
229
+        });
230
+        $this->afterUserFullySetup($user, $previouslySetupProviders);
231
+        $this->eventLogger->end('fs:setup:user:full');
232
+    }
233
+
234
+    /**
235
+     * part of the user setup that is run only once per user
236
+     */
237
+    private function oneTimeUserSetup(IUser $user) {
238
+        if (in_array($user->getUID(), $this->setupUsers, true)) {
239
+            return;
240
+        }
241
+        $this->setupUsers[] = $user->getUID();
242
+
243
+        $this->eventLogger->start('fs:setup:user:onetime', 'Onetime filesystem for user');
244
+
245
+        $this->setupBuiltinWrappers();
246
+
247
+        $prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
248
+
249
+        OC_Hook::emit('OC_Filesystem', 'preSetup', ['user' => $user->getUID()]);
250
+
251
+        Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
252
+
253
+        $userDir = '/' . $user->getUID() . '/files';
254
+
255
+        Filesystem::initInternal($userDir);
256
+
257
+        if ($this->lockdownManager->canAccessFilesystem()) {
258
+            $this->eventLogger->start('fs:setup:user:home', 'Setup home filesystem for user');
259
+            // home mounts are handled separate since we need to ensure this is mounted before we call the other mount providers
260
+            $homeMount = $this->mountProviderCollection->getHomeMountForUser($user);
261
+            $this->mountManager->addMount($homeMount);
262
+
263
+            if ($homeMount->getStorageRootId() === -1) {
264
+                $this->eventLogger->start('fs:setup:user:home:scan', 'Scan home filesystem for user');
265
+                $homeMount->getStorage()->mkdir('');
266
+                $homeMount->getStorage()->getScanner()->scan('');
267
+                $this->eventLogger->end('fs:setup:user:home:scan');
268
+            }
269
+            $this->eventLogger->end('fs:setup:user:home');
270
+        } else {
271
+            $this->mountManager->addMount(new MountPoint(
272
+                new NullStorage([]),
273
+                '/' . $user->getUID()
274
+            ));
275
+            $this->mountManager->addMount(new MountPoint(
276
+                new NullStorage([]),
277
+                '/' . $user->getUID() . '/files'
278
+            ));
279
+            $this->setupUsersComplete[] = $user->getUID();
280
+        }
281
+
282
+        $this->listenForNewMountProviders();
283
+
284
+        $this->eventLogger->end('fs:setup:user:onetime');
285
+    }
286
+
287
+    /**
288
+     * Final housekeeping after a user has been fully setup
289
+     */
290
+    private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
291
+        $this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
292
+        $userRoot = '/' . $user->getUID() . '/';
293
+        $mounts = $this->mountManager->getAll();
294
+        $mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
295
+            return strpos($mount->getMountPoint(), $userRoot) === 0;
296
+        });
297
+        $allProviders = array_map(function (IMountProvider $provider) {
298
+            return get_class($provider);
299
+        }, $this->mountProviderCollection->getProviders());
300
+        $newProviders = array_diff($allProviders, $previouslySetupProviders);
301
+        $mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
302
+            return !in_array($mount->getMountProvider(), $previouslySetupProviders);
303
+        });
304
+        $this->userMountCache->registerMounts($user, $mounts, $newProviders);
305
+
306
+        $cacheDuration = $this->config->getSystemValueInt('fs_mount_cache_duration', 5 * 60);
307
+        if ($cacheDuration > 0) {
308
+            $this->cache->set($user->getUID(), true, $cacheDuration);
309
+            $this->fullSetupRequired[$user->getUID()] = false;
310
+        }
311
+        $this->eventLogger->end('fs:setup:user:full:post');
312
+    }
313
+
314
+    /**
315
+     * @param IUser $user
316
+     * @param IMountPoint $mounts
317
+     * @return void
318
+     * @throws \OCP\HintException
319
+     * @throws \OC\ServerNotAvailableException
320
+     */
321
+    private function setupForUserWith(IUser $user, callable $mountCallback): void {
322
+        $this->setupRoot();
323
+
324
+        if (!$this->isSetupStarted($user)) {
325
+            $this->oneTimeUserSetup($user);
326
+        }
327
+
328
+        if ($this->lockdownManager->canAccessFilesystem()) {
329
+            $mountCallback();
330
+        }
331
+        $this->eventLogger->start('fs:setup:user:post-init-mountpoint', 'post_initMountPoints legacy hook');
332
+        \OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
333
+        $this->eventLogger->end('fs:setup:user:post-init-mountpoint');
334
+
335
+        $userDir = '/' . $user->getUID() . '/files';
336
+        $this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
337
+        OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
338
+        $this->eventLogger->end('fs:setup:user:setup-hook');
339
+    }
340
+
341
+    /**
342
+     * Set up the root filesystem
343
+     */
344
+    public function setupRoot(): void {
345
+        //setting up the filesystem twice can only lead to trouble
346
+        if ($this->rootSetup) {
347
+            return;
348
+        }
349
+        $this->rootSetup = true;
350
+
351
+        $this->eventLogger->start('fs:setup:root', 'Setup root filesystem');
352
+
353
+        $this->setupBuiltinWrappers();
354
+
355
+        $rootMounts = $this->mountProviderCollection->getRootMounts();
356
+        foreach ($rootMounts as $rootMountProvider) {
357
+            $this->mountManager->addMount($rootMountProvider);
358
+        }
359
+
360
+        $this->eventLogger->end('fs:setup:root');
361
+    }
362
+
363
+    /**
364
+     * Get the user to setup for a path or `null` if the root needs to be setup
365
+     *
366
+     * @param string $path
367
+     * @return IUser|null
368
+     */
369
+    private function getUserForPath(string $path) {
370
+        if (strpos($path, '/__groupfolders') === 0) {
371
+            return null;
372
+        } elseif (substr_count($path, '/') < 2) {
373
+            if ($user = $this->userSession->getUser()) {
374
+                return $user;
375
+            } else {
376
+                return null;
377
+            }
378
+        } elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
379
+            return null;
380
+        } else {
381
+            [, $userId] = explode('/', $path);
382
+        }
383
+
384
+        return $this->userManager->get($userId);
385
+    }
386
+
387
+    /**
388
+     * Set up the filesystem for the specified path
389
+     */
390
+    public function setupForPath(string $path, bool $includeChildren = false): void {
391
+        $user = $this->getUserForPath($path);
392
+        if (!$user) {
393
+            $this->setupRoot();
394
+            return;
395
+        }
396
+
397
+        if ($this->isSetupComplete($user)) {
398
+            return;
399
+        }
400
+
401
+        if ($this->fullSetupRequired($user)) {
402
+            $this->setupForUser($user);
403
+            return;
404
+        }
405
+
406
+        // for the user's home folder, and includes children we need everything always
407
+        if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
408
+            $this->setupForUser($user);
409
+            return;
410
+        }
411
+
412
+        if (!isset($this->setupUserMountProviders[$user->getUID()])) {
413
+            $this->setupUserMountProviders[$user->getUID()] = [];
414
+        }
415
+        $setupProviders = &$this->setupUserMountProviders[$user->getUID()];
416
+        $currentProviders = [];
417
+
418
+        try {
419
+            $cachedMount = $this->userMountCache->getMountForPath($user, $path);
420
+        } catch (NotFoundException $e) {
421
+            $this->setupForUser($user);
422
+            return;
423
+        }
424
+
425
+        if (!$this->isSetupStarted($user)) {
426
+            $this->oneTimeUserSetup($user);
427
+        }
428
+
429
+        $this->eventLogger->start('fs:setup:user:path', "Setup $path filesystem for user");
430
+        $this->eventLogger->start('fs:setup:user:path:find', "Find mountpoint for $path");
431
+
432
+        $mounts = [];
433
+        if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
434
+            $currentProviders[] = $cachedMount->getMountProvider();
435
+            if ($cachedMount->getMountProvider()) {
436
+                $setupProviders[] = $cachedMount->getMountProvider();
437
+                $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
438
+            } else {
439
+                $this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
440
+                $this->eventLogger->end('fs:setup:user:path:find');
441
+                $this->setupForUser($user);
442
+                $this->eventLogger->end('fs:setup:user:path');
443
+                return;
444
+            }
445
+        }
446
+
447
+        if ($includeChildren) {
448
+            $subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
449
+            $this->eventLogger->end('fs:setup:user:path:find');
450
+
451
+            $needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
452
+                return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
453
+            }, false);
454
+
455
+            if ($needsFullSetup) {
456
+                $this->logger->debug("mount has no provider set, performing full setup");
457
+                $this->setupForUser($user);
458
+                $this->eventLogger->end('fs:setup:user:path');
459
+                return;
460
+            } else {
461
+                foreach ($subCachedMounts as $cachedMount) {
462
+                    if (!in_array($cachedMount->getMountProvider(), $setupProviders)) {
463
+                        $currentProviders[] = $cachedMount->getMountProvider();
464
+                        $setupProviders[] = $cachedMount->getMountProvider();
465
+                        $mounts = array_merge($mounts, $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]));
466
+                    }
467
+                }
468
+            }
469
+        } else {
470
+            $this->eventLogger->end('fs:setup:user:path:find');
471
+        }
472
+
473
+        if (count($mounts)) {
474
+            $this->userMountCache->registerMounts($user, $mounts, $currentProviders);
475
+            $this->setupForUserWith($user, function () use ($mounts) {
476
+                array_walk($mounts, [$this->mountManager, 'addMount']);
477
+            });
478
+        } elseif (!$this->isSetupStarted($user)) {
479
+            $this->oneTimeUserSetup($user);
480
+        }
481
+        $this->eventLogger->end('fs:setup:user:path');
482
+    }
483
+
484
+    private function fullSetupRequired(IUser $user): bool {
485
+        // we perform a "cached" setup only after having done the full setup recently
486
+        // this is also used to trigger a full setup after handling events that are likely
487
+        // to change the available mounts
488
+        if (!isset($this->fullSetupRequired[$user->getUID()])) {
489
+            $this->fullSetupRequired[$user->getUID()] = !$this->cache->get($user->getUID());
490
+        }
491
+        return $this->fullSetupRequired[$user->getUID()];
492
+    }
493
+
494
+    /**
495
+     * @param string $path
496
+     * @param string[] $providers
497
+     */
498
+    public function setupForProvider(string $path, array $providers): void {
499
+        $user = $this->getUserForPath($path);
500
+        if (!$user) {
501
+            $this->setupRoot();
502
+            return;
503
+        }
504
+
505
+        if ($this->isSetupComplete($user)) {
506
+            return;
507
+        }
508
+
509
+        if ($this->fullSetupRequired($user)) {
510
+            $this->setupForUser($user);
511
+            return;
512
+        }
513
+
514
+        $this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
515
+
516
+        // home providers are always used
517
+        $providers = array_filter($providers, function (string $provider) {
518
+            return !is_subclass_of($provider, IHomeMountProvider::class);
519
+        });
520
+
521
+        if (in_array('', $providers)) {
522
+            $this->setupForUser($user);
523
+            return;
524
+        }
525
+        $setupProviders = $this->setupUserMountProviders[$user->getUID()] ?? [];
526
+
527
+        $providers = array_diff($providers, $setupProviders);
528
+        if (count($providers) === 0) {
529
+            if (!$this->isSetupStarted($user)) {
530
+                $this->oneTimeUserSetup($user);
531
+            }
532
+            $this->eventLogger->end('fs:setup:user:providers');
533
+            return;
534
+        } else {
535
+            $this->setupUserMountProviders[$user->getUID()] = array_merge($setupProviders, $providers);
536
+            $mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, $providers);
537
+        }
538
+
539
+        $this->userMountCache->registerMounts($user, $mounts, $providers);
540
+        $this->setupForUserWith($user, function () use ($mounts) {
541
+            array_walk($mounts, [$this->mountManager, 'addMount']);
542
+        });
543
+        $this->eventLogger->end('fs:setup:user:providers');
544
+    }
545
+
546
+    public function tearDown() {
547
+        $this->setupUsers = [];
548
+        $this->setupUsersComplete = [];
549
+        $this->setupUserMountProviders = [];
550
+        $this->fullSetupRequired = [];
551
+        $this->rootSetup = false;
552
+        $this->mountManager->clear();
553
+        $this->eventDispatcher->dispatchTyped(new FilesystemTornDownEvent());
554
+    }
555
+
556
+    /**
557
+     * Get mounts from mount providers that are registered after setup
558
+     */
559
+    private function listenForNewMountProviders() {
560
+        if (!$this->listeningForProviders) {
561
+            $this->listeningForProviders = true;
562
+            $this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
563
+                IMountProvider $provider
564
+            ) {
565
+                foreach ($this->setupUsers as $userId) {
566
+                    $user = $this->userManager->get($userId);
567
+                    if ($user) {
568
+                        $mounts = $provider->getMountsForUser($user, Filesystem::getLoader());
569
+                        array_walk($mounts, [$this->mountManager, 'addMount']);
570
+                    }
571
+                }
572
+            });
573
+        }
574
+    }
575
+
576
+    private function setupListeners() {
577
+        // note that this event handling is intentionally pessimistic
578
+        // clearing the cache to often is better than not enough
579
+
580
+        $this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
581
+            $this->cache->remove($event->getUser()->getUID());
582
+        });
583
+        $this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
584
+            $this->cache->remove($event->getUser()->getUID());
585
+        });
586
+        $this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
587
+            $this->cache->remove($event->getShare()->getSharedWith());
588
+        });
589
+        $this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
590
+        ) {
591
+            if ($user = $event->getUser()) {
592
+                $this->cache->remove($user->getUID());
593
+            } else {
594
+                $this->cache->clear();
595
+            }
596
+        });
597
+
598
+        $genericEvents = [
599
+            'OCA\Circles\Events\CreatingCircleEvent',
600
+            'OCA\Circles\Events\DestroyingCircleEvent',
601
+            'OCA\Circles\Events\AddingCircleMemberEvent',
602
+            'OCA\Circles\Events\RemovingCircleMemberEvent',
603
+        ];
604
+
605
+        foreach ($genericEvents as $genericEvent) {
606
+            $this->eventDispatcher->addListener($genericEvent, function ($event) {
607
+                $this->cache->clear();
608
+            });
609
+        }
610
+    }
611 611
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -132,14 +132,14 @@  discard block
 block discarded – undo
132 132
 		OC_App::loadApps(['filesystem']);
133 133
 		$prevLogging = Filesystem::logWarningWhenAddingStorageWrapper(false);
134 134
 
135
-		Filesystem::addStorageWrapper('mount_options', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
135
+		Filesystem::addStorageWrapper('mount_options', function($mountPoint, IStorage $storage, IMountPoint $mount) {
136 136
 			if ($storage->instanceOfStorage(Common::class)) {
137 137
 				$storage->setMountOptions($mount->getOptions());
138 138
 			}
139 139
 			return $storage;
140 140
 		});
141 141
 
142
-		Filesystem::addStorageWrapper('enable_sharing', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
142
+		Filesystem::addStorageWrapper('enable_sharing', function($mountPoint, IStorage $storage, IMountPoint $mount) {
143 143
 			if (!$mount->getOption('enable_sharing', true)) {
144 144
 				return new PermissionsMask([
145 145
 					'storage' => $storage,
@@ -150,21 +150,21 @@  discard block
 block discarded – undo
150 150
 		});
151 151
 
152 152
 		// install storage availability wrapper, before most other wrappers
153
-		Filesystem::addStorageWrapper('oc_availability', function ($mountPoint, IStorage $storage) {
153
+		Filesystem::addStorageWrapper('oc_availability', function($mountPoint, IStorage $storage) {
154 154
 			if (!$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage') && !$storage->isLocal()) {
155 155
 				return new Availability(['storage' => $storage]);
156 156
 			}
157 157
 			return $storage;
158 158
 		});
159 159
 
160
-		Filesystem::addStorageWrapper('oc_encoding', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
160
+		Filesystem::addStorageWrapper('oc_encoding', function($mountPoint, IStorage $storage, IMountPoint $mount) {
161 161
 			if ($mount->getOption('encoding_compatibility', false) && !$storage->instanceOfStorage('\OCA\Files_Sharing\SharedStorage')) {
162 162
 				return new Encoding(['storage' => $storage]);
163 163
 			}
164 164
 			return $storage;
165 165
 		});
166 166
 
167
-		Filesystem::addStorageWrapper('oc_quota', function ($mountPoint, $storage) {
167
+		Filesystem::addStorageWrapper('oc_quota', function($mountPoint, $storage) {
168 168
 			// set up quota for home storages, even for other users
169 169
 			// which can happen when using sharing
170 170
 
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 			if ($storage->instanceOfStorage(HomeObjectStoreStorage::class) || $storage->instanceOfStorage(Home::class)) {
175 175
 				if (is_object($storage->getUser())) {
176 176
 					$user = $storage->getUser();
177
-					return new Quota(['storage' => $storage, 'quotaCallback' => function () use ($user) {
177
+					return new Quota(['storage' => $storage, 'quotaCallback' => function() use ($user) {
178 178
 						return OC_Util::getUserQuota($user);
179 179
 					}, 'root' => 'files']);
180 180
 				}
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 			return $storage;
184 184
 		});
185 185
 
186
-		Filesystem::addStorageWrapper('readonly', function ($mountPoint, IStorage $storage, IMountPoint $mount) {
186
+		Filesystem::addStorageWrapper('readonly', function($mountPoint, IStorage $storage, IMountPoint $mount) {
187 187
 			/*
188 188
 			 * Do not allow any operations that modify the storage
189 189
 			 */
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 
221 221
 		$previouslySetupProviders = $this->setupUserMountProviders[$user->getUID()];
222 222
 
223
-		$this->setupForUserWith($user, function () use ($user) {
224
-			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function (
223
+		$this->setupForUserWith($user, function() use ($user) {
224
+			$this->mountProviderCollection->addMountForUser($user, $this->mountManager, function(
225 225
 				IMountProvider $provider
226 226
 			) use ($user) {
227 227
 				return !in_array(get_class($provider), $this->setupUserMountProviders[$user->getUID()]);
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 
251 251
 		Filesystem::logWarningWhenAddingStorageWrapper($prevLogging);
252 252
 
253
-		$userDir = '/' . $user->getUID() . '/files';
253
+		$userDir = '/'.$user->getUID().'/files';
254 254
 
255 255
 		Filesystem::initInternal($userDir);
256 256
 
@@ -270,11 +270,11 @@  discard block
 block discarded – undo
270 270
 		} else {
271 271
 			$this->mountManager->addMount(new MountPoint(
272 272
 				new NullStorage([]),
273
-				'/' . $user->getUID()
273
+				'/'.$user->getUID()
274 274
 			));
275 275
 			$this->mountManager->addMount(new MountPoint(
276 276
 				new NullStorage([]),
277
-				'/' . $user->getUID() . '/files'
277
+				'/'.$user->getUID().'/files'
278 278
 			));
279 279
 			$this->setupUsersComplete[] = $user->getUID();
280 280
 		}
@@ -289,16 +289,16 @@  discard block
 block discarded – undo
289 289
 	 */
290 290
 	private function afterUserFullySetup(IUser $user, array $previouslySetupProviders): void {
291 291
 		$this->eventLogger->start('fs:setup:user:full:post', 'Housekeeping after user is setup');
292
-		$userRoot = '/' . $user->getUID() . '/';
292
+		$userRoot = '/'.$user->getUID().'/';
293 293
 		$mounts = $this->mountManager->getAll();
294
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($userRoot) {
294
+		$mounts = array_filter($mounts, function(IMountPoint $mount) use ($userRoot) {
295 295
 			return strpos($mount->getMountPoint(), $userRoot) === 0;
296 296
 		});
297
-		$allProviders = array_map(function (IMountProvider $provider) {
297
+		$allProviders = array_map(function(IMountProvider $provider) {
298 298
 			return get_class($provider);
299 299
 		}, $this->mountProviderCollection->getProviders());
300 300
 		$newProviders = array_diff($allProviders, $previouslySetupProviders);
301
-		$mounts = array_filter($mounts, function (IMountPoint $mount) use ($previouslySetupProviders) {
301
+		$mounts = array_filter($mounts, function(IMountPoint $mount) use ($previouslySetupProviders) {
302 302
 			return !in_array($mount->getMountProvider(), $previouslySetupProviders);
303 303
 		});
304 304
 		$this->userMountCache->registerMounts($user, $mounts, $newProviders);
@@ -332,7 +332,7 @@  discard block
 block discarded – undo
332 332
 		\OC_Hook::emit('OC_Filesystem', 'post_initMountPoints', ['user' => $user->getUID()]);
333 333
 		$this->eventLogger->end('fs:setup:user:post-init-mountpoint');
334 334
 
335
-		$userDir = '/' . $user->getUID() . '/files';
335
+		$userDir = '/'.$user->getUID().'/files';
336 336
 		$this->eventLogger->start('fs:setup:user:setup-hook', 'setup legacy hook');
337 337
 		OC_Hook::emit('OC_Filesystem', 'setup', ['user' => $user->getUID(), 'user_dir' => $userDir]);
338 338
 		$this->eventLogger->end('fs:setup:user:setup-hook');
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 			} else {
376 376
 				return null;
377 377
 			}
378
-		} elseif (strpos($path, '/appdata_' . \OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
378
+		} elseif (strpos($path, '/appdata_'.\OC_Util::getInstanceId()) === 0 || strpos($path, '/files_external/') === 0) {
379 379
 			return null;
380 380
 		} else {
381 381
 			[, $userId] = explode('/', $path);
@@ -404,7 +404,7 @@  discard block
 block discarded – undo
404 404
 		}
405 405
 
406 406
 		// for the user's home folder, and includes children we need everything always
407
-		if (rtrim($path) === "/" . $user->getUID() . "/files" && $includeChildren) {
407
+		if (rtrim($path) === "/".$user->getUID()."/files" && $includeChildren) {
408 408
 			$this->setupForUser($user);
409 409
 			return;
410 410
 		}
@@ -436,7 +436,7 @@  discard block
 block discarded – undo
436 436
 				$setupProviders[] = $cachedMount->getMountProvider();
437 437
 				$mounts = $this->mountProviderCollection->getUserMountsForProviderClasses($user, [$cachedMount->getMountProvider()]);
438 438
 			} else {
439
-				$this->logger->debug("mount at " . $cachedMount->getMountPoint() . " has no provider set, performing full setup");
439
+				$this->logger->debug("mount at ".$cachedMount->getMountPoint()." has no provider set, performing full setup");
440 440
 				$this->eventLogger->end('fs:setup:user:path:find');
441 441
 				$this->setupForUser($user);
442 442
 				$this->eventLogger->end('fs:setup:user:path');
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
 			$subCachedMounts = $this->userMountCache->getMountsInPath($user, $path);
449 449
 			$this->eventLogger->end('fs:setup:user:path:find');
450 450
 
451
-			$needsFullSetup = array_reduce($subCachedMounts, function (bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
451
+			$needsFullSetup = array_reduce($subCachedMounts, function(bool $needsFullSetup, ICachedMountInfo $cachedMountInfo) {
452 452
 				return $needsFullSetup || $cachedMountInfo->getMountProvider() === '';
453 453
 			}, false);
454 454
 
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 
473 473
 		if (count($mounts)) {
474 474
 			$this->userMountCache->registerMounts($user, $mounts, $currentProviders);
475
-			$this->setupForUserWith($user, function () use ($mounts) {
475
+			$this->setupForUserWith($user, function() use ($mounts) {
476 476
 				array_walk($mounts, [$this->mountManager, 'addMount']);
477 477
 			});
478 478
 		} elseif (!$this->isSetupStarted($user)) {
@@ -511,10 +511,10 @@  discard block
 block discarded – undo
511 511
 			return;
512 512
 		}
513 513
 
514
-		$this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for " . implode(', ', $providers));
514
+		$this->eventLogger->start('fs:setup:user:providers', "Setup filesystem for ".implode(', ', $providers));
515 515
 
516 516
 		// home providers are always used
517
-		$providers = array_filter($providers, function (string $provider) {
517
+		$providers = array_filter($providers, function(string $provider) {
518 518
 			return !is_subclass_of($provider, IHomeMountProvider::class);
519 519
 		});
520 520
 
@@ -537,7 +537,7 @@  discard block
 block discarded – undo
537 537
 		}
538 538
 
539 539
 		$this->userMountCache->registerMounts($user, $mounts, $providers);
540
-		$this->setupForUserWith($user, function () use ($mounts) {
540
+		$this->setupForUserWith($user, function() use ($mounts) {
541 541
 			array_walk($mounts, [$this->mountManager, 'addMount']);
542 542
 		});
543 543
 		$this->eventLogger->end('fs:setup:user:providers');
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 	private function listenForNewMountProviders() {
560 560
 		if (!$this->listeningForProviders) {
561 561
 			$this->listeningForProviders = true;
562
-			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function (
562
+			$this->mountProviderCollection->listen('\OC\Files\Config', 'registerMountProvider', function(
563 563
 				IMountProvider $provider
564 564
 			) {
565 565
 				foreach ($this->setupUsers as $userId) {
@@ -577,16 +577,16 @@  discard block
 block discarded – undo
577 577
 		// note that this event handling is intentionally pessimistic
578 578
 		// clearing the cache to often is better than not enough
579 579
 
580
-		$this->eventDispatcher->addListener(UserAddedEvent::class, function (UserAddedEvent $event) {
580
+		$this->eventDispatcher->addListener(UserAddedEvent::class, function(UserAddedEvent $event) {
581 581
 			$this->cache->remove($event->getUser()->getUID());
582 582
 		});
583
-		$this->eventDispatcher->addListener(UserRemovedEvent::class, function (UserRemovedEvent $event) {
583
+		$this->eventDispatcher->addListener(UserRemovedEvent::class, function(UserRemovedEvent $event) {
584 584
 			$this->cache->remove($event->getUser()->getUID());
585 585
 		});
586
-		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function (ShareCreatedEvent $event) {
586
+		$this->eventDispatcher->addListener(ShareCreatedEvent::class, function(ShareCreatedEvent $event) {
587 587
 			$this->cache->remove($event->getShare()->getSharedWith());
588 588
 		});
589
-		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function (InvalidateMountCacheEvent $event
589
+		$this->eventDispatcher->addListener(InvalidateMountCacheEvent::class, function(InvalidateMountCacheEvent $event
590 590
 		) {
591 591
 			if ($user = $event->getUser()) {
592 592
 				$this->cache->remove($user->getUID());
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
 		];
604 604
 
605 605
 		foreach ($genericEvents as $genericEvent) {
606
-			$this->eventDispatcher->addListener($genericEvent, function ($event) {
606
+			$this->eventDispatcher->addListener($genericEvent, function($event) {
607 607
 				$this->cache->clear();
608 608
 			});
609 609
 		}
Please login to merge, or discard this patch.
lib/private/Files/Config/UserMountCache.php 2 patches
Indentation   +435 added lines, -435 removed lines patch added patch discarded remove patch
@@ -46,439 +46,439 @@
 block discarded – undo
46 46
  * Cache mounts points per user in the cache so we can easily look them up
47 47
  */
48 48
 class UserMountCache implements IUserMountCache {
49
-	private IDBConnection $connection;
50
-	private IUserManager $userManager;
51
-
52
-	/**
53
-	 * Cached mount info.
54
-	 * @var CappedMemoryCache<ICachedMountInfo[]>
55
-	 **/
56
-	private CappedMemoryCache $mountsForUsers;
57
-	private LoggerInterface $logger;
58
-	/** @var CappedMemoryCache<array> */
59
-	private CappedMemoryCache $cacheInfoCache;
60
-	private IEventLogger $eventLogger;
61
-
62
-	/**
63
-	 * UserMountCache constructor.
64
-	 */
65
-	public function __construct(
66
-		IDBConnection $connection,
67
-		IUserManager $userManager,
68
-		LoggerInterface $logger,
69
-		IEventLogger $eventLogger
70
-	) {
71
-		$this->connection = $connection;
72
-		$this->userManager = $userManager;
73
-		$this->logger = $logger;
74
-		$this->eventLogger = $eventLogger;
75
-		$this->cacheInfoCache = new CappedMemoryCache();
76
-		$this->mountsForUsers = new CappedMemoryCache();
77
-	}
78
-
79
-	public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) {
80
-		$this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user');
81
-		// filter out non-proper storages coming from unit tests
82
-		$mounts = array_filter($mounts, function (IMountPoint $mount) {
83
-			return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache());
84
-		});
85
-		/** @var ICachedMountInfo[] $newMounts */
86
-		$newMounts = array_map(function (IMountPoint $mount) use ($user) {
87
-			// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
88
-			if ($mount->getStorageRootId() === -1) {
89
-				return null;
90
-			} else {
91
-				return new LazyStorageMountInfo($user, $mount);
92
-			}
93
-		}, $mounts);
94
-		$newMounts = array_values(array_filter($newMounts));
95
-		$newMountRootIds = array_map(function (ICachedMountInfo $mount) {
96
-			return $mount->getRootId();
97
-		}, $newMounts);
98
-		$newMounts = array_combine($newMountRootIds, $newMounts);
99
-
100
-		$cachedMounts = $this->getMountsForUser($user);
101
-		if (is_array($mountProviderClasses)) {
102
-			$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) {
103
-				// for existing mounts that didn't have a mount provider set
104
-				// we still want the ones that map to new mounts
105
-				if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountInfo->getRootId()])) {
106
-					return true;
107
-				}
108
-				return in_array($mountInfo->getMountProvider(), $mountProviderClasses);
109
-			});
110
-		}
111
-		$cachedMountRootIds = array_map(function (ICachedMountInfo $mount) {
112
-			return $mount->getRootId();
113
-		}, $cachedMounts);
114
-		$cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);
115
-
116
-		$addedMounts = [];
117
-		$removedMounts = [];
118
-
119
-		foreach ($newMounts as $rootId => $newMount) {
120
-			if (!isset($cachedMounts[$rootId])) {
121
-				$addedMounts[] = $newMount;
122
-			}
123
-		}
124
-
125
-		foreach ($cachedMounts as $rootId => $cachedMount) {
126
-			if (!isset($newMounts[$rootId])) {
127
-				$removedMounts[] = $cachedMount;
128
-			}
129
-		}
130
-
131
-		$changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
132
-
133
-		foreach ($addedMounts as $mount) {
134
-			$this->addToCache($mount);
135
-			/** @psalm-suppress InvalidArgument */
136
-			$this->mountsForUsers[$user->getUID()][] = $mount;
137
-		}
138
-		foreach ($removedMounts as $mount) {
139
-			$this->removeFromCache($mount);
140
-			$index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
141
-			unset($this->mountsForUsers[$user->getUID()][$index]);
142
-		}
143
-		foreach ($changedMounts as $mount) {
144
-			$this->updateCachedMount($mount);
145
-		}
146
-		$this->eventLogger->end('fs:setup:user:register');
147
-	}
148
-
149
-	/**
150
-	 * @param ICachedMountInfo[] $newMounts
151
-	 * @param ICachedMountInfo[] $cachedMounts
152
-	 * @return ICachedMountInfo[]
153
-	 */
154
-	private function findChangedMounts(array $newMounts, array $cachedMounts) {
155
-		$new = [];
156
-		foreach ($newMounts as $mount) {
157
-			$new[$mount->getRootId()] = $mount;
158
-		}
159
-		$changed = [];
160
-		foreach ($cachedMounts as $cachedMount) {
161
-			$rootId = $cachedMount->getRootId();
162
-			if (isset($new[$rootId])) {
163
-				$newMount = $new[$rootId];
164
-				if (
165
-					$newMount->getMountPoint() !== $cachedMount->getMountPoint() ||
166
-					$newMount->getStorageId() !== $cachedMount->getStorageId() ||
167
-					$newMount->getMountId() !== $cachedMount->getMountId() ||
168
-					$newMount->getMountProvider() !== $cachedMount->getMountProvider()
169
-				) {
170
-					$changed[] = $newMount;
171
-				}
172
-			}
173
-		}
174
-		return $changed;
175
-	}
176
-
177
-	private function addToCache(ICachedMountInfo $mount) {
178
-		if ($mount->getStorageId() !== -1) {
179
-			$this->connection->insertIfNotExist('*PREFIX*mounts', [
180
-				'storage_id' => $mount->getStorageId(),
181
-				'root_id' => $mount->getRootId(),
182
-				'user_id' => $mount->getUser()->getUID(),
183
-				'mount_point' => $mount->getMountPoint(),
184
-				'mount_id' => $mount->getMountId(),
185
-				'mount_provider_class' => $mount->getMountProvider(),
186
-			], ['root_id', 'user_id']);
187
-		} else {
188
-			// in some cases this is legitimate, like orphaned shares
189
-			$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
190
-		}
191
-	}
192
-
193
-	private function updateCachedMount(ICachedMountInfo $mount) {
194
-		$builder = $this->connection->getQueryBuilder();
195
-
196
-		$query = $builder->update('mounts')
197
-			->set('storage_id', $builder->createNamedParameter($mount->getStorageId()))
198
-			->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
199
-			->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT))
200
-			->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider()))
201
-			->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
202
-			->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));
203
-
204
-		$query->execute();
205
-	}
206
-
207
-	private function removeFromCache(ICachedMountInfo $mount) {
208
-		$builder = $this->connection->getQueryBuilder();
209
-
210
-		$query = $builder->delete('mounts')
211
-			->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
212
-			->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));
213
-		$query->execute();
214
-	}
215
-
216
-	private function dbRowToMountInfo(array $row) {
217
-		$user = $this->userManager->get($row['user_id']);
218
-		if (is_null($user)) {
219
-			return null;
220
-		}
221
-		$mount_id = $row['mount_id'];
222
-		if (!is_null($mount_id)) {
223
-			$mount_id = (int)$mount_id;
224
-		}
225
-		return new CachedMountInfo(
226
-			$user,
227
-			(int)$row['storage_id'],
228
-			(int)$row['root_id'],
229
-			$row['mount_point'],
230
-			$row['mount_provider_class'] ?? '',
231
-			$mount_id,
232
-			isset($row['path']) ? $row['path'] : '',
233
-		);
234
-	}
235
-
236
-	/**
237
-	 * @param IUser $user
238
-	 * @return ICachedMountInfo[]
239
-	 */
240
-	public function getMountsForUser(IUser $user) {
241
-		if (!isset($this->mountsForUsers[$user->getUID()])) {
242
-			$builder = $this->connection->getQueryBuilder();
243
-			$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
244
-				->from('mounts', 'm')
245
-				->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
246
-				->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));
247
-
248
-			$result = $query->execute();
249
-			$rows = $result->fetchAll();
250
-			$result->closeCursor();
251
-
252
-			$this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
253
-		}
254
-		return $this->mountsForUsers[$user->getUID()];
255
-	}
256
-
257
-	/**
258
-	 * @param int $numericStorageId
259
-	 * @param string|null $user limit the results to a single user
260
-	 * @return CachedMountInfo[]
261
-	 */
262
-	public function getMountsForStorageId($numericStorageId, $user = null) {
263
-		$builder = $this->connection->getQueryBuilder();
264
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
265
-			->from('mounts', 'm')
266
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
267
-			->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT)));
268
-
269
-		if ($user) {
270
-			$query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
271
-		}
272
-
273
-		$result = $query->execute();
274
-		$rows = $result->fetchAll();
275
-		$result->closeCursor();
276
-
277
-		return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
278
-	}
279
-
280
-	/**
281
-	 * @param int $rootFileId
282
-	 * @return CachedMountInfo[]
283
-	 */
284
-	public function getMountsForRootId($rootFileId) {
285
-		$builder = $this->connection->getQueryBuilder();
286
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
287
-			->from('mounts', 'm')
288
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
289
-			->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT)));
290
-
291
-		$result = $query->execute();
292
-		$rows = $result->fetchAll();
293
-		$result->closeCursor();
294
-
295
-		return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
296
-	}
297
-
298
-	/**
299
-	 * @param $fileId
300
-	 * @return array{int, string, int}
301
-	 * @throws \OCP\Files\NotFoundException
302
-	 */
303
-	private function getCacheInfoFromFileId($fileId): array {
304
-		if (!isset($this->cacheInfoCache[$fileId])) {
305
-			$builder = $this->connection->getQueryBuilder();
306
-			$query = $builder->select('storage', 'path', 'mimetype')
307
-				->from('filecache')
308
-				->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
309
-
310
-			$result = $query->execute();
311
-			$row = $result->fetch();
312
-			$result->closeCursor();
313
-
314
-			if (is_array($row)) {
315
-				$this->cacheInfoCache[$fileId] = [
316
-					(int)$row['storage'],
317
-					(string)$row['path'],
318
-					(int)$row['mimetype']
319
-				];
320
-			} else {
321
-				throw new NotFoundException('File with id "' . $fileId . '" not found');
322
-			}
323
-		}
324
-		return $this->cacheInfoCache[$fileId];
325
-	}
326
-
327
-	/**
328
-	 * @param int $fileId
329
-	 * @param string|null $user optionally restrict the results to a single user
330
-	 * @return ICachedMountFileInfo[]
331
-	 * @since 9.0.0
332
-	 */
333
-	public function getMountsForFileId($fileId, $user = null) {
334
-		try {
335
-			[$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId);
336
-		} catch (NotFoundException $e) {
337
-			return [];
338
-		}
339
-		$builder = $this->connection->getQueryBuilder();
340
-		$query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
341
-			->from('mounts', 'm')
342
-			->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
343
-			->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT)));
344
-
345
-		if ($user) {
346
-			$query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
347
-		}
348
-
349
-		$result = $query->execute();
350
-		$rows = $result->fetchAll();
351
-		$result->closeCursor();
352
-		// filter mounts that are from the same storage but a different directory
353
-		$filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) {
354
-			if ($fileId === (int)$row['root_id']) {
355
-				return true;
356
-			}
357
-			$internalMountPath = $row['path'] ?? '';
358
-
359
-			return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
360
-		});
361
-
362
-		$filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts));
363
-		return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
364
-			return new CachedMountFileInfo(
365
-				$mount->getUser(),
366
-				$mount->getStorageId(),
367
-				$mount->getRootId(),
368
-				$mount->getMountPoint(),
369
-				$mount->getMountId(),
370
-				$mount->getMountProvider(),
371
-				$mount->getRootInternalPath(),
372
-				$internalPath
373
-			);
374
-		}, $filteredMounts);
375
-	}
376
-
377
-	/**
378
-	 * Remove all cached mounts for a user
379
-	 *
380
-	 * @param IUser $user
381
-	 */
382
-	public function removeUserMounts(IUser $user) {
383
-		$builder = $this->connection->getQueryBuilder();
384
-
385
-		$query = $builder->delete('mounts')
386
-			->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
387
-		$query->execute();
388
-	}
389
-
390
-	public function removeUserStorageMount($storageId, $userId) {
391
-		$builder = $this->connection->getQueryBuilder();
392
-
393
-		$query = $builder->delete('mounts')
394
-			->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId)))
395
-			->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
396
-		$query->execute();
397
-	}
398
-
399
-	public function remoteStorageMounts($storageId) {
400
-		$builder = $this->connection->getQueryBuilder();
401
-
402
-		$query = $builder->delete('mounts')
403
-			->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
404
-		$query->execute();
405
-	}
406
-
407
-	/**
408
-	 * @param array $users
409
-	 * @return array
410
-	 */
411
-	public function getUsedSpaceForUsers(array $users) {
412
-		$builder = $this->connection->getQueryBuilder();
413
-
414
-		$slash = $builder->createNamedParameter('/');
415
-
416
-		$mountPoint = $builder->func()->concat(
417
-			$builder->func()->concat($slash, 'user_id'),
418
-			$slash
419
-		);
420
-
421
-		$userIds = array_map(function (IUser $user) {
422
-			return $user->getUID();
423
-		}, $users);
424
-
425
-		$query = $builder->select('m.user_id', 'f.size')
426
-			->from('mounts', 'm')
427
-			->innerJoin('m', 'filecache', 'f',
428
-				$builder->expr()->andX(
429
-					$builder->expr()->eq('m.storage_id', 'f.storage'),
430
-					$builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files')))
431
-				))
432
-			->where($builder->expr()->eq('m.mount_point', $mountPoint))
433
-			->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY)));
434
-
435
-		$result = $query->execute();
436
-
437
-		$results = [];
438
-		while ($row = $result->fetch()) {
439
-			$results[$row['user_id']] = $row['size'];
440
-		}
441
-		$result->closeCursor();
442
-		return $results;
443
-	}
444
-
445
-	public function clear(): void {
446
-		$this->cacheInfoCache = new CappedMemoryCache();
447
-		$this->mountsForUsers = new CappedMemoryCache();
448
-	}
449
-
450
-	public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
451
-		$mounts = $this->getMountsForUser($user);
452
-		$mountPoints = array_map(function (ICachedMountInfo $mount) {
453
-			return $mount->getMountPoint();
454
-		}, $mounts);
455
-		$mounts = array_combine($mountPoints, $mounts);
456
-
457
-		$current = $path;
458
-		// walk up the directory tree until we find a path that has a mountpoint set
459
-		// the loop will return if a mountpoint is found or break if none are found
460
-		while (true) {
461
-			$mountPoint = $current . '/';
462
-			if (isset($mounts[$mountPoint])) {
463
-				return $mounts[$mountPoint];
464
-			} elseif ($current === '') {
465
-				break;
466
-			}
467
-
468
-			$current = dirname($current);
469
-			if ($current === '.' || $current === '/') {
470
-				$current = '';
471
-			}
472
-		}
473
-
474
-		throw new NotFoundException("No cached mount for path " . $path);
475
-	}
476
-
477
-	public function getMountsInPath(IUser $user, string $path): array {
478
-		$path = rtrim($path, '/') . '/';
479
-		$mounts = $this->getMountsForUser($user);
480
-		return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) {
481
-			return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0;
482
-		});
483
-	}
49
+    private IDBConnection $connection;
50
+    private IUserManager $userManager;
51
+
52
+    /**
53
+     * Cached mount info.
54
+     * @var CappedMemoryCache<ICachedMountInfo[]>
55
+     **/
56
+    private CappedMemoryCache $mountsForUsers;
57
+    private LoggerInterface $logger;
58
+    /** @var CappedMemoryCache<array> */
59
+    private CappedMemoryCache $cacheInfoCache;
60
+    private IEventLogger $eventLogger;
61
+
62
+    /**
63
+     * UserMountCache constructor.
64
+     */
65
+    public function __construct(
66
+        IDBConnection $connection,
67
+        IUserManager $userManager,
68
+        LoggerInterface $logger,
69
+        IEventLogger $eventLogger
70
+    ) {
71
+        $this->connection = $connection;
72
+        $this->userManager = $userManager;
73
+        $this->logger = $logger;
74
+        $this->eventLogger = $eventLogger;
75
+        $this->cacheInfoCache = new CappedMemoryCache();
76
+        $this->mountsForUsers = new CappedMemoryCache();
77
+    }
78
+
79
+    public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) {
80
+        $this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user');
81
+        // filter out non-proper storages coming from unit tests
82
+        $mounts = array_filter($mounts, function (IMountPoint $mount) {
83
+            return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache());
84
+        });
85
+        /** @var ICachedMountInfo[] $newMounts */
86
+        $newMounts = array_map(function (IMountPoint $mount) use ($user) {
87
+            // filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
88
+            if ($mount->getStorageRootId() === -1) {
89
+                return null;
90
+            } else {
91
+                return new LazyStorageMountInfo($user, $mount);
92
+            }
93
+        }, $mounts);
94
+        $newMounts = array_values(array_filter($newMounts));
95
+        $newMountRootIds = array_map(function (ICachedMountInfo $mount) {
96
+            return $mount->getRootId();
97
+        }, $newMounts);
98
+        $newMounts = array_combine($newMountRootIds, $newMounts);
99
+
100
+        $cachedMounts = $this->getMountsForUser($user);
101
+        if (is_array($mountProviderClasses)) {
102
+            $cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) {
103
+                // for existing mounts that didn't have a mount provider set
104
+                // we still want the ones that map to new mounts
105
+                if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountInfo->getRootId()])) {
106
+                    return true;
107
+                }
108
+                return in_array($mountInfo->getMountProvider(), $mountProviderClasses);
109
+            });
110
+        }
111
+        $cachedMountRootIds = array_map(function (ICachedMountInfo $mount) {
112
+            return $mount->getRootId();
113
+        }, $cachedMounts);
114
+        $cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);
115
+
116
+        $addedMounts = [];
117
+        $removedMounts = [];
118
+
119
+        foreach ($newMounts as $rootId => $newMount) {
120
+            if (!isset($cachedMounts[$rootId])) {
121
+                $addedMounts[] = $newMount;
122
+            }
123
+        }
124
+
125
+        foreach ($cachedMounts as $rootId => $cachedMount) {
126
+            if (!isset($newMounts[$rootId])) {
127
+                $removedMounts[] = $cachedMount;
128
+            }
129
+        }
130
+
131
+        $changedMounts = $this->findChangedMounts($newMounts, $cachedMounts);
132
+
133
+        foreach ($addedMounts as $mount) {
134
+            $this->addToCache($mount);
135
+            /** @psalm-suppress InvalidArgument */
136
+            $this->mountsForUsers[$user->getUID()][] = $mount;
137
+        }
138
+        foreach ($removedMounts as $mount) {
139
+            $this->removeFromCache($mount);
140
+            $index = array_search($mount, $this->mountsForUsers[$user->getUID()]);
141
+            unset($this->mountsForUsers[$user->getUID()][$index]);
142
+        }
143
+        foreach ($changedMounts as $mount) {
144
+            $this->updateCachedMount($mount);
145
+        }
146
+        $this->eventLogger->end('fs:setup:user:register');
147
+    }
148
+
149
+    /**
150
+     * @param ICachedMountInfo[] $newMounts
151
+     * @param ICachedMountInfo[] $cachedMounts
152
+     * @return ICachedMountInfo[]
153
+     */
154
+    private function findChangedMounts(array $newMounts, array $cachedMounts) {
155
+        $new = [];
156
+        foreach ($newMounts as $mount) {
157
+            $new[$mount->getRootId()] = $mount;
158
+        }
159
+        $changed = [];
160
+        foreach ($cachedMounts as $cachedMount) {
161
+            $rootId = $cachedMount->getRootId();
162
+            if (isset($new[$rootId])) {
163
+                $newMount = $new[$rootId];
164
+                if (
165
+                    $newMount->getMountPoint() !== $cachedMount->getMountPoint() ||
166
+                    $newMount->getStorageId() !== $cachedMount->getStorageId() ||
167
+                    $newMount->getMountId() !== $cachedMount->getMountId() ||
168
+                    $newMount->getMountProvider() !== $cachedMount->getMountProvider()
169
+                ) {
170
+                    $changed[] = $newMount;
171
+                }
172
+            }
173
+        }
174
+        return $changed;
175
+    }
176
+
177
+    private function addToCache(ICachedMountInfo $mount) {
178
+        if ($mount->getStorageId() !== -1) {
179
+            $this->connection->insertIfNotExist('*PREFIX*mounts', [
180
+                'storage_id' => $mount->getStorageId(),
181
+                'root_id' => $mount->getRootId(),
182
+                'user_id' => $mount->getUser()->getUID(),
183
+                'mount_point' => $mount->getMountPoint(),
184
+                'mount_id' => $mount->getMountId(),
185
+                'mount_provider_class' => $mount->getMountProvider(),
186
+            ], ['root_id', 'user_id']);
187
+        } else {
188
+            // in some cases this is legitimate, like orphaned shares
189
+            $this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
190
+        }
191
+    }
192
+
193
+    private function updateCachedMount(ICachedMountInfo $mount) {
194
+        $builder = $this->connection->getQueryBuilder();
195
+
196
+        $query = $builder->update('mounts')
197
+            ->set('storage_id', $builder->createNamedParameter($mount->getStorageId()))
198
+            ->set('mount_point', $builder->createNamedParameter($mount->getMountPoint()))
199
+            ->set('mount_id', $builder->createNamedParameter($mount->getMountId(), IQueryBuilder::PARAM_INT))
200
+            ->set('mount_provider_class', $builder->createNamedParameter($mount->getMountProvider()))
201
+            ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
202
+            ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));
203
+
204
+        $query->execute();
205
+    }
206
+
207
+    private function removeFromCache(ICachedMountInfo $mount) {
208
+        $builder = $this->connection->getQueryBuilder();
209
+
210
+        $query = $builder->delete('mounts')
211
+            ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($mount->getUser()->getUID())))
212
+            ->andWhere($builder->expr()->eq('root_id', $builder->createNamedParameter($mount->getRootId(), IQueryBuilder::PARAM_INT)));
213
+        $query->execute();
214
+    }
215
+
216
+    private function dbRowToMountInfo(array $row) {
217
+        $user = $this->userManager->get($row['user_id']);
218
+        if (is_null($user)) {
219
+            return null;
220
+        }
221
+        $mount_id = $row['mount_id'];
222
+        if (!is_null($mount_id)) {
223
+            $mount_id = (int)$mount_id;
224
+        }
225
+        return new CachedMountInfo(
226
+            $user,
227
+            (int)$row['storage_id'],
228
+            (int)$row['root_id'],
229
+            $row['mount_point'],
230
+            $row['mount_provider_class'] ?? '',
231
+            $mount_id,
232
+            isset($row['path']) ? $row['path'] : '',
233
+        );
234
+    }
235
+
236
+    /**
237
+     * @param IUser $user
238
+     * @return ICachedMountInfo[]
239
+     */
240
+    public function getMountsForUser(IUser $user) {
241
+        if (!isset($this->mountsForUsers[$user->getUID()])) {
242
+            $builder = $this->connection->getQueryBuilder();
243
+            $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
244
+                ->from('mounts', 'm')
245
+                ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
246
+                ->where($builder->expr()->eq('user_id', $builder->createPositionalParameter($user->getUID())));
247
+
248
+            $result = $query->execute();
249
+            $rows = $result->fetchAll();
250
+            $result->closeCursor();
251
+
252
+            $this->mountsForUsers[$user->getUID()] = array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
253
+        }
254
+        return $this->mountsForUsers[$user->getUID()];
255
+    }
256
+
257
+    /**
258
+     * @param int $numericStorageId
259
+     * @param string|null $user limit the results to a single user
260
+     * @return CachedMountInfo[]
261
+     */
262
+    public function getMountsForStorageId($numericStorageId, $user = null) {
263
+        $builder = $this->connection->getQueryBuilder();
264
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
265
+            ->from('mounts', 'm')
266
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
267
+            ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($numericStorageId, IQueryBuilder::PARAM_INT)));
268
+
269
+        if ($user) {
270
+            $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
271
+        }
272
+
273
+        $result = $query->execute();
274
+        $rows = $result->fetchAll();
275
+        $result->closeCursor();
276
+
277
+        return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
278
+    }
279
+
280
+    /**
281
+     * @param int $rootFileId
282
+     * @return CachedMountInfo[]
283
+     */
284
+    public function getMountsForRootId($rootFileId) {
285
+        $builder = $this->connection->getQueryBuilder();
286
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
287
+            ->from('mounts', 'm')
288
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
289
+            ->where($builder->expr()->eq('root_id', $builder->createPositionalParameter($rootFileId, IQueryBuilder::PARAM_INT)));
290
+
291
+        $result = $query->execute();
292
+        $rows = $result->fetchAll();
293
+        $result->closeCursor();
294
+
295
+        return array_filter(array_map([$this, 'dbRowToMountInfo'], $rows));
296
+    }
297
+
298
+    /**
299
+     * @param $fileId
300
+     * @return array{int, string, int}
301
+     * @throws \OCP\Files\NotFoundException
302
+     */
303
+    private function getCacheInfoFromFileId($fileId): array {
304
+        if (!isset($this->cacheInfoCache[$fileId])) {
305
+            $builder = $this->connection->getQueryBuilder();
306
+            $query = $builder->select('storage', 'path', 'mimetype')
307
+                ->from('filecache')
308
+                ->where($builder->expr()->eq('fileid', $builder->createNamedParameter($fileId, IQueryBuilder::PARAM_INT)));
309
+
310
+            $result = $query->execute();
311
+            $row = $result->fetch();
312
+            $result->closeCursor();
313
+
314
+            if (is_array($row)) {
315
+                $this->cacheInfoCache[$fileId] = [
316
+                    (int)$row['storage'],
317
+                    (string)$row['path'],
318
+                    (int)$row['mimetype']
319
+                ];
320
+            } else {
321
+                throw new NotFoundException('File with id "' . $fileId . '" not found');
322
+            }
323
+        }
324
+        return $this->cacheInfoCache[$fileId];
325
+    }
326
+
327
+    /**
328
+     * @param int $fileId
329
+     * @param string|null $user optionally restrict the results to a single user
330
+     * @return ICachedMountFileInfo[]
331
+     * @since 9.0.0
332
+     */
333
+    public function getMountsForFileId($fileId, $user = null) {
334
+        try {
335
+            [$storageId, $internalPath] = $this->getCacheInfoFromFileId($fileId);
336
+        } catch (NotFoundException $e) {
337
+            return [];
338
+        }
339
+        $builder = $this->connection->getQueryBuilder();
340
+        $query = $builder->select('storage_id', 'root_id', 'user_id', 'mount_point', 'mount_id', 'f.path', 'mount_provider_class')
341
+            ->from('mounts', 'm')
342
+            ->innerJoin('m', 'filecache', 'f', $builder->expr()->eq('m.root_id', 'f.fileid'))
343
+            ->where($builder->expr()->eq('storage_id', $builder->createPositionalParameter($storageId, IQueryBuilder::PARAM_INT)));
344
+
345
+        if ($user) {
346
+            $query->andWhere($builder->expr()->eq('user_id', $builder->createPositionalParameter($user)));
347
+        }
348
+
349
+        $result = $query->execute();
350
+        $rows = $result->fetchAll();
351
+        $result->closeCursor();
352
+        // filter mounts that are from the same storage but a different directory
353
+        $filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) {
354
+            if ($fileId === (int)$row['root_id']) {
355
+                return true;
356
+            }
357
+            $internalMountPath = $row['path'] ?? '';
358
+
359
+            return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
360
+        });
361
+
362
+        $filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts));
363
+        return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
364
+            return new CachedMountFileInfo(
365
+                $mount->getUser(),
366
+                $mount->getStorageId(),
367
+                $mount->getRootId(),
368
+                $mount->getMountPoint(),
369
+                $mount->getMountId(),
370
+                $mount->getMountProvider(),
371
+                $mount->getRootInternalPath(),
372
+                $internalPath
373
+            );
374
+        }, $filteredMounts);
375
+    }
376
+
377
+    /**
378
+     * Remove all cached mounts for a user
379
+     *
380
+     * @param IUser $user
381
+     */
382
+    public function removeUserMounts(IUser $user) {
383
+        $builder = $this->connection->getQueryBuilder();
384
+
385
+        $query = $builder->delete('mounts')
386
+            ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($user->getUID())));
387
+        $query->execute();
388
+    }
389
+
390
+    public function removeUserStorageMount($storageId, $userId) {
391
+        $builder = $this->connection->getQueryBuilder();
392
+
393
+        $query = $builder->delete('mounts')
394
+            ->where($builder->expr()->eq('user_id', $builder->createNamedParameter($userId)))
395
+            ->andWhere($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
396
+        $query->execute();
397
+    }
398
+
399
+    public function remoteStorageMounts($storageId) {
400
+        $builder = $this->connection->getQueryBuilder();
401
+
402
+        $query = $builder->delete('mounts')
403
+            ->where($builder->expr()->eq('storage_id', $builder->createNamedParameter($storageId, IQueryBuilder::PARAM_INT)));
404
+        $query->execute();
405
+    }
406
+
407
+    /**
408
+     * @param array $users
409
+     * @return array
410
+     */
411
+    public function getUsedSpaceForUsers(array $users) {
412
+        $builder = $this->connection->getQueryBuilder();
413
+
414
+        $slash = $builder->createNamedParameter('/');
415
+
416
+        $mountPoint = $builder->func()->concat(
417
+            $builder->func()->concat($slash, 'user_id'),
418
+            $slash
419
+        );
420
+
421
+        $userIds = array_map(function (IUser $user) {
422
+            return $user->getUID();
423
+        }, $users);
424
+
425
+        $query = $builder->select('m.user_id', 'f.size')
426
+            ->from('mounts', 'm')
427
+            ->innerJoin('m', 'filecache', 'f',
428
+                $builder->expr()->andX(
429
+                    $builder->expr()->eq('m.storage_id', 'f.storage'),
430
+                    $builder->expr()->eq('f.path_hash', $builder->createNamedParameter(md5('files')))
431
+                ))
432
+            ->where($builder->expr()->eq('m.mount_point', $mountPoint))
433
+            ->andWhere($builder->expr()->in('m.user_id', $builder->createNamedParameter($userIds, IQueryBuilder::PARAM_STR_ARRAY)));
434
+
435
+        $result = $query->execute();
436
+
437
+        $results = [];
438
+        while ($row = $result->fetch()) {
439
+            $results[$row['user_id']] = $row['size'];
440
+        }
441
+        $result->closeCursor();
442
+        return $results;
443
+    }
444
+
445
+    public function clear(): void {
446
+        $this->cacheInfoCache = new CappedMemoryCache();
447
+        $this->mountsForUsers = new CappedMemoryCache();
448
+    }
449
+
450
+    public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
451
+        $mounts = $this->getMountsForUser($user);
452
+        $mountPoints = array_map(function (ICachedMountInfo $mount) {
453
+            return $mount->getMountPoint();
454
+        }, $mounts);
455
+        $mounts = array_combine($mountPoints, $mounts);
456
+
457
+        $current = $path;
458
+        // walk up the directory tree until we find a path that has a mountpoint set
459
+        // the loop will return if a mountpoint is found or break if none are found
460
+        while (true) {
461
+            $mountPoint = $current . '/';
462
+            if (isset($mounts[$mountPoint])) {
463
+                return $mounts[$mountPoint];
464
+            } elseif ($current === '') {
465
+                break;
466
+            }
467
+
468
+            $current = dirname($current);
469
+            if ($current === '.' || $current === '/') {
470
+                $current = '';
471
+            }
472
+        }
473
+
474
+        throw new NotFoundException("No cached mount for path " . $path);
475
+    }
476
+
477
+    public function getMountsInPath(IUser $user, string $path): array {
478
+        $path = rtrim($path, '/') . '/';
479
+        $mounts = $this->getMountsForUser($user);
480
+        return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) {
481
+            return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0;
482
+        });
483
+    }
484 484
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -79,11 +79,11 @@  discard block
 block discarded – undo
79 79
 	public function registerMounts(IUser $user, array $mounts, array $mountProviderClasses = null) {
80 80
 		$this->eventLogger->start('fs:setup:user:register', 'Registering mounts for user');
81 81
 		// filter out non-proper storages coming from unit tests
82
-		$mounts = array_filter($mounts, function (IMountPoint $mount) {
82
+		$mounts = array_filter($mounts, function(IMountPoint $mount) {
83 83
 			return $mount instanceof SharedMount || ($mount->getStorage() && $mount->getStorage()->getCache());
84 84
 		});
85 85
 		/** @var ICachedMountInfo[] $newMounts */
86
-		$newMounts = array_map(function (IMountPoint $mount) use ($user) {
86
+		$newMounts = array_map(function(IMountPoint $mount) use ($user) {
87 87
 			// filter out any storages which aren't scanned yet since we aren't interested in files from those storages (yet)
88 88
 			if ($mount->getStorageRootId() === -1) {
89 89
 				return null;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 			}
93 93
 		}, $mounts);
94 94
 		$newMounts = array_values(array_filter($newMounts));
95
-		$newMountRootIds = array_map(function (ICachedMountInfo $mount) {
95
+		$newMountRootIds = array_map(function(ICachedMountInfo $mount) {
96 96
 			return $mount->getRootId();
97 97
 		}, $newMounts);
98 98
 		$newMounts = array_combine($newMountRootIds, $newMounts);
99 99
 
100 100
 		$cachedMounts = $this->getMountsForUser($user);
101 101
 		if (is_array($mountProviderClasses)) {
102
-			$cachedMounts = array_filter($cachedMounts, function (ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) {
102
+			$cachedMounts = array_filter($cachedMounts, function(ICachedMountInfo $mountInfo) use ($mountProviderClasses, $newMounts) {
103 103
 				// for existing mounts that didn't have a mount provider set
104 104
 				// we still want the ones that map to new mounts
105 105
 				if ($mountInfo->getMountProvider() === '' && isset($newMounts[$mountInfo->getRootId()])) {
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 				return in_array($mountInfo->getMountProvider(), $mountProviderClasses);
109 109
 			});
110 110
 		}
111
-		$cachedMountRootIds = array_map(function (ICachedMountInfo $mount) {
111
+		$cachedMountRootIds = array_map(function(ICachedMountInfo $mount) {
112 112
 			return $mount->getRootId();
113 113
 		}, $cachedMounts);
114 114
 		$cachedMounts = array_combine($cachedMountRootIds, $cachedMounts);
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 			], ['root_id', 'user_id']);
187 187
 		} else {
188 188
 			// in some cases this is legitimate, like orphaned shares
189
-			$this->logger->debug('Could not get storage info for mount at ' . $mount->getMountPoint());
189
+			$this->logger->debug('Could not get storage info for mount at '.$mount->getMountPoint());
190 190
 		}
191 191
 	}
192 192
 
@@ -220,12 +220,12 @@  discard block
 block discarded – undo
220 220
 		}
221 221
 		$mount_id = $row['mount_id'];
222 222
 		if (!is_null($mount_id)) {
223
-			$mount_id = (int)$mount_id;
223
+			$mount_id = (int) $mount_id;
224 224
 		}
225 225
 		return new CachedMountInfo(
226 226
 			$user,
227
-			(int)$row['storage_id'],
228
-			(int)$row['root_id'],
227
+			(int) $row['storage_id'],
228
+			(int) $row['root_id'],
229 229
 			$row['mount_point'],
230 230
 			$row['mount_provider_class'] ?? '',
231 231
 			$mount_id,
@@ -313,12 +313,12 @@  discard block
 block discarded – undo
313 313
 
314 314
 			if (is_array($row)) {
315 315
 				$this->cacheInfoCache[$fileId] = [
316
-					(int)$row['storage'],
317
-					(string)$row['path'],
318
-					(int)$row['mimetype']
316
+					(int) $row['storage'],
317
+					(string) $row['path'],
318
+					(int) $row['mimetype']
319 319
 				];
320 320
 			} else {
321
-				throw new NotFoundException('File with id "' . $fileId . '" not found');
321
+				throw new NotFoundException('File with id "'.$fileId.'" not found');
322 322
 			}
323 323
 		}
324 324
 		return $this->cacheInfoCache[$fileId];
@@ -350,17 +350,17 @@  discard block
 block discarded – undo
350 350
 		$rows = $result->fetchAll();
351 351
 		$result->closeCursor();
352 352
 		// filter mounts that are from the same storage but a different directory
353
-		$filteredMounts = array_filter($rows, function (array $row) use ($internalPath, $fileId) {
354
-			if ($fileId === (int)$row['root_id']) {
353
+		$filteredMounts = array_filter($rows, function(array $row) use ($internalPath, $fileId) {
354
+			if ($fileId === (int) $row['root_id']) {
355 355
 				return true;
356 356
 			}
357 357
 			$internalMountPath = $row['path'] ?? '';
358 358
 
359
-			return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath . '/';
359
+			return $internalMountPath === '' || substr($internalPath, 0, strlen($internalMountPath) + 1) === $internalMountPath.'/';
360 360
 		});
361 361
 
362 362
 		$filteredMounts = array_filter(array_map([$this, 'dbRowToMountInfo'], $filteredMounts));
363
-		return array_map(function (ICachedMountInfo $mount) use ($internalPath) {
363
+		return array_map(function(ICachedMountInfo $mount) use ($internalPath) {
364 364
 			return new CachedMountFileInfo(
365 365
 				$mount->getUser(),
366 366
 				$mount->getStorageId(),
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
 			$slash
419 419
 		);
420 420
 
421
-		$userIds = array_map(function (IUser $user) {
421
+		$userIds = array_map(function(IUser $user) {
422 422
 			return $user->getUID();
423 423
 		}, $users);
424 424
 
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
 
450 450
 	public function getMountForPath(IUser $user, string $path): ICachedMountInfo {
451 451
 		$mounts = $this->getMountsForUser($user);
452
-		$mountPoints = array_map(function (ICachedMountInfo $mount) {
452
+		$mountPoints = array_map(function(ICachedMountInfo $mount) {
453 453
 			return $mount->getMountPoint();
454 454
 		}, $mounts);
455 455
 		$mounts = array_combine($mountPoints, $mounts);
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 		// walk up the directory tree until we find a path that has a mountpoint set
459 459
 		// the loop will return if a mountpoint is found or break if none are found
460 460
 		while (true) {
461
-			$mountPoint = $current . '/';
461
+			$mountPoint = $current.'/';
462 462
 			if (isset($mounts[$mountPoint])) {
463 463
 				return $mounts[$mountPoint];
464 464
 			} elseif ($current === '') {
@@ -471,13 +471,13 @@  discard block
 block discarded – undo
471 471
 			}
472 472
 		}
473 473
 
474
-		throw new NotFoundException("No cached mount for path " . $path);
474
+		throw new NotFoundException("No cached mount for path ".$path);
475 475
 	}
476 476
 
477 477
 	public function getMountsInPath(IUser $user, string $path): array {
478
-		$path = rtrim($path, '/') . '/';
478
+		$path = rtrim($path, '/').'/';
479 479
 		$mounts = $this->getMountsForUser($user);
480
-		return array_filter($mounts, function (ICachedMountInfo $mount) use ($path) {
480
+		return array_filter($mounts, function(ICachedMountInfo $mount) use ($path) {
481 481
 			return $mount->getMountPoint() !== $path && strpos($mount->getMountPoint(), $path) === 0;
482 482
 		});
483 483
 	}
Please login to merge, or discard this patch.
lib/private/Files/Config/MountProviderCollection.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -38,216 +38,216 @@
 block discarded – undo
38 38
 use OCP\IUser;
39 39
 
40 40
 class MountProviderCollection implements IMountProviderCollection, Emitter {
41
-	use EmitterTrait;
42
-
43
-	/**
44
-	 * @var \OCP\Files\Config\IHomeMountProvider[]
45
-	 */
46
-	private $homeProviders = [];
47
-
48
-	/**
49
-	 * @var \OCP\Files\Config\IMountProvider[]
50
-	 */
51
-	private $providers = [];
52
-
53
-	/** @var \OCP\Files\Config\IRootMountProvider[] */
54
-	private $rootProviders = [];
55
-
56
-	/**
57
-	 * @var \OCP\Files\Storage\IStorageFactory
58
-	 */
59
-	private $loader;
60
-
61
-	/**
62
-	 * @var \OCP\Files\Config\IUserMountCache
63
-	 */
64
-	private $mountCache;
65
-
66
-	/** @var callable[] */
67
-	private $mountFilters = [];
68
-
69
-	private IEventLogger $eventLogger;
70
-
71
-	/**
72
-	 * @param \OCP\Files\Storage\IStorageFactory $loader
73
-	 * @param IUserMountCache $mountCache
74
-	 */
75
-	public function __construct(
76
-		IStorageFactory $loader,
77
-		IUserMountCache $mountCache,
78
-		IEventLogger $eventLogger
79
-	) {
80
-		$this->loader = $loader;
81
-		$this->mountCache = $mountCache;
82
-		$this->eventLogger = $eventLogger;
83
-	}
84
-
85
-	private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
86
-		$class = str_replace('\\', '_', get_class($provider));
87
-		$uid = $user->getUID();
88
-		$this->eventLogger->start('fs:setup:provider:' . $class, "Getting mounts from $class for $uid");
89
-		$mounts = $provider->getMountsForUser($user, $loader) ?? [];
90
-		$this->eventLogger->end('fs:setup:provider:' . $class);
91
-		return $mounts;
92
-	}
93
-
94
-	/**
95
-	 * @param IUser $user
96
-	 * @param IMountProvider[] $providers
97
-	 * @return IMountPoint[]
98
-	 */
99
-	private function getUserMountsForProviders(IUser $user, array $providers): array {
100
-		$loader = $this->loader;
101
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
102
-			return $this->getMountsFromProvider($provider, $user, $loader);
103
-		}, $providers);
104
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
105
-			return array_merge($mounts, $providerMounts);
106
-		}, []);
107
-		return $this->filterMounts($user, $mounts);
108
-	}
109
-
110
-	public function getMountsForUser(IUser $user): array {
111
-		return $this->getUserMountsForProviders($user, $this->providers);
112
-	}
113
-
114
-	public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
115
-		$providers = array_filter(
116
-			$this->providers,
117
-			fn (IMountProvider $mountProvider) => (in_array(get_class($mountProvider), $mountProviderClasses))
118
-		);
119
-		return $this->getUserMountsForProviders($user, $providers);
120
-	}
121
-
122
-	public function addMountForUser(IUser $user, IMountManager $mountManager, callable $providerFilter = null) {
123
-		// shared mount provider gets to go last since it needs to know existing files
124
-		// to check for name collisions
125
-		$firstMounts = [];
126
-		if ($providerFilter) {
127
-			$providers = array_filter($this->providers, $providerFilter);
128
-		} else {
129
-			$providers = $this->providers;
130
-		}
131
-		$firstProviders = array_filter($providers, function (IMountProvider $provider) {
132
-			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
133
-		});
134
-		$lastProviders = array_filter($providers, function (IMountProvider $provider) {
135
-			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
136
-		});
137
-		foreach ($firstProviders as $provider) {
138
-			$mounts = $this->getMountsFromProvider($provider, $user, $this->loader);
139
-			$firstMounts = array_merge($firstMounts, $mounts);
140
-		}
141
-		$firstMounts = $this->filterMounts($user, $firstMounts);
142
-		array_walk($firstMounts, [$mountManager, 'addMount']);
143
-
144
-		$lateMounts = [];
145
-		foreach ($lastProviders as $provider) {
146
-			$mounts = $this->getMountsFromProvider($provider, $user, $this->loader);
147
-			$lateMounts = array_merge($lateMounts, $mounts);
148
-		}
149
-
150
-		$lateMounts = $this->filterMounts($user, $lateMounts);
151
-		$this->eventLogger->start("fs:setup:add-mounts", "Add mounts to the filesystem");
152
-		array_walk($lateMounts, [$mountManager, 'addMount']);
153
-		$this->eventLogger->end("fs:setup:add-mounts");
154
-
155
-		return array_merge($lateMounts, $firstMounts);
156
-	}
157
-
158
-	/**
159
-	 * Get the configured home mount for this user
160
-	 *
161
-	 * @param \OCP\IUser $user
162
-	 * @return \OCP\Files\Mount\IMountPoint
163
-	 * @since 9.1.0
164
-	 */
165
-	public function getHomeMountForUser(IUser $user) {
166
-		/** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
167
-		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
168
-		foreach ($providers as $homeProvider) {
169
-			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
170
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
171
-				return $mount;
172
-			}
173
-		}
174
-		throw new \Exception('No home storage configured for user ' . $user);
175
-	}
176
-
177
-	/**
178
-	 * Add a provider for mount points
179
-	 *
180
-	 * @param \OCP\Files\Config\IMountProvider $provider
181
-	 */
182
-	public function registerProvider(IMountProvider $provider) {
183
-		$this->providers[] = $provider;
184
-
185
-		$this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
186
-	}
187
-
188
-	public function registerMountFilter(callable $filter) {
189
-		$this->mountFilters[] = $filter;
190
-	}
191
-
192
-	private function filterMounts(IUser $user, array $mountPoints) {
193
-		return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
194
-			foreach ($this->mountFilters as $filter) {
195
-				if ($filter($mountPoint, $user) === false) {
196
-					return false;
197
-				}
198
-			}
199
-			return true;
200
-		});
201
-	}
202
-
203
-	/**
204
-	 * Add a provider for home mount points
205
-	 *
206
-	 * @param \OCP\Files\Config\IHomeMountProvider $provider
207
-	 * @since 9.1.0
208
-	 */
209
-	public function registerHomeProvider(IHomeMountProvider $provider) {
210
-		$this->homeProviders[] = $provider;
211
-		$this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
212
-	}
213
-
214
-	/**
215
-	 * Get the mount cache which can be used to search for mounts without setting up the filesystem
216
-	 *
217
-	 * @return IUserMountCache
218
-	 */
219
-	public function getMountCache() {
220
-		return $this->mountCache;
221
-	}
222
-
223
-	public function registerRootProvider(IRootMountProvider $provider) {
224
-		$this->rootProviders[] = $provider;
225
-	}
226
-
227
-	/**
228
-	 * Get all root mountpoints
229
-	 *
230
-	 * @return \OCP\Files\Mount\IMountPoint[]
231
-	 * @since 20.0.0
232
-	 */
233
-	public function getRootMounts(): array {
234
-		$loader = $this->loader;
235
-		$mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
236
-			return $provider->getRootMounts($loader);
237
-		}, $this->rootProviders);
238
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
239
-			return array_merge($mounts, $providerMounts);
240
-		}, []);
241
-		return $mounts;
242
-	}
243
-
244
-	public function clearProviders() {
245
-		$this->providers = [];
246
-		$this->homeProviders = [];
247
-		$this->rootProviders = [];
248
-	}
249
-
250
-	public function getProviders(): array {
251
-		return $this->providers;
252
-	}
41
+    use EmitterTrait;
42
+
43
+    /**
44
+     * @var \OCP\Files\Config\IHomeMountProvider[]
45
+     */
46
+    private $homeProviders = [];
47
+
48
+    /**
49
+     * @var \OCP\Files\Config\IMountProvider[]
50
+     */
51
+    private $providers = [];
52
+
53
+    /** @var \OCP\Files\Config\IRootMountProvider[] */
54
+    private $rootProviders = [];
55
+
56
+    /**
57
+     * @var \OCP\Files\Storage\IStorageFactory
58
+     */
59
+    private $loader;
60
+
61
+    /**
62
+     * @var \OCP\Files\Config\IUserMountCache
63
+     */
64
+    private $mountCache;
65
+
66
+    /** @var callable[] */
67
+    private $mountFilters = [];
68
+
69
+    private IEventLogger $eventLogger;
70
+
71
+    /**
72
+     * @param \OCP\Files\Storage\IStorageFactory $loader
73
+     * @param IUserMountCache $mountCache
74
+     */
75
+    public function __construct(
76
+        IStorageFactory $loader,
77
+        IUserMountCache $mountCache,
78
+        IEventLogger $eventLogger
79
+    ) {
80
+        $this->loader = $loader;
81
+        $this->mountCache = $mountCache;
82
+        $this->eventLogger = $eventLogger;
83
+    }
84
+
85
+    private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
86
+        $class = str_replace('\\', '_', get_class($provider));
87
+        $uid = $user->getUID();
88
+        $this->eventLogger->start('fs:setup:provider:' . $class, "Getting mounts from $class for $uid");
89
+        $mounts = $provider->getMountsForUser($user, $loader) ?? [];
90
+        $this->eventLogger->end('fs:setup:provider:' . $class);
91
+        return $mounts;
92
+    }
93
+
94
+    /**
95
+     * @param IUser $user
96
+     * @param IMountProvider[] $providers
97
+     * @return IMountPoint[]
98
+     */
99
+    private function getUserMountsForProviders(IUser $user, array $providers): array {
100
+        $loader = $this->loader;
101
+        $mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
102
+            return $this->getMountsFromProvider($provider, $user, $loader);
103
+        }, $providers);
104
+        $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
105
+            return array_merge($mounts, $providerMounts);
106
+        }, []);
107
+        return $this->filterMounts($user, $mounts);
108
+    }
109
+
110
+    public function getMountsForUser(IUser $user): array {
111
+        return $this->getUserMountsForProviders($user, $this->providers);
112
+    }
113
+
114
+    public function getUserMountsForProviderClasses(IUser $user, array $mountProviderClasses): array {
115
+        $providers = array_filter(
116
+            $this->providers,
117
+            fn (IMountProvider $mountProvider) => (in_array(get_class($mountProvider), $mountProviderClasses))
118
+        );
119
+        return $this->getUserMountsForProviders($user, $providers);
120
+    }
121
+
122
+    public function addMountForUser(IUser $user, IMountManager $mountManager, callable $providerFilter = null) {
123
+        // shared mount provider gets to go last since it needs to know existing files
124
+        // to check for name collisions
125
+        $firstMounts = [];
126
+        if ($providerFilter) {
127
+            $providers = array_filter($this->providers, $providerFilter);
128
+        } else {
129
+            $providers = $this->providers;
130
+        }
131
+        $firstProviders = array_filter($providers, function (IMountProvider $provider) {
132
+            return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
133
+        });
134
+        $lastProviders = array_filter($providers, function (IMountProvider $provider) {
135
+            return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
136
+        });
137
+        foreach ($firstProviders as $provider) {
138
+            $mounts = $this->getMountsFromProvider($provider, $user, $this->loader);
139
+            $firstMounts = array_merge($firstMounts, $mounts);
140
+        }
141
+        $firstMounts = $this->filterMounts($user, $firstMounts);
142
+        array_walk($firstMounts, [$mountManager, 'addMount']);
143
+
144
+        $lateMounts = [];
145
+        foreach ($lastProviders as $provider) {
146
+            $mounts = $this->getMountsFromProvider($provider, $user, $this->loader);
147
+            $lateMounts = array_merge($lateMounts, $mounts);
148
+        }
149
+
150
+        $lateMounts = $this->filterMounts($user, $lateMounts);
151
+        $this->eventLogger->start("fs:setup:add-mounts", "Add mounts to the filesystem");
152
+        array_walk($lateMounts, [$mountManager, 'addMount']);
153
+        $this->eventLogger->end("fs:setup:add-mounts");
154
+
155
+        return array_merge($lateMounts, $firstMounts);
156
+    }
157
+
158
+    /**
159
+     * Get the configured home mount for this user
160
+     *
161
+     * @param \OCP\IUser $user
162
+     * @return \OCP\Files\Mount\IMountPoint
163
+     * @since 9.1.0
164
+     */
165
+    public function getHomeMountForUser(IUser $user) {
166
+        /** @var \OCP\Files\Config\IHomeMountProvider[] $providers */
167
+        $providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
168
+        foreach ($providers as $homeProvider) {
169
+            if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
170
+                $mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
171
+                return $mount;
172
+            }
173
+        }
174
+        throw new \Exception('No home storage configured for user ' . $user);
175
+    }
176
+
177
+    /**
178
+     * Add a provider for mount points
179
+     *
180
+     * @param \OCP\Files\Config\IMountProvider $provider
181
+     */
182
+    public function registerProvider(IMountProvider $provider) {
183
+        $this->providers[] = $provider;
184
+
185
+        $this->emit('\OC\Files\Config', 'registerMountProvider', [$provider]);
186
+    }
187
+
188
+    public function registerMountFilter(callable $filter) {
189
+        $this->mountFilters[] = $filter;
190
+    }
191
+
192
+    private function filterMounts(IUser $user, array $mountPoints) {
193
+        return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
194
+            foreach ($this->mountFilters as $filter) {
195
+                if ($filter($mountPoint, $user) === false) {
196
+                    return false;
197
+                }
198
+            }
199
+            return true;
200
+        });
201
+    }
202
+
203
+    /**
204
+     * Add a provider for home mount points
205
+     *
206
+     * @param \OCP\Files\Config\IHomeMountProvider $provider
207
+     * @since 9.1.0
208
+     */
209
+    public function registerHomeProvider(IHomeMountProvider $provider) {
210
+        $this->homeProviders[] = $provider;
211
+        $this->emit('\OC\Files\Config', 'registerHomeMountProvider', [$provider]);
212
+    }
213
+
214
+    /**
215
+     * Get the mount cache which can be used to search for mounts without setting up the filesystem
216
+     *
217
+     * @return IUserMountCache
218
+     */
219
+    public function getMountCache() {
220
+        return $this->mountCache;
221
+    }
222
+
223
+    public function registerRootProvider(IRootMountProvider $provider) {
224
+        $this->rootProviders[] = $provider;
225
+    }
226
+
227
+    /**
228
+     * Get all root mountpoints
229
+     *
230
+     * @return \OCP\Files\Mount\IMountPoint[]
231
+     * @since 20.0.0
232
+     */
233
+    public function getRootMounts(): array {
234
+        $loader = $this->loader;
235
+        $mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
236
+            return $provider->getRootMounts($loader);
237
+        }, $this->rootProviders);
238
+        $mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
239
+            return array_merge($mounts, $providerMounts);
240
+        }, []);
241
+        return $mounts;
242
+    }
243
+
244
+    public function clearProviders() {
245
+        $this->providers = [];
246
+        $this->homeProviders = [];
247
+        $this->rootProviders = [];
248
+    }
249
+
250
+    public function getProviders(): array {
251
+        return $this->providers;
252
+    }
253 253
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	private function getMountsFromProvider(IMountProvider $provider, IUser $user, IStorageFactory $loader): array {
86 86
 		$class = str_replace('\\', '_', get_class($provider));
87 87
 		$uid = $user->getUID();
88
-		$this->eventLogger->start('fs:setup:provider:' . $class, "Getting mounts from $class for $uid");
88
+		$this->eventLogger->start('fs:setup:provider:'.$class, "Getting mounts from $class for $uid");
89 89
 		$mounts = $provider->getMountsForUser($user, $loader) ?? [];
90
-		$this->eventLogger->end('fs:setup:provider:' . $class);
90
+		$this->eventLogger->end('fs:setup:provider:'.$class);
91 91
 		return $mounts;
92 92
 	}
93 93
 
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	private function getUserMountsForProviders(IUser $user, array $providers): array {
100 100
 		$loader = $this->loader;
101
-		$mounts = array_map(function (IMountProvider $provider) use ($user, $loader) {
101
+		$mounts = array_map(function(IMountProvider $provider) use ($user, $loader) {
102 102
 			return $this->getMountsFromProvider($provider, $user, $loader);
103 103
 		}, $providers);
104
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
104
+		$mounts = array_reduce($mounts, function(array $mounts, array $providerMounts) {
105 105
 			return array_merge($mounts, $providerMounts);
106 106
 		}, []);
107 107
 		return $this->filterMounts($user, $mounts);
@@ -128,10 +128,10 @@  discard block
 block discarded – undo
128 128
 		} else {
129 129
 			$providers = $this->providers;
130 130
 		}
131
-		$firstProviders = array_filter($providers, function (IMountProvider $provider) {
131
+		$firstProviders = array_filter($providers, function(IMountProvider $provider) {
132 132
 			return (get_class($provider) !== 'OCA\Files_Sharing\MountProvider');
133 133
 		});
134
-		$lastProviders = array_filter($providers, function (IMountProvider $provider) {
134
+		$lastProviders = array_filter($providers, function(IMountProvider $provider) {
135 135
 			return (get_class($provider) === 'OCA\Files_Sharing\MountProvider');
136 136
 		});
137 137
 		foreach ($firstProviders as $provider) {
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 		$providers = array_reverse($this->homeProviders); // call the latest registered provider first to give apps an opportunity to overwrite builtin
168 168
 		foreach ($providers as $homeProvider) {
169 169
 			if ($mount = $homeProvider->getHomeMountForUser($user, $this->loader)) {
170
-				$mount->setMountPoint('/' . $user->getUID()); //make sure the mountpoint is what we expect
170
+				$mount->setMountPoint('/'.$user->getUID()); //make sure the mountpoint is what we expect
171 171
 				return $mount;
172 172
 			}
173 173
 		}
174
-		throw new \Exception('No home storage configured for user ' . $user);
174
+		throw new \Exception('No home storage configured for user '.$user);
175 175
 	}
176 176
 
177 177
 	/**
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
 	}
191 191
 
192 192
 	private function filterMounts(IUser $user, array $mountPoints) {
193
-		return array_filter($mountPoints, function (IMountPoint $mountPoint) use ($user) {
193
+		return array_filter($mountPoints, function(IMountPoint $mountPoint) use ($user) {
194 194
 			foreach ($this->mountFilters as $filter) {
195 195
 				if ($filter($mountPoint, $user) === false) {
196 196
 					return false;
@@ -232,10 +232,10 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	public function getRootMounts(): array {
234 234
 		$loader = $this->loader;
235
-		$mounts = array_map(function (IRootMountProvider $provider) use ($loader) {
235
+		$mounts = array_map(function(IRootMountProvider $provider) use ($loader) {
236 236
 			return $provider->getRootMounts($loader);
237 237
 		}, $this->rootProviders);
238
-		$mounts = array_reduce($mounts, function (array $mounts, array $providerMounts) {
238
+		$mounts = array_reduce($mounts, function(array $mounts, array $providerMounts) {
239 239
 			return array_merge($mounts, $providerMounts);
240 240
 		}, []);
241 241
 		return $mounts;
Please login to merge, or discard this patch.