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