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