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