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