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