Passed
Push — master ( 757a84...ccabc6 )
by Morris
24:05 queued 11:37
created
lib/private/Server.php 1 patch
Indentation   +1888 added lines, -1888 removed lines patch added patch discarded remove patch
@@ -170,1897 +170,1897 @@
 block discarded – undo
170 170
  * TODO: hookup all manager classes
171 171
  */
172 172
 class Server extends ServerContainer implements IServerContainer {
173
-	/** @var string */
174
-	private $webRoot;
175
-
176
-	/**
177
-	 * @param string $webRoot
178
-	 * @param \OC\Config $config
179
-	 */
180
-	public function __construct($webRoot, \OC\Config $config) {
181
-		parent::__construct();
182
-		$this->webRoot = $webRoot;
183
-
184
-		// To find out if we are running from CLI or not
185
-		$this->registerParameter('isCLI', \OC::$CLI);
186
-
187
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
188
-			return $c;
189
-		});
190
-
191
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
192
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
193
-
194
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
195
-		$this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
196
-
197
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
198
-		$this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
199
-
200
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
201
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
202
-
203
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
204
-
205
-
206
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
207
-			return new PreviewManager(
208
-				$c->getConfig(),
209
-				$c->getRootFolder(),
210
-				$c->getAppDataDir('preview'),
211
-				$c->getEventDispatcher(),
212
-				$c->getSession()->get('user_id')
213
-			);
214
-		});
215
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
216
-
217
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
218
-			return new \OC\Preview\Watcher(
219
-				$c->getAppDataDir('preview')
220
-			);
221
-		});
222
-
223
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
224
-			$view = new View();
225
-			$util = new Encryption\Util(
226
-				$view,
227
-				$c->getUserManager(),
228
-				$c->getGroupManager(),
229
-				$c->getConfig()
230
-			);
231
-			return new Encryption\Manager(
232
-				$c->getConfig(),
233
-				$c->getLogger(),
234
-				$c->getL10N('core'),
235
-				new View(),
236
-				$util,
237
-				new ArrayCache()
238
-			);
239
-		});
240
-		$this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
241
-
242
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
243
-			$util = new Encryption\Util(
244
-				new View(),
245
-				$c->getUserManager(),
246
-				$c->getGroupManager(),
247
-				$c->getConfig()
248
-			);
249
-			return new Encryption\File(
250
-				$util,
251
-				$c->getRootFolder(),
252
-				$c->getShareManager()
253
-			);
254
-		});
255
-
256
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
257
-			$view = new View();
258
-			$util = new Encryption\Util(
259
-				$view,
260
-				$c->getUserManager(),
261
-				$c->getGroupManager(),
262
-				$c->getConfig()
263
-			);
264
-
265
-			return new Encryption\Keys\Storage($view, $util);
266
-		});
267
-		$this->registerService('TagMapper', function (Server $c) {
268
-			return new TagMapper($c->getDatabaseConnection());
269
-		});
270
-
271
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
272
-			$tagMapper = $c->query('TagMapper');
273
-			return new TagManager($tagMapper, $c->getUserSession());
274
-		});
275
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
276
-
277
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
278
-			$config = $c->getConfig();
279
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
280
-			return new $factoryClass($this);
281
-		});
282
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
283
-			return $c->query('SystemTagManagerFactory')->getManager();
284
-		});
285
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
286
-
287
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
288
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
289
-		});
290
-		$this->registerService('RootFolder', function (Server $c) {
291
-			$manager = \OC\Files\Filesystem::getMountManager(null);
292
-			$view = new View();
293
-			$root = new Root(
294
-				$manager,
295
-				$view,
296
-				null,
297
-				$c->getUserMountCache(),
298
-				$this->getLogger(),
299
-				$this->getUserManager()
300
-			);
301
-			$connector = new HookConnector($root, $view);
302
-			$connector->viewToNode();
303
-
304
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
305
-			$previewConnector->connectWatcher();
306
-
307
-			return $root;
308
-		});
309
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
310
-
311
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
312
-			return new LazyRoot(function () use ($c) {
313
-				return $c->query('RootFolder');
314
-			});
315
-		});
316
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
317
-
318
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
319
-			return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
320
-		});
321
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
322
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
323
-
324
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
325
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
326
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
327
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
328
-			});
329
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
330
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
331
-			});
332
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
333
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
334
-			});
335
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
336
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
337
-			});
338
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
339
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
340
-			});
341
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
342
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
343
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
344
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
345
-			});
346
-			return $groupManager;
347
-		});
348
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
349
-
350
-		$this->registerService(Store::class, function (Server $c) {
351
-			$session = $c->getSession();
352
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
353
-				$tokenProvider = $c->query(IProvider::class);
354
-			} else {
355
-				$tokenProvider = null;
356
-			}
357
-			$logger = $c->getLogger();
358
-			return new Store($session, $logger, $tokenProvider);
359
-		});
360
-		$this->registerAlias(IStore::class, Store::class);
361
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
362
-			$dbConnection = $c->getDatabaseConnection();
363
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
364
-		});
365
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
366
-
367
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
368
-			$manager = $c->getUserManager();
369
-			$session = new \OC\Session\Memory('');
370
-			$timeFactory = new TimeFactory();
371
-			// Token providers might require a working database. This code
372
-			// might however be called when ownCloud is not yet setup.
373
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
374
-				$defaultTokenProvider = $c->query(IProvider::class);
375
-			} else {
376
-				$defaultTokenProvider = null;
377
-			}
378
-
379
-			$dispatcher = $c->getEventDispatcher();
380
-
381
-			$userSession = new \OC\User\Session(
382
-				$manager,
383
-				$session,
384
-				$timeFactory,
385
-				$defaultTokenProvider,
386
-				$c->getConfig(),
387
-				$c->getSecureRandom(),
388
-				$c->getLockdownManager(),
389
-				$c->getLogger()
390
-			);
391
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
392
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
393
-			});
394
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
395
-				/** @var $user \OC\User\User */
396
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
397
-			});
398
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
399
-				/** @var $user \OC\User\User */
400
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
401
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
402
-			});
403
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
404
-				/** @var $user \OC\User\User */
405
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
406
-			});
407
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
408
-				/** @var $user \OC\User\User */
409
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
410
-			});
411
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
412
-				/** @var $user \OC\User\User */
413
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
414
-			});
415
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
416
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
417
-			});
418
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
419
-				/** @var $user \OC\User\User */
420
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
421
-			});
422
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
423
-				/** @var $user \OC\User\User */
424
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
425
-			});
426
-			$userSession->listen('\OC\User', 'logout', function () {
427
-				\OC_Hook::emit('OC_User', 'logout', array());
428
-			});
429
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
430
-				/** @var $user \OC\User\User */
431
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
432
-			});
433
-			return $userSession;
434
-		});
435
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
436
-		$this->registerAlias('UserSession', \OC\User\Session::class);
437
-
438
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
439
-
440
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
441
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
442
-
443
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
444
-			return new \OC\AllConfig(
445
-				$c->getSystemConfig()
446
-			);
447
-		});
448
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
449
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
450
-
451
-		$this->registerService('SystemConfig', function ($c) use ($config) {
452
-			return new \OC\SystemConfig($config);
453
-		});
454
-
455
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
456
-			return new \OC\AppConfig($c->getDatabaseConnection());
457
-		});
458
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
459
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
460
-
461
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
462
-			return new \OC\L10N\Factory(
463
-				$c->getConfig(),
464
-				$c->getRequest(),
465
-				$c->getUserSession(),
466
-				\OC::$SERVERROOT
467
-			);
468
-		});
469
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
470
-
471
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
472
-			$config = $c->getConfig();
473
-			$cacheFactory = $c->getMemCacheFactory();
474
-			$request = $c->getRequest();
475
-			return new \OC\URLGenerator(
476
-				$config,
477
-				$cacheFactory,
478
-				$request
479
-			);
480
-		});
481
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
482
-
483
-		$this->registerAlias('AppFetcher', AppFetcher::class);
484
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
485
-
486
-		$this->registerService(\OCP\ICache::class, function ($c) {
487
-			return new Cache\File();
488
-		});
489
-		$this->registerAlias('UserCache', \OCP\ICache::class);
490
-
491
-		$this->registerService(Factory::class, function (Server $c) {
492
-
493
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
494
-				ArrayCache::class,
495
-				ArrayCache::class,
496
-				ArrayCache::class
497
-			);
498
-			$config = $c->getConfig();
499
-
500
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
501
-				$v = \OC_App::getAppVersions();
502
-				$v['core'] = implode(',', \OC_Util::getVersion());
503
-				$version = implode(',', $v);
504
-				$instanceId = \OC_Util::getInstanceId();
505
-				$path = \OC::$SERVERROOT;
506
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
507
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
508
-					$config->getSystemValue('memcache.local', null),
509
-					$config->getSystemValue('memcache.distributed', null),
510
-					$config->getSystemValue('memcache.locking', null)
511
-				);
512
-			}
513
-			return $arrayCacheFactory;
514
-
515
-		});
516
-		$this->registerAlias('MemCacheFactory', Factory::class);
517
-		$this->registerAlias(ICacheFactory::class, Factory::class);
518
-
519
-		$this->registerService('RedisFactory', function (Server $c) {
520
-			$systemConfig = $c->getSystemConfig();
521
-			return new RedisFactory($systemConfig);
522
-		});
523
-
524
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
525
-			return new \OC\Activity\Manager(
526
-				$c->getRequest(),
527
-				$c->getUserSession(),
528
-				$c->getConfig(),
529
-				$c->query(IValidator::class)
530
-			);
531
-		});
532
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
533
-
534
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
535
-			return new \OC\Activity\EventMerger(
536
-				$c->getL10N('lib')
537
-			);
538
-		});
539
-		$this->registerAlias(IValidator::class, Validator::class);
540
-
541
-		$this->registerService(AvatarManager::class, function(Server $c) {
542
-			return new AvatarManager(
543
-				$c->query(\OC\User\Manager::class),
544
-				$c->getAppDataDir('avatar'),
545
-				$c->getL10N('lib'),
546
-				$c->getLogger(),
547
-				$c->getConfig()
548
-			);
549
-		});
550
-		$this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
551
-		$this->registerAlias('AvatarManager', AvatarManager::class);
552
-
553
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
554
-
555
-		$this->registerService(\OC\Log::class, function (Server $c) {
556
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
557
-			$factory = new LogFactory($c, $this->getSystemConfig());
558
-			$logger = $factory->get($logType);
559
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
560
-
561
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
562
-		});
563
-		$this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
564
-		$this->registerAlias('Logger', \OC\Log::class);
565
-
566
-		$this->registerService(ILogFactory::class, function (Server $c) {
567
-			return new LogFactory($c, $this->getSystemConfig());
568
-		});
569
-
570
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
571
-			$config = $c->getConfig();
572
-			return new \OC\BackgroundJob\JobList(
573
-				$c->getDatabaseConnection(),
574
-				$config,
575
-				new TimeFactory()
576
-			);
577
-		});
578
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
579
-
580
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
581
-			$cacheFactory = $c->getMemCacheFactory();
582
-			$logger = $c->getLogger();
583
-			if ($cacheFactory->isLocalCacheAvailable()) {
584
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
585
-			} else {
586
-				$router = new \OC\Route\Router($logger);
587
-			}
588
-			return $router;
589
-		});
590
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
591
-
592
-		$this->registerService(\OCP\ISearch::class, function ($c) {
593
-			return new Search();
594
-		});
595
-		$this->registerAlias('Search', \OCP\ISearch::class);
596
-
597
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
598
-			return new \OC\Security\RateLimiting\Limiter(
599
-				$this->getUserSession(),
600
-				$this->getRequest(),
601
-				new \OC\AppFramework\Utility\TimeFactory(),
602
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
603
-			);
604
-		});
605
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
606
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
607
-				$this->getMemCacheFactory(),
608
-				new \OC\AppFramework\Utility\TimeFactory()
609
-			);
610
-		});
611
-
612
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
613
-			return new SecureRandom();
614
-		});
615
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
616
-
617
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
618
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
619
-		});
620
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
621
-
622
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
623
-			return new Hasher($c->getConfig());
624
-		});
625
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
626
-
627
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
628
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
629
-		});
630
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
631
-
632
-		$this->registerService(IDBConnection::class, function (Server $c) {
633
-			$systemConfig = $c->getSystemConfig();
634
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
635
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
636
-			if (!$factory->isValidType($type)) {
637
-				throw new \OC\DatabaseException('Invalid database type');
638
-			}
639
-			$connectionParams = $factory->createConnectionParams();
640
-			$connection = $factory->getConnection($type, $connectionParams);
641
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
642
-			return $connection;
643
-		});
644
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
645
-
646
-
647
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
648
-			$user = \OC_User::getUser();
649
-			$uid = $user ? $user : null;
650
-			return new ClientService(
651
-				$c->getConfig(),
652
-				new \OC\Security\CertificateManager(
653
-					$uid,
654
-					new View(),
655
-					$c->getConfig(),
656
-					$c->getLogger(),
657
-					$c->getSecureRandom()
658
-				)
659
-			);
660
-		});
661
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
662
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
663
-			$eventLogger = new EventLogger();
664
-			if ($c->getSystemConfig()->getValue('debug', false)) {
665
-				// In debug mode, module is being activated by default
666
-				$eventLogger->activate();
667
-			}
668
-			return $eventLogger;
669
-		});
670
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
671
-
672
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
673
-			$queryLogger = new QueryLogger();
674
-			if ($c->getSystemConfig()->getValue('debug', false)) {
675
-				// In debug mode, module is being activated by default
676
-				$queryLogger->activate();
677
-			}
678
-			return $queryLogger;
679
-		});
680
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
681
-
682
-		$this->registerService(TempManager::class, function (Server $c) {
683
-			return new TempManager(
684
-				$c->getLogger(),
685
-				$c->getConfig()
686
-			);
687
-		});
688
-		$this->registerAlias('TempManager', TempManager::class);
689
-		$this->registerAlias(ITempManager::class, TempManager::class);
690
-
691
-		$this->registerService(AppManager::class, function (Server $c) {
692
-			return new \OC\App\AppManager(
693
-				$c->getUserSession(),
694
-				$c->query(\OC\AppConfig::class),
695
-				$c->getGroupManager(),
696
-				$c->getMemCacheFactory(),
697
-				$c->getEventDispatcher()
698
-			);
699
-		});
700
-		$this->registerAlias('AppManager', AppManager::class);
701
-		$this->registerAlias(IAppManager::class, AppManager::class);
702
-
703
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
704
-			return new DateTimeZone(
705
-				$c->getConfig(),
706
-				$c->getSession()
707
-			);
708
-		});
709
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
710
-
711
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
712
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
713
-
714
-			return new DateTimeFormatter(
715
-				$c->getDateTimeZone()->getTimeZone(),
716
-				$c->getL10N('lib', $language)
717
-			);
718
-		});
719
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
720
-
721
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
722
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
723
-			$listener = new UserMountCacheListener($mountCache);
724
-			$listener->listen($c->getUserManager());
725
-			return $mountCache;
726
-		});
727
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
728
-
729
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
730
-			$loader = \OC\Files\Filesystem::getLoader();
731
-			$mountCache = $c->query('UserMountCache');
732
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
733
-
734
-			// builtin providers
735
-
736
-			$config = $c->getConfig();
737
-			$manager->registerProvider(new CacheMountProvider($config));
738
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
739
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
740
-
741
-			return $manager;
742
-		});
743
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
744
-
745
-		$this->registerService('IniWrapper', function ($c) {
746
-			return new IniGetWrapper();
747
-		});
748
-		$this->registerService('AsyncCommandBus', function (Server $c) {
749
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
750
-			if ($busClass) {
751
-				list($app, $class) = explode('::', $busClass, 2);
752
-				if ($c->getAppManager()->isInstalled($app)) {
753
-					\OC_App::loadApp($app);
754
-					return $c->query($class);
755
-				} else {
756
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
757
-				}
758
-			} else {
759
-				$jobList = $c->getJobList();
760
-				return new CronBus($jobList);
761
-			}
762
-		});
763
-		$this->registerService('TrustedDomainHelper', function ($c) {
764
-			return new TrustedDomainHelper($this->getConfig());
765
-		});
766
-		$this->registerService(Throttler::class, function (Server $c) {
767
-			return new Throttler(
768
-				$c->getDatabaseConnection(),
769
-				new TimeFactory(),
770
-				$c->getLogger(),
771
-				$c->getConfig()
772
-			);
773
-		});
774
-		$this->registerAlias('Throttler', Throttler::class);
775
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
776
-			// IConfig and IAppManager requires a working database. This code
777
-			// might however be called when ownCloud is not yet setup.
778
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
779
-				$config = $c->getConfig();
780
-				$appManager = $c->getAppManager();
781
-			} else {
782
-				$config = null;
783
-				$appManager = null;
784
-			}
785
-
786
-			return new Checker(
787
-				new EnvironmentHelper(),
788
-				new FileAccessHelper(),
789
-				new AppLocator(),
790
-				$config,
791
-				$c->getMemCacheFactory(),
792
-				$appManager,
793
-				$c->getTempManager()
794
-			);
795
-		});
796
-		$this->registerService(\OCP\IRequest::class, function ($c) {
797
-			if (isset($this['urlParams'])) {
798
-				$urlParams = $this['urlParams'];
799
-			} else {
800
-				$urlParams = [];
801
-			}
802
-
803
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
804
-				&& in_array('fakeinput', stream_get_wrappers())
805
-			) {
806
-				$stream = 'fakeinput://data';
807
-			} else {
808
-				$stream = 'php://input';
809
-			}
810
-
811
-			return new Request(
812
-				[
813
-					'get' => $_GET,
814
-					'post' => $_POST,
815
-					'files' => $_FILES,
816
-					'server' => $_SERVER,
817
-					'env' => $_ENV,
818
-					'cookies' => $_COOKIE,
819
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
820
-						? $_SERVER['REQUEST_METHOD']
821
-						: '',
822
-					'urlParams' => $urlParams,
823
-				],
824
-				$this->getSecureRandom(),
825
-				$this->getConfig(),
826
-				$this->getCsrfTokenManager(),
827
-				$stream
828
-			);
829
-		});
830
-		$this->registerAlias('Request', \OCP\IRequest::class);
831
-
832
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
833
-			return new Mailer(
834
-				$c->getConfig(),
835
-				$c->getLogger(),
836
-				$c->query(Defaults::class),
837
-				$c->getURLGenerator(),
838
-				$c->getL10N('lib')
839
-			);
840
-		});
841
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
842
-
843
-		$this->registerService('LDAPProvider', function (Server $c) {
844
-			$config = $c->getConfig();
845
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
846
-			if (is_null($factoryClass)) {
847
-				throw new \Exception('ldapProviderFactory not set');
848
-			}
849
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
850
-			$factory = new $factoryClass($this);
851
-			return $factory->getLDAPProvider();
852
-		});
853
-		$this->registerService(ILockingProvider::class, function (Server $c) {
854
-			$ini = $c->getIniWrapper();
855
-			$config = $c->getConfig();
856
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
857
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
858
-				/** @var \OC\Memcache\Factory $memcacheFactory */
859
-				$memcacheFactory = $c->getMemCacheFactory();
860
-				$memcache = $memcacheFactory->createLocking('lock');
861
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
862
-					return new MemcacheLockingProvider($memcache, $ttl);
863
-				}
864
-				return new DBLockingProvider(
865
-					$c->getDatabaseConnection(),
866
-					$c->getLogger(),
867
-					new TimeFactory(),
868
-					$ttl,
869
-					!\OC::$CLI
870
-				);
871
-			}
872
-			return new NoopLockingProvider();
873
-		});
874
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
875
-
876
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
877
-			return new \OC\Files\Mount\Manager();
878
-		});
879
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
880
-
881
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
882
-			return new \OC\Files\Type\Detection(
883
-				$c->getURLGenerator(),
884
-				\OC::$configDir,
885
-				\OC::$SERVERROOT . '/resources/config/'
886
-			);
887
-		});
888
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
889
-
890
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
891
-			return new \OC\Files\Type\Loader(
892
-				$c->getDatabaseConnection()
893
-			);
894
-		});
895
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
896
-		$this->registerService(BundleFetcher::class, function () {
897
-			return new BundleFetcher($this->getL10N('lib'));
898
-		});
899
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
900
-			return new Manager(
901
-				$c->query(IValidator::class)
902
-			);
903
-		});
904
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
905
-
906
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
907
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
908
-			$manager->registerCapability(function () use ($c) {
909
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
910
-			});
911
-			$manager->registerCapability(function () use ($c) {
912
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
913
-			});
914
-			return $manager;
915
-		});
916
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
917
-
918
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
919
-			$config = $c->getConfig();
920
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
921
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
922
-			$factory = new $factoryClass($this);
923
-			$manager = $factory->getManager();
924
-
925
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
926
-				$manager = $c->getUserManager();
927
-				$user = $manager->get($id);
928
-				if(is_null($user)) {
929
-					$l = $c->getL10N('core');
930
-					$displayName = $l->t('Unknown user');
931
-				} else {
932
-					$displayName = $user->getDisplayName();
933
-				}
934
-				return $displayName;
935
-			});
936
-
937
-			return $manager;
938
-		});
939
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
940
-
941
-		$this->registerService('ThemingDefaults', function (Server $c) {
942
-			/*
173
+    /** @var string */
174
+    private $webRoot;
175
+
176
+    /**
177
+     * @param string $webRoot
178
+     * @param \OC\Config $config
179
+     */
180
+    public function __construct($webRoot, \OC\Config $config) {
181
+        parent::__construct();
182
+        $this->webRoot = $webRoot;
183
+
184
+        // To find out if we are running from CLI or not
185
+        $this->registerParameter('isCLI', \OC::$CLI);
186
+
187
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
188
+            return $c;
189
+        });
190
+
191
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
192
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
193
+
194
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
195
+        $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
196
+
197
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
198
+        $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
199
+
200
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
201
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
202
+
203
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
204
+
205
+
206
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
207
+            return new PreviewManager(
208
+                $c->getConfig(),
209
+                $c->getRootFolder(),
210
+                $c->getAppDataDir('preview'),
211
+                $c->getEventDispatcher(),
212
+                $c->getSession()->get('user_id')
213
+            );
214
+        });
215
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
216
+
217
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
218
+            return new \OC\Preview\Watcher(
219
+                $c->getAppDataDir('preview')
220
+            );
221
+        });
222
+
223
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
224
+            $view = new View();
225
+            $util = new Encryption\Util(
226
+                $view,
227
+                $c->getUserManager(),
228
+                $c->getGroupManager(),
229
+                $c->getConfig()
230
+            );
231
+            return new Encryption\Manager(
232
+                $c->getConfig(),
233
+                $c->getLogger(),
234
+                $c->getL10N('core'),
235
+                new View(),
236
+                $util,
237
+                new ArrayCache()
238
+            );
239
+        });
240
+        $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
241
+
242
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
243
+            $util = new Encryption\Util(
244
+                new View(),
245
+                $c->getUserManager(),
246
+                $c->getGroupManager(),
247
+                $c->getConfig()
248
+            );
249
+            return new Encryption\File(
250
+                $util,
251
+                $c->getRootFolder(),
252
+                $c->getShareManager()
253
+            );
254
+        });
255
+
256
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
257
+            $view = new View();
258
+            $util = new Encryption\Util(
259
+                $view,
260
+                $c->getUserManager(),
261
+                $c->getGroupManager(),
262
+                $c->getConfig()
263
+            );
264
+
265
+            return new Encryption\Keys\Storage($view, $util);
266
+        });
267
+        $this->registerService('TagMapper', function (Server $c) {
268
+            return new TagMapper($c->getDatabaseConnection());
269
+        });
270
+
271
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
272
+            $tagMapper = $c->query('TagMapper');
273
+            return new TagManager($tagMapper, $c->getUserSession());
274
+        });
275
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
276
+
277
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
278
+            $config = $c->getConfig();
279
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
280
+            return new $factoryClass($this);
281
+        });
282
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
283
+            return $c->query('SystemTagManagerFactory')->getManager();
284
+        });
285
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
286
+
287
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
288
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
289
+        });
290
+        $this->registerService('RootFolder', function (Server $c) {
291
+            $manager = \OC\Files\Filesystem::getMountManager(null);
292
+            $view = new View();
293
+            $root = new Root(
294
+                $manager,
295
+                $view,
296
+                null,
297
+                $c->getUserMountCache(),
298
+                $this->getLogger(),
299
+                $this->getUserManager()
300
+            );
301
+            $connector = new HookConnector($root, $view);
302
+            $connector->viewToNode();
303
+
304
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
305
+            $previewConnector->connectWatcher();
306
+
307
+            return $root;
308
+        });
309
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
310
+
311
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
312
+            return new LazyRoot(function () use ($c) {
313
+                return $c->query('RootFolder');
314
+            });
315
+        });
316
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
317
+
318
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
319
+            return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
320
+        });
321
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
322
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
323
+
324
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
325
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
326
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
327
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
328
+            });
329
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
330
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
331
+            });
332
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
333
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
334
+            });
335
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
336
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
337
+            });
338
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
339
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
340
+            });
341
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
342
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
343
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
344
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
345
+            });
346
+            return $groupManager;
347
+        });
348
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
349
+
350
+        $this->registerService(Store::class, function (Server $c) {
351
+            $session = $c->getSession();
352
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
353
+                $tokenProvider = $c->query(IProvider::class);
354
+            } else {
355
+                $tokenProvider = null;
356
+            }
357
+            $logger = $c->getLogger();
358
+            return new Store($session, $logger, $tokenProvider);
359
+        });
360
+        $this->registerAlias(IStore::class, Store::class);
361
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
362
+            $dbConnection = $c->getDatabaseConnection();
363
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
364
+        });
365
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
366
+
367
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
368
+            $manager = $c->getUserManager();
369
+            $session = new \OC\Session\Memory('');
370
+            $timeFactory = new TimeFactory();
371
+            // Token providers might require a working database. This code
372
+            // might however be called when ownCloud is not yet setup.
373
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
374
+                $defaultTokenProvider = $c->query(IProvider::class);
375
+            } else {
376
+                $defaultTokenProvider = null;
377
+            }
378
+
379
+            $dispatcher = $c->getEventDispatcher();
380
+
381
+            $userSession = new \OC\User\Session(
382
+                $manager,
383
+                $session,
384
+                $timeFactory,
385
+                $defaultTokenProvider,
386
+                $c->getConfig(),
387
+                $c->getSecureRandom(),
388
+                $c->getLockdownManager(),
389
+                $c->getLogger()
390
+            );
391
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
392
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
393
+            });
394
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
395
+                /** @var $user \OC\User\User */
396
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
397
+            });
398
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
399
+                /** @var $user \OC\User\User */
400
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
401
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
402
+            });
403
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
404
+                /** @var $user \OC\User\User */
405
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
406
+            });
407
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
408
+                /** @var $user \OC\User\User */
409
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
410
+            });
411
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
412
+                /** @var $user \OC\User\User */
413
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
414
+            });
415
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
416
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
417
+            });
418
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
419
+                /** @var $user \OC\User\User */
420
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
421
+            });
422
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
423
+                /** @var $user \OC\User\User */
424
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
425
+            });
426
+            $userSession->listen('\OC\User', 'logout', function () {
427
+                \OC_Hook::emit('OC_User', 'logout', array());
428
+            });
429
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
430
+                /** @var $user \OC\User\User */
431
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
432
+            });
433
+            return $userSession;
434
+        });
435
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
436
+        $this->registerAlias('UserSession', \OC\User\Session::class);
437
+
438
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
439
+
440
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
441
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
442
+
443
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
444
+            return new \OC\AllConfig(
445
+                $c->getSystemConfig()
446
+            );
447
+        });
448
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
449
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
450
+
451
+        $this->registerService('SystemConfig', function ($c) use ($config) {
452
+            return new \OC\SystemConfig($config);
453
+        });
454
+
455
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
456
+            return new \OC\AppConfig($c->getDatabaseConnection());
457
+        });
458
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
459
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
460
+
461
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
462
+            return new \OC\L10N\Factory(
463
+                $c->getConfig(),
464
+                $c->getRequest(),
465
+                $c->getUserSession(),
466
+                \OC::$SERVERROOT
467
+            );
468
+        });
469
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
470
+
471
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
472
+            $config = $c->getConfig();
473
+            $cacheFactory = $c->getMemCacheFactory();
474
+            $request = $c->getRequest();
475
+            return new \OC\URLGenerator(
476
+                $config,
477
+                $cacheFactory,
478
+                $request
479
+            );
480
+        });
481
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
482
+
483
+        $this->registerAlias('AppFetcher', AppFetcher::class);
484
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
485
+
486
+        $this->registerService(\OCP\ICache::class, function ($c) {
487
+            return new Cache\File();
488
+        });
489
+        $this->registerAlias('UserCache', \OCP\ICache::class);
490
+
491
+        $this->registerService(Factory::class, function (Server $c) {
492
+
493
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
494
+                ArrayCache::class,
495
+                ArrayCache::class,
496
+                ArrayCache::class
497
+            );
498
+            $config = $c->getConfig();
499
+
500
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
501
+                $v = \OC_App::getAppVersions();
502
+                $v['core'] = implode(',', \OC_Util::getVersion());
503
+                $version = implode(',', $v);
504
+                $instanceId = \OC_Util::getInstanceId();
505
+                $path = \OC::$SERVERROOT;
506
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
507
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
508
+                    $config->getSystemValue('memcache.local', null),
509
+                    $config->getSystemValue('memcache.distributed', null),
510
+                    $config->getSystemValue('memcache.locking', null)
511
+                );
512
+            }
513
+            return $arrayCacheFactory;
514
+
515
+        });
516
+        $this->registerAlias('MemCacheFactory', Factory::class);
517
+        $this->registerAlias(ICacheFactory::class, Factory::class);
518
+
519
+        $this->registerService('RedisFactory', function (Server $c) {
520
+            $systemConfig = $c->getSystemConfig();
521
+            return new RedisFactory($systemConfig);
522
+        });
523
+
524
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
525
+            return new \OC\Activity\Manager(
526
+                $c->getRequest(),
527
+                $c->getUserSession(),
528
+                $c->getConfig(),
529
+                $c->query(IValidator::class)
530
+            );
531
+        });
532
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
533
+
534
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
535
+            return new \OC\Activity\EventMerger(
536
+                $c->getL10N('lib')
537
+            );
538
+        });
539
+        $this->registerAlias(IValidator::class, Validator::class);
540
+
541
+        $this->registerService(AvatarManager::class, function(Server $c) {
542
+            return new AvatarManager(
543
+                $c->query(\OC\User\Manager::class),
544
+                $c->getAppDataDir('avatar'),
545
+                $c->getL10N('lib'),
546
+                $c->getLogger(),
547
+                $c->getConfig()
548
+            );
549
+        });
550
+        $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
551
+        $this->registerAlias('AvatarManager', AvatarManager::class);
552
+
553
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
554
+
555
+        $this->registerService(\OC\Log::class, function (Server $c) {
556
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
557
+            $factory = new LogFactory($c, $this->getSystemConfig());
558
+            $logger = $factory->get($logType);
559
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
560
+
561
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
562
+        });
563
+        $this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
564
+        $this->registerAlias('Logger', \OC\Log::class);
565
+
566
+        $this->registerService(ILogFactory::class, function (Server $c) {
567
+            return new LogFactory($c, $this->getSystemConfig());
568
+        });
569
+
570
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
571
+            $config = $c->getConfig();
572
+            return new \OC\BackgroundJob\JobList(
573
+                $c->getDatabaseConnection(),
574
+                $config,
575
+                new TimeFactory()
576
+            );
577
+        });
578
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
579
+
580
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
581
+            $cacheFactory = $c->getMemCacheFactory();
582
+            $logger = $c->getLogger();
583
+            if ($cacheFactory->isLocalCacheAvailable()) {
584
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
585
+            } else {
586
+                $router = new \OC\Route\Router($logger);
587
+            }
588
+            return $router;
589
+        });
590
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
591
+
592
+        $this->registerService(\OCP\ISearch::class, function ($c) {
593
+            return new Search();
594
+        });
595
+        $this->registerAlias('Search', \OCP\ISearch::class);
596
+
597
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
598
+            return new \OC\Security\RateLimiting\Limiter(
599
+                $this->getUserSession(),
600
+                $this->getRequest(),
601
+                new \OC\AppFramework\Utility\TimeFactory(),
602
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
603
+            );
604
+        });
605
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
606
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
607
+                $this->getMemCacheFactory(),
608
+                new \OC\AppFramework\Utility\TimeFactory()
609
+            );
610
+        });
611
+
612
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
613
+            return new SecureRandom();
614
+        });
615
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
616
+
617
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
618
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
619
+        });
620
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
621
+
622
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
623
+            return new Hasher($c->getConfig());
624
+        });
625
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
626
+
627
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
628
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
629
+        });
630
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
631
+
632
+        $this->registerService(IDBConnection::class, function (Server $c) {
633
+            $systemConfig = $c->getSystemConfig();
634
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
635
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
636
+            if (!$factory->isValidType($type)) {
637
+                throw new \OC\DatabaseException('Invalid database type');
638
+            }
639
+            $connectionParams = $factory->createConnectionParams();
640
+            $connection = $factory->getConnection($type, $connectionParams);
641
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
642
+            return $connection;
643
+        });
644
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
645
+
646
+
647
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
648
+            $user = \OC_User::getUser();
649
+            $uid = $user ? $user : null;
650
+            return new ClientService(
651
+                $c->getConfig(),
652
+                new \OC\Security\CertificateManager(
653
+                    $uid,
654
+                    new View(),
655
+                    $c->getConfig(),
656
+                    $c->getLogger(),
657
+                    $c->getSecureRandom()
658
+                )
659
+            );
660
+        });
661
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
662
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
663
+            $eventLogger = new EventLogger();
664
+            if ($c->getSystemConfig()->getValue('debug', false)) {
665
+                // In debug mode, module is being activated by default
666
+                $eventLogger->activate();
667
+            }
668
+            return $eventLogger;
669
+        });
670
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
671
+
672
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
673
+            $queryLogger = new QueryLogger();
674
+            if ($c->getSystemConfig()->getValue('debug', false)) {
675
+                // In debug mode, module is being activated by default
676
+                $queryLogger->activate();
677
+            }
678
+            return $queryLogger;
679
+        });
680
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
681
+
682
+        $this->registerService(TempManager::class, function (Server $c) {
683
+            return new TempManager(
684
+                $c->getLogger(),
685
+                $c->getConfig()
686
+            );
687
+        });
688
+        $this->registerAlias('TempManager', TempManager::class);
689
+        $this->registerAlias(ITempManager::class, TempManager::class);
690
+
691
+        $this->registerService(AppManager::class, function (Server $c) {
692
+            return new \OC\App\AppManager(
693
+                $c->getUserSession(),
694
+                $c->query(\OC\AppConfig::class),
695
+                $c->getGroupManager(),
696
+                $c->getMemCacheFactory(),
697
+                $c->getEventDispatcher()
698
+            );
699
+        });
700
+        $this->registerAlias('AppManager', AppManager::class);
701
+        $this->registerAlias(IAppManager::class, AppManager::class);
702
+
703
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
704
+            return new DateTimeZone(
705
+                $c->getConfig(),
706
+                $c->getSession()
707
+            );
708
+        });
709
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
710
+
711
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
712
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
713
+
714
+            return new DateTimeFormatter(
715
+                $c->getDateTimeZone()->getTimeZone(),
716
+                $c->getL10N('lib', $language)
717
+            );
718
+        });
719
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
720
+
721
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
722
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
723
+            $listener = new UserMountCacheListener($mountCache);
724
+            $listener->listen($c->getUserManager());
725
+            return $mountCache;
726
+        });
727
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
728
+
729
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
730
+            $loader = \OC\Files\Filesystem::getLoader();
731
+            $mountCache = $c->query('UserMountCache');
732
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
733
+
734
+            // builtin providers
735
+
736
+            $config = $c->getConfig();
737
+            $manager->registerProvider(new CacheMountProvider($config));
738
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
739
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
740
+
741
+            return $manager;
742
+        });
743
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
744
+
745
+        $this->registerService('IniWrapper', function ($c) {
746
+            return new IniGetWrapper();
747
+        });
748
+        $this->registerService('AsyncCommandBus', function (Server $c) {
749
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
750
+            if ($busClass) {
751
+                list($app, $class) = explode('::', $busClass, 2);
752
+                if ($c->getAppManager()->isInstalled($app)) {
753
+                    \OC_App::loadApp($app);
754
+                    return $c->query($class);
755
+                } else {
756
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
757
+                }
758
+            } else {
759
+                $jobList = $c->getJobList();
760
+                return new CronBus($jobList);
761
+            }
762
+        });
763
+        $this->registerService('TrustedDomainHelper', function ($c) {
764
+            return new TrustedDomainHelper($this->getConfig());
765
+        });
766
+        $this->registerService(Throttler::class, function (Server $c) {
767
+            return new Throttler(
768
+                $c->getDatabaseConnection(),
769
+                new TimeFactory(),
770
+                $c->getLogger(),
771
+                $c->getConfig()
772
+            );
773
+        });
774
+        $this->registerAlias('Throttler', Throttler::class);
775
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
776
+            // IConfig and IAppManager requires a working database. This code
777
+            // might however be called when ownCloud is not yet setup.
778
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
779
+                $config = $c->getConfig();
780
+                $appManager = $c->getAppManager();
781
+            } else {
782
+                $config = null;
783
+                $appManager = null;
784
+            }
785
+
786
+            return new Checker(
787
+                new EnvironmentHelper(),
788
+                new FileAccessHelper(),
789
+                new AppLocator(),
790
+                $config,
791
+                $c->getMemCacheFactory(),
792
+                $appManager,
793
+                $c->getTempManager()
794
+            );
795
+        });
796
+        $this->registerService(\OCP\IRequest::class, function ($c) {
797
+            if (isset($this['urlParams'])) {
798
+                $urlParams = $this['urlParams'];
799
+            } else {
800
+                $urlParams = [];
801
+            }
802
+
803
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
804
+                && in_array('fakeinput', stream_get_wrappers())
805
+            ) {
806
+                $stream = 'fakeinput://data';
807
+            } else {
808
+                $stream = 'php://input';
809
+            }
810
+
811
+            return new Request(
812
+                [
813
+                    'get' => $_GET,
814
+                    'post' => $_POST,
815
+                    'files' => $_FILES,
816
+                    'server' => $_SERVER,
817
+                    'env' => $_ENV,
818
+                    'cookies' => $_COOKIE,
819
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
820
+                        ? $_SERVER['REQUEST_METHOD']
821
+                        : '',
822
+                    'urlParams' => $urlParams,
823
+                ],
824
+                $this->getSecureRandom(),
825
+                $this->getConfig(),
826
+                $this->getCsrfTokenManager(),
827
+                $stream
828
+            );
829
+        });
830
+        $this->registerAlias('Request', \OCP\IRequest::class);
831
+
832
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
833
+            return new Mailer(
834
+                $c->getConfig(),
835
+                $c->getLogger(),
836
+                $c->query(Defaults::class),
837
+                $c->getURLGenerator(),
838
+                $c->getL10N('lib')
839
+            );
840
+        });
841
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
842
+
843
+        $this->registerService('LDAPProvider', function (Server $c) {
844
+            $config = $c->getConfig();
845
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
846
+            if (is_null($factoryClass)) {
847
+                throw new \Exception('ldapProviderFactory not set');
848
+            }
849
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
850
+            $factory = new $factoryClass($this);
851
+            return $factory->getLDAPProvider();
852
+        });
853
+        $this->registerService(ILockingProvider::class, function (Server $c) {
854
+            $ini = $c->getIniWrapper();
855
+            $config = $c->getConfig();
856
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
857
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
858
+                /** @var \OC\Memcache\Factory $memcacheFactory */
859
+                $memcacheFactory = $c->getMemCacheFactory();
860
+                $memcache = $memcacheFactory->createLocking('lock');
861
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
862
+                    return new MemcacheLockingProvider($memcache, $ttl);
863
+                }
864
+                return new DBLockingProvider(
865
+                    $c->getDatabaseConnection(),
866
+                    $c->getLogger(),
867
+                    new TimeFactory(),
868
+                    $ttl,
869
+                    !\OC::$CLI
870
+                );
871
+            }
872
+            return new NoopLockingProvider();
873
+        });
874
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
875
+
876
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
877
+            return new \OC\Files\Mount\Manager();
878
+        });
879
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
880
+
881
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
882
+            return new \OC\Files\Type\Detection(
883
+                $c->getURLGenerator(),
884
+                \OC::$configDir,
885
+                \OC::$SERVERROOT . '/resources/config/'
886
+            );
887
+        });
888
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
889
+
890
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
891
+            return new \OC\Files\Type\Loader(
892
+                $c->getDatabaseConnection()
893
+            );
894
+        });
895
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
896
+        $this->registerService(BundleFetcher::class, function () {
897
+            return new BundleFetcher($this->getL10N('lib'));
898
+        });
899
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
900
+            return new Manager(
901
+                $c->query(IValidator::class)
902
+            );
903
+        });
904
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
905
+
906
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
907
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
908
+            $manager->registerCapability(function () use ($c) {
909
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
910
+            });
911
+            $manager->registerCapability(function () use ($c) {
912
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
913
+            });
914
+            return $manager;
915
+        });
916
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
917
+
918
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
919
+            $config = $c->getConfig();
920
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
921
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
922
+            $factory = new $factoryClass($this);
923
+            $manager = $factory->getManager();
924
+
925
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
926
+                $manager = $c->getUserManager();
927
+                $user = $manager->get($id);
928
+                if(is_null($user)) {
929
+                    $l = $c->getL10N('core');
930
+                    $displayName = $l->t('Unknown user');
931
+                } else {
932
+                    $displayName = $user->getDisplayName();
933
+                }
934
+                return $displayName;
935
+            });
936
+
937
+            return $manager;
938
+        });
939
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
940
+
941
+        $this->registerService('ThemingDefaults', function (Server $c) {
942
+            /*
943 943
 			 * Dark magic for autoloader.
944 944
 			 * If we do a class_exists it will try to load the class which will
945 945
 			 * make composer cache the result. Resulting in errors when enabling
946 946
 			 * the theming app.
947 947
 			 */
948
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
949
-			if (isset($prefixes['OCA\\Theming\\'])) {
950
-				$classExists = true;
951
-			} else {
952
-				$classExists = false;
953
-			}
954
-
955
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
956
-				return new ThemingDefaults(
957
-					$c->getConfig(),
958
-					$c->getL10N('theming'),
959
-					$c->getURLGenerator(),
960
-					$c->getMemCacheFactory(),
961
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
962
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
963
-					$c->getAppManager(),
964
-					$c->getNavigationManager()
965
-				);
966
-			}
967
-			return new \OC_Defaults();
968
-		});
969
-		$this->registerService(SCSSCacher::class, function (Server $c) {
970
-			return new SCSSCacher(
971
-				$c->getLogger(),
972
-				$c->query(\OC\Files\AppData\Factory::class),
973
-				$c->getURLGenerator(),
974
-				$c->getConfig(),
975
-				$c->getThemingDefaults(),
976
-				\OC::$SERVERROOT,
977
-				$this->getMemCacheFactory(),
978
-				$c->query(IconsCacher::class),
979
-				new TimeFactory()
980
-			);
981
-		});
982
-		$this->registerService(JSCombiner::class, function (Server $c) {
983
-			return new JSCombiner(
984
-				$c->getAppDataDir('js'),
985
-				$c->getURLGenerator(),
986
-				$this->getMemCacheFactory(),
987
-				$c->getSystemConfig(),
988
-				$c->getLogger()
989
-			);
990
-		});
991
-		$this->registerService(EventDispatcher::class, function () {
992
-			return new EventDispatcher();
993
-		});
994
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
995
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
996
-
997
-		$this->registerService('CryptoWrapper', function (Server $c) {
998
-			// FIXME: Instantiiated here due to cyclic dependency
999
-			$request = new Request(
1000
-				[
1001
-					'get' => $_GET,
1002
-					'post' => $_POST,
1003
-					'files' => $_FILES,
1004
-					'server' => $_SERVER,
1005
-					'env' => $_ENV,
1006
-					'cookies' => $_COOKIE,
1007
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1008
-						? $_SERVER['REQUEST_METHOD']
1009
-						: null,
1010
-				],
1011
-				$c->getSecureRandom(),
1012
-				$c->getConfig()
1013
-			);
1014
-
1015
-			return new CryptoWrapper(
1016
-				$c->getConfig(),
1017
-				$c->getCrypto(),
1018
-				$c->getSecureRandom(),
1019
-				$request
1020
-			);
1021
-		});
1022
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1023
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1024
-
1025
-			return new CsrfTokenManager(
1026
-				$tokenGenerator,
1027
-				$c->query(SessionStorage::class)
1028
-			);
1029
-		});
1030
-		$this->registerService(SessionStorage::class, function (Server $c) {
1031
-			return new SessionStorage($c->getSession());
1032
-		});
1033
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1034
-			return new ContentSecurityPolicyManager();
1035
-		});
1036
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1037
-
1038
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1039
-			return new ContentSecurityPolicyNonceManager(
1040
-				$c->getCsrfTokenManager(),
1041
-				$c->getRequest()
1042
-			);
1043
-		});
1044
-
1045
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1046
-			$config = $c->getConfig();
1047
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1048
-			/** @var \OCP\Share\IProviderFactory $factory */
1049
-			$factory = new $factoryClass($this);
1050
-
1051
-			$manager = new \OC\Share20\Manager(
1052
-				$c->getLogger(),
1053
-				$c->getConfig(),
1054
-				$c->getSecureRandom(),
1055
-				$c->getHasher(),
1056
-				$c->getMountManager(),
1057
-				$c->getGroupManager(),
1058
-				$c->getL10N('lib'),
1059
-				$c->getL10NFactory(),
1060
-				$factory,
1061
-				$c->getUserManager(),
1062
-				$c->getLazyRootFolder(),
1063
-				$c->getEventDispatcher(),
1064
-				$c->getMailer(),
1065
-				$c->getURLGenerator(),
1066
-				$c->getThemingDefaults()
1067
-			);
1068
-
1069
-			return $manager;
1070
-		});
1071
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1072
-
1073
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1074
-			$instance = new Collaboration\Collaborators\Search($c);
1075
-
1076
-			// register default plugins
1077
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1078
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1079
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1080
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1081
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1082
-
1083
-			return $instance;
1084
-		});
1085
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1086
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1087
-
1088
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1089
-
1090
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1091
-
1092
-		$this->registerService('SettingsManager', function (Server $c) {
1093
-			$manager = new \OC\Settings\Manager(
1094
-				$c->getLogger(),
1095
-				$c->getL10N('lib'),
1096
-				$c->getURLGenerator(),
1097
-				$c
1098
-			);
1099
-			return $manager;
1100
-		});
1101
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1102
-			return new \OC\Files\AppData\Factory(
1103
-				$c->getRootFolder(),
1104
-				$c->getSystemConfig()
1105
-			);
1106
-		});
1107
-
1108
-		$this->registerService('LockdownManager', function (Server $c) {
1109
-			return new LockdownManager(function () use ($c) {
1110
-				return $c->getSession();
1111
-			});
1112
-		});
1113
-
1114
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1115
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1116
-		});
1117
-
1118
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1119
-			return new CloudIdManager();
1120
-		});
1121
-
1122
-		$this->registerService(IConfig::class, function (Server $c) {
1123
-			return new GlobalScale\Config($c->getConfig());
1124
-		});
1125
-
1126
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1127
-			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1128
-		});
1129
-
1130
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1131
-			return new CloudFederationFactory();
1132
-		});
1133
-
1134
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1135
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1136
-
1137
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1138
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1139
-
1140
-		$this->registerService(Defaults::class, function (Server $c) {
1141
-			return new Defaults(
1142
-				$c->getThemingDefaults()
1143
-			);
1144
-		});
1145
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1146
-
1147
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1148
-			return $c->query(\OCP\IUserSession::class)->getSession();
1149
-		});
1150
-
1151
-		$this->registerService(IShareHelper::class, function (Server $c) {
1152
-			return new ShareHelper(
1153
-				$c->query(\OCP\Share\IManager::class)
1154
-			);
1155
-		});
1156
-
1157
-		$this->registerService(Installer::class, function(Server $c) {
1158
-			return new Installer(
1159
-				$c->getAppFetcher(),
1160
-				$c->getHTTPClientService(),
1161
-				$c->getTempManager(),
1162
-				$c->getLogger(),
1163
-				$c->getConfig()
1164
-			);
1165
-		});
1166
-
1167
-		$this->registerService(IApiFactory::class, function(Server $c) {
1168
-			return new ApiFactory($c->getHTTPClientService());
1169
-		});
1170
-
1171
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1172
-			$memcacheFactory = $c->getMemCacheFactory();
1173
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1174
-		});
1175
-
1176
-		$this->registerService(IContactsStore::class, function(Server $c) {
1177
-			return new ContactsStore(
1178
-				$c->getContactsManager(),
1179
-				$c->getConfig(),
1180
-				$c->getUserManager(),
1181
-				$c->getGroupManager()
1182
-			);
1183
-		});
1184
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1185
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1186
-
1187
-		$this->registerService(IStorageFactory::class, function() {
1188
-			return new StorageFactory();
1189
-		});
1190
-
1191
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1192
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1193
-
1194
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1195
-			return new \OC\Security\IdentityProof\Manager(
1196
-				$c->query(\OC\Files\AppData\Factory::class),
1197
-				$c->getCrypto(),
1198
-				$c->getConfig()
1199
-			);
1200
-		});
1201
-
1202
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1203
-
1204
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1205
-
1206
-		$this->connectDispatcher();
1207
-	}
1208
-
1209
-	/**
1210
-	 * @return \OCP\Calendar\IManager
1211
-	 */
1212
-	public function getCalendarManager() {
1213
-		return $this->query('CalendarManager');
1214
-	}
1215
-
1216
-	/**
1217
-	 * @return \OCP\Calendar\Resource\IManager
1218
-	 */
1219
-	public function getCalendarResourceBackendManager() {
1220
-		return $this->query('CalendarResourceBackendManager');
1221
-	}
1222
-
1223
-	/**
1224
-	 * @return \OCP\Calendar\Room\IManager
1225
-	 */
1226
-	public function getCalendarRoomBackendManager() {
1227
-		return $this->query('CalendarRoomBackendManager');
1228
-	}
1229
-
1230
-	private function connectDispatcher() {
1231
-		$dispatcher = $this->getEventDispatcher();
1232
-
1233
-		// Delete avatar on user deletion
1234
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1235
-			$logger = $this->getLogger();
1236
-			$manager = $this->getAvatarManager();
1237
-			/** @var IUser $user */
1238
-			$user = $e->getSubject();
1239
-
1240
-			try {
1241
-				$avatar = $manager->getAvatar($user->getUID());
1242
-				$avatar->remove();
1243
-			} catch (NotFoundException $e) {
1244
-				// no avatar to remove
1245
-			} catch (\Exception $e) {
1246
-				// Ignore exceptions
1247
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1248
-			}
1249
-		});
1250
-
1251
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1252
-			$manager = $this->getAvatarManager();
1253
-			/** @var IUser $user */
1254
-			$user = $e->getSubject();
1255
-			$feature = $e->getArgument('feature');
1256
-			$oldValue = $e->getArgument('oldValue');
1257
-			$value = $e->getArgument('value');
1258
-
1259
-			// We only change the avatar on display name changes
1260
-			if ($feature !== 'displayName') {
1261
-				return;
1262
-			}
1263
-
1264
-			try {
1265
-				$avatar = $manager->getAvatar($user->getUID());
1266
-				$avatar->userChanged($feature, $oldValue, $value);
1267
-			} catch (NotFoundException $e) {
1268
-				// no avatar to remove
1269
-			}
1270
-		});
1271
-	}
1272
-
1273
-	/**
1274
-	 * @return \OCP\Contacts\IManager
1275
-	 */
1276
-	public function getContactsManager() {
1277
-		return $this->query('ContactsManager');
1278
-	}
1279
-
1280
-	/**
1281
-	 * @return \OC\Encryption\Manager
1282
-	 */
1283
-	public function getEncryptionManager() {
1284
-		return $this->query('EncryptionManager');
1285
-	}
1286
-
1287
-	/**
1288
-	 * @return \OC\Encryption\File
1289
-	 */
1290
-	public function getEncryptionFilesHelper() {
1291
-		return $this->query('EncryptionFileHelper');
1292
-	}
1293
-
1294
-	/**
1295
-	 * @return \OCP\Encryption\Keys\IStorage
1296
-	 */
1297
-	public function getEncryptionKeyStorage() {
1298
-		return $this->query('EncryptionKeyStorage');
1299
-	}
1300
-
1301
-	/**
1302
-	 * The current request object holding all information about the request
1303
-	 * currently being processed is returned from this method.
1304
-	 * In case the current execution was not initiated by a web request null is returned
1305
-	 *
1306
-	 * @return \OCP\IRequest
1307
-	 */
1308
-	public function getRequest() {
1309
-		return $this->query('Request');
1310
-	}
1311
-
1312
-	/**
1313
-	 * Returns the preview manager which can create preview images for a given file
1314
-	 *
1315
-	 * @return \OCP\IPreview
1316
-	 */
1317
-	public function getPreviewManager() {
1318
-		return $this->query('PreviewManager');
1319
-	}
1320
-
1321
-	/**
1322
-	 * Returns the tag manager which can get and set tags for different object types
1323
-	 *
1324
-	 * @see \OCP\ITagManager::load()
1325
-	 * @return \OCP\ITagManager
1326
-	 */
1327
-	public function getTagManager() {
1328
-		return $this->query('TagManager');
1329
-	}
1330
-
1331
-	/**
1332
-	 * Returns the system-tag manager
1333
-	 *
1334
-	 * @return \OCP\SystemTag\ISystemTagManager
1335
-	 *
1336
-	 * @since 9.0.0
1337
-	 */
1338
-	public function getSystemTagManager() {
1339
-		return $this->query('SystemTagManager');
1340
-	}
1341
-
1342
-	/**
1343
-	 * Returns the system-tag object mapper
1344
-	 *
1345
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1346
-	 *
1347
-	 * @since 9.0.0
1348
-	 */
1349
-	public function getSystemTagObjectMapper() {
1350
-		return $this->query('SystemTagObjectMapper');
1351
-	}
1352
-
1353
-	/**
1354
-	 * Returns the avatar manager, used for avatar functionality
1355
-	 *
1356
-	 * @return \OCP\IAvatarManager
1357
-	 */
1358
-	public function getAvatarManager() {
1359
-		return $this->query('AvatarManager');
1360
-	}
1361
-
1362
-	/**
1363
-	 * Returns the root folder of ownCloud's data directory
1364
-	 *
1365
-	 * @return \OCP\Files\IRootFolder
1366
-	 */
1367
-	public function getRootFolder() {
1368
-		return $this->query('LazyRootFolder');
1369
-	}
1370
-
1371
-	/**
1372
-	 * Returns the root folder of ownCloud's data directory
1373
-	 * This is the lazy variant so this gets only initialized once it
1374
-	 * is actually used.
1375
-	 *
1376
-	 * @return \OCP\Files\IRootFolder
1377
-	 */
1378
-	public function getLazyRootFolder() {
1379
-		return $this->query('LazyRootFolder');
1380
-	}
1381
-
1382
-	/**
1383
-	 * Returns a view to ownCloud's files folder
1384
-	 *
1385
-	 * @param string $userId user ID
1386
-	 * @return \OCP\Files\Folder|null
1387
-	 */
1388
-	public function getUserFolder($userId = null) {
1389
-		if ($userId === null) {
1390
-			$user = $this->getUserSession()->getUser();
1391
-			if (!$user) {
1392
-				return null;
1393
-			}
1394
-			$userId = $user->getUID();
1395
-		}
1396
-		$root = $this->getRootFolder();
1397
-		return $root->getUserFolder($userId);
1398
-	}
1399
-
1400
-	/**
1401
-	 * Returns an app-specific view in ownClouds data directory
1402
-	 *
1403
-	 * @return \OCP\Files\Folder
1404
-	 * @deprecated since 9.2.0 use IAppData
1405
-	 */
1406
-	public function getAppFolder() {
1407
-		$dir = '/' . \OC_App::getCurrentApp();
1408
-		$root = $this->getRootFolder();
1409
-		if (!$root->nodeExists($dir)) {
1410
-			$folder = $root->newFolder($dir);
1411
-		} else {
1412
-			$folder = $root->get($dir);
1413
-		}
1414
-		return $folder;
1415
-	}
1416
-
1417
-	/**
1418
-	 * @return \OC\User\Manager
1419
-	 */
1420
-	public function getUserManager() {
1421
-		return $this->query('UserManager');
1422
-	}
1423
-
1424
-	/**
1425
-	 * @return \OC\Group\Manager
1426
-	 */
1427
-	public function getGroupManager() {
1428
-		return $this->query('GroupManager');
1429
-	}
1430
-
1431
-	/**
1432
-	 * @return \OC\User\Session
1433
-	 */
1434
-	public function getUserSession() {
1435
-		return $this->query('UserSession');
1436
-	}
1437
-
1438
-	/**
1439
-	 * @return \OCP\ISession
1440
-	 */
1441
-	public function getSession() {
1442
-		return $this->query('UserSession')->getSession();
1443
-	}
1444
-
1445
-	/**
1446
-	 * @param \OCP\ISession $session
1447
-	 */
1448
-	public function setSession(\OCP\ISession $session) {
1449
-		$this->query(SessionStorage::class)->setSession($session);
1450
-		$this->query('UserSession')->setSession($session);
1451
-		$this->query(Store::class)->setSession($session);
1452
-	}
1453
-
1454
-	/**
1455
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1456
-	 */
1457
-	public function getTwoFactorAuthManager() {
1458
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1459
-	}
1460
-
1461
-	/**
1462
-	 * @return \OC\NavigationManager
1463
-	 */
1464
-	public function getNavigationManager() {
1465
-		return $this->query('NavigationManager');
1466
-	}
1467
-
1468
-	/**
1469
-	 * @return \OCP\IConfig
1470
-	 */
1471
-	public function getConfig() {
1472
-		return $this->query('AllConfig');
1473
-	}
1474
-
1475
-	/**
1476
-	 * @return \OC\SystemConfig
1477
-	 */
1478
-	public function getSystemConfig() {
1479
-		return $this->query('SystemConfig');
1480
-	}
1481
-
1482
-	/**
1483
-	 * Returns the app config manager
1484
-	 *
1485
-	 * @return \OCP\IAppConfig
1486
-	 */
1487
-	public function getAppConfig() {
1488
-		return $this->query('AppConfig');
1489
-	}
1490
-
1491
-	/**
1492
-	 * @return \OCP\L10N\IFactory
1493
-	 */
1494
-	public function getL10NFactory() {
1495
-		return $this->query('L10NFactory');
1496
-	}
1497
-
1498
-	/**
1499
-	 * get an L10N instance
1500
-	 *
1501
-	 * @param string $app appid
1502
-	 * @param string $lang
1503
-	 * @return IL10N
1504
-	 */
1505
-	public function getL10N($app, $lang = null) {
1506
-		return $this->getL10NFactory()->get($app, $lang);
1507
-	}
1508
-
1509
-	/**
1510
-	 * @return \OCP\IURLGenerator
1511
-	 */
1512
-	public function getURLGenerator() {
1513
-		return $this->query('URLGenerator');
1514
-	}
1515
-
1516
-	/**
1517
-	 * @return AppFetcher
1518
-	 */
1519
-	public function getAppFetcher() {
1520
-		return $this->query(AppFetcher::class);
1521
-	}
1522
-
1523
-	/**
1524
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1525
-	 * getMemCacheFactory() instead.
1526
-	 *
1527
-	 * @return \OCP\ICache
1528
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1529
-	 */
1530
-	public function getCache() {
1531
-		return $this->query('UserCache');
1532
-	}
1533
-
1534
-	/**
1535
-	 * Returns an \OCP\CacheFactory instance
1536
-	 *
1537
-	 * @return \OCP\ICacheFactory
1538
-	 */
1539
-	public function getMemCacheFactory() {
1540
-		return $this->query('MemCacheFactory');
1541
-	}
1542
-
1543
-	/**
1544
-	 * Returns an \OC\RedisFactory instance
1545
-	 *
1546
-	 * @return \OC\RedisFactory
1547
-	 */
1548
-	public function getGetRedisFactory() {
1549
-		return $this->query('RedisFactory');
1550
-	}
1551
-
1552
-
1553
-	/**
1554
-	 * Returns the current session
1555
-	 *
1556
-	 * @return \OCP\IDBConnection
1557
-	 */
1558
-	public function getDatabaseConnection() {
1559
-		return $this->query('DatabaseConnection');
1560
-	}
1561
-
1562
-	/**
1563
-	 * Returns the activity manager
1564
-	 *
1565
-	 * @return \OCP\Activity\IManager
1566
-	 */
1567
-	public function getActivityManager() {
1568
-		return $this->query('ActivityManager');
1569
-	}
1570
-
1571
-	/**
1572
-	 * Returns an job list for controlling background jobs
1573
-	 *
1574
-	 * @return \OCP\BackgroundJob\IJobList
1575
-	 */
1576
-	public function getJobList() {
1577
-		return $this->query('JobList');
1578
-	}
1579
-
1580
-	/**
1581
-	 * Returns a logger instance
1582
-	 *
1583
-	 * @return \OCP\ILogger
1584
-	 */
1585
-	public function getLogger() {
1586
-		return $this->query('Logger');
1587
-	}
1588
-
1589
-	/**
1590
-	 * @return ILogFactory
1591
-	 * @throws \OCP\AppFramework\QueryException
1592
-	 */
1593
-	public function getLogFactory() {
1594
-		return $this->query(ILogFactory::class);
1595
-	}
1596
-
1597
-	/**
1598
-	 * Returns a router for generating and matching urls
1599
-	 *
1600
-	 * @return \OCP\Route\IRouter
1601
-	 */
1602
-	public function getRouter() {
1603
-		return $this->query('Router');
1604
-	}
1605
-
1606
-	/**
1607
-	 * Returns a search instance
1608
-	 *
1609
-	 * @return \OCP\ISearch
1610
-	 */
1611
-	public function getSearch() {
1612
-		return $this->query('Search');
1613
-	}
1614
-
1615
-	/**
1616
-	 * Returns a SecureRandom instance
1617
-	 *
1618
-	 * @return \OCP\Security\ISecureRandom
1619
-	 */
1620
-	public function getSecureRandom() {
1621
-		return $this->query('SecureRandom');
1622
-	}
1623
-
1624
-	/**
1625
-	 * Returns a Crypto instance
1626
-	 *
1627
-	 * @return \OCP\Security\ICrypto
1628
-	 */
1629
-	public function getCrypto() {
1630
-		return $this->query('Crypto');
1631
-	}
1632
-
1633
-	/**
1634
-	 * Returns a Hasher instance
1635
-	 *
1636
-	 * @return \OCP\Security\IHasher
1637
-	 */
1638
-	public function getHasher() {
1639
-		return $this->query('Hasher');
1640
-	}
1641
-
1642
-	/**
1643
-	 * Returns a CredentialsManager instance
1644
-	 *
1645
-	 * @return \OCP\Security\ICredentialsManager
1646
-	 */
1647
-	public function getCredentialsManager() {
1648
-		return $this->query('CredentialsManager');
1649
-	}
1650
-
1651
-	/**
1652
-	 * Get the certificate manager for the user
1653
-	 *
1654
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1655
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1656
-	 */
1657
-	public function getCertificateManager($userId = '') {
1658
-		if ($userId === '') {
1659
-			$userSession = $this->getUserSession();
1660
-			$user = $userSession->getUser();
1661
-			if (is_null($user)) {
1662
-				return null;
1663
-			}
1664
-			$userId = $user->getUID();
1665
-		}
1666
-		return new CertificateManager(
1667
-			$userId,
1668
-			new View(),
1669
-			$this->getConfig(),
1670
-			$this->getLogger(),
1671
-			$this->getSecureRandom()
1672
-		);
1673
-	}
1674
-
1675
-	/**
1676
-	 * Returns an instance of the HTTP client service
1677
-	 *
1678
-	 * @return \OCP\Http\Client\IClientService
1679
-	 */
1680
-	public function getHTTPClientService() {
1681
-		return $this->query('HttpClientService');
1682
-	}
1683
-
1684
-	/**
1685
-	 * Create a new event source
1686
-	 *
1687
-	 * @return \OCP\IEventSource
1688
-	 */
1689
-	public function createEventSource() {
1690
-		return new \OC_EventSource();
1691
-	}
1692
-
1693
-	/**
1694
-	 * Get the active event logger
1695
-	 *
1696
-	 * The returned logger only logs data when debug mode is enabled
1697
-	 *
1698
-	 * @return \OCP\Diagnostics\IEventLogger
1699
-	 */
1700
-	public function getEventLogger() {
1701
-		return $this->query('EventLogger');
1702
-	}
1703
-
1704
-	/**
1705
-	 * Get the active query logger
1706
-	 *
1707
-	 * The returned logger only logs data when debug mode is enabled
1708
-	 *
1709
-	 * @return \OCP\Diagnostics\IQueryLogger
1710
-	 */
1711
-	public function getQueryLogger() {
1712
-		return $this->query('QueryLogger');
1713
-	}
1714
-
1715
-	/**
1716
-	 * Get the manager for temporary files and folders
1717
-	 *
1718
-	 * @return \OCP\ITempManager
1719
-	 */
1720
-	public function getTempManager() {
1721
-		return $this->query('TempManager');
1722
-	}
1723
-
1724
-	/**
1725
-	 * Get the app manager
1726
-	 *
1727
-	 * @return \OCP\App\IAppManager
1728
-	 */
1729
-	public function getAppManager() {
1730
-		return $this->query('AppManager');
1731
-	}
1732
-
1733
-	/**
1734
-	 * Creates a new mailer
1735
-	 *
1736
-	 * @return \OCP\Mail\IMailer
1737
-	 */
1738
-	public function getMailer() {
1739
-		return $this->query('Mailer');
1740
-	}
1741
-
1742
-	/**
1743
-	 * Get the webroot
1744
-	 *
1745
-	 * @return string
1746
-	 */
1747
-	public function getWebRoot() {
1748
-		return $this->webRoot;
1749
-	}
1750
-
1751
-	/**
1752
-	 * @return \OC\OCSClient
1753
-	 */
1754
-	public function getOcsClient() {
1755
-		return $this->query('OcsClient');
1756
-	}
1757
-
1758
-	/**
1759
-	 * @return \OCP\IDateTimeZone
1760
-	 */
1761
-	public function getDateTimeZone() {
1762
-		return $this->query('DateTimeZone');
1763
-	}
1764
-
1765
-	/**
1766
-	 * @return \OCP\IDateTimeFormatter
1767
-	 */
1768
-	public function getDateTimeFormatter() {
1769
-		return $this->query('DateTimeFormatter');
1770
-	}
1771
-
1772
-	/**
1773
-	 * @return \OCP\Files\Config\IMountProviderCollection
1774
-	 */
1775
-	public function getMountProviderCollection() {
1776
-		return $this->query('MountConfigManager');
1777
-	}
1778
-
1779
-	/**
1780
-	 * Get the IniWrapper
1781
-	 *
1782
-	 * @return IniGetWrapper
1783
-	 */
1784
-	public function getIniWrapper() {
1785
-		return $this->query('IniWrapper');
1786
-	}
1787
-
1788
-	/**
1789
-	 * @return \OCP\Command\IBus
1790
-	 */
1791
-	public function getCommandBus() {
1792
-		return $this->query('AsyncCommandBus');
1793
-	}
1794
-
1795
-	/**
1796
-	 * Get the trusted domain helper
1797
-	 *
1798
-	 * @return TrustedDomainHelper
1799
-	 */
1800
-	public function getTrustedDomainHelper() {
1801
-		return $this->query('TrustedDomainHelper');
1802
-	}
1803
-
1804
-	/**
1805
-	 * Get the locking provider
1806
-	 *
1807
-	 * @return \OCP\Lock\ILockingProvider
1808
-	 * @since 8.1.0
1809
-	 */
1810
-	public function getLockingProvider() {
1811
-		return $this->query('LockingProvider');
1812
-	}
1813
-
1814
-	/**
1815
-	 * @return \OCP\Files\Mount\IMountManager
1816
-	 **/
1817
-	function getMountManager() {
1818
-		return $this->query('MountManager');
1819
-	}
1820
-
1821
-	/** @return \OCP\Files\Config\IUserMountCache */
1822
-	function getUserMountCache() {
1823
-		return $this->query('UserMountCache');
1824
-	}
1825
-
1826
-	/**
1827
-	 * Get the MimeTypeDetector
1828
-	 *
1829
-	 * @return \OCP\Files\IMimeTypeDetector
1830
-	 */
1831
-	public function getMimeTypeDetector() {
1832
-		return $this->query('MimeTypeDetector');
1833
-	}
1834
-
1835
-	/**
1836
-	 * Get the MimeTypeLoader
1837
-	 *
1838
-	 * @return \OCP\Files\IMimeTypeLoader
1839
-	 */
1840
-	public function getMimeTypeLoader() {
1841
-		return $this->query('MimeTypeLoader');
1842
-	}
1843
-
1844
-	/**
1845
-	 * Get the manager of all the capabilities
1846
-	 *
1847
-	 * @return \OC\CapabilitiesManager
1848
-	 */
1849
-	public function getCapabilitiesManager() {
1850
-		return $this->query('CapabilitiesManager');
1851
-	}
1852
-
1853
-	/**
1854
-	 * Get the EventDispatcher
1855
-	 *
1856
-	 * @return EventDispatcherInterface
1857
-	 * @since 8.2.0
1858
-	 */
1859
-	public function getEventDispatcher() {
1860
-		return $this->query('EventDispatcher');
1861
-	}
1862
-
1863
-	/**
1864
-	 * Get the Notification Manager
1865
-	 *
1866
-	 * @return \OCP\Notification\IManager
1867
-	 * @since 8.2.0
1868
-	 */
1869
-	public function getNotificationManager() {
1870
-		return $this->query('NotificationManager');
1871
-	}
1872
-
1873
-	/**
1874
-	 * @return \OCP\Comments\ICommentsManager
1875
-	 */
1876
-	public function getCommentsManager() {
1877
-		return $this->query('CommentsManager');
1878
-	}
1879
-
1880
-	/**
1881
-	 * @return \OCA\Theming\ThemingDefaults
1882
-	 */
1883
-	public function getThemingDefaults() {
1884
-		return $this->query('ThemingDefaults');
1885
-	}
1886
-
1887
-	/**
1888
-	 * @return \OC\IntegrityCheck\Checker
1889
-	 */
1890
-	public function getIntegrityCodeChecker() {
1891
-		return $this->query('IntegrityCodeChecker');
1892
-	}
1893
-
1894
-	/**
1895
-	 * @return \OC\Session\CryptoWrapper
1896
-	 */
1897
-	public function getSessionCryptoWrapper() {
1898
-		return $this->query('CryptoWrapper');
1899
-	}
1900
-
1901
-	/**
1902
-	 * @return CsrfTokenManager
1903
-	 */
1904
-	public function getCsrfTokenManager() {
1905
-		return $this->query('CsrfTokenManager');
1906
-	}
1907
-
1908
-	/**
1909
-	 * @return Throttler
1910
-	 */
1911
-	public function getBruteForceThrottler() {
1912
-		return $this->query('Throttler');
1913
-	}
1914
-
1915
-	/**
1916
-	 * @return IContentSecurityPolicyManager
1917
-	 */
1918
-	public function getContentSecurityPolicyManager() {
1919
-		return $this->query('ContentSecurityPolicyManager');
1920
-	}
1921
-
1922
-	/**
1923
-	 * @return ContentSecurityPolicyNonceManager
1924
-	 */
1925
-	public function getContentSecurityPolicyNonceManager() {
1926
-		return $this->query('ContentSecurityPolicyNonceManager');
1927
-	}
1928
-
1929
-	/**
1930
-	 * Not a public API as of 8.2, wait for 9.0
1931
-	 *
1932
-	 * @return \OCA\Files_External\Service\BackendService
1933
-	 */
1934
-	public function getStoragesBackendService() {
1935
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1936
-	}
1937
-
1938
-	/**
1939
-	 * Not a public API as of 8.2, wait for 9.0
1940
-	 *
1941
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1942
-	 */
1943
-	public function getGlobalStoragesService() {
1944
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1945
-	}
1946
-
1947
-	/**
1948
-	 * Not a public API as of 8.2, wait for 9.0
1949
-	 *
1950
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1951
-	 */
1952
-	public function getUserGlobalStoragesService() {
1953
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1954
-	}
1955
-
1956
-	/**
1957
-	 * Not a public API as of 8.2, wait for 9.0
1958
-	 *
1959
-	 * @return \OCA\Files_External\Service\UserStoragesService
1960
-	 */
1961
-	public function getUserStoragesService() {
1962
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1963
-	}
1964
-
1965
-	/**
1966
-	 * @return \OCP\Share\IManager
1967
-	 */
1968
-	public function getShareManager() {
1969
-		return $this->query('ShareManager');
1970
-	}
1971
-
1972
-	/**
1973
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1974
-	 */
1975
-	public function getCollaboratorSearch() {
1976
-		return $this->query('CollaboratorSearch');
1977
-	}
1978
-
1979
-	/**
1980
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1981
-	 */
1982
-	public function getAutoCompleteManager(){
1983
-		return $this->query(IManager::class);
1984
-	}
1985
-
1986
-	/**
1987
-	 * Returns the LDAP Provider
1988
-	 *
1989
-	 * @return \OCP\LDAP\ILDAPProvider
1990
-	 */
1991
-	public function getLDAPProvider() {
1992
-		return $this->query('LDAPProvider');
1993
-	}
1994
-
1995
-	/**
1996
-	 * @return \OCP\Settings\IManager
1997
-	 */
1998
-	public function getSettingsManager() {
1999
-		return $this->query('SettingsManager');
2000
-	}
2001
-
2002
-	/**
2003
-	 * @return \OCP\Files\IAppData
2004
-	 */
2005
-	public function getAppDataDir($app) {
2006
-		/** @var \OC\Files\AppData\Factory $factory */
2007
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
2008
-		return $factory->get($app);
2009
-	}
2010
-
2011
-	/**
2012
-	 * @return \OCP\Lockdown\ILockdownManager
2013
-	 */
2014
-	public function getLockdownManager() {
2015
-		return $this->query('LockdownManager');
2016
-	}
2017
-
2018
-	/**
2019
-	 * @return \OCP\Federation\ICloudIdManager
2020
-	 */
2021
-	public function getCloudIdManager() {
2022
-		return $this->query(ICloudIdManager::class);
2023
-	}
2024
-
2025
-	/**
2026
-	 * @return \OCP\GlobalScale\IConfig
2027
-	 */
2028
-	public function getGlobalScaleConfig() {
2029
-		return $this->query(IConfig::class);
2030
-	}
2031
-
2032
-	/**
2033
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2034
-	 */
2035
-	public function getCloudFederationProviderManager() {
2036
-		return $this->query(ICloudFederationProviderManager::class);
2037
-	}
2038
-
2039
-	/**
2040
-	 * @return \OCP\Remote\Api\IApiFactory
2041
-	 */
2042
-	public function getRemoteApiFactory() {
2043
-		return $this->query(IApiFactory::class);
2044
-	}
2045
-
2046
-	/**
2047
-	 * @return \OCP\Federation\ICloudFederationFactory
2048
-	 */
2049
-	public function getCloudFederationFactory() {
2050
-		return $this->query(ICloudFederationFactory::class);
2051
-	}
2052
-
2053
-	/**
2054
-	 * @return \OCP\Remote\IInstanceFactory
2055
-	 */
2056
-	public function getRemoteInstanceFactory() {
2057
-		return $this->query(IInstanceFactory::class);
2058
-	}
2059
-
2060
-	/**
2061
-	 * @return IStorageFactory
2062
-	 */
2063
-	public function getStorageFactory() {
2064
-		return $this->query(IStorageFactory::class);
2065
-	}
948
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
949
+            if (isset($prefixes['OCA\\Theming\\'])) {
950
+                $classExists = true;
951
+            } else {
952
+                $classExists = false;
953
+            }
954
+
955
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
956
+                return new ThemingDefaults(
957
+                    $c->getConfig(),
958
+                    $c->getL10N('theming'),
959
+                    $c->getURLGenerator(),
960
+                    $c->getMemCacheFactory(),
961
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
962
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
963
+                    $c->getAppManager(),
964
+                    $c->getNavigationManager()
965
+                );
966
+            }
967
+            return new \OC_Defaults();
968
+        });
969
+        $this->registerService(SCSSCacher::class, function (Server $c) {
970
+            return new SCSSCacher(
971
+                $c->getLogger(),
972
+                $c->query(\OC\Files\AppData\Factory::class),
973
+                $c->getURLGenerator(),
974
+                $c->getConfig(),
975
+                $c->getThemingDefaults(),
976
+                \OC::$SERVERROOT,
977
+                $this->getMemCacheFactory(),
978
+                $c->query(IconsCacher::class),
979
+                new TimeFactory()
980
+            );
981
+        });
982
+        $this->registerService(JSCombiner::class, function (Server $c) {
983
+            return new JSCombiner(
984
+                $c->getAppDataDir('js'),
985
+                $c->getURLGenerator(),
986
+                $this->getMemCacheFactory(),
987
+                $c->getSystemConfig(),
988
+                $c->getLogger()
989
+            );
990
+        });
991
+        $this->registerService(EventDispatcher::class, function () {
992
+            return new EventDispatcher();
993
+        });
994
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
995
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
996
+
997
+        $this->registerService('CryptoWrapper', function (Server $c) {
998
+            // FIXME: Instantiiated here due to cyclic dependency
999
+            $request = new Request(
1000
+                [
1001
+                    'get' => $_GET,
1002
+                    'post' => $_POST,
1003
+                    'files' => $_FILES,
1004
+                    'server' => $_SERVER,
1005
+                    'env' => $_ENV,
1006
+                    'cookies' => $_COOKIE,
1007
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1008
+                        ? $_SERVER['REQUEST_METHOD']
1009
+                        : null,
1010
+                ],
1011
+                $c->getSecureRandom(),
1012
+                $c->getConfig()
1013
+            );
1014
+
1015
+            return new CryptoWrapper(
1016
+                $c->getConfig(),
1017
+                $c->getCrypto(),
1018
+                $c->getSecureRandom(),
1019
+                $request
1020
+            );
1021
+        });
1022
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1023
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1024
+
1025
+            return new CsrfTokenManager(
1026
+                $tokenGenerator,
1027
+                $c->query(SessionStorage::class)
1028
+            );
1029
+        });
1030
+        $this->registerService(SessionStorage::class, function (Server $c) {
1031
+            return new SessionStorage($c->getSession());
1032
+        });
1033
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1034
+            return new ContentSecurityPolicyManager();
1035
+        });
1036
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1037
+
1038
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1039
+            return new ContentSecurityPolicyNonceManager(
1040
+                $c->getCsrfTokenManager(),
1041
+                $c->getRequest()
1042
+            );
1043
+        });
1044
+
1045
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1046
+            $config = $c->getConfig();
1047
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1048
+            /** @var \OCP\Share\IProviderFactory $factory */
1049
+            $factory = new $factoryClass($this);
1050
+
1051
+            $manager = new \OC\Share20\Manager(
1052
+                $c->getLogger(),
1053
+                $c->getConfig(),
1054
+                $c->getSecureRandom(),
1055
+                $c->getHasher(),
1056
+                $c->getMountManager(),
1057
+                $c->getGroupManager(),
1058
+                $c->getL10N('lib'),
1059
+                $c->getL10NFactory(),
1060
+                $factory,
1061
+                $c->getUserManager(),
1062
+                $c->getLazyRootFolder(),
1063
+                $c->getEventDispatcher(),
1064
+                $c->getMailer(),
1065
+                $c->getURLGenerator(),
1066
+                $c->getThemingDefaults()
1067
+            );
1068
+
1069
+            return $manager;
1070
+        });
1071
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1072
+
1073
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1074
+            $instance = new Collaboration\Collaborators\Search($c);
1075
+
1076
+            // register default plugins
1077
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1078
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1079
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1080
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1081
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1082
+
1083
+            return $instance;
1084
+        });
1085
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1086
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1087
+
1088
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1089
+
1090
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1091
+
1092
+        $this->registerService('SettingsManager', function (Server $c) {
1093
+            $manager = new \OC\Settings\Manager(
1094
+                $c->getLogger(),
1095
+                $c->getL10N('lib'),
1096
+                $c->getURLGenerator(),
1097
+                $c
1098
+            );
1099
+            return $manager;
1100
+        });
1101
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1102
+            return new \OC\Files\AppData\Factory(
1103
+                $c->getRootFolder(),
1104
+                $c->getSystemConfig()
1105
+            );
1106
+        });
1107
+
1108
+        $this->registerService('LockdownManager', function (Server $c) {
1109
+            return new LockdownManager(function () use ($c) {
1110
+                return $c->getSession();
1111
+            });
1112
+        });
1113
+
1114
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1115
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1116
+        });
1117
+
1118
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1119
+            return new CloudIdManager();
1120
+        });
1121
+
1122
+        $this->registerService(IConfig::class, function (Server $c) {
1123
+            return new GlobalScale\Config($c->getConfig());
1124
+        });
1125
+
1126
+        $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1127
+            return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1128
+        });
1129
+
1130
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1131
+            return new CloudFederationFactory();
1132
+        });
1133
+
1134
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1135
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1136
+
1137
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1138
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1139
+
1140
+        $this->registerService(Defaults::class, function (Server $c) {
1141
+            return new Defaults(
1142
+                $c->getThemingDefaults()
1143
+            );
1144
+        });
1145
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1146
+
1147
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1148
+            return $c->query(\OCP\IUserSession::class)->getSession();
1149
+        });
1150
+
1151
+        $this->registerService(IShareHelper::class, function (Server $c) {
1152
+            return new ShareHelper(
1153
+                $c->query(\OCP\Share\IManager::class)
1154
+            );
1155
+        });
1156
+
1157
+        $this->registerService(Installer::class, function(Server $c) {
1158
+            return new Installer(
1159
+                $c->getAppFetcher(),
1160
+                $c->getHTTPClientService(),
1161
+                $c->getTempManager(),
1162
+                $c->getLogger(),
1163
+                $c->getConfig()
1164
+            );
1165
+        });
1166
+
1167
+        $this->registerService(IApiFactory::class, function(Server $c) {
1168
+            return new ApiFactory($c->getHTTPClientService());
1169
+        });
1170
+
1171
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1172
+            $memcacheFactory = $c->getMemCacheFactory();
1173
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1174
+        });
1175
+
1176
+        $this->registerService(IContactsStore::class, function(Server $c) {
1177
+            return new ContactsStore(
1178
+                $c->getContactsManager(),
1179
+                $c->getConfig(),
1180
+                $c->getUserManager(),
1181
+                $c->getGroupManager()
1182
+            );
1183
+        });
1184
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1185
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1186
+
1187
+        $this->registerService(IStorageFactory::class, function() {
1188
+            return new StorageFactory();
1189
+        });
1190
+
1191
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1192
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1193
+
1194
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1195
+            return new \OC\Security\IdentityProof\Manager(
1196
+                $c->query(\OC\Files\AppData\Factory::class),
1197
+                $c->getCrypto(),
1198
+                $c->getConfig()
1199
+            );
1200
+        });
1201
+
1202
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1203
+
1204
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1205
+
1206
+        $this->connectDispatcher();
1207
+    }
1208
+
1209
+    /**
1210
+     * @return \OCP\Calendar\IManager
1211
+     */
1212
+    public function getCalendarManager() {
1213
+        return $this->query('CalendarManager');
1214
+    }
1215
+
1216
+    /**
1217
+     * @return \OCP\Calendar\Resource\IManager
1218
+     */
1219
+    public function getCalendarResourceBackendManager() {
1220
+        return $this->query('CalendarResourceBackendManager');
1221
+    }
1222
+
1223
+    /**
1224
+     * @return \OCP\Calendar\Room\IManager
1225
+     */
1226
+    public function getCalendarRoomBackendManager() {
1227
+        return $this->query('CalendarRoomBackendManager');
1228
+    }
1229
+
1230
+    private function connectDispatcher() {
1231
+        $dispatcher = $this->getEventDispatcher();
1232
+
1233
+        // Delete avatar on user deletion
1234
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1235
+            $logger = $this->getLogger();
1236
+            $manager = $this->getAvatarManager();
1237
+            /** @var IUser $user */
1238
+            $user = $e->getSubject();
1239
+
1240
+            try {
1241
+                $avatar = $manager->getAvatar($user->getUID());
1242
+                $avatar->remove();
1243
+            } catch (NotFoundException $e) {
1244
+                // no avatar to remove
1245
+            } catch (\Exception $e) {
1246
+                // Ignore exceptions
1247
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1248
+            }
1249
+        });
1250
+
1251
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1252
+            $manager = $this->getAvatarManager();
1253
+            /** @var IUser $user */
1254
+            $user = $e->getSubject();
1255
+            $feature = $e->getArgument('feature');
1256
+            $oldValue = $e->getArgument('oldValue');
1257
+            $value = $e->getArgument('value');
1258
+
1259
+            // We only change the avatar on display name changes
1260
+            if ($feature !== 'displayName') {
1261
+                return;
1262
+            }
1263
+
1264
+            try {
1265
+                $avatar = $manager->getAvatar($user->getUID());
1266
+                $avatar->userChanged($feature, $oldValue, $value);
1267
+            } catch (NotFoundException $e) {
1268
+                // no avatar to remove
1269
+            }
1270
+        });
1271
+    }
1272
+
1273
+    /**
1274
+     * @return \OCP\Contacts\IManager
1275
+     */
1276
+    public function getContactsManager() {
1277
+        return $this->query('ContactsManager');
1278
+    }
1279
+
1280
+    /**
1281
+     * @return \OC\Encryption\Manager
1282
+     */
1283
+    public function getEncryptionManager() {
1284
+        return $this->query('EncryptionManager');
1285
+    }
1286
+
1287
+    /**
1288
+     * @return \OC\Encryption\File
1289
+     */
1290
+    public function getEncryptionFilesHelper() {
1291
+        return $this->query('EncryptionFileHelper');
1292
+    }
1293
+
1294
+    /**
1295
+     * @return \OCP\Encryption\Keys\IStorage
1296
+     */
1297
+    public function getEncryptionKeyStorage() {
1298
+        return $this->query('EncryptionKeyStorage');
1299
+    }
1300
+
1301
+    /**
1302
+     * The current request object holding all information about the request
1303
+     * currently being processed is returned from this method.
1304
+     * In case the current execution was not initiated by a web request null is returned
1305
+     *
1306
+     * @return \OCP\IRequest
1307
+     */
1308
+    public function getRequest() {
1309
+        return $this->query('Request');
1310
+    }
1311
+
1312
+    /**
1313
+     * Returns the preview manager which can create preview images for a given file
1314
+     *
1315
+     * @return \OCP\IPreview
1316
+     */
1317
+    public function getPreviewManager() {
1318
+        return $this->query('PreviewManager');
1319
+    }
1320
+
1321
+    /**
1322
+     * Returns the tag manager which can get and set tags for different object types
1323
+     *
1324
+     * @see \OCP\ITagManager::load()
1325
+     * @return \OCP\ITagManager
1326
+     */
1327
+    public function getTagManager() {
1328
+        return $this->query('TagManager');
1329
+    }
1330
+
1331
+    /**
1332
+     * Returns the system-tag manager
1333
+     *
1334
+     * @return \OCP\SystemTag\ISystemTagManager
1335
+     *
1336
+     * @since 9.0.0
1337
+     */
1338
+    public function getSystemTagManager() {
1339
+        return $this->query('SystemTagManager');
1340
+    }
1341
+
1342
+    /**
1343
+     * Returns the system-tag object mapper
1344
+     *
1345
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1346
+     *
1347
+     * @since 9.0.0
1348
+     */
1349
+    public function getSystemTagObjectMapper() {
1350
+        return $this->query('SystemTagObjectMapper');
1351
+    }
1352
+
1353
+    /**
1354
+     * Returns the avatar manager, used for avatar functionality
1355
+     *
1356
+     * @return \OCP\IAvatarManager
1357
+     */
1358
+    public function getAvatarManager() {
1359
+        return $this->query('AvatarManager');
1360
+    }
1361
+
1362
+    /**
1363
+     * Returns the root folder of ownCloud's data directory
1364
+     *
1365
+     * @return \OCP\Files\IRootFolder
1366
+     */
1367
+    public function getRootFolder() {
1368
+        return $this->query('LazyRootFolder');
1369
+    }
1370
+
1371
+    /**
1372
+     * Returns the root folder of ownCloud's data directory
1373
+     * This is the lazy variant so this gets only initialized once it
1374
+     * is actually used.
1375
+     *
1376
+     * @return \OCP\Files\IRootFolder
1377
+     */
1378
+    public function getLazyRootFolder() {
1379
+        return $this->query('LazyRootFolder');
1380
+    }
1381
+
1382
+    /**
1383
+     * Returns a view to ownCloud's files folder
1384
+     *
1385
+     * @param string $userId user ID
1386
+     * @return \OCP\Files\Folder|null
1387
+     */
1388
+    public function getUserFolder($userId = null) {
1389
+        if ($userId === null) {
1390
+            $user = $this->getUserSession()->getUser();
1391
+            if (!$user) {
1392
+                return null;
1393
+            }
1394
+            $userId = $user->getUID();
1395
+        }
1396
+        $root = $this->getRootFolder();
1397
+        return $root->getUserFolder($userId);
1398
+    }
1399
+
1400
+    /**
1401
+     * Returns an app-specific view in ownClouds data directory
1402
+     *
1403
+     * @return \OCP\Files\Folder
1404
+     * @deprecated since 9.2.0 use IAppData
1405
+     */
1406
+    public function getAppFolder() {
1407
+        $dir = '/' . \OC_App::getCurrentApp();
1408
+        $root = $this->getRootFolder();
1409
+        if (!$root->nodeExists($dir)) {
1410
+            $folder = $root->newFolder($dir);
1411
+        } else {
1412
+            $folder = $root->get($dir);
1413
+        }
1414
+        return $folder;
1415
+    }
1416
+
1417
+    /**
1418
+     * @return \OC\User\Manager
1419
+     */
1420
+    public function getUserManager() {
1421
+        return $this->query('UserManager');
1422
+    }
1423
+
1424
+    /**
1425
+     * @return \OC\Group\Manager
1426
+     */
1427
+    public function getGroupManager() {
1428
+        return $this->query('GroupManager');
1429
+    }
1430
+
1431
+    /**
1432
+     * @return \OC\User\Session
1433
+     */
1434
+    public function getUserSession() {
1435
+        return $this->query('UserSession');
1436
+    }
1437
+
1438
+    /**
1439
+     * @return \OCP\ISession
1440
+     */
1441
+    public function getSession() {
1442
+        return $this->query('UserSession')->getSession();
1443
+    }
1444
+
1445
+    /**
1446
+     * @param \OCP\ISession $session
1447
+     */
1448
+    public function setSession(\OCP\ISession $session) {
1449
+        $this->query(SessionStorage::class)->setSession($session);
1450
+        $this->query('UserSession')->setSession($session);
1451
+        $this->query(Store::class)->setSession($session);
1452
+    }
1453
+
1454
+    /**
1455
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1456
+     */
1457
+    public function getTwoFactorAuthManager() {
1458
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1459
+    }
1460
+
1461
+    /**
1462
+     * @return \OC\NavigationManager
1463
+     */
1464
+    public function getNavigationManager() {
1465
+        return $this->query('NavigationManager');
1466
+    }
1467
+
1468
+    /**
1469
+     * @return \OCP\IConfig
1470
+     */
1471
+    public function getConfig() {
1472
+        return $this->query('AllConfig');
1473
+    }
1474
+
1475
+    /**
1476
+     * @return \OC\SystemConfig
1477
+     */
1478
+    public function getSystemConfig() {
1479
+        return $this->query('SystemConfig');
1480
+    }
1481
+
1482
+    /**
1483
+     * Returns the app config manager
1484
+     *
1485
+     * @return \OCP\IAppConfig
1486
+     */
1487
+    public function getAppConfig() {
1488
+        return $this->query('AppConfig');
1489
+    }
1490
+
1491
+    /**
1492
+     * @return \OCP\L10N\IFactory
1493
+     */
1494
+    public function getL10NFactory() {
1495
+        return $this->query('L10NFactory');
1496
+    }
1497
+
1498
+    /**
1499
+     * get an L10N instance
1500
+     *
1501
+     * @param string $app appid
1502
+     * @param string $lang
1503
+     * @return IL10N
1504
+     */
1505
+    public function getL10N($app, $lang = null) {
1506
+        return $this->getL10NFactory()->get($app, $lang);
1507
+    }
1508
+
1509
+    /**
1510
+     * @return \OCP\IURLGenerator
1511
+     */
1512
+    public function getURLGenerator() {
1513
+        return $this->query('URLGenerator');
1514
+    }
1515
+
1516
+    /**
1517
+     * @return AppFetcher
1518
+     */
1519
+    public function getAppFetcher() {
1520
+        return $this->query(AppFetcher::class);
1521
+    }
1522
+
1523
+    /**
1524
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1525
+     * getMemCacheFactory() instead.
1526
+     *
1527
+     * @return \OCP\ICache
1528
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1529
+     */
1530
+    public function getCache() {
1531
+        return $this->query('UserCache');
1532
+    }
1533
+
1534
+    /**
1535
+     * Returns an \OCP\CacheFactory instance
1536
+     *
1537
+     * @return \OCP\ICacheFactory
1538
+     */
1539
+    public function getMemCacheFactory() {
1540
+        return $this->query('MemCacheFactory');
1541
+    }
1542
+
1543
+    /**
1544
+     * Returns an \OC\RedisFactory instance
1545
+     *
1546
+     * @return \OC\RedisFactory
1547
+     */
1548
+    public function getGetRedisFactory() {
1549
+        return $this->query('RedisFactory');
1550
+    }
1551
+
1552
+
1553
+    /**
1554
+     * Returns the current session
1555
+     *
1556
+     * @return \OCP\IDBConnection
1557
+     */
1558
+    public function getDatabaseConnection() {
1559
+        return $this->query('DatabaseConnection');
1560
+    }
1561
+
1562
+    /**
1563
+     * Returns the activity manager
1564
+     *
1565
+     * @return \OCP\Activity\IManager
1566
+     */
1567
+    public function getActivityManager() {
1568
+        return $this->query('ActivityManager');
1569
+    }
1570
+
1571
+    /**
1572
+     * Returns an job list for controlling background jobs
1573
+     *
1574
+     * @return \OCP\BackgroundJob\IJobList
1575
+     */
1576
+    public function getJobList() {
1577
+        return $this->query('JobList');
1578
+    }
1579
+
1580
+    /**
1581
+     * Returns a logger instance
1582
+     *
1583
+     * @return \OCP\ILogger
1584
+     */
1585
+    public function getLogger() {
1586
+        return $this->query('Logger');
1587
+    }
1588
+
1589
+    /**
1590
+     * @return ILogFactory
1591
+     * @throws \OCP\AppFramework\QueryException
1592
+     */
1593
+    public function getLogFactory() {
1594
+        return $this->query(ILogFactory::class);
1595
+    }
1596
+
1597
+    /**
1598
+     * Returns a router for generating and matching urls
1599
+     *
1600
+     * @return \OCP\Route\IRouter
1601
+     */
1602
+    public function getRouter() {
1603
+        return $this->query('Router');
1604
+    }
1605
+
1606
+    /**
1607
+     * Returns a search instance
1608
+     *
1609
+     * @return \OCP\ISearch
1610
+     */
1611
+    public function getSearch() {
1612
+        return $this->query('Search');
1613
+    }
1614
+
1615
+    /**
1616
+     * Returns a SecureRandom instance
1617
+     *
1618
+     * @return \OCP\Security\ISecureRandom
1619
+     */
1620
+    public function getSecureRandom() {
1621
+        return $this->query('SecureRandom');
1622
+    }
1623
+
1624
+    /**
1625
+     * Returns a Crypto instance
1626
+     *
1627
+     * @return \OCP\Security\ICrypto
1628
+     */
1629
+    public function getCrypto() {
1630
+        return $this->query('Crypto');
1631
+    }
1632
+
1633
+    /**
1634
+     * Returns a Hasher instance
1635
+     *
1636
+     * @return \OCP\Security\IHasher
1637
+     */
1638
+    public function getHasher() {
1639
+        return $this->query('Hasher');
1640
+    }
1641
+
1642
+    /**
1643
+     * Returns a CredentialsManager instance
1644
+     *
1645
+     * @return \OCP\Security\ICredentialsManager
1646
+     */
1647
+    public function getCredentialsManager() {
1648
+        return $this->query('CredentialsManager');
1649
+    }
1650
+
1651
+    /**
1652
+     * Get the certificate manager for the user
1653
+     *
1654
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1655
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1656
+     */
1657
+    public function getCertificateManager($userId = '') {
1658
+        if ($userId === '') {
1659
+            $userSession = $this->getUserSession();
1660
+            $user = $userSession->getUser();
1661
+            if (is_null($user)) {
1662
+                return null;
1663
+            }
1664
+            $userId = $user->getUID();
1665
+        }
1666
+        return new CertificateManager(
1667
+            $userId,
1668
+            new View(),
1669
+            $this->getConfig(),
1670
+            $this->getLogger(),
1671
+            $this->getSecureRandom()
1672
+        );
1673
+    }
1674
+
1675
+    /**
1676
+     * Returns an instance of the HTTP client service
1677
+     *
1678
+     * @return \OCP\Http\Client\IClientService
1679
+     */
1680
+    public function getHTTPClientService() {
1681
+        return $this->query('HttpClientService');
1682
+    }
1683
+
1684
+    /**
1685
+     * Create a new event source
1686
+     *
1687
+     * @return \OCP\IEventSource
1688
+     */
1689
+    public function createEventSource() {
1690
+        return new \OC_EventSource();
1691
+    }
1692
+
1693
+    /**
1694
+     * Get the active event logger
1695
+     *
1696
+     * The returned logger only logs data when debug mode is enabled
1697
+     *
1698
+     * @return \OCP\Diagnostics\IEventLogger
1699
+     */
1700
+    public function getEventLogger() {
1701
+        return $this->query('EventLogger');
1702
+    }
1703
+
1704
+    /**
1705
+     * Get the active query logger
1706
+     *
1707
+     * The returned logger only logs data when debug mode is enabled
1708
+     *
1709
+     * @return \OCP\Diagnostics\IQueryLogger
1710
+     */
1711
+    public function getQueryLogger() {
1712
+        return $this->query('QueryLogger');
1713
+    }
1714
+
1715
+    /**
1716
+     * Get the manager for temporary files and folders
1717
+     *
1718
+     * @return \OCP\ITempManager
1719
+     */
1720
+    public function getTempManager() {
1721
+        return $this->query('TempManager');
1722
+    }
1723
+
1724
+    /**
1725
+     * Get the app manager
1726
+     *
1727
+     * @return \OCP\App\IAppManager
1728
+     */
1729
+    public function getAppManager() {
1730
+        return $this->query('AppManager');
1731
+    }
1732
+
1733
+    /**
1734
+     * Creates a new mailer
1735
+     *
1736
+     * @return \OCP\Mail\IMailer
1737
+     */
1738
+    public function getMailer() {
1739
+        return $this->query('Mailer');
1740
+    }
1741
+
1742
+    /**
1743
+     * Get the webroot
1744
+     *
1745
+     * @return string
1746
+     */
1747
+    public function getWebRoot() {
1748
+        return $this->webRoot;
1749
+    }
1750
+
1751
+    /**
1752
+     * @return \OC\OCSClient
1753
+     */
1754
+    public function getOcsClient() {
1755
+        return $this->query('OcsClient');
1756
+    }
1757
+
1758
+    /**
1759
+     * @return \OCP\IDateTimeZone
1760
+     */
1761
+    public function getDateTimeZone() {
1762
+        return $this->query('DateTimeZone');
1763
+    }
1764
+
1765
+    /**
1766
+     * @return \OCP\IDateTimeFormatter
1767
+     */
1768
+    public function getDateTimeFormatter() {
1769
+        return $this->query('DateTimeFormatter');
1770
+    }
1771
+
1772
+    /**
1773
+     * @return \OCP\Files\Config\IMountProviderCollection
1774
+     */
1775
+    public function getMountProviderCollection() {
1776
+        return $this->query('MountConfigManager');
1777
+    }
1778
+
1779
+    /**
1780
+     * Get the IniWrapper
1781
+     *
1782
+     * @return IniGetWrapper
1783
+     */
1784
+    public function getIniWrapper() {
1785
+        return $this->query('IniWrapper');
1786
+    }
1787
+
1788
+    /**
1789
+     * @return \OCP\Command\IBus
1790
+     */
1791
+    public function getCommandBus() {
1792
+        return $this->query('AsyncCommandBus');
1793
+    }
1794
+
1795
+    /**
1796
+     * Get the trusted domain helper
1797
+     *
1798
+     * @return TrustedDomainHelper
1799
+     */
1800
+    public function getTrustedDomainHelper() {
1801
+        return $this->query('TrustedDomainHelper');
1802
+    }
1803
+
1804
+    /**
1805
+     * Get the locking provider
1806
+     *
1807
+     * @return \OCP\Lock\ILockingProvider
1808
+     * @since 8.1.0
1809
+     */
1810
+    public function getLockingProvider() {
1811
+        return $this->query('LockingProvider');
1812
+    }
1813
+
1814
+    /**
1815
+     * @return \OCP\Files\Mount\IMountManager
1816
+     **/
1817
+    function getMountManager() {
1818
+        return $this->query('MountManager');
1819
+    }
1820
+
1821
+    /** @return \OCP\Files\Config\IUserMountCache */
1822
+    function getUserMountCache() {
1823
+        return $this->query('UserMountCache');
1824
+    }
1825
+
1826
+    /**
1827
+     * Get the MimeTypeDetector
1828
+     *
1829
+     * @return \OCP\Files\IMimeTypeDetector
1830
+     */
1831
+    public function getMimeTypeDetector() {
1832
+        return $this->query('MimeTypeDetector');
1833
+    }
1834
+
1835
+    /**
1836
+     * Get the MimeTypeLoader
1837
+     *
1838
+     * @return \OCP\Files\IMimeTypeLoader
1839
+     */
1840
+    public function getMimeTypeLoader() {
1841
+        return $this->query('MimeTypeLoader');
1842
+    }
1843
+
1844
+    /**
1845
+     * Get the manager of all the capabilities
1846
+     *
1847
+     * @return \OC\CapabilitiesManager
1848
+     */
1849
+    public function getCapabilitiesManager() {
1850
+        return $this->query('CapabilitiesManager');
1851
+    }
1852
+
1853
+    /**
1854
+     * Get the EventDispatcher
1855
+     *
1856
+     * @return EventDispatcherInterface
1857
+     * @since 8.2.0
1858
+     */
1859
+    public function getEventDispatcher() {
1860
+        return $this->query('EventDispatcher');
1861
+    }
1862
+
1863
+    /**
1864
+     * Get the Notification Manager
1865
+     *
1866
+     * @return \OCP\Notification\IManager
1867
+     * @since 8.2.0
1868
+     */
1869
+    public function getNotificationManager() {
1870
+        return $this->query('NotificationManager');
1871
+    }
1872
+
1873
+    /**
1874
+     * @return \OCP\Comments\ICommentsManager
1875
+     */
1876
+    public function getCommentsManager() {
1877
+        return $this->query('CommentsManager');
1878
+    }
1879
+
1880
+    /**
1881
+     * @return \OCA\Theming\ThemingDefaults
1882
+     */
1883
+    public function getThemingDefaults() {
1884
+        return $this->query('ThemingDefaults');
1885
+    }
1886
+
1887
+    /**
1888
+     * @return \OC\IntegrityCheck\Checker
1889
+     */
1890
+    public function getIntegrityCodeChecker() {
1891
+        return $this->query('IntegrityCodeChecker');
1892
+    }
1893
+
1894
+    /**
1895
+     * @return \OC\Session\CryptoWrapper
1896
+     */
1897
+    public function getSessionCryptoWrapper() {
1898
+        return $this->query('CryptoWrapper');
1899
+    }
1900
+
1901
+    /**
1902
+     * @return CsrfTokenManager
1903
+     */
1904
+    public function getCsrfTokenManager() {
1905
+        return $this->query('CsrfTokenManager');
1906
+    }
1907
+
1908
+    /**
1909
+     * @return Throttler
1910
+     */
1911
+    public function getBruteForceThrottler() {
1912
+        return $this->query('Throttler');
1913
+    }
1914
+
1915
+    /**
1916
+     * @return IContentSecurityPolicyManager
1917
+     */
1918
+    public function getContentSecurityPolicyManager() {
1919
+        return $this->query('ContentSecurityPolicyManager');
1920
+    }
1921
+
1922
+    /**
1923
+     * @return ContentSecurityPolicyNonceManager
1924
+     */
1925
+    public function getContentSecurityPolicyNonceManager() {
1926
+        return $this->query('ContentSecurityPolicyNonceManager');
1927
+    }
1928
+
1929
+    /**
1930
+     * Not a public API as of 8.2, wait for 9.0
1931
+     *
1932
+     * @return \OCA\Files_External\Service\BackendService
1933
+     */
1934
+    public function getStoragesBackendService() {
1935
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1936
+    }
1937
+
1938
+    /**
1939
+     * Not a public API as of 8.2, wait for 9.0
1940
+     *
1941
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1942
+     */
1943
+    public function getGlobalStoragesService() {
1944
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1945
+    }
1946
+
1947
+    /**
1948
+     * Not a public API as of 8.2, wait for 9.0
1949
+     *
1950
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1951
+     */
1952
+    public function getUserGlobalStoragesService() {
1953
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1954
+    }
1955
+
1956
+    /**
1957
+     * Not a public API as of 8.2, wait for 9.0
1958
+     *
1959
+     * @return \OCA\Files_External\Service\UserStoragesService
1960
+     */
1961
+    public function getUserStoragesService() {
1962
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1963
+    }
1964
+
1965
+    /**
1966
+     * @return \OCP\Share\IManager
1967
+     */
1968
+    public function getShareManager() {
1969
+        return $this->query('ShareManager');
1970
+    }
1971
+
1972
+    /**
1973
+     * @return \OCP\Collaboration\Collaborators\ISearch
1974
+     */
1975
+    public function getCollaboratorSearch() {
1976
+        return $this->query('CollaboratorSearch');
1977
+    }
1978
+
1979
+    /**
1980
+     * @return \OCP\Collaboration\AutoComplete\IManager
1981
+     */
1982
+    public function getAutoCompleteManager(){
1983
+        return $this->query(IManager::class);
1984
+    }
1985
+
1986
+    /**
1987
+     * Returns the LDAP Provider
1988
+     *
1989
+     * @return \OCP\LDAP\ILDAPProvider
1990
+     */
1991
+    public function getLDAPProvider() {
1992
+        return $this->query('LDAPProvider');
1993
+    }
1994
+
1995
+    /**
1996
+     * @return \OCP\Settings\IManager
1997
+     */
1998
+    public function getSettingsManager() {
1999
+        return $this->query('SettingsManager');
2000
+    }
2001
+
2002
+    /**
2003
+     * @return \OCP\Files\IAppData
2004
+     */
2005
+    public function getAppDataDir($app) {
2006
+        /** @var \OC\Files\AppData\Factory $factory */
2007
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
2008
+        return $factory->get($app);
2009
+    }
2010
+
2011
+    /**
2012
+     * @return \OCP\Lockdown\ILockdownManager
2013
+     */
2014
+    public function getLockdownManager() {
2015
+        return $this->query('LockdownManager');
2016
+    }
2017
+
2018
+    /**
2019
+     * @return \OCP\Federation\ICloudIdManager
2020
+     */
2021
+    public function getCloudIdManager() {
2022
+        return $this->query(ICloudIdManager::class);
2023
+    }
2024
+
2025
+    /**
2026
+     * @return \OCP\GlobalScale\IConfig
2027
+     */
2028
+    public function getGlobalScaleConfig() {
2029
+        return $this->query(IConfig::class);
2030
+    }
2031
+
2032
+    /**
2033
+     * @return \OCP\Federation\ICloudFederationProviderManager
2034
+     */
2035
+    public function getCloudFederationProviderManager() {
2036
+        return $this->query(ICloudFederationProviderManager::class);
2037
+    }
2038
+
2039
+    /**
2040
+     * @return \OCP\Remote\Api\IApiFactory
2041
+     */
2042
+    public function getRemoteApiFactory() {
2043
+        return $this->query(IApiFactory::class);
2044
+    }
2045
+
2046
+    /**
2047
+     * @return \OCP\Federation\ICloudFederationFactory
2048
+     */
2049
+    public function getCloudFederationFactory() {
2050
+        return $this->query(ICloudFederationFactory::class);
2051
+    }
2052
+
2053
+    /**
2054
+     * @return \OCP\Remote\IInstanceFactory
2055
+     */
2056
+    public function getRemoteInstanceFactory() {
2057
+        return $this->query(IInstanceFactory::class);
2058
+    }
2059
+
2060
+    /**
2061
+     * @return IStorageFactory
2062
+     */
2063
+    public function getStorageFactory() {
2064
+        return $this->query(IStorageFactory::class);
2065
+    }
2066 2066
 }
Please login to merge, or discard this patch.
lib/private/Avatar/UserAvatar.php 1 patch
Indentation   +289 added lines, -289 removed lines patch added patch discarded remove patch
@@ -39,293 +39,293 @@
 block discarded – undo
39 39
  * This class represents a registered user's avatar.
40 40
  */
41 41
 class UserAvatar extends Avatar {
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	/** @var ISimpleFolder */
46
-	private $folder;
47
-
48
-	/** @var IL10N */
49
-	private $l;
50
-
51
-	/** @var User */
52
-	private $user;
53
-
54
-	/**
55
-	 * UserAvatar constructor.
56
-	 *
57
-	 * @param IConfig $config The configuration
58
-	 * @param ISimpleFolder $folder The avatar files folder
59
-	 * @param IL10N $l The localization helper
60
-	 * @param User $user The user this class manages the avatar for
61
-	 * @param ILogger $logger The logger
62
-	 */
63
-	public function __construct(
64
-		ISimpleFolder $folder,
65
-		IL10N $l,
66
-		$user,
67
-		ILogger $logger,
68
-		IConfig $config) {
69
-		parent::__construct($logger);
70
-		$this->folder = $folder;
71
-		$this->l = $l;
72
-		$this->user = $user;
73
-		$this->config = $config;
74
-	}
75
-
76
-	/**
77
-	 * Check if an avatar exists for the user
78
-	 *
79
-	 * @return bool
80
-	 */
81
-	public function exists() {
82
-		return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
83
-	}
84
-
85
-	/**
86
-	 * Sets the users avatar.
87
-	 *
88
-	 * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
89
-	 * @throws \Exception if the provided file is not a jpg or png image
90
-	 * @throws \Exception if the provided image is not valid
91
-	 * @throws NotSquareException if the image is not square
92
-	 * @return void
93
-	 */
94
-	public function set($data) {
95
-		$img = $this->getAvatarImage($data);
96
-		$data = $img->data();
97
-
98
-		$this->validateAvatar($img);
99
-
100
-		$this->remove();
101
-		$type = $this->getAvatarImageType($img);
102
-		$file = $this->folder->newFile('avatar.' . $type);
103
-		$file->putContent($data);
104
-
105
-		try {
106
-			$generated = $this->folder->getFile('generated');
107
-			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'false');
108
-			$generated->delete();
109
-		} catch (NotFoundException $e) {
110
-			//
111
-		}
112
-
113
-		$this->user->triggerChange('avatar', $file);
114
-	}
115
-
116
-	/**
117
-	 * Returns an image from several sources.
118
-	 *
119
-	 * @param IImage|resource|string $data An image object, imagedata or path to the avatar
120
-	 * @return IImage
121
-	 */
122
-	private function getAvatarImage($data) {
123
-		if ($data instanceof IImage) {
124
-			return $data;
125
-		}
126
-
127
-		$img = new OC_Image();
128
-		if (is_resource($data) && get_resource_type($data) === 'gd') {
129
-			$img->setResource($data);
130
-		} elseif (is_resource($data)) {
131
-			$img->loadFromFileHandle($data);
132
-		} else {
133
-			try {
134
-				// detect if it is a path or maybe the images as string
135
-				$result = @realpath($data);
136
-				if ($result === false || $result === null) {
137
-					$img->loadFromData($data);
138
-				} else {
139
-					$img->loadFromFile($data);
140
-				}
141
-			} catch (\Error $e) {
142
-				$img->loadFromData($data);
143
-			}
144
-		}
145
-
146
-		return $img;
147
-	}
148
-
149
-	/**
150
-	 * Returns the avatar image type.
151
-	 *
152
-	 * @param IImage $avatar
153
-	 * @return string
154
-	 */
155
-	private function getAvatarImageType(IImage $avatar) {
156
-		$type = substr($avatar->mimeType(), -3);
157
-		if ($type === 'peg') {
158
-			$type = 'jpg';
159
-		}
160
-		return $type;
161
-	}
162
-
163
-	/**
164
-	 * Validates an avatar image:
165
-	 * - must be "png" or "jpg"
166
-	 * - must be "valid"
167
-	 * - must be in square format
168
-	 *
169
-	 * @param IImage $avatar The avatar to validate
170
-	 * @throws \Exception if the provided file is not a jpg or png image
171
-	 * @throws \Exception if the provided image is not valid
172
-	 * @throws NotSquareException if the image is not square
173
-	 */
174
-	private function validateAvatar(IImage $avatar) {
175
-		$type = $this->getAvatarImageType($avatar);
176
-
177
-		if ($type !== 'jpg' && $type !== 'png') {
178
-			throw new \Exception($this->l->t('Unknown filetype'));
179
-		}
180
-
181
-		if (!$avatar->valid()) {
182
-			throw new \Exception($this->l->t('Invalid image'));
183
-		}
184
-
185
-		if (!($avatar->height() === $avatar->width())) {
186
-			throw new NotSquareException($this->l->t('Avatar image is not square'));
187
-		}
188
-	}
189
-
190
-	/**
191
-	 * Removes the users avatar.
192
-	 * @return void
193
-	 * @throws \OCP\Files\NotPermittedException
194
-	 * @throws \OCP\PreConditionNotMetException
195
-	 */
196
-	public function remove() {
197
-		$avatars = $this->folder->getDirectoryListing();
198
-
199
-		$this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
200
-			(int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
201
-
202
-		foreach ($avatars as $avatar) {
203
-			$avatar->delete();
204
-		}
205
-		$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
206
-		$this->user->triggerChange('avatar', '');
207
-	}
208
-
209
-	/**
210
-	 * Get the extension of the avatar. If there is no avatar throw Exception
211
-	 *
212
-	 * @return string
213
-	 * @throws NotFoundException
214
-	 */
215
-	private function getExtension() {
216
-		if ($this->folder->fileExists('avatar.jpg')) {
217
-			return 'jpg';
218
-		} elseif ($this->folder->fileExists('avatar.png')) {
219
-			return 'png';
220
-		}
221
-		throw new NotFoundException;
222
-	}
223
-
224
-	/**
225
-	 * Returns the avatar for an user.
226
-	 *
227
-	 * If there is no avatar file yet, one is generated.
228
-	 *
229
-	 * @param int $size
230
-	 * @return ISimpleFile
231
-	 * @throws NotFoundException
232
-	 * @throws \OCP\Files\NotPermittedException
233
-	 * @throws \OCP\PreConditionNotMetException
234
-	 */
235
-	public function getFile($size) {
236
-		$size = (int) $size;
237
-
238
-		try {
239
-			$ext = $this->getExtension();
240
-		} catch (NotFoundException $e) {
241
-			if (!$data = $this->generateAvatarFromSvg(1024)) {
242
-				$data = $this->generateAvatar($this->getDisplayName(), 1024);
243
-			}
244
-			$avatar = $this->folder->newFile('avatar.png');
245
-			$avatar->putContent($data);
246
-			$ext = 'png';
247
-
248
-			$this->folder->newFile('generated');
249
-			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
250
-		}
251
-
252
-		if ($size === -1) {
253
-			$path = 'avatar.' . $ext;
254
-		} else {
255
-			$path = 'avatar.' . $size . '.' . $ext;
256
-		}
257
-
258
-		try {
259
-			$file = $this->folder->getFile($path);
260
-		} catch (NotFoundException $e) {
261
-			if ($size <= 0) {
262
-				throw new NotFoundException;
263
-			}
264
-
265
-			if ($this->folder->fileExists('generated')) {
266
-				if (!$data = $this->generateAvatarFromSvg($size)) {
267
-					$data = $this->generateAvatar($this->getDisplayName(), $size);
268
-				}
269
-
270
-			} else {
271
-				$avatar = new OC_Image();
272
-				$file = $this->folder->getFile('avatar.' . $ext);
273
-				$avatar->loadFromData($file->getContent());
274
-				$avatar->resize($size);
275
-				$data = $avatar->data();
276
-			}
277
-
278
-			try {
279
-				$file = $this->folder->newFile($path);
280
-				$file->putContent($data);
281
-			} catch (NotPermittedException $e) {
282
-				$this->logger->error('Failed to save avatar for ' . $this->user->getUID());
283
-				throw new NotFoundException();
284
-			}
285
-
286
-		}
287
-
288
-		if ($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
289
-			$generated = $this->folder->fileExists('generated') ? 'true' : 'false';
290
-			$this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', $generated);
291
-		}
292
-
293
-		return $file;
294
-	}
295
-
296
-	/**
297
-	 * Returns the user display name.
298
-	 *
299
-	 * @return string
300
-	 */
301
-	public function getDisplayName(): string {
302
-		return $this->user->getDisplayName();
303
-	}
304
-
305
-	/**
306
-	 * Handles user changes.
307
-	 *
308
-	 * @param string $feature The changed feature
309
-	 * @param mixed $oldValue The previous value
310
-	 * @param mixed $newValue The new value
311
-	 * @throws NotPermittedException
312
-	 * @throws \OCP\PreConditionNotMetException
313
-	 */
314
-	public function userChanged($feature, $oldValue, $newValue) {
315
-		// If the avatar is not generated (so an uploaded image) we skip this
316
-		if (!$this->folder->fileExists('generated')) {
317
-			return;
318
-		}
319
-
320
-		$this->remove();
321
-	}
322
-
323
-	/**
324
-	 * Check if the avatar of a user is a custom uploaded one
325
-	 *
326
-	 * @return bool
327
-	 */
328
-	public function isCustomAvatar(): bool {
329
-		return $this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', 'false') !== 'true';
330
-	}
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    /** @var ISimpleFolder */
46
+    private $folder;
47
+
48
+    /** @var IL10N */
49
+    private $l;
50
+
51
+    /** @var User */
52
+    private $user;
53
+
54
+    /**
55
+     * UserAvatar constructor.
56
+     *
57
+     * @param IConfig $config The configuration
58
+     * @param ISimpleFolder $folder The avatar files folder
59
+     * @param IL10N $l The localization helper
60
+     * @param User $user The user this class manages the avatar for
61
+     * @param ILogger $logger The logger
62
+     */
63
+    public function __construct(
64
+        ISimpleFolder $folder,
65
+        IL10N $l,
66
+        $user,
67
+        ILogger $logger,
68
+        IConfig $config) {
69
+        parent::__construct($logger);
70
+        $this->folder = $folder;
71
+        $this->l = $l;
72
+        $this->user = $user;
73
+        $this->config = $config;
74
+    }
75
+
76
+    /**
77
+     * Check if an avatar exists for the user
78
+     *
79
+     * @return bool
80
+     */
81
+    public function exists() {
82
+        return $this->folder->fileExists('avatar.jpg') || $this->folder->fileExists('avatar.png');
83
+    }
84
+
85
+    /**
86
+     * Sets the users avatar.
87
+     *
88
+     * @param IImage|resource|string $data An image object, imagedata or path to set a new avatar
89
+     * @throws \Exception if the provided file is not a jpg or png image
90
+     * @throws \Exception if the provided image is not valid
91
+     * @throws NotSquareException if the image is not square
92
+     * @return void
93
+     */
94
+    public function set($data) {
95
+        $img = $this->getAvatarImage($data);
96
+        $data = $img->data();
97
+
98
+        $this->validateAvatar($img);
99
+
100
+        $this->remove();
101
+        $type = $this->getAvatarImageType($img);
102
+        $file = $this->folder->newFile('avatar.' . $type);
103
+        $file->putContent($data);
104
+
105
+        try {
106
+            $generated = $this->folder->getFile('generated');
107
+            $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'false');
108
+            $generated->delete();
109
+        } catch (NotFoundException $e) {
110
+            //
111
+        }
112
+
113
+        $this->user->triggerChange('avatar', $file);
114
+    }
115
+
116
+    /**
117
+     * Returns an image from several sources.
118
+     *
119
+     * @param IImage|resource|string $data An image object, imagedata or path to the avatar
120
+     * @return IImage
121
+     */
122
+    private function getAvatarImage($data) {
123
+        if ($data instanceof IImage) {
124
+            return $data;
125
+        }
126
+
127
+        $img = new OC_Image();
128
+        if (is_resource($data) && get_resource_type($data) === 'gd') {
129
+            $img->setResource($data);
130
+        } elseif (is_resource($data)) {
131
+            $img->loadFromFileHandle($data);
132
+        } else {
133
+            try {
134
+                // detect if it is a path or maybe the images as string
135
+                $result = @realpath($data);
136
+                if ($result === false || $result === null) {
137
+                    $img->loadFromData($data);
138
+                } else {
139
+                    $img->loadFromFile($data);
140
+                }
141
+            } catch (\Error $e) {
142
+                $img->loadFromData($data);
143
+            }
144
+        }
145
+
146
+        return $img;
147
+    }
148
+
149
+    /**
150
+     * Returns the avatar image type.
151
+     *
152
+     * @param IImage $avatar
153
+     * @return string
154
+     */
155
+    private function getAvatarImageType(IImage $avatar) {
156
+        $type = substr($avatar->mimeType(), -3);
157
+        if ($type === 'peg') {
158
+            $type = 'jpg';
159
+        }
160
+        return $type;
161
+    }
162
+
163
+    /**
164
+     * Validates an avatar image:
165
+     * - must be "png" or "jpg"
166
+     * - must be "valid"
167
+     * - must be in square format
168
+     *
169
+     * @param IImage $avatar The avatar to validate
170
+     * @throws \Exception if the provided file is not a jpg or png image
171
+     * @throws \Exception if the provided image is not valid
172
+     * @throws NotSquareException if the image is not square
173
+     */
174
+    private function validateAvatar(IImage $avatar) {
175
+        $type = $this->getAvatarImageType($avatar);
176
+
177
+        if ($type !== 'jpg' && $type !== 'png') {
178
+            throw new \Exception($this->l->t('Unknown filetype'));
179
+        }
180
+
181
+        if (!$avatar->valid()) {
182
+            throw new \Exception($this->l->t('Invalid image'));
183
+        }
184
+
185
+        if (!($avatar->height() === $avatar->width())) {
186
+            throw new NotSquareException($this->l->t('Avatar image is not square'));
187
+        }
188
+    }
189
+
190
+    /**
191
+     * Removes the users avatar.
192
+     * @return void
193
+     * @throws \OCP\Files\NotPermittedException
194
+     * @throws \OCP\PreConditionNotMetException
195
+     */
196
+    public function remove() {
197
+        $avatars = $this->folder->getDirectoryListing();
198
+
199
+        $this->config->setUserValue($this->user->getUID(), 'avatar', 'version',
200
+            (int) $this->config->getUserValue($this->user->getUID(), 'avatar', 'version', 0) + 1);
201
+
202
+        foreach ($avatars as $avatar) {
203
+            $avatar->delete();
204
+        }
205
+        $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
206
+        $this->user->triggerChange('avatar', '');
207
+    }
208
+
209
+    /**
210
+     * Get the extension of the avatar. If there is no avatar throw Exception
211
+     *
212
+     * @return string
213
+     * @throws NotFoundException
214
+     */
215
+    private function getExtension() {
216
+        if ($this->folder->fileExists('avatar.jpg')) {
217
+            return 'jpg';
218
+        } elseif ($this->folder->fileExists('avatar.png')) {
219
+            return 'png';
220
+        }
221
+        throw new NotFoundException;
222
+    }
223
+
224
+    /**
225
+     * Returns the avatar for an user.
226
+     *
227
+     * If there is no avatar file yet, one is generated.
228
+     *
229
+     * @param int $size
230
+     * @return ISimpleFile
231
+     * @throws NotFoundException
232
+     * @throws \OCP\Files\NotPermittedException
233
+     * @throws \OCP\PreConditionNotMetException
234
+     */
235
+    public function getFile($size) {
236
+        $size = (int) $size;
237
+
238
+        try {
239
+            $ext = $this->getExtension();
240
+        } catch (NotFoundException $e) {
241
+            if (!$data = $this->generateAvatarFromSvg(1024)) {
242
+                $data = $this->generateAvatar($this->getDisplayName(), 1024);
243
+            }
244
+            $avatar = $this->folder->newFile('avatar.png');
245
+            $avatar->putContent($data);
246
+            $ext = 'png';
247
+
248
+            $this->folder->newFile('generated');
249
+            $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', 'true');
250
+        }
251
+
252
+        if ($size === -1) {
253
+            $path = 'avatar.' . $ext;
254
+        } else {
255
+            $path = 'avatar.' . $size . '.' . $ext;
256
+        }
257
+
258
+        try {
259
+            $file = $this->folder->getFile($path);
260
+        } catch (NotFoundException $e) {
261
+            if ($size <= 0) {
262
+                throw new NotFoundException;
263
+            }
264
+
265
+            if ($this->folder->fileExists('generated')) {
266
+                if (!$data = $this->generateAvatarFromSvg($size)) {
267
+                    $data = $this->generateAvatar($this->getDisplayName(), $size);
268
+                }
269
+
270
+            } else {
271
+                $avatar = new OC_Image();
272
+                $file = $this->folder->getFile('avatar.' . $ext);
273
+                $avatar->loadFromData($file->getContent());
274
+                $avatar->resize($size);
275
+                $data = $avatar->data();
276
+            }
277
+
278
+            try {
279
+                $file = $this->folder->newFile($path);
280
+                $file->putContent($data);
281
+            } catch (NotPermittedException $e) {
282
+                $this->logger->error('Failed to save avatar for ' . $this->user->getUID());
283
+                throw new NotFoundException();
284
+            }
285
+
286
+        }
287
+
288
+        if ($this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', null) === null) {
289
+            $generated = $this->folder->fileExists('generated') ? 'true' : 'false';
290
+            $this->config->setUserValue($this->user->getUID(), 'avatar', 'generated', $generated);
291
+        }
292
+
293
+        return $file;
294
+    }
295
+
296
+    /**
297
+     * Returns the user display name.
298
+     *
299
+     * @return string
300
+     */
301
+    public function getDisplayName(): string {
302
+        return $this->user->getDisplayName();
303
+    }
304
+
305
+    /**
306
+     * Handles user changes.
307
+     *
308
+     * @param string $feature The changed feature
309
+     * @param mixed $oldValue The previous value
310
+     * @param mixed $newValue The new value
311
+     * @throws NotPermittedException
312
+     * @throws \OCP\PreConditionNotMetException
313
+     */
314
+    public function userChanged($feature, $oldValue, $newValue) {
315
+        // If the avatar is not generated (so an uploaded image) we skip this
316
+        if (!$this->folder->fileExists('generated')) {
317
+            return;
318
+        }
319
+
320
+        $this->remove();
321
+    }
322
+
323
+    /**
324
+     * Check if the avatar of a user is a custom uploaded one
325
+     *
326
+     * @return bool
327
+     */
328
+    public function isCustomAvatar(): bool {
329
+        return $this->config->getUserValue($this->user->getUID(), 'avatar', 'generated', 'false') !== 'true';
330
+    }
331 331
 }
Please login to merge, or discard this patch.