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