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