Passed
Push — master ( 1f4312...5a0318 )
by John
27:53 queued 17:39
created
core/Command/Maintenance/Mimetype/UpdateJS.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -33,30 +33,30 @@
 block discarded – undo
33 33
 
34 34
 class UpdateJS extends Command {
35 35
 
36
-	/** @var IMimeTypeDetector */
37
-	protected $mimetypeDetector;
38
-
39
-	public function __construct(
40
-		IMimeTypeDetector $mimetypeDetector
41
-	) {
42
-		parent::__construct();
43
-		$this->mimetypeDetector = $mimetypeDetector;
44
-	}
45
-
46
-	protected function configure() {
47
-		$this
48
-			->setName('maintenance:mimetype:update-js')
49
-			->setDescription('Update mimetypelist.js');
50
-	}
51
-
52
-	protected function execute(InputInterface $input, OutputInterface $output) {
53
-		// Fetch all the aliases
54
-		$aliases = $this->mimetypeDetector->getAllAliases();
55
-
56
-		// Output the JS
57
-		$generatedMimetypeFile = new GenerateMimetypeFileBuilder();
58
-		file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases));
59
-
60
-		$output->writeln('<info>mimetypelist.js is updated');
61
-	}
36
+    /** @var IMimeTypeDetector */
37
+    protected $mimetypeDetector;
38
+
39
+    public function __construct(
40
+        IMimeTypeDetector $mimetypeDetector
41
+    ) {
42
+        parent::__construct();
43
+        $this->mimetypeDetector = $mimetypeDetector;
44
+    }
45
+
46
+    protected function configure() {
47
+        $this
48
+            ->setName('maintenance:mimetype:update-js')
49
+            ->setDescription('Update mimetypelist.js');
50
+    }
51
+
52
+    protected function execute(InputInterface $input, OutputInterface $output) {
53
+        // Fetch all the aliases
54
+        $aliases = $this->mimetypeDetector->getAllAliases();
55
+
56
+        // Output the JS
57
+        $generatedMimetypeFile = new GenerateMimetypeFileBuilder();
58
+        file_put_contents(\OC::$SERVERROOT.'/core/js/mimetypelist.js', $generatedMimetypeFile->generateFile($aliases));
59
+
60
+        $output->writeln('<info>mimetypelist.js is updated');
61
+    }
62 62
 }
Please login to merge, or discard this patch.
core/Command/Maintenance/Mimetype/GenerateMimetypeFileBuilder.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -25,68 +25,68 @@  discard block
 block discarded – undo
25 25
 
26 26
 class GenerateMimetypeFileBuilder
27 27
 {
28
-	/**
29
-	 * Generate mime type list file
30
-	 * @param $aliases
31
-	 * @return string
32
-	 */
33
-	public function generateFile(array $aliases): string {
34
-		// Remove comments
35
-		$keys = array_filter(array_keys($aliases), function($k) {
36
-			return $k[0] === '_';
37
-		});
38
-		foreach($keys as $key) {
39
-			unset($aliases[$key]);
40
-		}
28
+    /**
29
+     * Generate mime type list file
30
+     * @param $aliases
31
+     * @return string
32
+     */
33
+    public function generateFile(array $aliases): string {
34
+        // Remove comments
35
+        $keys = array_filter(array_keys($aliases), function($k) {
36
+            return $k[0] === '_';
37
+        });
38
+        foreach($keys as $key) {
39
+            unset($aliases[$key]);
40
+        }
41 41
 
42
-		// Fetch all files
43
-		$dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
42
+        // Fetch all files
43
+        $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
44 44
 
45
-		$files = [];
46
-		foreach($dir as $fileInfo) {
47
-			if ($fileInfo->isFile()) {
48
-				$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
49
-				$files[] = $file;
50
-			}
51
-		}
45
+        $files = [];
46
+        foreach($dir as $fileInfo) {
47
+            if ($fileInfo->isFile()) {
48
+                $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
49
+                $files[] = $file;
50
+            }
51
+        }
52 52
 
53
-		//Remove duplicates
54
-		$files = array_values(array_unique($files));
55
-		sort($files);
53
+        //Remove duplicates
54
+        $files = array_values(array_unique($files));
55
+        sort($files);
56 56
 
57
-		// Fetch all themes!
58
-		$themes = [];
59
-		$dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
60
-		foreach($dirs as $dir) {
61
-			//Valid theme dir
62
-			if ($dir->isFile() || $dir->isDot()) {
63
-				continue;
64
-			}
57
+        // Fetch all themes!
58
+        $themes = [];
59
+        $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
60
+        foreach($dirs as $dir) {
61
+            //Valid theme dir
62
+            if ($dir->isFile() || $dir->isDot()) {
63
+                continue;
64
+            }
65 65
 
66
-			$theme = $dir->getFilename();
67
-			$themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
68
-			// Check if this theme has its own filetype icons
69
-			if (!file_exists($themeDir)) {
70
-				continue;
71
-			}
66
+            $theme = $dir->getFilename();
67
+            $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
68
+            // Check if this theme has its own filetype icons
69
+            if (!file_exists($themeDir)) {
70
+                continue;
71
+            }
72 72
 
73
-			$themes[$theme] = [];
74
-			// Fetch all the theme icons!
75
-			$themeIt = new \DirectoryIterator($themeDir);
76
-			foreach ($themeIt as $fileInfo) {
77
-				if ($fileInfo->isFile()) {
78
-					$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
79
-					$themes[$theme][] = $file;
80
-				}
81
-			}
73
+            $themes[$theme] = [];
74
+            // Fetch all the theme icons!
75
+            $themeIt = new \DirectoryIterator($themeDir);
76
+            foreach ($themeIt as $fileInfo) {
77
+                if ($fileInfo->isFile()) {
78
+                    $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
79
+                    $themes[$theme][] = $file;
80
+                }
81
+            }
82 82
 
83
-			//Remove Duplicates
84
-			$themes[$theme] = array_values(array_unique($themes[$theme]));
85
-			sort($themes[$theme]);
86
-		}
83
+            //Remove Duplicates
84
+            $themes[$theme] = array_values(array_unique($themes[$theme]));
85
+            sort($themes[$theme]);
86
+        }
87 87
 
88
-		//Generate the JS
89
-		return '/**
88
+        //Generate the JS
89
+        return '/**
90 90
 * This file is automatically generated
91 91
 * DO NOT EDIT MANUALLY!
92 92
 *
@@ -100,6 +100,6 @@  discard block
 block discarded – undo
100 100
 	themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
101 101
 };
102 102
 ';
103
-	}
103
+    }
104 104
 
105 105
 }
106 106
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 		$keys = array_filter(array_keys($aliases), function($k) {
36 36
 			return $k[0] === '_';
37 37
 		});
38
-		foreach($keys as $key) {
38
+		foreach ($keys as $key) {
39 39
 			unset($aliases[$key]);
40 40
 		}
41 41
 
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 		$dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes');
44 44
 
45 45
 		$files = [];
46
-		foreach($dir as $fileInfo) {
46
+		foreach ($dir as $fileInfo) {
47 47
 			if ($fileInfo->isFile()) {
48 48
 				$file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename());
49 49
 				$files[] = $file;
@@ -57,14 +57,14 @@  discard block
 block discarded – undo
57 57
 		// Fetch all themes!
58 58
 		$themes = [];
59 59
 		$dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/');
60
-		foreach($dirs as $dir) {
60
+		foreach ($dirs as $dir) {
61 61
 			//Valid theme dir
62 62
 			if ($dir->isFile() || $dir->isDot()) {
63 63
 				continue;
64 64
 			}
65 65
 
66 66
 			$theme = $dir->getFilename();
67
-			$themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/';
67
+			$themeDir = $dir->getPath().'/'.$theme.'/core/img/filetypes/';
68 68
 			// Check if this theme has its own filetype icons
69 69
 			if (!file_exists($themeDir)) {
70 70
 				continue;
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 * To regenerate this file run ./occ maintenance:mimetype:update-js
96 96
 */
97 97
 OC.MimeTypeList={
98
-	aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ',
99
-	files: ' . json_encode($files, JSON_PRETTY_PRINT) . ',
100
-	themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . '
98
+	aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).',
99
+	files: ' . json_encode($files, JSON_PRETTY_PRINT).',
100
+	themes: ' . json_encode($themes, JSON_PRETTY_PRINT).'
101 101
 };
102 102
 ';
103 103
 	}
Please login to merge, or discard this patch.
lib/private/IntegrityCheck/Checker.php 2 patches
Indentation   +536 added lines, -536 removed lines patch added patch discarded remove patch
@@ -54,540 +54,540 @@
 block discarded – undo
54 54
  * @package OC\IntegrityCheck
55 55
  */
56 56
 class Checker {
57
-	const CACHE_KEY = 'oc.integritycheck.checker';
58
-	/** @var EnvironmentHelper */
59
-	private $environmentHelper;
60
-	/** @var AppLocator */
61
-	private $appLocator;
62
-	/** @var FileAccessHelper */
63
-	private $fileAccessHelper;
64
-	/** @var IConfig */
65
-	private $config;
66
-	/** @var ICache */
67
-	private $cache;
68
-	/** @var IAppManager */
69
-	private $appManager;
70
-	/** @var ITempManager */
71
-	private $tempManager;
72
-	/** @var IMimeTypeDetector */
73
-	private $mimeTypeDetector;
74
-
75
-	/**
76
-	 * @param EnvironmentHelper $environmentHelper
77
-	 * @param FileAccessHelper $fileAccessHelper
78
-	 * @param AppLocator $appLocator
79
-	 * @param IConfig $config
80
-	 * @param ICacheFactory $cacheFactory
81
-	 * @param IAppManager $appManager
82
-	 * @param ITempManager $tempManager
83
-	 * @param IMimeTypeDetector $mimeTypeDetector
84
-	 */
85
-	public function __construct(EnvironmentHelper $environmentHelper,
86
-								FileAccessHelper $fileAccessHelper,
87
-								AppLocator $appLocator,
88
-								IConfig $config = null,
89
-								ICacheFactory $cacheFactory,
90
-								IAppManager $appManager = null,
91
-								ITempManager $tempManager,
92
-								IMimeTypeDetector $mimeTypeDetector) {
93
-		$this->environmentHelper = $environmentHelper;
94
-		$this->fileAccessHelper = $fileAccessHelper;
95
-		$this->appLocator = $appLocator;
96
-		$this->config = $config;
97
-		$this->cache = $cacheFactory->createDistributed(self::CACHE_KEY);
98
-		$this->appManager = $appManager;
99
-		$this->tempManager = $tempManager;
100
-		$this->mimeTypeDetector = $mimeTypeDetector;
101
-	}
102
-
103
-	/**
104
-	 * Whether code signing is enforced or not.
105
-	 *
106
-	 * @return bool
107
-	 */
108
-	public function isCodeCheckEnforced(): bool {
109
-		$notSignedChannels = [ '', 'git'];
110
-		if (\in_array($this->environmentHelper->getChannel(), $notSignedChannels, true)) {
111
-			return false;
112
-		}
113
-
114
-		/**
115
-		 * This config option is undocumented and supposed to be so, it's only
116
-		 * applicable for very specific scenarios and we should not advertise it
117
-		 * too prominent. So please do not add it to config.sample.php.
118
-		 */
119
-		$isIntegrityCheckDisabled = false;
120
-		if ($this->config !== null) {
121
-			$isIntegrityCheckDisabled = $this->config->getSystemValue('integrity.check.disabled', false);
122
-		}
123
-		if ($isIntegrityCheckDisabled === true) {
124
-			return false;
125
-		}
126
-
127
-		return true;
128
-	}
129
-
130
-	/**
131
-	 * Enumerates all files belonging to the folder. Sensible defaults are excluded.
132
-	 *
133
-	 * @param string $folderToIterate
134
-	 * @param string $root
135
-	 * @return \RecursiveIteratorIterator
136
-	 * @throws \Exception
137
-	 */
138
-	private function getFolderIterator(string $folderToIterate, string $root = ''): \RecursiveIteratorIterator {
139
-		$dirItr = new \RecursiveDirectoryIterator(
140
-			$folderToIterate,
141
-			\RecursiveDirectoryIterator::SKIP_DOTS
142
-		);
143
-		if($root === '') {
144
-			$root = \OC::$SERVERROOT;
145
-		}
146
-		$root = rtrim($root, '/');
147
-
148
-		$excludeGenericFilesIterator = new ExcludeFileByNameFilterIterator($dirItr);
149
-		$excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator, $root);
150
-
151
-		return new \RecursiveIteratorIterator(
152
-			$excludeFoldersIterator,
153
-			\RecursiveIteratorIterator::SELF_FIRST
154
-		);
155
-	}
156
-
157
-	/**
158
-	 * Returns an array of ['filename' => 'SHA512-hash-of-file'] for all files found
159
-	 * in the iterator.
160
-	 *
161
-	 * @param \RecursiveIteratorIterator $iterator
162
-	 * @param string $path
163
-	 * @return array Array of hashes.
164
-	 */
165
-	private function generateHashes(\RecursiveIteratorIterator $iterator,
166
-									string $path): array {
167
-		$hashes = [];
168
-
169
-		$baseDirectoryLength = \strlen($path);
170
-		foreach($iterator as $filename => $data) {
171
-			/** @var \DirectoryIterator $data */
172
-			if($data->isDir()) {
173
-				continue;
174
-			}
175
-
176
-			$relativeFileName = substr($filename, $baseDirectoryLength);
177
-			$relativeFileName = ltrim($relativeFileName, '/');
178
-
179
-			// Exclude signature.json files in the appinfo and root folder
180
-			if($relativeFileName === 'appinfo/signature.json') {
181
-				continue;
182
-			}
183
-			// Exclude signature.json files in the appinfo and core folder
184
-			if($relativeFileName === 'core/signature.json') {
185
-				continue;
186
-			}
187
-
188
-			// The .htaccess file in the root folder of ownCloud can contain
189
-			// custom content after the installation due to the fact that dynamic
190
-			// content is written into it at installation time as well. This
191
-			// includes for example the 404 and 403 instructions.
192
-			// Thus we ignore everything below the first occurrence of
193
-			// "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the
194
-			// hash generated based on this.
195
-			if($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') {
196
-				$fileContent = file_get_contents($filename);
197
-				$explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent);
198
-				if(\count($explodedArray) === 2) {
199
-					$hashes[$relativeFileName] = hash('sha512', $explodedArray[0]);
200
-					continue;
201
-				}
202
-			}
203
-			if ($filename === $this->environmentHelper->getServerRoot() . '/core/js/mimetypelist.js') {
204
-				$oldMimetypeList = new GenerateMimetypeFileBuilder();
205
-				$newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases());
206
-				if($newFile === file_get_contents($filename)) {
207
-					$hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases()));
208
-					continue;
209
-				}
210
-			}
211
-
212
-			$hashes[$relativeFileName] = hash_file('sha512', $filename);
213
-		}
214
-
215
-		return $hashes;
216
-	}
217
-
218
-	/**
219
-	 * Creates the signature data
220
-	 *
221
-	 * @param array $hashes
222
-	 * @param X509 $certificate
223
-	 * @param RSA $privateKey
224
-	 * @return array
225
-	 */
226
-	private function createSignatureData(array $hashes,
227
-										 X509 $certificate,
228
-										 RSA $privateKey): array {
229
-		ksort($hashes);
230
-
231
-		$privateKey->setSignatureMode(RSA::SIGNATURE_PSS);
232
-		$privateKey->setMGFHash('sha512');
233
-		// See https://tools.ietf.org/html/rfc3447#page-38
234
-		$privateKey->setSaltLength(0);
235
-		$signature = $privateKey->sign(json_encode($hashes));
236
-
237
-		return [
238
-				'hashes' => $hashes,
239
-				'signature' => base64_encode($signature),
240
-				'certificate' => $certificate->saveX509($certificate->currentCert),
241
-			];
242
-	}
243
-
244
-	/**
245
-	 * Write the signature of the app in the specified folder
246
-	 *
247
-	 * @param string $path
248
-	 * @param X509 $certificate
249
-	 * @param RSA $privateKey
250
-	 * @throws \Exception
251
-	 */
252
-	public function writeAppSignature($path,
253
-									  X509 $certificate,
254
-									  RSA $privateKey) {
255
-		$appInfoDir = $path . '/appinfo';
256
-		try {
257
-			$this->fileAccessHelper->assertDirectoryExists($appInfoDir);
258
-
259
-			$iterator = $this->getFolderIterator($path);
260
-			$hashes = $this->generateHashes($iterator, $path);
261
-			$signature = $this->createSignatureData($hashes, $certificate, $privateKey);
262
-				$this->fileAccessHelper->file_put_contents(
263
-					$appInfoDir . '/signature.json',
264
-				json_encode($signature, JSON_PRETTY_PRINT)
265
-			);
266
-		} catch (\Exception $e){
267
-			if (!$this->fileAccessHelper->is_writable($appInfoDir)) {
268
-				throw new \Exception($appInfoDir . ' is not writable');
269
-			}
270
-			throw $e;
271
-		}
272
-	}
273
-
274
-	/**
275
-	 * Write the signature of core
276
-	 *
277
-	 * @param X509 $certificate
278
-	 * @param RSA $rsa
279
-	 * @param string $path
280
-	 * @throws \Exception
281
-	 */
282
-	public function writeCoreSignature(X509 $certificate,
283
-									   RSA $rsa,
284
-									   $path) {
285
-		$coreDir = $path . '/core';
286
-		try {
287
-
288
-			$this->fileAccessHelper->assertDirectoryExists($coreDir);
289
-			$iterator = $this->getFolderIterator($path, $path);
290
-			$hashes = $this->generateHashes($iterator, $path);
291
-			$signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
292
-			$this->fileAccessHelper->file_put_contents(
293
-				$coreDir . '/signature.json',
294
-				json_encode($signatureData, JSON_PRETTY_PRINT)
295
-			);
296
-		} catch (\Exception $e){
297
-			if (!$this->fileAccessHelper->is_writable($coreDir)) {
298
-				throw new \Exception($coreDir . ' is not writable');
299
-			}
300
-			throw $e;
301
-		}
302
-	}
303
-
304
-	/**
305
-	 * Verifies the signature for the specified path.
306
-	 *
307
-	 * @param string $signaturePath
308
-	 * @param string $basePath
309
-	 * @param string $certificateCN
310
-	 * @return array
311
-	 * @throws InvalidSignatureException
312
-	 * @throws \Exception
313
-	 */
314
-	private function verify(string $signaturePath, string $basePath, string $certificateCN): array {
315
-		if(!$this->isCodeCheckEnforced()) {
316
-			return [];
317
-		}
318
-
319
-		$content = $this->fileAccessHelper->file_get_contents($signaturePath);
320
-		$signatureData = null;
321
-
322
-		if (\is_string($content)) {
323
-			$signatureData = json_decode($content, true);
324
-		}
325
-		if(!\is_array($signatureData)) {
326
-			throw new InvalidSignatureException('Signature data not found.');
327
-		}
328
-
329
-		$expectedHashes = $signatureData['hashes'];
330
-		ksort($expectedHashes);
331
-		$signature = base64_decode($signatureData['signature']);
332
-		$certificate = $signatureData['certificate'];
333
-
334
-		// Check if certificate is signed by Nextcloud Root Authority
335
-		$x509 = new \phpseclib\File\X509();
336
-		$rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt');
337
-		$x509->loadCA($rootCertificatePublicKey);
338
-		$x509->loadX509($certificate);
339
-		if(!$x509->validateSignature()) {
340
-			throw new InvalidSignatureException('Certificate is not valid.');
341
-		}
342
-		// Verify if certificate has proper CN. "core" CN is always trusted.
343
-		if($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') {
344
-			throw new InvalidSignatureException(
345
-					sprintf('Certificate is not valid for required scope. (Requested: %s, current: CN=%s)', $certificateCN, $x509->getDN(true)['CN'])
346
-			);
347
-		}
348
-
349
-		// Check if the signature of the files is valid
350
-		$rsa = new \phpseclib\Crypt\RSA();
351
-		$rsa->loadKey($x509->currentCert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey']);
352
-		$rsa->setSignatureMode(RSA::SIGNATURE_PSS);
353
-		$rsa->setMGFHash('sha512');
354
-		// See https://tools.ietf.org/html/rfc3447#page-38
355
-		$rsa->setSaltLength(0);
356
-		if(!$rsa->verify(json_encode($expectedHashes), $signature)) {
357
-			throw new InvalidSignatureException('Signature could not get verified.');
358
-		}
359
-
360
-		// Fixes for the updater as shipped with ownCloud 9.0.x: The updater is
361
-		// replaced after the code integrity check is performed.
362
-		//
363
-		// Due to this reason we exclude the whole updater/ folder from the code
364
-		// integrity check.
365
-		if($basePath === $this->environmentHelper->getServerRoot()) {
366
-			foreach($expectedHashes as $fileName => $hash) {
367
-				if(strpos($fileName, 'updater/') === 0) {
368
-					unset($expectedHashes[$fileName]);
369
-				}
370
-			}
371
-		}
372
-
373
-		// Compare the list of files which are not identical
374
-		$currentInstanceHashes = $this->generateHashes($this->getFolderIterator($basePath), $basePath);
375
-		$differencesA = array_diff($expectedHashes, $currentInstanceHashes);
376
-		$differencesB = array_diff($currentInstanceHashes, $expectedHashes);
377
-		$differences = array_unique(array_merge($differencesA, $differencesB));
378
-		$differenceArray = [];
379
-		foreach($differences as $filename => $hash) {
380
-			// Check if file should not exist in the new signature table
381
-			if(!array_key_exists($filename, $expectedHashes)) {
382
-				$differenceArray['EXTRA_FILE'][$filename]['expected'] = '';
383
-				$differenceArray['EXTRA_FILE'][$filename]['current'] = $hash;
384
-				continue;
385
-			}
386
-
387
-			// Check if file is missing
388
-			if(!array_key_exists($filename, $currentInstanceHashes)) {
389
-				$differenceArray['FILE_MISSING'][$filename]['expected'] = $expectedHashes[$filename];
390
-				$differenceArray['FILE_MISSING'][$filename]['current'] = '';
391
-				continue;
392
-			}
393
-
394
-			// Check if hash does mismatch
395
-			if($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) {
396
-				$differenceArray['INVALID_HASH'][$filename]['expected'] = $expectedHashes[$filename];
397
-				$differenceArray['INVALID_HASH'][$filename]['current'] = $currentInstanceHashes[$filename];
398
-				continue;
399
-			}
400
-
401
-			// Should never happen.
402
-			throw new \Exception('Invalid behaviour in file hash comparison experienced. Please report this error to the developers.');
403
-		}
404
-
405
-		return $differenceArray;
406
-	}
407
-
408
-	/**
409
-	 * Whether the code integrity check has passed successful or not
410
-	 *
411
-	 * @return bool
412
-	 */
413
-	public function hasPassedCheck(): bool {
414
-		$results = $this->getResults();
415
-		if(empty($results)) {
416
-			return true;
417
-		}
418
-
419
-		return false;
420
-	}
421
-
422
-	/**
423
-	 * @return array
424
-	 */
425
-	public function getResults(): array {
426
-		$cachedResults = $this->cache->get(self::CACHE_KEY);
427
-		if(!\is_null($cachedResults)) {
428
-			return json_decode($cachedResults, true);
429
-		}
430
-
431
-		if ($this->config !== null) {
432
-			return json_decode($this->config->getAppValue('core', self::CACHE_KEY, '{}'), true);
433
-		}
434
-		return [];
435
-	}
436
-
437
-	/**
438
-	 * Stores the results in the app config as well as cache
439
-	 *
440
-	 * @param string $scope
441
-	 * @param array $result
442
-	 */
443
-	private function storeResults(string $scope, array $result) {
444
-		$resultArray = $this->getResults();
445
-		unset($resultArray[$scope]);
446
-		if(!empty($result)) {
447
-			$resultArray[$scope] = $result;
448
-		}
449
-		if ($this->config !== null) {
450
-			$this->config->setAppValue('core', self::CACHE_KEY, json_encode($resultArray));
451
-		}
452
-		$this->cache->set(self::CACHE_KEY, json_encode($resultArray));
453
-	}
454
-
455
-	/**
456
-	 *
457
-	 * Clean previous results for a proper rescanning. Otherwise
458
-	 */
459
-	private function cleanResults() {
460
-		$this->config->deleteAppValue('core', self::CACHE_KEY);
461
-		$this->cache->remove(self::CACHE_KEY);
462
-	}
463
-
464
-	/**
465
-	 * Verify the signature of $appId. Returns an array with the following content:
466
-	 * [
467
-	 * 	'FILE_MISSING' =>
468
-	 * 	[
469
-	 * 		'filename' => [
470
-	 * 			'expected' => 'expectedSHA512',
471
-	 * 			'current' => 'currentSHA512',
472
-	 * 		],
473
-	 * 	],
474
-	 * 	'EXTRA_FILE' =>
475
-	 * 	[
476
-	 * 		'filename' => [
477
-	 * 			'expected' => 'expectedSHA512',
478
-	 * 			'current' => 'currentSHA512',
479
-	 * 		],
480
-	 * 	],
481
-	 * 	'INVALID_HASH' =>
482
-	 * 	[
483
-	 * 		'filename' => [
484
-	 * 			'expected' => 'expectedSHA512',
485
-	 * 			'current' => 'currentSHA512',
486
-	 * 		],
487
-	 * 	],
488
-	 * ]
489
-	 *
490
-	 * Array may be empty in case no problems have been found.
491
-	 *
492
-	 * @param string $appId
493
-	 * @param string $path Optional path. If none is given it will be guessed.
494
-	 * @return array
495
-	 */
496
-	public function verifyAppSignature(string $appId, string $path = ''): array {
497
-		try {
498
-			if($path === '') {
499
-				$path = $this->appLocator->getAppPath($appId);
500
-			}
501
-			$result = $this->verify(
502
-					$path . '/appinfo/signature.json',
503
-					$path,
504
-					$appId
505
-			);
506
-		} catch (\Exception $e) {
507
-			$result = [
508
-					'EXCEPTION' => [
509
-							'class' => \get_class($e),
510
-							'message' => $e->getMessage(),
511
-					],
512
-			];
513
-		}
514
-		$this->storeResults($appId, $result);
515
-
516
-		return $result;
517
-	}
518
-
519
-	/**
520
-	 * Verify the signature of core. Returns an array with the following content:
521
-	 * [
522
-	 * 	'FILE_MISSING' =>
523
-	 * 	[
524
-	 * 		'filename' => [
525
-	 * 			'expected' => 'expectedSHA512',
526
-	 * 			'current' => 'currentSHA512',
527
-	 * 		],
528
-	 * 	],
529
-	 * 	'EXTRA_FILE' =>
530
-	 * 	[
531
-	 * 		'filename' => [
532
-	 * 			'expected' => 'expectedSHA512',
533
-	 * 			'current' => 'currentSHA512',
534
-	 * 		],
535
-	 * 	],
536
-	 * 	'INVALID_HASH' =>
537
-	 * 	[
538
-	 * 		'filename' => [
539
-	 * 			'expected' => 'expectedSHA512',
540
-	 * 			'current' => 'currentSHA512',
541
-	 * 		],
542
-	 * 	],
543
-	 * ]
544
-	 *
545
-	 * Array may be empty in case no problems have been found.
546
-	 *
547
-	 * @return array
548
-	 */
549
-	public function verifyCoreSignature(): array {
550
-		try {
551
-			$result = $this->verify(
552
-					$this->environmentHelper->getServerRoot() . '/core/signature.json',
553
-					$this->environmentHelper->getServerRoot(),
554
-					'core'
555
-			);
556
-		} catch (\Exception $e) {
557
-			$result = [
558
-					'EXCEPTION' => [
559
-							'class' => \get_class($e),
560
-							'message' => $e->getMessage(),
561
-					],
562
-			];
563
-		}
564
-		$this->storeResults('core', $result);
565
-
566
-		return $result;
567
-	}
568
-
569
-	/**
570
-	 * Verify the core code of the instance as well as all applicable applications
571
-	 * and store the results.
572
-	 */
573
-	public function runInstanceVerification() {
574
-		$this->cleanResults();
575
-		$this->verifyCoreSignature();
576
-		$appIds = $this->appLocator->getAllApps();
577
-		foreach($appIds as $appId) {
578
-			// If an application is shipped a valid signature is required
579
-			$isShipped = $this->appManager->isShipped($appId);
580
-			$appNeedsToBeChecked = false;
581
-			if ($isShipped) {
582
-				$appNeedsToBeChecked = true;
583
-			} elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId) . '/appinfo/signature.json')) {
584
-				// Otherwise only if the application explicitly ships a signature.json file
585
-				$appNeedsToBeChecked = true;
586
-			}
587
-
588
-			if($appNeedsToBeChecked) {
589
-				$this->verifyAppSignature($appId);
590
-			}
591
-		}
592
-	}
57
+    const CACHE_KEY = 'oc.integritycheck.checker';
58
+    /** @var EnvironmentHelper */
59
+    private $environmentHelper;
60
+    /** @var AppLocator */
61
+    private $appLocator;
62
+    /** @var FileAccessHelper */
63
+    private $fileAccessHelper;
64
+    /** @var IConfig */
65
+    private $config;
66
+    /** @var ICache */
67
+    private $cache;
68
+    /** @var IAppManager */
69
+    private $appManager;
70
+    /** @var ITempManager */
71
+    private $tempManager;
72
+    /** @var IMimeTypeDetector */
73
+    private $mimeTypeDetector;
74
+
75
+    /**
76
+     * @param EnvironmentHelper $environmentHelper
77
+     * @param FileAccessHelper $fileAccessHelper
78
+     * @param AppLocator $appLocator
79
+     * @param IConfig $config
80
+     * @param ICacheFactory $cacheFactory
81
+     * @param IAppManager $appManager
82
+     * @param ITempManager $tempManager
83
+     * @param IMimeTypeDetector $mimeTypeDetector
84
+     */
85
+    public function __construct(EnvironmentHelper $environmentHelper,
86
+                                FileAccessHelper $fileAccessHelper,
87
+                                AppLocator $appLocator,
88
+                                IConfig $config = null,
89
+                                ICacheFactory $cacheFactory,
90
+                                IAppManager $appManager = null,
91
+                                ITempManager $tempManager,
92
+                                IMimeTypeDetector $mimeTypeDetector) {
93
+        $this->environmentHelper = $environmentHelper;
94
+        $this->fileAccessHelper = $fileAccessHelper;
95
+        $this->appLocator = $appLocator;
96
+        $this->config = $config;
97
+        $this->cache = $cacheFactory->createDistributed(self::CACHE_KEY);
98
+        $this->appManager = $appManager;
99
+        $this->tempManager = $tempManager;
100
+        $this->mimeTypeDetector = $mimeTypeDetector;
101
+    }
102
+
103
+    /**
104
+     * Whether code signing is enforced or not.
105
+     *
106
+     * @return bool
107
+     */
108
+    public function isCodeCheckEnforced(): bool {
109
+        $notSignedChannels = [ '', 'git'];
110
+        if (\in_array($this->environmentHelper->getChannel(), $notSignedChannels, true)) {
111
+            return false;
112
+        }
113
+
114
+        /**
115
+         * This config option is undocumented and supposed to be so, it's only
116
+         * applicable for very specific scenarios and we should not advertise it
117
+         * too prominent. So please do not add it to config.sample.php.
118
+         */
119
+        $isIntegrityCheckDisabled = false;
120
+        if ($this->config !== null) {
121
+            $isIntegrityCheckDisabled = $this->config->getSystemValue('integrity.check.disabled', false);
122
+        }
123
+        if ($isIntegrityCheckDisabled === true) {
124
+            return false;
125
+        }
126
+
127
+        return true;
128
+    }
129
+
130
+    /**
131
+     * Enumerates all files belonging to the folder. Sensible defaults are excluded.
132
+     *
133
+     * @param string $folderToIterate
134
+     * @param string $root
135
+     * @return \RecursiveIteratorIterator
136
+     * @throws \Exception
137
+     */
138
+    private function getFolderIterator(string $folderToIterate, string $root = ''): \RecursiveIteratorIterator {
139
+        $dirItr = new \RecursiveDirectoryIterator(
140
+            $folderToIterate,
141
+            \RecursiveDirectoryIterator::SKIP_DOTS
142
+        );
143
+        if($root === '') {
144
+            $root = \OC::$SERVERROOT;
145
+        }
146
+        $root = rtrim($root, '/');
147
+
148
+        $excludeGenericFilesIterator = new ExcludeFileByNameFilterIterator($dirItr);
149
+        $excludeFoldersIterator = new ExcludeFoldersByPathFilterIterator($excludeGenericFilesIterator, $root);
150
+
151
+        return new \RecursiveIteratorIterator(
152
+            $excludeFoldersIterator,
153
+            \RecursiveIteratorIterator::SELF_FIRST
154
+        );
155
+    }
156
+
157
+    /**
158
+     * Returns an array of ['filename' => 'SHA512-hash-of-file'] for all files found
159
+     * in the iterator.
160
+     *
161
+     * @param \RecursiveIteratorIterator $iterator
162
+     * @param string $path
163
+     * @return array Array of hashes.
164
+     */
165
+    private function generateHashes(\RecursiveIteratorIterator $iterator,
166
+                                    string $path): array {
167
+        $hashes = [];
168
+
169
+        $baseDirectoryLength = \strlen($path);
170
+        foreach($iterator as $filename => $data) {
171
+            /** @var \DirectoryIterator $data */
172
+            if($data->isDir()) {
173
+                continue;
174
+            }
175
+
176
+            $relativeFileName = substr($filename, $baseDirectoryLength);
177
+            $relativeFileName = ltrim($relativeFileName, '/');
178
+
179
+            // Exclude signature.json files in the appinfo and root folder
180
+            if($relativeFileName === 'appinfo/signature.json') {
181
+                continue;
182
+            }
183
+            // Exclude signature.json files in the appinfo and core folder
184
+            if($relativeFileName === 'core/signature.json') {
185
+                continue;
186
+            }
187
+
188
+            // The .htaccess file in the root folder of ownCloud can contain
189
+            // custom content after the installation due to the fact that dynamic
190
+            // content is written into it at installation time as well. This
191
+            // includes for example the 404 and 403 instructions.
192
+            // Thus we ignore everything below the first occurrence of
193
+            // "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the
194
+            // hash generated based on this.
195
+            if($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') {
196
+                $fileContent = file_get_contents($filename);
197
+                $explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent);
198
+                if(\count($explodedArray) === 2) {
199
+                    $hashes[$relativeFileName] = hash('sha512', $explodedArray[0]);
200
+                    continue;
201
+                }
202
+            }
203
+            if ($filename === $this->environmentHelper->getServerRoot() . '/core/js/mimetypelist.js') {
204
+                $oldMimetypeList = new GenerateMimetypeFileBuilder();
205
+                $newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases());
206
+                if($newFile === file_get_contents($filename)) {
207
+                    $hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases()));
208
+                    continue;
209
+                }
210
+            }
211
+
212
+            $hashes[$relativeFileName] = hash_file('sha512', $filename);
213
+        }
214
+
215
+        return $hashes;
216
+    }
217
+
218
+    /**
219
+     * Creates the signature data
220
+     *
221
+     * @param array $hashes
222
+     * @param X509 $certificate
223
+     * @param RSA $privateKey
224
+     * @return array
225
+     */
226
+    private function createSignatureData(array $hashes,
227
+                                            X509 $certificate,
228
+                                            RSA $privateKey): array {
229
+        ksort($hashes);
230
+
231
+        $privateKey->setSignatureMode(RSA::SIGNATURE_PSS);
232
+        $privateKey->setMGFHash('sha512');
233
+        // See https://tools.ietf.org/html/rfc3447#page-38
234
+        $privateKey->setSaltLength(0);
235
+        $signature = $privateKey->sign(json_encode($hashes));
236
+
237
+        return [
238
+                'hashes' => $hashes,
239
+                'signature' => base64_encode($signature),
240
+                'certificate' => $certificate->saveX509($certificate->currentCert),
241
+            ];
242
+    }
243
+
244
+    /**
245
+     * Write the signature of the app in the specified folder
246
+     *
247
+     * @param string $path
248
+     * @param X509 $certificate
249
+     * @param RSA $privateKey
250
+     * @throws \Exception
251
+     */
252
+    public function writeAppSignature($path,
253
+                                        X509 $certificate,
254
+                                        RSA $privateKey) {
255
+        $appInfoDir = $path . '/appinfo';
256
+        try {
257
+            $this->fileAccessHelper->assertDirectoryExists($appInfoDir);
258
+
259
+            $iterator = $this->getFolderIterator($path);
260
+            $hashes = $this->generateHashes($iterator, $path);
261
+            $signature = $this->createSignatureData($hashes, $certificate, $privateKey);
262
+                $this->fileAccessHelper->file_put_contents(
263
+                    $appInfoDir . '/signature.json',
264
+                json_encode($signature, JSON_PRETTY_PRINT)
265
+            );
266
+        } catch (\Exception $e){
267
+            if (!$this->fileAccessHelper->is_writable($appInfoDir)) {
268
+                throw new \Exception($appInfoDir . ' is not writable');
269
+            }
270
+            throw $e;
271
+        }
272
+    }
273
+
274
+    /**
275
+     * Write the signature of core
276
+     *
277
+     * @param X509 $certificate
278
+     * @param RSA $rsa
279
+     * @param string $path
280
+     * @throws \Exception
281
+     */
282
+    public function writeCoreSignature(X509 $certificate,
283
+                                        RSA $rsa,
284
+                                        $path) {
285
+        $coreDir = $path . '/core';
286
+        try {
287
+
288
+            $this->fileAccessHelper->assertDirectoryExists($coreDir);
289
+            $iterator = $this->getFolderIterator($path, $path);
290
+            $hashes = $this->generateHashes($iterator, $path);
291
+            $signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
292
+            $this->fileAccessHelper->file_put_contents(
293
+                $coreDir . '/signature.json',
294
+                json_encode($signatureData, JSON_PRETTY_PRINT)
295
+            );
296
+        } catch (\Exception $e){
297
+            if (!$this->fileAccessHelper->is_writable($coreDir)) {
298
+                throw new \Exception($coreDir . ' is not writable');
299
+            }
300
+            throw $e;
301
+        }
302
+    }
303
+
304
+    /**
305
+     * Verifies the signature for the specified path.
306
+     *
307
+     * @param string $signaturePath
308
+     * @param string $basePath
309
+     * @param string $certificateCN
310
+     * @return array
311
+     * @throws InvalidSignatureException
312
+     * @throws \Exception
313
+     */
314
+    private function verify(string $signaturePath, string $basePath, string $certificateCN): array {
315
+        if(!$this->isCodeCheckEnforced()) {
316
+            return [];
317
+        }
318
+
319
+        $content = $this->fileAccessHelper->file_get_contents($signaturePath);
320
+        $signatureData = null;
321
+
322
+        if (\is_string($content)) {
323
+            $signatureData = json_decode($content, true);
324
+        }
325
+        if(!\is_array($signatureData)) {
326
+            throw new InvalidSignatureException('Signature data not found.');
327
+        }
328
+
329
+        $expectedHashes = $signatureData['hashes'];
330
+        ksort($expectedHashes);
331
+        $signature = base64_decode($signatureData['signature']);
332
+        $certificate = $signatureData['certificate'];
333
+
334
+        // Check if certificate is signed by Nextcloud Root Authority
335
+        $x509 = new \phpseclib\File\X509();
336
+        $rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt');
337
+        $x509->loadCA($rootCertificatePublicKey);
338
+        $x509->loadX509($certificate);
339
+        if(!$x509->validateSignature()) {
340
+            throw new InvalidSignatureException('Certificate is not valid.');
341
+        }
342
+        // Verify if certificate has proper CN. "core" CN is always trusted.
343
+        if($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') {
344
+            throw new InvalidSignatureException(
345
+                    sprintf('Certificate is not valid for required scope. (Requested: %s, current: CN=%s)', $certificateCN, $x509->getDN(true)['CN'])
346
+            );
347
+        }
348
+
349
+        // Check if the signature of the files is valid
350
+        $rsa = new \phpseclib\Crypt\RSA();
351
+        $rsa->loadKey($x509->currentCert['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey']);
352
+        $rsa->setSignatureMode(RSA::SIGNATURE_PSS);
353
+        $rsa->setMGFHash('sha512');
354
+        // See https://tools.ietf.org/html/rfc3447#page-38
355
+        $rsa->setSaltLength(0);
356
+        if(!$rsa->verify(json_encode($expectedHashes), $signature)) {
357
+            throw new InvalidSignatureException('Signature could not get verified.');
358
+        }
359
+
360
+        // Fixes for the updater as shipped with ownCloud 9.0.x: The updater is
361
+        // replaced after the code integrity check is performed.
362
+        //
363
+        // Due to this reason we exclude the whole updater/ folder from the code
364
+        // integrity check.
365
+        if($basePath === $this->environmentHelper->getServerRoot()) {
366
+            foreach($expectedHashes as $fileName => $hash) {
367
+                if(strpos($fileName, 'updater/') === 0) {
368
+                    unset($expectedHashes[$fileName]);
369
+                }
370
+            }
371
+        }
372
+
373
+        // Compare the list of files which are not identical
374
+        $currentInstanceHashes = $this->generateHashes($this->getFolderIterator($basePath), $basePath);
375
+        $differencesA = array_diff($expectedHashes, $currentInstanceHashes);
376
+        $differencesB = array_diff($currentInstanceHashes, $expectedHashes);
377
+        $differences = array_unique(array_merge($differencesA, $differencesB));
378
+        $differenceArray = [];
379
+        foreach($differences as $filename => $hash) {
380
+            // Check if file should not exist in the new signature table
381
+            if(!array_key_exists($filename, $expectedHashes)) {
382
+                $differenceArray['EXTRA_FILE'][$filename]['expected'] = '';
383
+                $differenceArray['EXTRA_FILE'][$filename]['current'] = $hash;
384
+                continue;
385
+            }
386
+
387
+            // Check if file is missing
388
+            if(!array_key_exists($filename, $currentInstanceHashes)) {
389
+                $differenceArray['FILE_MISSING'][$filename]['expected'] = $expectedHashes[$filename];
390
+                $differenceArray['FILE_MISSING'][$filename]['current'] = '';
391
+                continue;
392
+            }
393
+
394
+            // Check if hash does mismatch
395
+            if($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) {
396
+                $differenceArray['INVALID_HASH'][$filename]['expected'] = $expectedHashes[$filename];
397
+                $differenceArray['INVALID_HASH'][$filename]['current'] = $currentInstanceHashes[$filename];
398
+                continue;
399
+            }
400
+
401
+            // Should never happen.
402
+            throw new \Exception('Invalid behaviour in file hash comparison experienced. Please report this error to the developers.');
403
+        }
404
+
405
+        return $differenceArray;
406
+    }
407
+
408
+    /**
409
+     * Whether the code integrity check has passed successful or not
410
+     *
411
+     * @return bool
412
+     */
413
+    public function hasPassedCheck(): bool {
414
+        $results = $this->getResults();
415
+        if(empty($results)) {
416
+            return true;
417
+        }
418
+
419
+        return false;
420
+    }
421
+
422
+    /**
423
+     * @return array
424
+     */
425
+    public function getResults(): array {
426
+        $cachedResults = $this->cache->get(self::CACHE_KEY);
427
+        if(!\is_null($cachedResults)) {
428
+            return json_decode($cachedResults, true);
429
+        }
430
+
431
+        if ($this->config !== null) {
432
+            return json_decode($this->config->getAppValue('core', self::CACHE_KEY, '{}'), true);
433
+        }
434
+        return [];
435
+    }
436
+
437
+    /**
438
+     * Stores the results in the app config as well as cache
439
+     *
440
+     * @param string $scope
441
+     * @param array $result
442
+     */
443
+    private function storeResults(string $scope, array $result) {
444
+        $resultArray = $this->getResults();
445
+        unset($resultArray[$scope]);
446
+        if(!empty($result)) {
447
+            $resultArray[$scope] = $result;
448
+        }
449
+        if ($this->config !== null) {
450
+            $this->config->setAppValue('core', self::CACHE_KEY, json_encode($resultArray));
451
+        }
452
+        $this->cache->set(self::CACHE_KEY, json_encode($resultArray));
453
+    }
454
+
455
+    /**
456
+     *
457
+     * Clean previous results for a proper rescanning. Otherwise
458
+     */
459
+    private function cleanResults() {
460
+        $this->config->deleteAppValue('core', self::CACHE_KEY);
461
+        $this->cache->remove(self::CACHE_KEY);
462
+    }
463
+
464
+    /**
465
+     * Verify the signature of $appId. Returns an array with the following content:
466
+     * [
467
+     * 	'FILE_MISSING' =>
468
+     * 	[
469
+     * 		'filename' => [
470
+     * 			'expected' => 'expectedSHA512',
471
+     * 			'current' => 'currentSHA512',
472
+     * 		],
473
+     * 	],
474
+     * 	'EXTRA_FILE' =>
475
+     * 	[
476
+     * 		'filename' => [
477
+     * 			'expected' => 'expectedSHA512',
478
+     * 			'current' => 'currentSHA512',
479
+     * 		],
480
+     * 	],
481
+     * 	'INVALID_HASH' =>
482
+     * 	[
483
+     * 		'filename' => [
484
+     * 			'expected' => 'expectedSHA512',
485
+     * 			'current' => 'currentSHA512',
486
+     * 		],
487
+     * 	],
488
+     * ]
489
+     *
490
+     * Array may be empty in case no problems have been found.
491
+     *
492
+     * @param string $appId
493
+     * @param string $path Optional path. If none is given it will be guessed.
494
+     * @return array
495
+     */
496
+    public function verifyAppSignature(string $appId, string $path = ''): array {
497
+        try {
498
+            if($path === '') {
499
+                $path = $this->appLocator->getAppPath($appId);
500
+            }
501
+            $result = $this->verify(
502
+                    $path . '/appinfo/signature.json',
503
+                    $path,
504
+                    $appId
505
+            );
506
+        } catch (\Exception $e) {
507
+            $result = [
508
+                    'EXCEPTION' => [
509
+                            'class' => \get_class($e),
510
+                            'message' => $e->getMessage(),
511
+                    ],
512
+            ];
513
+        }
514
+        $this->storeResults($appId, $result);
515
+
516
+        return $result;
517
+    }
518
+
519
+    /**
520
+     * Verify the signature of core. Returns an array with the following content:
521
+     * [
522
+     * 	'FILE_MISSING' =>
523
+     * 	[
524
+     * 		'filename' => [
525
+     * 			'expected' => 'expectedSHA512',
526
+     * 			'current' => 'currentSHA512',
527
+     * 		],
528
+     * 	],
529
+     * 	'EXTRA_FILE' =>
530
+     * 	[
531
+     * 		'filename' => [
532
+     * 			'expected' => 'expectedSHA512',
533
+     * 			'current' => 'currentSHA512',
534
+     * 		],
535
+     * 	],
536
+     * 	'INVALID_HASH' =>
537
+     * 	[
538
+     * 		'filename' => [
539
+     * 			'expected' => 'expectedSHA512',
540
+     * 			'current' => 'currentSHA512',
541
+     * 		],
542
+     * 	],
543
+     * ]
544
+     *
545
+     * Array may be empty in case no problems have been found.
546
+     *
547
+     * @return array
548
+     */
549
+    public function verifyCoreSignature(): array {
550
+        try {
551
+            $result = $this->verify(
552
+                    $this->environmentHelper->getServerRoot() . '/core/signature.json',
553
+                    $this->environmentHelper->getServerRoot(),
554
+                    'core'
555
+            );
556
+        } catch (\Exception $e) {
557
+            $result = [
558
+                    'EXCEPTION' => [
559
+                            'class' => \get_class($e),
560
+                            'message' => $e->getMessage(),
561
+                    ],
562
+            ];
563
+        }
564
+        $this->storeResults('core', $result);
565
+
566
+        return $result;
567
+    }
568
+
569
+    /**
570
+     * Verify the core code of the instance as well as all applicable applications
571
+     * and store the results.
572
+     */
573
+    public function runInstanceVerification() {
574
+        $this->cleanResults();
575
+        $this->verifyCoreSignature();
576
+        $appIds = $this->appLocator->getAllApps();
577
+        foreach($appIds as $appId) {
578
+            // If an application is shipped a valid signature is required
579
+            $isShipped = $this->appManager->isShipped($appId);
580
+            $appNeedsToBeChecked = false;
581
+            if ($isShipped) {
582
+                $appNeedsToBeChecked = true;
583
+            } elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId) . '/appinfo/signature.json')) {
584
+                // Otherwise only if the application explicitly ships a signature.json file
585
+                $appNeedsToBeChecked = true;
586
+            }
587
+
588
+            if($appNeedsToBeChecked) {
589
+                $this->verifyAppSignature($appId);
590
+            }
591
+        }
592
+    }
593 593
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return bool
107 107
 	 */
108 108
 	public function isCodeCheckEnforced(): bool {
109
-		$notSignedChannels = [ '', 'git'];
109
+		$notSignedChannels = ['', 'git'];
110 110
 		if (\in_array($this->environmentHelper->getChannel(), $notSignedChannels, true)) {
111 111
 			return false;
112 112
 		}
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 			$folderToIterate,
141 141
 			\RecursiveDirectoryIterator::SKIP_DOTS
142 142
 		);
143
-		if($root === '') {
143
+		if ($root === '') {
144 144
 			$root = \OC::$SERVERROOT;
145 145
 		}
146 146
 		$root = rtrim($root, '/');
@@ -167,9 +167,9 @@  discard block
 block discarded – undo
167 167
 		$hashes = [];
168 168
 
169 169
 		$baseDirectoryLength = \strlen($path);
170
-		foreach($iterator as $filename => $data) {
170
+		foreach ($iterator as $filename => $data) {
171 171
 			/** @var \DirectoryIterator $data */
172
-			if($data->isDir()) {
172
+			if ($data->isDir()) {
173 173
 				continue;
174 174
 			}
175 175
 
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 			$relativeFileName = ltrim($relativeFileName, '/');
178 178
 
179 179
 			// Exclude signature.json files in the appinfo and root folder
180
-			if($relativeFileName === 'appinfo/signature.json') {
180
+			if ($relativeFileName === 'appinfo/signature.json') {
181 181
 				continue;
182 182
 			}
183 183
 			// Exclude signature.json files in the appinfo and core folder
184
-			if($relativeFileName === 'core/signature.json') {
184
+			if ($relativeFileName === 'core/signature.json') {
185 185
 				continue;
186 186
 			}
187 187
 
@@ -192,18 +192,18 @@  discard block
 block discarded – undo
192 192
 			// Thus we ignore everything below the first occurrence of
193 193
 			// "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####" and have the
194 194
 			// hash generated based on this.
195
-			if($filename === $this->environmentHelper->getServerRoot() . '/.htaccess') {
195
+			if ($filename === $this->environmentHelper->getServerRoot().'/.htaccess') {
196 196
 				$fileContent = file_get_contents($filename);
197 197
 				$explodedArray = explode('#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####', $fileContent);
198
-				if(\count($explodedArray) === 2) {
198
+				if (\count($explodedArray) === 2) {
199 199
 					$hashes[$relativeFileName] = hash('sha512', $explodedArray[0]);
200 200
 					continue;
201 201
 				}
202 202
 			}
203
-			if ($filename === $this->environmentHelper->getServerRoot() . '/core/js/mimetypelist.js') {
203
+			if ($filename === $this->environmentHelper->getServerRoot().'/core/js/mimetypelist.js') {
204 204
 				$oldMimetypeList = new GenerateMimetypeFileBuilder();
205 205
 				$newFile = $oldMimetypeList->generateFile($this->mimeTypeDetector->getAllAliases());
206
-				if($newFile === file_get_contents($filename)) {
206
+				if ($newFile === file_get_contents($filename)) {
207 207
 					$hashes[$relativeFileName] = hash('sha512', $oldMimetypeList->generateFile($this->mimeTypeDetector->getOnlyDefaultAliases()));
208 208
 					continue;
209 209
 				}
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	public function writeAppSignature($path,
253 253
 									  X509 $certificate,
254 254
 									  RSA $privateKey) {
255
-		$appInfoDir = $path . '/appinfo';
255
+		$appInfoDir = $path.'/appinfo';
256 256
 		try {
257 257
 			$this->fileAccessHelper->assertDirectoryExists($appInfoDir);
258 258
 
@@ -260,12 +260,12 @@  discard block
 block discarded – undo
260 260
 			$hashes = $this->generateHashes($iterator, $path);
261 261
 			$signature = $this->createSignatureData($hashes, $certificate, $privateKey);
262 262
 				$this->fileAccessHelper->file_put_contents(
263
-					$appInfoDir . '/signature.json',
263
+					$appInfoDir.'/signature.json',
264 264
 				json_encode($signature, JSON_PRETTY_PRINT)
265 265
 			);
266
-		} catch (\Exception $e){
266
+		} catch (\Exception $e) {
267 267
 			if (!$this->fileAccessHelper->is_writable($appInfoDir)) {
268
-				throw new \Exception($appInfoDir . ' is not writable');
268
+				throw new \Exception($appInfoDir.' is not writable');
269 269
 			}
270 270
 			throw $e;
271 271
 		}
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	public function writeCoreSignature(X509 $certificate,
283 283
 									   RSA $rsa,
284 284
 									   $path) {
285
-		$coreDir = $path . '/core';
285
+		$coreDir = $path.'/core';
286 286
 		try {
287 287
 
288 288
 			$this->fileAccessHelper->assertDirectoryExists($coreDir);
@@ -290,12 +290,12 @@  discard block
 block discarded – undo
290 290
 			$hashes = $this->generateHashes($iterator, $path);
291 291
 			$signatureData = $this->createSignatureData($hashes, $certificate, $rsa);
292 292
 			$this->fileAccessHelper->file_put_contents(
293
-				$coreDir . '/signature.json',
293
+				$coreDir.'/signature.json',
294 294
 				json_encode($signatureData, JSON_PRETTY_PRINT)
295 295
 			);
296
-		} catch (\Exception $e){
296
+		} catch (\Exception $e) {
297 297
 			if (!$this->fileAccessHelper->is_writable($coreDir)) {
298
-				throw new \Exception($coreDir . ' is not writable');
298
+				throw new \Exception($coreDir.' is not writable');
299 299
 			}
300 300
 			throw $e;
301 301
 		}
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	 * @throws \Exception
313 313
 	 */
314 314
 	private function verify(string $signaturePath, string $basePath, string $certificateCN): array {
315
-		if(!$this->isCodeCheckEnforced()) {
315
+		if (!$this->isCodeCheckEnforced()) {
316 316
 			return [];
317 317
 		}
318 318
 
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 		if (\is_string($content)) {
323 323
 			$signatureData = json_decode($content, true);
324 324
 		}
325
-		if(!\is_array($signatureData)) {
325
+		if (!\is_array($signatureData)) {
326 326
 			throw new InvalidSignatureException('Signature data not found.');
327 327
 		}
328 328
 
@@ -336,11 +336,11 @@  discard block
 block discarded – undo
336 336
 		$rootCertificatePublicKey = $this->fileAccessHelper->file_get_contents($this->environmentHelper->getServerRoot().'/resources/codesigning/root.crt');
337 337
 		$x509->loadCA($rootCertificatePublicKey);
338 338
 		$x509->loadX509($certificate);
339
-		if(!$x509->validateSignature()) {
339
+		if (!$x509->validateSignature()) {
340 340
 			throw new InvalidSignatureException('Certificate is not valid.');
341 341
 		}
342 342
 		// Verify if certificate has proper CN. "core" CN is always trusted.
343
-		if($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') {
343
+		if ($x509->getDN(X509::DN_OPENSSL)['CN'] !== $certificateCN && $x509->getDN(X509::DN_OPENSSL)['CN'] !== 'core') {
344 344
 			throw new InvalidSignatureException(
345 345
 					sprintf('Certificate is not valid for required scope. (Requested: %s, current: CN=%s)', $certificateCN, $x509->getDN(true)['CN'])
346 346
 			);
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 		$rsa->setMGFHash('sha512');
354 354
 		// See https://tools.ietf.org/html/rfc3447#page-38
355 355
 		$rsa->setSaltLength(0);
356
-		if(!$rsa->verify(json_encode($expectedHashes), $signature)) {
356
+		if (!$rsa->verify(json_encode($expectedHashes), $signature)) {
357 357
 			throw new InvalidSignatureException('Signature could not get verified.');
358 358
 		}
359 359
 
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 		//
363 363
 		// Due to this reason we exclude the whole updater/ folder from the code
364 364
 		// integrity check.
365
-		if($basePath === $this->environmentHelper->getServerRoot()) {
366
-			foreach($expectedHashes as $fileName => $hash) {
367
-				if(strpos($fileName, 'updater/') === 0) {
365
+		if ($basePath === $this->environmentHelper->getServerRoot()) {
366
+			foreach ($expectedHashes as $fileName => $hash) {
367
+				if (strpos($fileName, 'updater/') === 0) {
368 368
 					unset($expectedHashes[$fileName]);
369 369
 				}
370 370
 			}
@@ -376,23 +376,23 @@  discard block
 block discarded – undo
376 376
 		$differencesB = array_diff($currentInstanceHashes, $expectedHashes);
377 377
 		$differences = array_unique(array_merge($differencesA, $differencesB));
378 378
 		$differenceArray = [];
379
-		foreach($differences as $filename => $hash) {
379
+		foreach ($differences as $filename => $hash) {
380 380
 			// Check if file should not exist in the new signature table
381
-			if(!array_key_exists($filename, $expectedHashes)) {
381
+			if (!array_key_exists($filename, $expectedHashes)) {
382 382
 				$differenceArray['EXTRA_FILE'][$filename]['expected'] = '';
383 383
 				$differenceArray['EXTRA_FILE'][$filename]['current'] = $hash;
384 384
 				continue;
385 385
 			}
386 386
 
387 387
 			// Check if file is missing
388
-			if(!array_key_exists($filename, $currentInstanceHashes)) {
388
+			if (!array_key_exists($filename, $currentInstanceHashes)) {
389 389
 				$differenceArray['FILE_MISSING'][$filename]['expected'] = $expectedHashes[$filename];
390 390
 				$differenceArray['FILE_MISSING'][$filename]['current'] = '';
391 391
 				continue;
392 392
 			}
393 393
 
394 394
 			// Check if hash does mismatch
395
-			if($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) {
395
+			if ($expectedHashes[$filename] !== $currentInstanceHashes[$filename]) {
396 396
 				$differenceArray['INVALID_HASH'][$filename]['expected'] = $expectedHashes[$filename];
397 397
 				$differenceArray['INVALID_HASH'][$filename]['current'] = $currentInstanceHashes[$filename];
398 398
 				continue;
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
 	 */
413 413
 	public function hasPassedCheck(): bool {
414 414
 		$results = $this->getResults();
415
-		if(empty($results)) {
415
+		if (empty($results)) {
416 416
 			return true;
417 417
 		}
418 418
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 	 */
425 425
 	public function getResults(): array {
426 426
 		$cachedResults = $this->cache->get(self::CACHE_KEY);
427
-		if(!\is_null($cachedResults)) {
427
+		if (!\is_null($cachedResults)) {
428 428
 			return json_decode($cachedResults, true);
429 429
 		}
430 430
 
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
 	private function storeResults(string $scope, array $result) {
444 444
 		$resultArray = $this->getResults();
445 445
 		unset($resultArray[$scope]);
446
-		if(!empty($result)) {
446
+		if (!empty($result)) {
447 447
 			$resultArray[$scope] = $result;
448 448
 		}
449 449
 		if ($this->config !== null) {
@@ -495,11 +495,11 @@  discard block
 block discarded – undo
495 495
 	 */
496 496
 	public function verifyAppSignature(string $appId, string $path = ''): array {
497 497
 		try {
498
-			if($path === '') {
498
+			if ($path === '') {
499 499
 				$path = $this->appLocator->getAppPath($appId);
500 500
 			}
501 501
 			$result = $this->verify(
502
-					$path . '/appinfo/signature.json',
502
+					$path.'/appinfo/signature.json',
503 503
 					$path,
504 504
 					$appId
505 505
 			);
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
 	public function verifyCoreSignature(): array {
550 550
 		try {
551 551
 			$result = $this->verify(
552
-					$this->environmentHelper->getServerRoot() . '/core/signature.json',
552
+					$this->environmentHelper->getServerRoot().'/core/signature.json',
553 553
 					$this->environmentHelper->getServerRoot(),
554 554
 					'core'
555 555
 			);
@@ -574,18 +574,18 @@  discard block
 block discarded – undo
574 574
 		$this->cleanResults();
575 575
 		$this->verifyCoreSignature();
576 576
 		$appIds = $this->appLocator->getAllApps();
577
-		foreach($appIds as $appId) {
577
+		foreach ($appIds as $appId) {
578 578
 			// If an application is shipped a valid signature is required
579 579
 			$isShipped = $this->appManager->isShipped($appId);
580 580
 			$appNeedsToBeChecked = false;
581 581
 			if ($isShipped) {
582 582
 				$appNeedsToBeChecked = true;
583
-			} elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId) . '/appinfo/signature.json')) {
583
+			} elseif ($this->fileAccessHelper->file_exists($this->appLocator->getAppPath($appId).'/appinfo/signature.json')) {
584 584
 				// Otherwise only if the application explicitly ships a signature.json file
585 585
 				$appNeedsToBeChecked = true;
586 586
 			}
587 587
 
588
-			if($appNeedsToBeChecked) {
588
+			if ($appNeedsToBeChecked) {
589 589
 				$this->verifyAppSignature($appId);
590 590
 			}
591 591
 		}
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +1899 added lines, -1899 removed lines patch added patch discarded remove patch
@@ -168,1908 +168,1908 @@
 block discarded – undo
168 168
  * TODO: hookup all manager classes
169 169
  */
170 170
 class Server extends ServerContainer implements IServerContainer {
171
-	/** @var string */
172
-	private $webRoot;
173
-
174
-	/**
175
-	 * @param string $webRoot
176
-	 * @param \OC\Config $config
177
-	 */
178
-	public function __construct($webRoot, \OC\Config $config) {
179
-		parent::__construct();
180
-		$this->webRoot = $webRoot;
181
-
182
-		// To find out if we are running from CLI or not
183
-		$this->registerParameter('isCLI', \OC::$CLI);
184
-
185
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
186
-			return $c;
187
-		});
188
-
189
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
190
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
191
-
192
-		$this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
193
-		$this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
194
-
195
-		$this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
196
-		$this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
197
-
198
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
199
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
200
-
201
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
202
-
203
-
204
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
205
-			return new PreviewManager(
206
-				$c->getConfig(),
207
-				$c->getRootFolder(),
208
-				$c->getAppDataDir('preview'),
209
-				$c->getEventDispatcher(),
210
-				$c->getGeneratorHelper(),
211
-				$c->getSession()->get('user_id')
212
-			);
213
-		});
214
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
215
-
216
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
217
-			return new \OC\Preview\Watcher(
218
-				$c->getAppDataDir('preview')
219
-			);
220
-		});
221
-
222
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
223
-			$view = new View();
224
-			$util = new Encryption\Util(
225
-				$view,
226
-				$c->getUserManager(),
227
-				$c->getGroupManager(),
228
-				$c->getConfig()
229
-			);
230
-			return new Encryption\Manager(
231
-				$c->getConfig(),
232
-				$c->getLogger(),
233
-				$c->getL10N('core'),
234
-				new View(),
235
-				$util,
236
-				new ArrayCache()
237
-			);
238
-		});
239
-		$this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
240
-
241
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
242
-			$util = new Encryption\Util(
243
-				new View(),
244
-				$c->getUserManager(),
245
-				$c->getGroupManager(),
246
-				$c->getConfig()
247
-			);
248
-			return new Encryption\File(
249
-				$util,
250
-				$c->getRootFolder(),
251
-				$c->getShareManager()
252
-			);
253
-		});
254
-
255
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
256
-			$view = new View();
257
-			$util = new Encryption\Util(
258
-				$view,
259
-				$c->getUserManager(),
260
-				$c->getGroupManager(),
261
-				$c->getConfig()
262
-			);
263
-
264
-			return new Encryption\Keys\Storage($view, $util);
265
-		});
266
-		$this->registerService('TagMapper', function (Server $c) {
267
-			return new TagMapper($c->getDatabaseConnection());
268
-		});
269
-
270
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
271
-			$tagMapper = $c->query('TagMapper');
272
-			return new TagManager($tagMapper, $c->getUserSession());
273
-		});
274
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
275
-
276
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
277
-			$config = $c->getConfig();
278
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
279
-			return new $factoryClass($this);
280
-		});
281
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
282
-			return $c->query('SystemTagManagerFactory')->getManager();
283
-		});
284
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
285
-
286
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
287
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
288
-		});
289
-		$this->registerService('RootFolder', function (Server $c) {
290
-			$manager = \OC\Files\Filesystem::getMountManager(null);
291
-			$view = new View();
292
-			$root = new Root(
293
-				$manager,
294
-				$view,
295
-				null,
296
-				$c->getUserMountCache(),
297
-				$this->getLogger(),
298
-				$this->getUserManager()
299
-			);
300
-			$connector = new HookConnector($root, $view);
301
-			$connector->viewToNode();
302
-
303
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
304
-			$previewConnector->connectWatcher();
305
-
306
-			return $root;
307
-		});
308
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
309
-
310
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
311
-			return new LazyRoot(function () use ($c) {
312
-				return $c->query('RootFolder');
313
-			});
314
-		});
315
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
316
-
317
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
318
-			return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
319
-		});
320
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
321
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
322
-
323
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
324
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
325
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
326
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
327
-			});
328
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
329
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
330
-			});
331
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
332
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
333
-			});
334
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
335
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
336
-			});
337
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
338
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
339
-			});
340
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
341
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
342
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
343
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
344
-			});
345
-			return $groupManager;
346
-		});
347
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
348
-
349
-		$this->registerService(Store::class, function (Server $c) {
350
-			$session = $c->getSession();
351
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
352
-				$tokenProvider = $c->query(IProvider::class);
353
-			} else {
354
-				$tokenProvider = null;
355
-			}
356
-			$logger = $c->getLogger();
357
-			return new Store($session, $logger, $tokenProvider);
358
-		});
359
-		$this->registerAlias(IStore::class, Store::class);
360
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
361
-			$dbConnection = $c->getDatabaseConnection();
362
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
363
-		});
364
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
365
-
366
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
367
-			$manager = $c->getUserManager();
368
-			$session = new \OC\Session\Memory('');
369
-			$timeFactory = new TimeFactory();
370
-			// Token providers might require a working database. This code
371
-			// might however be called when ownCloud is not yet setup.
372
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
373
-				$defaultTokenProvider = $c->query(IProvider::class);
374
-			} else {
375
-				$defaultTokenProvider = null;
376
-			}
377
-
378
-			$dispatcher = $c->getEventDispatcher();
379
-
380
-			$userSession = new \OC\User\Session(
381
-				$manager,
382
-				$session,
383
-				$timeFactory,
384
-				$defaultTokenProvider,
385
-				$c->getConfig(),
386
-				$c->getSecureRandom(),
387
-				$c->getLockdownManager(),
388
-				$c->getLogger()
389
-			);
390
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
391
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
392
-			});
393
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
394
-				/** @var $user \OC\User\User */
395
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
396
-			});
397
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
398
-				/** @var $user \OC\User\User */
399
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
400
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
401
-			});
402
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
403
-				/** @var $user \OC\User\User */
404
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
405
-			});
406
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
407
-				/** @var $user \OC\User\User */
408
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
409
-			});
410
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
411
-				/** @var $user \OC\User\User */
412
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
413
-			});
414
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
415
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
416
-			});
417
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
418
-				/** @var $user \OC\User\User */
419
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
420
-			});
421
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
422
-				/** @var $user \OC\User\User */
423
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
424
-			});
425
-			$userSession->listen('\OC\User', 'logout', function () {
426
-				\OC_Hook::emit('OC_User', 'logout', array());
427
-			});
428
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
429
-				/** @var $user \OC\User\User */
430
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
431
-			});
432
-			return $userSession;
433
-		});
434
-		$this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
435
-		$this->registerAlias('UserSession', \OC\User\Session::class);
436
-
437
-		$this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
438
-
439
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
440
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
441
-
442
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
443
-			return new \OC\AllConfig(
444
-				$c->getSystemConfig()
445
-			);
446
-		});
447
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
448
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
449
-
450
-		$this->registerService('SystemConfig', function ($c) use ($config) {
451
-			return new \OC\SystemConfig($config);
452
-		});
453
-
454
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
455
-			return new \OC\AppConfig($c->getDatabaseConnection());
456
-		});
457
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
458
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
459
-
460
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
461
-			return new \OC\L10N\Factory(
462
-				$c->getConfig(),
463
-				$c->getRequest(),
464
-				$c->getUserSession(),
465
-				\OC::$SERVERROOT
466
-			);
467
-		});
468
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
469
-
470
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
471
-			$config = $c->getConfig();
472
-			$cacheFactory = $c->getMemCacheFactory();
473
-			$request = $c->getRequest();
474
-			return new \OC\URLGenerator(
475
-				$config,
476
-				$cacheFactory,
477
-				$request
478
-			);
479
-		});
480
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
481
-
482
-		$this->registerAlias('AppFetcher', AppFetcher::class);
483
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
484
-
485
-		$this->registerService(\OCP\ICache::class, function ($c) {
486
-			return new Cache\File();
487
-		});
488
-		$this->registerAlias('UserCache', \OCP\ICache::class);
489
-
490
-		$this->registerService(Factory::class, function (Server $c) {
491
-
492
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
493
-				ArrayCache::class,
494
-				ArrayCache::class,
495
-				ArrayCache::class
496
-			);
497
-			$config = $c->getConfig();
498
-
499
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
500
-				$v = \OC_App::getAppVersions();
501
-				$v['core'] = implode(',', \OC_Util::getVersion());
502
-				$version = implode(',', $v);
503
-				$instanceId = \OC_Util::getInstanceId();
504
-				$path = \OC::$SERVERROOT;
505
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
506
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
507
-					$config->getSystemValue('memcache.local', null),
508
-					$config->getSystemValue('memcache.distributed', null),
509
-					$config->getSystemValue('memcache.locking', null)
510
-				);
511
-			}
512
-			return $arrayCacheFactory;
513
-
514
-		});
515
-		$this->registerAlias('MemCacheFactory', Factory::class);
516
-		$this->registerAlias(ICacheFactory::class, Factory::class);
517
-
518
-		$this->registerService('RedisFactory', function (Server $c) {
519
-			$systemConfig = $c->getSystemConfig();
520
-			return new RedisFactory($systemConfig);
521
-		});
522
-
523
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
524
-			return new \OC\Activity\Manager(
525
-				$c->getRequest(),
526
-				$c->getUserSession(),
527
-				$c->getConfig(),
528
-				$c->query(IValidator::class)
529
-			);
530
-		});
531
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
532
-
533
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
534
-			return new \OC\Activity\EventMerger(
535
-				$c->getL10N('lib')
536
-			);
537
-		});
538
-		$this->registerAlias(IValidator::class, Validator::class);
539
-
540
-		$this->registerService(AvatarManager::class, function(Server $c) {
541
-			return new AvatarManager(
542
-				$c->query(\OC\User\Manager::class),
543
-				$c->getAppDataDir('avatar'),
544
-				$c->getL10N('lib'),
545
-				$c->getLogger(),
546
-				$c->getConfig()
547
-			);
548
-		});
549
-		$this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
550
-		$this->registerAlias('AvatarManager', AvatarManager::class);
551
-
552
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
553
-		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
554
-
555
-		$this->registerService(\OC\Log::class, function (Server $c) {
556
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
557
-			$factory = new LogFactory($c, $this->getSystemConfig());
558
-			$logger = $factory->get($logType);
559
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
560
-
561
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
562
-		});
563
-		$this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
564
-		$this->registerAlias('Logger', \OC\Log::class);
565
-
566
-		$this->registerService(ILogFactory::class, function (Server $c) {
567
-			return new LogFactory($c, $this->getSystemConfig());
568
-		});
569
-
570
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
571
-			$config = $c->getConfig();
572
-			return new \OC\BackgroundJob\JobList(
573
-				$c->getDatabaseConnection(),
574
-				$config,
575
-				new TimeFactory()
576
-			);
577
-		});
578
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
579
-
580
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
581
-			$cacheFactory = $c->getMemCacheFactory();
582
-			$logger = $c->getLogger();
583
-			if ($cacheFactory->isLocalCacheAvailable()) {
584
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
585
-			} else {
586
-				$router = new \OC\Route\Router($logger);
587
-			}
588
-			return $router;
589
-		});
590
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
591
-
592
-		$this->registerService(\OCP\ISearch::class, function ($c) {
593
-			return new Search();
594
-		});
595
-		$this->registerAlias('Search', \OCP\ISearch::class);
596
-
597
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
598
-			return new \OC\Security\RateLimiting\Limiter(
599
-				$this->getUserSession(),
600
-				$this->getRequest(),
601
-				new \OC\AppFramework\Utility\TimeFactory(),
602
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
603
-			);
604
-		});
605
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
606
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
607
-				$this->getMemCacheFactory(),
608
-				new \OC\AppFramework\Utility\TimeFactory()
609
-			);
610
-		});
611
-
612
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
613
-			return new SecureRandom();
614
-		});
615
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
616
-
617
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
618
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
619
-		});
620
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
621
-
622
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
623
-			return new Hasher($c->getConfig());
624
-		});
625
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
626
-
627
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
628
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
629
-		});
630
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
631
-
632
-		$this->registerService(IDBConnection::class, function (Server $c) {
633
-			$systemConfig = $c->getSystemConfig();
634
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
635
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
636
-			if (!$factory->isValidType($type)) {
637
-				throw new \OC\DatabaseException('Invalid database type');
638
-			}
639
-			$connectionParams = $factory->createConnectionParams();
640
-			$connection = $factory->getConnection($type, $connectionParams);
641
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
642
-			return $connection;
643
-		});
644
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
645
-
646
-
647
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
648
-			$user = \OC_User::getUser();
649
-			$uid = $user ? $user : null;
650
-			return new ClientService(
651
-				$c->getConfig(),
652
-				new \OC\Security\CertificateManager(
653
-					$uid,
654
-					new View(),
655
-					$c->getConfig(),
656
-					$c->getLogger(),
657
-					$c->getSecureRandom()
658
-				)
659
-			);
660
-		});
661
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
662
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
663
-			$eventLogger = new EventLogger();
664
-			if ($c->getSystemConfig()->getValue('debug', false)) {
665
-				// In debug mode, module is being activated by default
666
-				$eventLogger->activate();
667
-			}
668
-			return $eventLogger;
669
-		});
670
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
671
-
672
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
673
-			$queryLogger = new QueryLogger();
674
-			if ($c->getSystemConfig()->getValue('debug', false)) {
675
-				// In debug mode, module is being activated by default
676
-				$queryLogger->activate();
677
-			}
678
-			return $queryLogger;
679
-		});
680
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
681
-
682
-		$this->registerService(TempManager::class, function (Server $c) {
683
-			return new TempManager(
684
-				$c->getLogger(),
685
-				$c->getConfig()
686
-			);
687
-		});
688
-		$this->registerAlias('TempManager', TempManager::class);
689
-		$this->registerAlias(ITempManager::class, TempManager::class);
690
-
691
-		$this->registerService(AppManager::class, function (Server $c) {
692
-			return new \OC\App\AppManager(
693
-				$c->getUserSession(),
694
-				$c->query(\OC\AppConfig::class),
695
-				$c->getGroupManager(),
696
-				$c->getMemCacheFactory(),
697
-				$c->getEventDispatcher()
698
-			);
699
-		});
700
-		$this->registerAlias('AppManager', AppManager::class);
701
-		$this->registerAlias(IAppManager::class, AppManager::class);
702
-
703
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
704
-			return new DateTimeZone(
705
-				$c->getConfig(),
706
-				$c->getSession()
707
-			);
708
-		});
709
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
710
-
711
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
712
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
713
-
714
-			return new DateTimeFormatter(
715
-				$c->getDateTimeZone()->getTimeZone(),
716
-				$c->getL10N('lib', $language)
717
-			);
718
-		});
719
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
720
-
721
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
722
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
723
-			$listener = new UserMountCacheListener($mountCache);
724
-			$listener->listen($c->getUserManager());
725
-			return $mountCache;
726
-		});
727
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
728
-
729
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
730
-			$loader = \OC\Files\Filesystem::getLoader();
731
-			$mountCache = $c->query('UserMountCache');
732
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
733
-
734
-			// builtin providers
735
-
736
-			$config = $c->getConfig();
737
-			$manager->registerProvider(new CacheMountProvider($config));
738
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
739
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
740
-
741
-			return $manager;
742
-		});
743
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
744
-
745
-		$this->registerService('IniWrapper', function ($c) {
746
-			return new IniGetWrapper();
747
-		});
748
-		$this->registerService('AsyncCommandBus', function (Server $c) {
749
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
750
-			if ($busClass) {
751
-				list($app, $class) = explode('::', $busClass, 2);
752
-				if ($c->getAppManager()->isInstalled($app)) {
753
-					\OC_App::loadApp($app);
754
-					return $c->query($class);
755
-				} else {
756
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
757
-				}
758
-			} else {
759
-				$jobList = $c->getJobList();
760
-				return new CronBus($jobList);
761
-			}
762
-		});
763
-		$this->registerService('TrustedDomainHelper', function ($c) {
764
-			return new TrustedDomainHelper($this->getConfig());
765
-		});
766
-		$this->registerService(Throttler::class, function (Server $c) {
767
-			return new Throttler(
768
-				$c->getDatabaseConnection(),
769
-				new TimeFactory(),
770
-				$c->getLogger(),
771
-				$c->getConfig()
772
-			);
773
-		});
774
-		$this->registerAlias('Throttler', Throttler::class);
775
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
776
-			// IConfig and IAppManager requires a working database. This code
777
-			// might however be called when ownCloud is not yet setup.
778
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
779
-				$config = $c->getConfig();
780
-				$appManager = $c->getAppManager();
781
-			} else {
782
-				$config = null;
783
-				$appManager = null;
784
-			}
785
-
786
-			return new Checker(
787
-				new EnvironmentHelper(),
788
-				new FileAccessHelper(),
789
-				new AppLocator(),
790
-				$config,
791
-				$c->getMemCacheFactory(),
792
-				$appManager,
793
-				$c->getTempManager(),
794
-				$c->getMimeTypeDetector()
795
-			);
796
-		});
797
-		$this->registerService(\OCP\IRequest::class, function ($c) {
798
-			if (isset($this['urlParams'])) {
799
-				$urlParams = $this['urlParams'];
800
-			} else {
801
-				$urlParams = [];
802
-			}
803
-
804
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
805
-				&& in_array('fakeinput', stream_get_wrappers())
806
-			) {
807
-				$stream = 'fakeinput://data';
808
-			} else {
809
-				$stream = 'php://input';
810
-			}
811
-
812
-			return new Request(
813
-				[
814
-					'get' => $_GET,
815
-					'post' => $_POST,
816
-					'files' => $_FILES,
817
-					'server' => $_SERVER,
818
-					'env' => $_ENV,
819
-					'cookies' => $_COOKIE,
820
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
821
-						? $_SERVER['REQUEST_METHOD']
822
-						: '',
823
-					'urlParams' => $urlParams,
824
-				],
825
-				$this->getSecureRandom(),
826
-				$this->getConfig(),
827
-				$this->getCsrfTokenManager(),
828
-				$stream
829
-			);
830
-		});
831
-		$this->registerAlias('Request', \OCP\IRequest::class);
832
-
833
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
834
-			return new Mailer(
835
-				$c->getConfig(),
836
-				$c->getLogger(),
837
-				$c->query(Defaults::class),
838
-				$c->getURLGenerator(),
839
-				$c->getL10N('lib')
840
-			);
841
-		});
842
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
843
-
844
-		$this->registerService('LDAPProvider', function (Server $c) {
845
-			$config = $c->getConfig();
846
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
847
-			if (is_null($factoryClass)) {
848
-				throw new \Exception('ldapProviderFactory not set');
849
-			}
850
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
851
-			$factory = new $factoryClass($this);
852
-			return $factory->getLDAPProvider();
853
-		});
854
-		$this->registerService(ILockingProvider::class, function (Server $c) {
855
-			$ini = $c->getIniWrapper();
856
-			$config = $c->getConfig();
857
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
858
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
859
-				/** @var \OC\Memcache\Factory $memcacheFactory */
860
-				$memcacheFactory = $c->getMemCacheFactory();
861
-				$memcache = $memcacheFactory->createLocking('lock');
862
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
863
-					return new MemcacheLockingProvider($memcache, $ttl);
864
-				}
865
-				return new DBLockingProvider(
866
-					$c->getDatabaseConnection(),
867
-					$c->getLogger(),
868
-					new TimeFactory(),
869
-					$ttl,
870
-					!\OC::$CLI
871
-				);
872
-			}
873
-			return new NoopLockingProvider();
874
-		});
875
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
876
-
877
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
878
-			return new \OC\Files\Mount\Manager();
879
-		});
880
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
881
-
882
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
883
-			return new \OC\Files\Type\Detection(
884
-				$c->getURLGenerator(),
885
-				\OC::$configDir,
886
-				\OC::$SERVERROOT . '/resources/config/'
887
-			);
888
-		});
889
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
890
-
891
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
892
-			return new \OC\Files\Type\Loader(
893
-				$c->getDatabaseConnection()
894
-			);
895
-		});
896
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
897
-		$this->registerService(BundleFetcher::class, function () {
898
-			return new BundleFetcher($this->getL10N('lib'));
899
-		});
900
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
901
-			return new Manager(
902
-				$c->query(IValidator::class)
903
-			);
904
-		});
905
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
906
-
907
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
908
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
909
-			$manager->registerCapability(function () use ($c) {
910
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
911
-			});
912
-			$manager->registerCapability(function () use ($c) {
913
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
914
-			});
915
-			return $manager;
916
-		});
917
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
918
-
919
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
920
-			$config = $c->getConfig();
921
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
922
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
923
-			$factory = new $factoryClass($this);
924
-			$manager = $factory->getManager();
925
-
926
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
927
-				$manager = $c->getUserManager();
928
-				$user = $manager->get($id);
929
-				if(is_null($user)) {
930
-					$l = $c->getL10N('core');
931
-					$displayName = $l->t('Unknown user');
932
-				} else {
933
-					$displayName = $user->getDisplayName();
934
-				}
935
-				return $displayName;
936
-			});
937
-
938
-			return $manager;
939
-		});
940
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
941
-
942
-		$this->registerService('ThemingDefaults', function (Server $c) {
943
-			/*
171
+    /** @var string */
172
+    private $webRoot;
173
+
174
+    /**
175
+     * @param string $webRoot
176
+     * @param \OC\Config $config
177
+     */
178
+    public function __construct($webRoot, \OC\Config $config) {
179
+        parent::__construct();
180
+        $this->webRoot = $webRoot;
181
+
182
+        // To find out if we are running from CLI or not
183
+        $this->registerParameter('isCLI', \OC::$CLI);
184
+
185
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
186
+            return $c;
187
+        });
188
+
189
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
190
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
191
+
192
+        $this->registerAlias(\OCP\Calendar\Resource\IManager::class, \OC\Calendar\Resource\Manager::class);
193
+        $this->registerAlias('CalendarResourceBackendManager', \OC\Calendar\Resource\Manager::class);
194
+
195
+        $this->registerAlias(\OCP\Calendar\Room\IManager::class, \OC\Calendar\Room\Manager::class);
196
+        $this->registerAlias('CalendarRoomBackendManager', \OC\Calendar\Room\Manager::class);
197
+
198
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
199
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
200
+
201
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
202
+
203
+
204
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
205
+            return new PreviewManager(
206
+                $c->getConfig(),
207
+                $c->getRootFolder(),
208
+                $c->getAppDataDir('preview'),
209
+                $c->getEventDispatcher(),
210
+                $c->getGeneratorHelper(),
211
+                $c->getSession()->get('user_id')
212
+            );
213
+        });
214
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
215
+
216
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
217
+            return new \OC\Preview\Watcher(
218
+                $c->getAppDataDir('preview')
219
+            );
220
+        });
221
+
222
+        $this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
223
+            $view = new View();
224
+            $util = new Encryption\Util(
225
+                $view,
226
+                $c->getUserManager(),
227
+                $c->getGroupManager(),
228
+                $c->getConfig()
229
+            );
230
+            return new Encryption\Manager(
231
+                $c->getConfig(),
232
+                $c->getLogger(),
233
+                $c->getL10N('core'),
234
+                new View(),
235
+                $util,
236
+                new ArrayCache()
237
+            );
238
+        });
239
+        $this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
240
+
241
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
242
+            $util = new Encryption\Util(
243
+                new View(),
244
+                $c->getUserManager(),
245
+                $c->getGroupManager(),
246
+                $c->getConfig()
247
+            );
248
+            return new Encryption\File(
249
+                $util,
250
+                $c->getRootFolder(),
251
+                $c->getShareManager()
252
+            );
253
+        });
254
+
255
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
256
+            $view = new View();
257
+            $util = new Encryption\Util(
258
+                $view,
259
+                $c->getUserManager(),
260
+                $c->getGroupManager(),
261
+                $c->getConfig()
262
+            );
263
+
264
+            return new Encryption\Keys\Storage($view, $util);
265
+        });
266
+        $this->registerService('TagMapper', function (Server $c) {
267
+            return new TagMapper($c->getDatabaseConnection());
268
+        });
269
+
270
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
271
+            $tagMapper = $c->query('TagMapper');
272
+            return new TagManager($tagMapper, $c->getUserSession());
273
+        });
274
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
275
+
276
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
277
+            $config = $c->getConfig();
278
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
279
+            return new $factoryClass($this);
280
+        });
281
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
282
+            return $c->query('SystemTagManagerFactory')->getManager();
283
+        });
284
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
285
+
286
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
287
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
288
+        });
289
+        $this->registerService('RootFolder', function (Server $c) {
290
+            $manager = \OC\Files\Filesystem::getMountManager(null);
291
+            $view = new View();
292
+            $root = new Root(
293
+                $manager,
294
+                $view,
295
+                null,
296
+                $c->getUserMountCache(),
297
+                $this->getLogger(),
298
+                $this->getUserManager()
299
+            );
300
+            $connector = new HookConnector($root, $view);
301
+            $connector->viewToNode();
302
+
303
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
304
+            $previewConnector->connectWatcher();
305
+
306
+            return $root;
307
+        });
308
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
309
+
310
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
311
+            return new LazyRoot(function () use ($c) {
312
+                return $c->query('RootFolder');
313
+            });
314
+        });
315
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
316
+
317
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
318
+            return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
319
+        });
320
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
321
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
322
+
323
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
324
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
325
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
326
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
327
+            });
328
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
329
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
330
+            });
331
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
332
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
333
+            });
334
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
335
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
336
+            });
337
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
338
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
339
+            });
340
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
341
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
342
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
343
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
344
+            });
345
+            return $groupManager;
346
+        });
347
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
348
+
349
+        $this->registerService(Store::class, function (Server $c) {
350
+            $session = $c->getSession();
351
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
352
+                $tokenProvider = $c->query(IProvider::class);
353
+            } else {
354
+                $tokenProvider = null;
355
+            }
356
+            $logger = $c->getLogger();
357
+            return new Store($session, $logger, $tokenProvider);
358
+        });
359
+        $this->registerAlias(IStore::class, Store::class);
360
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
361
+            $dbConnection = $c->getDatabaseConnection();
362
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
363
+        });
364
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
365
+
366
+        $this->registerService(\OC\User\Session::class, function (Server $c) {
367
+            $manager = $c->getUserManager();
368
+            $session = new \OC\Session\Memory('');
369
+            $timeFactory = new TimeFactory();
370
+            // Token providers might require a working database. This code
371
+            // might however be called when ownCloud is not yet setup.
372
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
373
+                $defaultTokenProvider = $c->query(IProvider::class);
374
+            } else {
375
+                $defaultTokenProvider = null;
376
+            }
377
+
378
+            $dispatcher = $c->getEventDispatcher();
379
+
380
+            $userSession = new \OC\User\Session(
381
+                $manager,
382
+                $session,
383
+                $timeFactory,
384
+                $defaultTokenProvider,
385
+                $c->getConfig(),
386
+                $c->getSecureRandom(),
387
+                $c->getLockdownManager(),
388
+                $c->getLogger()
389
+            );
390
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
391
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
392
+            });
393
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
394
+                /** @var $user \OC\User\User */
395
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
396
+            });
397
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
398
+                /** @var $user \OC\User\User */
399
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
400
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
401
+            });
402
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
403
+                /** @var $user \OC\User\User */
404
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
405
+            });
406
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
407
+                /** @var $user \OC\User\User */
408
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
409
+            });
410
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
411
+                /** @var $user \OC\User\User */
412
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
413
+            });
414
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
415
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
416
+            });
417
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
418
+                /** @var $user \OC\User\User */
419
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
420
+            });
421
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
422
+                /** @var $user \OC\User\User */
423
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
424
+            });
425
+            $userSession->listen('\OC\User', 'logout', function () {
426
+                \OC_Hook::emit('OC_User', 'logout', array());
427
+            });
428
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
429
+                /** @var $user \OC\User\User */
430
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
431
+            });
432
+            return $userSession;
433
+        });
434
+        $this->registerAlias(\OCP\IUserSession::class, \OC\User\Session::class);
435
+        $this->registerAlias('UserSession', \OC\User\Session::class);
436
+
437
+        $this->registerAlias(\OCP\Authentication\TwoFactorAuth\IRegistry::class, \OC\Authentication\TwoFactorAuth\Registry::class);
438
+
439
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
440
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
441
+
442
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
443
+            return new \OC\AllConfig(
444
+                $c->getSystemConfig()
445
+            );
446
+        });
447
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
448
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
449
+
450
+        $this->registerService('SystemConfig', function ($c) use ($config) {
451
+            return new \OC\SystemConfig($config);
452
+        });
453
+
454
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
455
+            return new \OC\AppConfig($c->getDatabaseConnection());
456
+        });
457
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
458
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
459
+
460
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
461
+            return new \OC\L10N\Factory(
462
+                $c->getConfig(),
463
+                $c->getRequest(),
464
+                $c->getUserSession(),
465
+                \OC::$SERVERROOT
466
+            );
467
+        });
468
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
469
+
470
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
471
+            $config = $c->getConfig();
472
+            $cacheFactory = $c->getMemCacheFactory();
473
+            $request = $c->getRequest();
474
+            return new \OC\URLGenerator(
475
+                $config,
476
+                $cacheFactory,
477
+                $request
478
+            );
479
+        });
480
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
481
+
482
+        $this->registerAlias('AppFetcher', AppFetcher::class);
483
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
484
+
485
+        $this->registerService(\OCP\ICache::class, function ($c) {
486
+            return new Cache\File();
487
+        });
488
+        $this->registerAlias('UserCache', \OCP\ICache::class);
489
+
490
+        $this->registerService(Factory::class, function (Server $c) {
491
+
492
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
493
+                ArrayCache::class,
494
+                ArrayCache::class,
495
+                ArrayCache::class
496
+            );
497
+            $config = $c->getConfig();
498
+
499
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
500
+                $v = \OC_App::getAppVersions();
501
+                $v['core'] = implode(',', \OC_Util::getVersion());
502
+                $version = implode(',', $v);
503
+                $instanceId = \OC_Util::getInstanceId();
504
+                $path = \OC::$SERVERROOT;
505
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
506
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
507
+                    $config->getSystemValue('memcache.local', null),
508
+                    $config->getSystemValue('memcache.distributed', null),
509
+                    $config->getSystemValue('memcache.locking', null)
510
+                );
511
+            }
512
+            return $arrayCacheFactory;
513
+
514
+        });
515
+        $this->registerAlias('MemCacheFactory', Factory::class);
516
+        $this->registerAlias(ICacheFactory::class, Factory::class);
517
+
518
+        $this->registerService('RedisFactory', function (Server $c) {
519
+            $systemConfig = $c->getSystemConfig();
520
+            return new RedisFactory($systemConfig);
521
+        });
522
+
523
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
524
+            return new \OC\Activity\Manager(
525
+                $c->getRequest(),
526
+                $c->getUserSession(),
527
+                $c->getConfig(),
528
+                $c->query(IValidator::class)
529
+            );
530
+        });
531
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
532
+
533
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
534
+            return new \OC\Activity\EventMerger(
535
+                $c->getL10N('lib')
536
+            );
537
+        });
538
+        $this->registerAlias(IValidator::class, Validator::class);
539
+
540
+        $this->registerService(AvatarManager::class, function(Server $c) {
541
+            return new AvatarManager(
542
+                $c->query(\OC\User\Manager::class),
543
+                $c->getAppDataDir('avatar'),
544
+                $c->getL10N('lib'),
545
+                $c->getLogger(),
546
+                $c->getConfig()
547
+            );
548
+        });
549
+        $this->registerAlias(\OCP\IAvatarManager::class, AvatarManager::class);
550
+        $this->registerAlias('AvatarManager', AvatarManager::class);
551
+
552
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
553
+        $this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
554
+
555
+        $this->registerService(\OC\Log::class, function (Server $c) {
556
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
557
+            $factory = new LogFactory($c, $this->getSystemConfig());
558
+            $logger = $factory->get($logType);
559
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
560
+
561
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
562
+        });
563
+        $this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
564
+        $this->registerAlias('Logger', \OC\Log::class);
565
+
566
+        $this->registerService(ILogFactory::class, function (Server $c) {
567
+            return new LogFactory($c, $this->getSystemConfig());
568
+        });
569
+
570
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
571
+            $config = $c->getConfig();
572
+            return new \OC\BackgroundJob\JobList(
573
+                $c->getDatabaseConnection(),
574
+                $config,
575
+                new TimeFactory()
576
+            );
577
+        });
578
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
579
+
580
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
581
+            $cacheFactory = $c->getMemCacheFactory();
582
+            $logger = $c->getLogger();
583
+            if ($cacheFactory->isLocalCacheAvailable()) {
584
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
585
+            } else {
586
+                $router = new \OC\Route\Router($logger);
587
+            }
588
+            return $router;
589
+        });
590
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
591
+
592
+        $this->registerService(\OCP\ISearch::class, function ($c) {
593
+            return new Search();
594
+        });
595
+        $this->registerAlias('Search', \OCP\ISearch::class);
596
+
597
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
598
+            return new \OC\Security\RateLimiting\Limiter(
599
+                $this->getUserSession(),
600
+                $this->getRequest(),
601
+                new \OC\AppFramework\Utility\TimeFactory(),
602
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
603
+            );
604
+        });
605
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
606
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
607
+                $this->getMemCacheFactory(),
608
+                new \OC\AppFramework\Utility\TimeFactory()
609
+            );
610
+        });
611
+
612
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
613
+            return new SecureRandom();
614
+        });
615
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
616
+
617
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
618
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
619
+        });
620
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
621
+
622
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
623
+            return new Hasher($c->getConfig());
624
+        });
625
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
626
+
627
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
628
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
629
+        });
630
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
631
+
632
+        $this->registerService(IDBConnection::class, function (Server $c) {
633
+            $systemConfig = $c->getSystemConfig();
634
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
635
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
636
+            if (!$factory->isValidType($type)) {
637
+                throw new \OC\DatabaseException('Invalid database type');
638
+            }
639
+            $connectionParams = $factory->createConnectionParams();
640
+            $connection = $factory->getConnection($type, $connectionParams);
641
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
642
+            return $connection;
643
+        });
644
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
645
+
646
+
647
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
648
+            $user = \OC_User::getUser();
649
+            $uid = $user ? $user : null;
650
+            return new ClientService(
651
+                $c->getConfig(),
652
+                new \OC\Security\CertificateManager(
653
+                    $uid,
654
+                    new View(),
655
+                    $c->getConfig(),
656
+                    $c->getLogger(),
657
+                    $c->getSecureRandom()
658
+                )
659
+            );
660
+        });
661
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
662
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
663
+            $eventLogger = new EventLogger();
664
+            if ($c->getSystemConfig()->getValue('debug', false)) {
665
+                // In debug mode, module is being activated by default
666
+                $eventLogger->activate();
667
+            }
668
+            return $eventLogger;
669
+        });
670
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
671
+
672
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
673
+            $queryLogger = new QueryLogger();
674
+            if ($c->getSystemConfig()->getValue('debug', false)) {
675
+                // In debug mode, module is being activated by default
676
+                $queryLogger->activate();
677
+            }
678
+            return $queryLogger;
679
+        });
680
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
681
+
682
+        $this->registerService(TempManager::class, function (Server $c) {
683
+            return new TempManager(
684
+                $c->getLogger(),
685
+                $c->getConfig()
686
+            );
687
+        });
688
+        $this->registerAlias('TempManager', TempManager::class);
689
+        $this->registerAlias(ITempManager::class, TempManager::class);
690
+
691
+        $this->registerService(AppManager::class, function (Server $c) {
692
+            return new \OC\App\AppManager(
693
+                $c->getUserSession(),
694
+                $c->query(\OC\AppConfig::class),
695
+                $c->getGroupManager(),
696
+                $c->getMemCacheFactory(),
697
+                $c->getEventDispatcher()
698
+            );
699
+        });
700
+        $this->registerAlias('AppManager', AppManager::class);
701
+        $this->registerAlias(IAppManager::class, AppManager::class);
702
+
703
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
704
+            return new DateTimeZone(
705
+                $c->getConfig(),
706
+                $c->getSession()
707
+            );
708
+        });
709
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
710
+
711
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
712
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
713
+
714
+            return new DateTimeFormatter(
715
+                $c->getDateTimeZone()->getTimeZone(),
716
+                $c->getL10N('lib', $language)
717
+            );
718
+        });
719
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
720
+
721
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
722
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
723
+            $listener = new UserMountCacheListener($mountCache);
724
+            $listener->listen($c->getUserManager());
725
+            return $mountCache;
726
+        });
727
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
728
+
729
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
730
+            $loader = \OC\Files\Filesystem::getLoader();
731
+            $mountCache = $c->query('UserMountCache');
732
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
733
+
734
+            // builtin providers
735
+
736
+            $config = $c->getConfig();
737
+            $manager->registerProvider(new CacheMountProvider($config));
738
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
739
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
740
+
741
+            return $manager;
742
+        });
743
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
744
+
745
+        $this->registerService('IniWrapper', function ($c) {
746
+            return new IniGetWrapper();
747
+        });
748
+        $this->registerService('AsyncCommandBus', function (Server $c) {
749
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
750
+            if ($busClass) {
751
+                list($app, $class) = explode('::', $busClass, 2);
752
+                if ($c->getAppManager()->isInstalled($app)) {
753
+                    \OC_App::loadApp($app);
754
+                    return $c->query($class);
755
+                } else {
756
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
757
+                }
758
+            } else {
759
+                $jobList = $c->getJobList();
760
+                return new CronBus($jobList);
761
+            }
762
+        });
763
+        $this->registerService('TrustedDomainHelper', function ($c) {
764
+            return new TrustedDomainHelper($this->getConfig());
765
+        });
766
+        $this->registerService(Throttler::class, function (Server $c) {
767
+            return new Throttler(
768
+                $c->getDatabaseConnection(),
769
+                new TimeFactory(),
770
+                $c->getLogger(),
771
+                $c->getConfig()
772
+            );
773
+        });
774
+        $this->registerAlias('Throttler', Throttler::class);
775
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
776
+            // IConfig and IAppManager requires a working database. This code
777
+            // might however be called when ownCloud is not yet setup.
778
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
779
+                $config = $c->getConfig();
780
+                $appManager = $c->getAppManager();
781
+            } else {
782
+                $config = null;
783
+                $appManager = null;
784
+            }
785
+
786
+            return new Checker(
787
+                new EnvironmentHelper(),
788
+                new FileAccessHelper(),
789
+                new AppLocator(),
790
+                $config,
791
+                $c->getMemCacheFactory(),
792
+                $appManager,
793
+                $c->getTempManager(),
794
+                $c->getMimeTypeDetector()
795
+            );
796
+        });
797
+        $this->registerService(\OCP\IRequest::class, function ($c) {
798
+            if (isset($this['urlParams'])) {
799
+                $urlParams = $this['urlParams'];
800
+            } else {
801
+                $urlParams = [];
802
+            }
803
+
804
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
805
+                && in_array('fakeinput', stream_get_wrappers())
806
+            ) {
807
+                $stream = 'fakeinput://data';
808
+            } else {
809
+                $stream = 'php://input';
810
+            }
811
+
812
+            return new Request(
813
+                [
814
+                    'get' => $_GET,
815
+                    'post' => $_POST,
816
+                    'files' => $_FILES,
817
+                    'server' => $_SERVER,
818
+                    'env' => $_ENV,
819
+                    'cookies' => $_COOKIE,
820
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
821
+                        ? $_SERVER['REQUEST_METHOD']
822
+                        : '',
823
+                    'urlParams' => $urlParams,
824
+                ],
825
+                $this->getSecureRandom(),
826
+                $this->getConfig(),
827
+                $this->getCsrfTokenManager(),
828
+                $stream
829
+            );
830
+        });
831
+        $this->registerAlias('Request', \OCP\IRequest::class);
832
+
833
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
834
+            return new Mailer(
835
+                $c->getConfig(),
836
+                $c->getLogger(),
837
+                $c->query(Defaults::class),
838
+                $c->getURLGenerator(),
839
+                $c->getL10N('lib')
840
+            );
841
+        });
842
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
843
+
844
+        $this->registerService('LDAPProvider', function (Server $c) {
845
+            $config = $c->getConfig();
846
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
847
+            if (is_null($factoryClass)) {
848
+                throw new \Exception('ldapProviderFactory not set');
849
+            }
850
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
851
+            $factory = new $factoryClass($this);
852
+            return $factory->getLDAPProvider();
853
+        });
854
+        $this->registerService(ILockingProvider::class, function (Server $c) {
855
+            $ini = $c->getIniWrapper();
856
+            $config = $c->getConfig();
857
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
858
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
859
+                /** @var \OC\Memcache\Factory $memcacheFactory */
860
+                $memcacheFactory = $c->getMemCacheFactory();
861
+                $memcache = $memcacheFactory->createLocking('lock');
862
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
863
+                    return new MemcacheLockingProvider($memcache, $ttl);
864
+                }
865
+                return new DBLockingProvider(
866
+                    $c->getDatabaseConnection(),
867
+                    $c->getLogger(),
868
+                    new TimeFactory(),
869
+                    $ttl,
870
+                    !\OC::$CLI
871
+                );
872
+            }
873
+            return new NoopLockingProvider();
874
+        });
875
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
876
+
877
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
878
+            return new \OC\Files\Mount\Manager();
879
+        });
880
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
881
+
882
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
883
+            return new \OC\Files\Type\Detection(
884
+                $c->getURLGenerator(),
885
+                \OC::$configDir,
886
+                \OC::$SERVERROOT . '/resources/config/'
887
+            );
888
+        });
889
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
890
+
891
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
892
+            return new \OC\Files\Type\Loader(
893
+                $c->getDatabaseConnection()
894
+            );
895
+        });
896
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
897
+        $this->registerService(BundleFetcher::class, function () {
898
+            return new BundleFetcher($this->getL10N('lib'));
899
+        });
900
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
901
+            return new Manager(
902
+                $c->query(IValidator::class)
903
+            );
904
+        });
905
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
906
+
907
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
908
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
909
+            $manager->registerCapability(function () use ($c) {
910
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
911
+            });
912
+            $manager->registerCapability(function () use ($c) {
913
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
914
+            });
915
+            return $manager;
916
+        });
917
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
918
+
919
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
920
+            $config = $c->getConfig();
921
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
922
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
923
+            $factory = new $factoryClass($this);
924
+            $manager = $factory->getManager();
925
+
926
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
927
+                $manager = $c->getUserManager();
928
+                $user = $manager->get($id);
929
+                if(is_null($user)) {
930
+                    $l = $c->getL10N('core');
931
+                    $displayName = $l->t('Unknown user');
932
+                } else {
933
+                    $displayName = $user->getDisplayName();
934
+                }
935
+                return $displayName;
936
+            });
937
+
938
+            return $manager;
939
+        });
940
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
941
+
942
+        $this->registerService('ThemingDefaults', function (Server $c) {
943
+            /*
944 944
 			 * Dark magic for autoloader.
945 945
 			 * If we do a class_exists it will try to load the class which will
946 946
 			 * make composer cache the result. Resulting in errors when enabling
947 947
 			 * the theming app.
948 948
 			 */
949
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
950
-			if (isset($prefixes['OCA\\Theming\\'])) {
951
-				$classExists = true;
952
-			} else {
953
-				$classExists = false;
954
-			}
955
-
956
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
957
-				return new ThemingDefaults(
958
-					$c->getConfig(),
959
-					$c->getL10N('theming'),
960
-					$c->getURLGenerator(),
961
-					$c->getMemCacheFactory(),
962
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
963
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
964
-					$c->getAppManager(),
965
-					$c->getNavigationManager()
966
-				);
967
-			}
968
-			return new \OC_Defaults();
969
-		});
970
-		$this->registerService(SCSSCacher::class, function (Server $c) {
971
-			return new SCSSCacher(
972
-				$c->getLogger(),
973
-				$c->query(\OC\Files\AppData\Factory::class),
974
-				$c->getURLGenerator(),
975
-				$c->getConfig(),
976
-				$c->getThemingDefaults(),
977
-				\OC::$SERVERROOT,
978
-				$this->getMemCacheFactory(),
979
-				$c->query(IconsCacher::class),
980
-				new TimeFactory()
981
-			);
982
-		});
983
-		$this->registerService(JSCombiner::class, function (Server $c) {
984
-			return new JSCombiner(
985
-				$c->getAppDataDir('js'),
986
-				$c->getURLGenerator(),
987
-				$this->getMemCacheFactory(),
988
-				$c->getSystemConfig(),
989
-				$c->getLogger()
990
-			);
991
-		});
992
-		$this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
993
-		$this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
994
-		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
995
-
996
-		$this->registerService('CryptoWrapper', function (Server $c) {
997
-			// FIXME: Instantiiated here due to cyclic dependency
998
-			$request = new Request(
999
-				[
1000
-					'get' => $_GET,
1001
-					'post' => $_POST,
1002
-					'files' => $_FILES,
1003
-					'server' => $_SERVER,
1004
-					'env' => $_ENV,
1005
-					'cookies' => $_COOKIE,
1006
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1007
-						? $_SERVER['REQUEST_METHOD']
1008
-						: null,
1009
-				],
1010
-				$c->getSecureRandom(),
1011
-				$c->getConfig()
1012
-			);
1013
-
1014
-			return new CryptoWrapper(
1015
-				$c->getConfig(),
1016
-				$c->getCrypto(),
1017
-				$c->getSecureRandom(),
1018
-				$request
1019
-			);
1020
-		});
1021
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1022
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1023
-
1024
-			return new CsrfTokenManager(
1025
-				$tokenGenerator,
1026
-				$c->query(SessionStorage::class)
1027
-			);
1028
-		});
1029
-		$this->registerService(SessionStorage::class, function (Server $c) {
1030
-			return new SessionStorage($c->getSession());
1031
-		});
1032
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1033
-			return new ContentSecurityPolicyManager();
1034
-		});
1035
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1036
-
1037
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1038
-			return new ContentSecurityPolicyNonceManager(
1039
-				$c->getCsrfTokenManager(),
1040
-				$c->getRequest()
1041
-			);
1042
-		});
1043
-
1044
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1045
-			$config = $c->getConfig();
1046
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1047
-			/** @var \OCP\Share\IProviderFactory $factory */
1048
-			$factory = new $factoryClass($this);
1049
-
1050
-			$manager = new \OC\Share20\Manager(
1051
-				$c->getLogger(),
1052
-				$c->getConfig(),
1053
-				$c->getSecureRandom(),
1054
-				$c->getHasher(),
1055
-				$c->getMountManager(),
1056
-				$c->getGroupManager(),
1057
-				$c->getL10N('lib'),
1058
-				$c->getL10NFactory(),
1059
-				$factory,
1060
-				$c->getUserManager(),
1061
-				$c->getLazyRootFolder(),
1062
-				$c->getEventDispatcher(),
1063
-				$c->getMailer(),
1064
-				$c->getURLGenerator(),
1065
-				$c->getThemingDefaults()
1066
-			);
1067
-
1068
-			return $manager;
1069
-		});
1070
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1071
-
1072
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1073
-			$instance = new Collaboration\Collaborators\Search($c);
1074
-
1075
-			// register default plugins
1076
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1077
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1078
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1079
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1080
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1081
-
1082
-			return $instance;
1083
-		});
1084
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1085
-		$this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1086
-
1087
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1088
-
1089
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1090
-
1091
-		$this->registerService('SettingsManager', function (Server $c) {
1092
-			$manager = new \OC\Settings\Manager(
1093
-				$c->getLogger(),
1094
-				$c->getL10NFactory(),
1095
-				$c->getURLGenerator(),
1096
-				$c
1097
-			);
1098
-			return $manager;
1099
-		});
1100
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1101
-			return new \OC\Files\AppData\Factory(
1102
-				$c->getRootFolder(),
1103
-				$c->getSystemConfig()
1104
-			);
1105
-		});
1106
-
1107
-		$this->registerService('LockdownManager', function (Server $c) {
1108
-			return new LockdownManager(function () use ($c) {
1109
-				return $c->getSession();
1110
-			});
1111
-		});
1112
-
1113
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1114
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1115
-		});
1116
-
1117
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1118
-			return new CloudIdManager();
1119
-		});
1120
-
1121
-		$this->registerService(IConfig::class, function (Server $c) {
1122
-			return new GlobalScale\Config($c->getConfig());
1123
-		});
1124
-
1125
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1126
-			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1127
-		});
1128
-
1129
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1130
-			return new CloudFederationFactory();
1131
-		});
1132
-
1133
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1134
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1135
-
1136
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1137
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1138
-
1139
-		$this->registerService(Defaults::class, function (Server $c) {
1140
-			return new Defaults(
1141
-				$c->getThemingDefaults()
1142
-			);
1143
-		});
1144
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1145
-
1146
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1147
-			return $c->query(\OCP\IUserSession::class)->getSession();
1148
-		});
1149
-
1150
-		$this->registerService(IShareHelper::class, function (Server $c) {
1151
-			return new ShareHelper(
1152
-				$c->query(\OCP\Share\IManager::class)
1153
-			);
1154
-		});
1155
-
1156
-		$this->registerService(Installer::class, function(Server $c) {
1157
-			return new Installer(
1158
-				$c->getAppFetcher(),
1159
-				$c->getHTTPClientService(),
1160
-				$c->getTempManager(),
1161
-				$c->getLogger(),
1162
-				$c->getConfig()
1163
-			);
1164
-		});
1165
-
1166
-		$this->registerService(IApiFactory::class, function(Server $c) {
1167
-			return new ApiFactory($c->getHTTPClientService());
1168
-		});
1169
-
1170
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1171
-			$memcacheFactory = $c->getMemCacheFactory();
1172
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1173
-		});
1174
-
1175
-		$this->registerService(IContactsStore::class, function(Server $c) {
1176
-			return new ContactsStore(
1177
-				$c->getContactsManager(),
1178
-				$c->getConfig(),
1179
-				$c->getUserManager(),
1180
-				$c->getGroupManager()
1181
-			);
1182
-		});
1183
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1184
-		$this->registerAlias(IAccountManager::class, AccountManager::class);
1185
-
1186
-		$this->registerService(IStorageFactory::class, function() {
1187
-			return new StorageFactory();
1188
-		});
1189
-
1190
-		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1191
-		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1192
-
1193
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1194
-			return new \OC\Security\IdentityProof\Manager(
1195
-				$c->query(\OC\Files\AppData\Factory::class),
1196
-				$c->getCrypto(),
1197
-				$c->getConfig()
1198
-			);
1199
-		});
1200
-
1201
-		$this->registerAlias(ISubAdmin::class, SubAdmin::class);
1202
-
1203
-		$this->registerAlias(IInitialStateService::class, InitialStateService::class);
1204
-
1205
-		$this->connectDispatcher();
1206
-	}
1207
-
1208
-	/**
1209
-	 * @return \OCP\Calendar\IManager
1210
-	 */
1211
-	public function getCalendarManager() {
1212
-		return $this->query('CalendarManager');
1213
-	}
1214
-
1215
-	/**
1216
-	 * @return \OCP\Calendar\Resource\IManager
1217
-	 */
1218
-	public function getCalendarResourceBackendManager() {
1219
-		return $this->query('CalendarResourceBackendManager');
1220
-	}
1221
-
1222
-	/**
1223
-	 * @return \OCP\Calendar\Room\IManager
1224
-	 */
1225
-	public function getCalendarRoomBackendManager() {
1226
-		return $this->query('CalendarRoomBackendManager');
1227
-	}
1228
-
1229
-	private function connectDispatcher() {
1230
-		$dispatcher = $this->getEventDispatcher();
1231
-
1232
-		// Delete avatar on user deletion
1233
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1234
-			$logger = $this->getLogger();
1235
-			$manager = $this->getAvatarManager();
1236
-			/** @var IUser $user */
1237
-			$user = $e->getSubject();
1238
-
1239
-			try {
1240
-				$avatar = $manager->getAvatar($user->getUID());
1241
-				$avatar->remove();
1242
-			} catch (NotFoundException $e) {
1243
-				// no avatar to remove
1244
-			} catch (\Exception $e) {
1245
-				// Ignore exceptions
1246
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1247
-			}
1248
-		});
1249
-
1250
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1251
-			$manager = $this->getAvatarManager();
1252
-			/** @var IUser $user */
1253
-			$user = $e->getSubject();
1254
-			$feature = $e->getArgument('feature');
1255
-			$oldValue = $e->getArgument('oldValue');
1256
-			$value = $e->getArgument('value');
1257
-
1258
-			// We only change the avatar on display name changes
1259
-			if ($feature !== 'displayName') {
1260
-				return;
1261
-			}
1262
-
1263
-			try {
1264
-				$avatar = $manager->getAvatar($user->getUID());
1265
-				$avatar->userChanged($feature, $oldValue, $value);
1266
-			} catch (NotFoundException $e) {
1267
-				// no avatar to remove
1268
-			}
1269
-		});
1270
-	}
1271
-
1272
-	/**
1273
-	 * @return \OCP\Contacts\IManager
1274
-	 */
1275
-	public function getContactsManager() {
1276
-		return $this->query('ContactsManager');
1277
-	}
1278
-
1279
-	/**
1280
-	 * @return \OC\Encryption\Manager
1281
-	 */
1282
-	public function getEncryptionManager() {
1283
-		return $this->query('EncryptionManager');
1284
-	}
1285
-
1286
-	/**
1287
-	 * @return \OC\Encryption\File
1288
-	 */
1289
-	public function getEncryptionFilesHelper() {
1290
-		return $this->query('EncryptionFileHelper');
1291
-	}
1292
-
1293
-	/**
1294
-	 * @return \OCP\Encryption\Keys\IStorage
1295
-	 */
1296
-	public function getEncryptionKeyStorage() {
1297
-		return $this->query('EncryptionKeyStorage');
1298
-	}
1299
-
1300
-	/**
1301
-	 * The current request object holding all information about the request
1302
-	 * currently being processed is returned from this method.
1303
-	 * In case the current execution was not initiated by a web request null is returned
1304
-	 *
1305
-	 * @return \OCP\IRequest
1306
-	 */
1307
-	public function getRequest() {
1308
-		return $this->query('Request');
1309
-	}
1310
-
1311
-	/**
1312
-	 * Returns the preview manager which can create preview images for a given file
1313
-	 *
1314
-	 * @return \OCP\IPreview
1315
-	 */
1316
-	public function getPreviewManager() {
1317
-		return $this->query('PreviewManager');
1318
-	}
1319
-
1320
-	/**
1321
-	 * Returns the tag manager which can get and set tags for different object types
1322
-	 *
1323
-	 * @see \OCP\ITagManager::load()
1324
-	 * @return \OCP\ITagManager
1325
-	 */
1326
-	public function getTagManager() {
1327
-		return $this->query('TagManager');
1328
-	}
1329
-
1330
-	/**
1331
-	 * Returns the system-tag manager
1332
-	 *
1333
-	 * @return \OCP\SystemTag\ISystemTagManager
1334
-	 *
1335
-	 * @since 9.0.0
1336
-	 */
1337
-	public function getSystemTagManager() {
1338
-		return $this->query('SystemTagManager');
1339
-	}
1340
-
1341
-	/**
1342
-	 * Returns the system-tag object mapper
1343
-	 *
1344
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1345
-	 *
1346
-	 * @since 9.0.0
1347
-	 */
1348
-	public function getSystemTagObjectMapper() {
1349
-		return $this->query('SystemTagObjectMapper');
1350
-	}
1351
-
1352
-	/**
1353
-	 * Returns the avatar manager, used for avatar functionality
1354
-	 *
1355
-	 * @return \OCP\IAvatarManager
1356
-	 */
1357
-	public function getAvatarManager() {
1358
-		return $this->query('AvatarManager');
1359
-	}
1360
-
1361
-	/**
1362
-	 * Returns the root folder of ownCloud's data directory
1363
-	 *
1364
-	 * @return \OCP\Files\IRootFolder
1365
-	 */
1366
-	public function getRootFolder() {
1367
-		return $this->query('LazyRootFolder');
1368
-	}
1369
-
1370
-	/**
1371
-	 * Returns the root folder of ownCloud's data directory
1372
-	 * This is the lazy variant so this gets only initialized once it
1373
-	 * is actually used.
1374
-	 *
1375
-	 * @return \OCP\Files\IRootFolder
1376
-	 */
1377
-	public function getLazyRootFolder() {
1378
-		return $this->query('LazyRootFolder');
1379
-	}
1380
-
1381
-	/**
1382
-	 * Returns a view to ownCloud's files folder
1383
-	 *
1384
-	 * @param string $userId user ID
1385
-	 * @return \OCP\Files\Folder|null
1386
-	 */
1387
-	public function getUserFolder($userId = null) {
1388
-		if ($userId === null) {
1389
-			$user = $this->getUserSession()->getUser();
1390
-			if (!$user) {
1391
-				return null;
1392
-			}
1393
-			$userId = $user->getUID();
1394
-		}
1395
-		$root = $this->getRootFolder();
1396
-		return $root->getUserFolder($userId);
1397
-	}
1398
-
1399
-	/**
1400
-	 * Returns an app-specific view in ownClouds data directory
1401
-	 *
1402
-	 * @return \OCP\Files\Folder
1403
-	 * @deprecated since 9.2.0 use IAppData
1404
-	 */
1405
-	public function getAppFolder() {
1406
-		$dir = '/' . \OC_App::getCurrentApp();
1407
-		$root = $this->getRootFolder();
1408
-		if (!$root->nodeExists($dir)) {
1409
-			$folder = $root->newFolder($dir);
1410
-		} else {
1411
-			$folder = $root->get($dir);
1412
-		}
1413
-		return $folder;
1414
-	}
1415
-
1416
-	/**
1417
-	 * @return \OC\User\Manager
1418
-	 */
1419
-	public function getUserManager() {
1420
-		return $this->query('UserManager');
1421
-	}
1422
-
1423
-	/**
1424
-	 * @return \OC\Group\Manager
1425
-	 */
1426
-	public function getGroupManager() {
1427
-		return $this->query('GroupManager');
1428
-	}
1429
-
1430
-	/**
1431
-	 * @return \OC\User\Session
1432
-	 */
1433
-	public function getUserSession() {
1434
-		return $this->query('UserSession');
1435
-	}
1436
-
1437
-	/**
1438
-	 * @return \OCP\ISession
1439
-	 */
1440
-	public function getSession() {
1441
-		return $this->query('UserSession')->getSession();
1442
-	}
1443
-
1444
-	/**
1445
-	 * @param \OCP\ISession $session
1446
-	 */
1447
-	public function setSession(\OCP\ISession $session) {
1448
-		$this->query(SessionStorage::class)->setSession($session);
1449
-		$this->query('UserSession')->setSession($session);
1450
-		$this->query(Store::class)->setSession($session);
1451
-	}
1452
-
1453
-	/**
1454
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1455
-	 */
1456
-	public function getTwoFactorAuthManager() {
1457
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1458
-	}
1459
-
1460
-	/**
1461
-	 * @return \OC\NavigationManager
1462
-	 */
1463
-	public function getNavigationManager() {
1464
-		return $this->query('NavigationManager');
1465
-	}
1466
-
1467
-	/**
1468
-	 * @return \OCP\IConfig
1469
-	 */
1470
-	public function getConfig() {
1471
-		return $this->query('AllConfig');
1472
-	}
1473
-
1474
-	/**
1475
-	 * @return \OC\SystemConfig
1476
-	 */
1477
-	public function getSystemConfig() {
1478
-		return $this->query('SystemConfig');
1479
-	}
1480
-
1481
-	/**
1482
-	 * Returns the app config manager
1483
-	 *
1484
-	 * @return \OCP\IAppConfig
1485
-	 */
1486
-	public function getAppConfig() {
1487
-		return $this->query('AppConfig');
1488
-	}
1489
-
1490
-	/**
1491
-	 * @return \OCP\L10N\IFactory
1492
-	 */
1493
-	public function getL10NFactory() {
1494
-		return $this->query('L10NFactory');
1495
-	}
1496
-
1497
-	/**
1498
-	 * get an L10N instance
1499
-	 *
1500
-	 * @param string $app appid
1501
-	 * @param string $lang
1502
-	 * @return IL10N
1503
-	 */
1504
-	public function getL10N($app, $lang = null) {
1505
-		return $this->getL10NFactory()->get($app, $lang);
1506
-	}
1507
-
1508
-	/**
1509
-	 * @return \OCP\IURLGenerator
1510
-	 */
1511
-	public function getURLGenerator() {
1512
-		return $this->query('URLGenerator');
1513
-	}
1514
-
1515
-	/**
1516
-	 * @return AppFetcher
1517
-	 */
1518
-	public function getAppFetcher() {
1519
-		return $this->query(AppFetcher::class);
1520
-	}
1521
-
1522
-	/**
1523
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1524
-	 * getMemCacheFactory() instead.
1525
-	 *
1526
-	 * @return \OCP\ICache
1527
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1528
-	 */
1529
-	public function getCache() {
1530
-		return $this->query('UserCache');
1531
-	}
1532
-
1533
-	/**
1534
-	 * Returns an \OCP\CacheFactory instance
1535
-	 *
1536
-	 * @return \OCP\ICacheFactory
1537
-	 */
1538
-	public function getMemCacheFactory() {
1539
-		return $this->query('MemCacheFactory');
1540
-	}
1541
-
1542
-	/**
1543
-	 * Returns an \OC\RedisFactory instance
1544
-	 *
1545
-	 * @return \OC\RedisFactory
1546
-	 */
1547
-	public function getGetRedisFactory() {
1548
-		return $this->query('RedisFactory');
1549
-	}
1550
-
1551
-
1552
-	/**
1553
-	 * Returns the current session
1554
-	 *
1555
-	 * @return \OCP\IDBConnection
1556
-	 */
1557
-	public function getDatabaseConnection() {
1558
-		return $this->query('DatabaseConnection');
1559
-	}
1560
-
1561
-	/**
1562
-	 * Returns the activity manager
1563
-	 *
1564
-	 * @return \OCP\Activity\IManager
1565
-	 */
1566
-	public function getActivityManager() {
1567
-		return $this->query('ActivityManager');
1568
-	}
1569
-
1570
-	/**
1571
-	 * Returns an job list for controlling background jobs
1572
-	 *
1573
-	 * @return \OCP\BackgroundJob\IJobList
1574
-	 */
1575
-	public function getJobList() {
1576
-		return $this->query('JobList');
1577
-	}
1578
-
1579
-	/**
1580
-	 * Returns a logger instance
1581
-	 *
1582
-	 * @return \OCP\ILogger
1583
-	 */
1584
-	public function getLogger() {
1585
-		return $this->query('Logger');
1586
-	}
1587
-
1588
-	/**
1589
-	 * @return ILogFactory
1590
-	 * @throws \OCP\AppFramework\QueryException
1591
-	 */
1592
-	public function getLogFactory() {
1593
-		return $this->query(ILogFactory::class);
1594
-	}
1595
-
1596
-	/**
1597
-	 * Returns a router for generating and matching urls
1598
-	 *
1599
-	 * @return \OCP\Route\IRouter
1600
-	 */
1601
-	public function getRouter() {
1602
-		return $this->query('Router');
1603
-	}
1604
-
1605
-	/**
1606
-	 * Returns a search instance
1607
-	 *
1608
-	 * @return \OCP\ISearch
1609
-	 */
1610
-	public function getSearch() {
1611
-		return $this->query('Search');
1612
-	}
1613
-
1614
-	/**
1615
-	 * Returns a SecureRandom instance
1616
-	 *
1617
-	 * @return \OCP\Security\ISecureRandom
1618
-	 */
1619
-	public function getSecureRandom() {
1620
-		return $this->query('SecureRandom');
1621
-	}
1622
-
1623
-	/**
1624
-	 * Returns a Crypto instance
1625
-	 *
1626
-	 * @return \OCP\Security\ICrypto
1627
-	 */
1628
-	public function getCrypto() {
1629
-		return $this->query('Crypto');
1630
-	}
1631
-
1632
-	/**
1633
-	 * Returns a Hasher instance
1634
-	 *
1635
-	 * @return \OCP\Security\IHasher
1636
-	 */
1637
-	public function getHasher() {
1638
-		return $this->query('Hasher');
1639
-	}
1640
-
1641
-	/**
1642
-	 * Returns a CredentialsManager instance
1643
-	 *
1644
-	 * @return \OCP\Security\ICredentialsManager
1645
-	 */
1646
-	public function getCredentialsManager() {
1647
-		return $this->query('CredentialsManager');
1648
-	}
1649
-
1650
-	/**
1651
-	 * Get the certificate manager for the user
1652
-	 *
1653
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1654
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1655
-	 */
1656
-	public function getCertificateManager($userId = '') {
1657
-		if ($userId === '') {
1658
-			$userSession = $this->getUserSession();
1659
-			$user = $userSession->getUser();
1660
-			if (is_null($user)) {
1661
-				return null;
1662
-			}
1663
-			$userId = $user->getUID();
1664
-		}
1665
-		return new CertificateManager(
1666
-			$userId,
1667
-			new View(),
1668
-			$this->getConfig(),
1669
-			$this->getLogger(),
1670
-			$this->getSecureRandom()
1671
-		);
1672
-	}
1673
-
1674
-	/**
1675
-	 * Returns an instance of the HTTP client service
1676
-	 *
1677
-	 * @return \OCP\Http\Client\IClientService
1678
-	 */
1679
-	public function getHTTPClientService() {
1680
-		return $this->query('HttpClientService');
1681
-	}
1682
-
1683
-	/**
1684
-	 * Create a new event source
1685
-	 *
1686
-	 * @return \OCP\IEventSource
1687
-	 */
1688
-	public function createEventSource() {
1689
-		return new \OC_EventSource();
1690
-	}
1691
-
1692
-	/**
1693
-	 * Get the active event logger
1694
-	 *
1695
-	 * The returned logger only logs data when debug mode is enabled
1696
-	 *
1697
-	 * @return \OCP\Diagnostics\IEventLogger
1698
-	 */
1699
-	public function getEventLogger() {
1700
-		return $this->query('EventLogger');
1701
-	}
1702
-
1703
-	/**
1704
-	 * Get the active query logger
1705
-	 *
1706
-	 * The returned logger only logs data when debug mode is enabled
1707
-	 *
1708
-	 * @return \OCP\Diagnostics\IQueryLogger
1709
-	 */
1710
-	public function getQueryLogger() {
1711
-		return $this->query('QueryLogger');
1712
-	}
1713
-
1714
-	/**
1715
-	 * Get the manager for temporary files and folders
1716
-	 *
1717
-	 * @return \OCP\ITempManager
1718
-	 */
1719
-	public function getTempManager() {
1720
-		return $this->query('TempManager');
1721
-	}
1722
-
1723
-	/**
1724
-	 * Get the app manager
1725
-	 *
1726
-	 * @return \OCP\App\IAppManager
1727
-	 */
1728
-	public function getAppManager() {
1729
-		return $this->query('AppManager');
1730
-	}
1731
-
1732
-	/**
1733
-	 * Creates a new mailer
1734
-	 *
1735
-	 * @return \OCP\Mail\IMailer
1736
-	 */
1737
-	public function getMailer() {
1738
-		return $this->query('Mailer');
1739
-	}
1740
-
1741
-	/**
1742
-	 * Get the webroot
1743
-	 *
1744
-	 * @return string
1745
-	 */
1746
-	public function getWebRoot() {
1747
-		return $this->webRoot;
1748
-	}
1749
-
1750
-	/**
1751
-	 * @return \OC\OCSClient
1752
-	 */
1753
-	public function getOcsClient() {
1754
-		return $this->query('OcsClient');
1755
-	}
1756
-
1757
-	/**
1758
-	 * @return \OCP\IDateTimeZone
1759
-	 */
1760
-	public function getDateTimeZone() {
1761
-		return $this->query('DateTimeZone');
1762
-	}
1763
-
1764
-	/**
1765
-	 * @return \OCP\IDateTimeFormatter
1766
-	 */
1767
-	public function getDateTimeFormatter() {
1768
-		return $this->query('DateTimeFormatter');
1769
-	}
1770
-
1771
-	/**
1772
-	 * @return \OCP\Files\Config\IMountProviderCollection
1773
-	 */
1774
-	public function getMountProviderCollection() {
1775
-		return $this->query('MountConfigManager');
1776
-	}
1777
-
1778
-	/**
1779
-	 * Get the IniWrapper
1780
-	 *
1781
-	 * @return IniGetWrapper
1782
-	 */
1783
-	public function getIniWrapper() {
1784
-		return $this->query('IniWrapper');
1785
-	}
1786
-
1787
-	/**
1788
-	 * @return \OCP\Command\IBus
1789
-	 */
1790
-	public function getCommandBus() {
1791
-		return $this->query('AsyncCommandBus');
1792
-	}
1793
-
1794
-	/**
1795
-	 * Get the trusted domain helper
1796
-	 *
1797
-	 * @return TrustedDomainHelper
1798
-	 */
1799
-	public function getTrustedDomainHelper() {
1800
-		return $this->query('TrustedDomainHelper');
1801
-	}
1802
-
1803
-	/**
1804
-	 * Get the locking provider
1805
-	 *
1806
-	 * @return \OCP\Lock\ILockingProvider
1807
-	 * @since 8.1.0
1808
-	 */
1809
-	public function getLockingProvider() {
1810
-		return $this->query('LockingProvider');
1811
-	}
1812
-
1813
-	/**
1814
-	 * @return \OCP\Files\Mount\IMountManager
1815
-	 **/
1816
-	function getMountManager() {
1817
-		return $this->query('MountManager');
1818
-	}
1819
-
1820
-	/** @return \OCP\Files\Config\IUserMountCache */
1821
-	function getUserMountCache() {
1822
-		return $this->query('UserMountCache');
1823
-	}
1824
-
1825
-	/**
1826
-	 * Get the MimeTypeDetector
1827
-	 *
1828
-	 * @return \OCP\Files\IMimeTypeDetector
1829
-	 */
1830
-	public function getMimeTypeDetector() {
1831
-		return $this->query('MimeTypeDetector');
1832
-	}
1833
-
1834
-	/**
1835
-	 * Get the MimeTypeLoader
1836
-	 *
1837
-	 * @return \OCP\Files\IMimeTypeLoader
1838
-	 */
1839
-	public function getMimeTypeLoader() {
1840
-		return $this->query('MimeTypeLoader');
1841
-	}
1842
-
1843
-	/**
1844
-	 * Get the manager of all the capabilities
1845
-	 *
1846
-	 * @return \OC\CapabilitiesManager
1847
-	 */
1848
-	public function getCapabilitiesManager() {
1849
-		return $this->query('CapabilitiesManager');
1850
-	}
1851
-
1852
-	/**
1853
-	 * Get the EventDispatcher
1854
-	 *
1855
-	 * @return EventDispatcherInterface
1856
-	 * @since 8.2.0
1857
-	 */
1858
-	public function getEventDispatcher() {
1859
-		return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
1860
-	}
1861
-
1862
-	/**
1863
-	 * Get the Notification Manager
1864
-	 *
1865
-	 * @return \OCP\Notification\IManager
1866
-	 * @since 8.2.0
1867
-	 */
1868
-	public function getNotificationManager() {
1869
-		return $this->query('NotificationManager');
1870
-	}
1871
-
1872
-	/**
1873
-	 * @return \OCP\Comments\ICommentsManager
1874
-	 */
1875
-	public function getCommentsManager() {
1876
-		return $this->query('CommentsManager');
1877
-	}
1878
-
1879
-	/**
1880
-	 * @return \OCA\Theming\ThemingDefaults
1881
-	 */
1882
-	public function getThemingDefaults() {
1883
-		return $this->query('ThemingDefaults');
1884
-	}
1885
-
1886
-	/**
1887
-	 * @return \OC\IntegrityCheck\Checker
1888
-	 */
1889
-	public function getIntegrityCodeChecker() {
1890
-		return $this->query('IntegrityCodeChecker');
1891
-	}
1892
-
1893
-	/**
1894
-	 * @return \OC\Session\CryptoWrapper
1895
-	 */
1896
-	public function getSessionCryptoWrapper() {
1897
-		return $this->query('CryptoWrapper');
1898
-	}
1899
-
1900
-	/**
1901
-	 * @return CsrfTokenManager
1902
-	 */
1903
-	public function getCsrfTokenManager() {
1904
-		return $this->query('CsrfTokenManager');
1905
-	}
1906
-
1907
-	/**
1908
-	 * @return Throttler
1909
-	 */
1910
-	public function getBruteForceThrottler() {
1911
-		return $this->query('Throttler');
1912
-	}
1913
-
1914
-	/**
1915
-	 * @return IContentSecurityPolicyManager
1916
-	 */
1917
-	public function getContentSecurityPolicyManager() {
1918
-		return $this->query('ContentSecurityPolicyManager');
1919
-	}
1920
-
1921
-	/**
1922
-	 * @return ContentSecurityPolicyNonceManager
1923
-	 */
1924
-	public function getContentSecurityPolicyNonceManager() {
1925
-		return $this->query('ContentSecurityPolicyNonceManager');
1926
-	}
1927
-
1928
-	/**
1929
-	 * Not a public API as of 8.2, wait for 9.0
1930
-	 *
1931
-	 * @return \OCA\Files_External\Service\BackendService
1932
-	 */
1933
-	public function getStoragesBackendService() {
1934
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1935
-	}
1936
-
1937
-	/**
1938
-	 * Not a public API as of 8.2, wait for 9.0
1939
-	 *
1940
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1941
-	 */
1942
-	public function getGlobalStoragesService() {
1943
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1944
-	}
1945
-
1946
-	/**
1947
-	 * Not a public API as of 8.2, wait for 9.0
1948
-	 *
1949
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1950
-	 */
1951
-	public function getUserGlobalStoragesService() {
1952
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1953
-	}
1954
-
1955
-	/**
1956
-	 * Not a public API as of 8.2, wait for 9.0
1957
-	 *
1958
-	 * @return \OCA\Files_External\Service\UserStoragesService
1959
-	 */
1960
-	public function getUserStoragesService() {
1961
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1962
-	}
1963
-
1964
-	/**
1965
-	 * @return \OCP\Share\IManager
1966
-	 */
1967
-	public function getShareManager() {
1968
-		return $this->query('ShareManager');
1969
-	}
1970
-
1971
-	/**
1972
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1973
-	 */
1974
-	public function getCollaboratorSearch() {
1975
-		return $this->query('CollaboratorSearch');
1976
-	}
1977
-
1978
-	/**
1979
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1980
-	 */
1981
-	public function getAutoCompleteManager(){
1982
-		return $this->query(IManager::class);
1983
-	}
1984
-
1985
-	/**
1986
-	 * Returns the LDAP Provider
1987
-	 *
1988
-	 * @return \OCP\LDAP\ILDAPProvider
1989
-	 */
1990
-	public function getLDAPProvider() {
1991
-		return $this->query('LDAPProvider');
1992
-	}
1993
-
1994
-	/**
1995
-	 * @return \OCP\Settings\IManager
1996
-	 */
1997
-	public function getSettingsManager() {
1998
-		return $this->query('SettingsManager');
1999
-	}
2000
-
2001
-	/**
2002
-	 * @return \OCP\Files\IAppData
2003
-	 */
2004
-	public function getAppDataDir($app) {
2005
-		/** @var \OC\Files\AppData\Factory $factory */
2006
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
2007
-		return $factory->get($app);
2008
-	}
2009
-
2010
-	/**
2011
-	 * @return \OCP\Lockdown\ILockdownManager
2012
-	 */
2013
-	public function getLockdownManager() {
2014
-		return $this->query('LockdownManager');
2015
-	}
2016
-
2017
-	/**
2018
-	 * @return \OCP\Federation\ICloudIdManager
2019
-	 */
2020
-	public function getCloudIdManager() {
2021
-		return $this->query(ICloudIdManager::class);
2022
-	}
2023
-
2024
-	/**
2025
-	 * @return \OCP\GlobalScale\IConfig
2026
-	 */
2027
-	public function getGlobalScaleConfig() {
2028
-		return $this->query(IConfig::class);
2029
-	}
2030
-
2031
-	/**
2032
-	 * @return \OCP\Federation\ICloudFederationProviderManager
2033
-	 */
2034
-	public function getCloudFederationProviderManager() {
2035
-		return $this->query(ICloudFederationProviderManager::class);
2036
-	}
2037
-
2038
-	/**
2039
-	 * @return \OCP\Remote\Api\IApiFactory
2040
-	 */
2041
-	public function getRemoteApiFactory() {
2042
-		return $this->query(IApiFactory::class);
2043
-	}
2044
-
2045
-	/**
2046
-	 * @return \OCP\Federation\ICloudFederationFactory
2047
-	 */
2048
-	public function getCloudFederationFactory() {
2049
-		return $this->query(ICloudFederationFactory::class);
2050
-	}
2051
-
2052
-	/**
2053
-	 * @return \OCP\Remote\IInstanceFactory
2054
-	 */
2055
-	public function getRemoteInstanceFactory() {
2056
-		return $this->query(IInstanceFactory::class);
2057
-	}
2058
-
2059
-	/**
2060
-	 * @return IStorageFactory
2061
-	 */
2062
-	public function getStorageFactory() {
2063
-		return $this->query(IStorageFactory::class);
2064
-	}
2065
-
2066
-	/**
2067
-	 * Get the Preview GeneratorHelper
2068
-	 *
2069
-	 * @return GeneratorHelper
2070
-	 * @since 17.0.0
2071
-	 */
2072
-	public function getGeneratorHelper() {
2073
-		return $this->query(\OC\Preview\GeneratorHelper::class);
2074
-	}
949
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
950
+            if (isset($prefixes['OCA\\Theming\\'])) {
951
+                $classExists = true;
952
+            } else {
953
+                $classExists = false;
954
+            }
955
+
956
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
957
+                return new ThemingDefaults(
958
+                    $c->getConfig(),
959
+                    $c->getL10N('theming'),
960
+                    $c->getURLGenerator(),
961
+                    $c->getMemCacheFactory(),
962
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
963
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
964
+                    $c->getAppManager(),
965
+                    $c->getNavigationManager()
966
+                );
967
+            }
968
+            return new \OC_Defaults();
969
+        });
970
+        $this->registerService(SCSSCacher::class, function (Server $c) {
971
+            return new SCSSCacher(
972
+                $c->getLogger(),
973
+                $c->query(\OC\Files\AppData\Factory::class),
974
+                $c->getURLGenerator(),
975
+                $c->getConfig(),
976
+                $c->getThemingDefaults(),
977
+                \OC::$SERVERROOT,
978
+                $this->getMemCacheFactory(),
979
+                $c->query(IconsCacher::class),
980
+                new TimeFactory()
981
+            );
982
+        });
983
+        $this->registerService(JSCombiner::class, function (Server $c) {
984
+            return new JSCombiner(
985
+                $c->getAppDataDir('js'),
986
+                $c->getURLGenerator(),
987
+                $this->getMemCacheFactory(),
988
+                $c->getSystemConfig(),
989
+                $c->getLogger()
990
+            );
991
+        });
992
+        $this->registerAlias(\OCP\EventDispatcher\IEventDispatcher::class, \OC\EventDispatcher\EventDispatcher::class);
993
+        $this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
994
+        $this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
995
+
996
+        $this->registerService('CryptoWrapper', function (Server $c) {
997
+            // FIXME: Instantiiated here due to cyclic dependency
998
+            $request = new Request(
999
+                [
1000
+                    'get' => $_GET,
1001
+                    'post' => $_POST,
1002
+                    'files' => $_FILES,
1003
+                    'server' => $_SERVER,
1004
+                    'env' => $_ENV,
1005
+                    'cookies' => $_COOKIE,
1006
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1007
+                        ? $_SERVER['REQUEST_METHOD']
1008
+                        : null,
1009
+                ],
1010
+                $c->getSecureRandom(),
1011
+                $c->getConfig()
1012
+            );
1013
+
1014
+            return new CryptoWrapper(
1015
+                $c->getConfig(),
1016
+                $c->getCrypto(),
1017
+                $c->getSecureRandom(),
1018
+                $request
1019
+            );
1020
+        });
1021
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1022
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1023
+
1024
+            return new CsrfTokenManager(
1025
+                $tokenGenerator,
1026
+                $c->query(SessionStorage::class)
1027
+            );
1028
+        });
1029
+        $this->registerService(SessionStorage::class, function (Server $c) {
1030
+            return new SessionStorage($c->getSession());
1031
+        });
1032
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1033
+            return new ContentSecurityPolicyManager();
1034
+        });
1035
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1036
+
1037
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1038
+            return new ContentSecurityPolicyNonceManager(
1039
+                $c->getCsrfTokenManager(),
1040
+                $c->getRequest()
1041
+            );
1042
+        });
1043
+
1044
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1045
+            $config = $c->getConfig();
1046
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1047
+            /** @var \OCP\Share\IProviderFactory $factory */
1048
+            $factory = new $factoryClass($this);
1049
+
1050
+            $manager = new \OC\Share20\Manager(
1051
+                $c->getLogger(),
1052
+                $c->getConfig(),
1053
+                $c->getSecureRandom(),
1054
+                $c->getHasher(),
1055
+                $c->getMountManager(),
1056
+                $c->getGroupManager(),
1057
+                $c->getL10N('lib'),
1058
+                $c->getL10NFactory(),
1059
+                $factory,
1060
+                $c->getUserManager(),
1061
+                $c->getLazyRootFolder(),
1062
+                $c->getEventDispatcher(),
1063
+                $c->getMailer(),
1064
+                $c->getURLGenerator(),
1065
+                $c->getThemingDefaults()
1066
+            );
1067
+
1068
+            return $manager;
1069
+        });
1070
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1071
+
1072
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1073
+            $instance = new Collaboration\Collaborators\Search($c);
1074
+
1075
+            // register default plugins
1076
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1077
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1078
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1079
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1080
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE_GROUP', 'class' => RemoteGroupPlugin::class]);
1081
+
1082
+            return $instance;
1083
+        });
1084
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1085
+        $this->registerAlias(\OCP\Collaboration\Collaborators\ISearchResult::class, \OC\Collaboration\Collaborators\SearchResult::class);
1086
+
1087
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1088
+
1089
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1090
+
1091
+        $this->registerService('SettingsManager', function (Server $c) {
1092
+            $manager = new \OC\Settings\Manager(
1093
+                $c->getLogger(),
1094
+                $c->getL10NFactory(),
1095
+                $c->getURLGenerator(),
1096
+                $c
1097
+            );
1098
+            return $manager;
1099
+        });
1100
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1101
+            return new \OC\Files\AppData\Factory(
1102
+                $c->getRootFolder(),
1103
+                $c->getSystemConfig()
1104
+            );
1105
+        });
1106
+
1107
+        $this->registerService('LockdownManager', function (Server $c) {
1108
+            return new LockdownManager(function () use ($c) {
1109
+                return $c->getSession();
1110
+            });
1111
+        });
1112
+
1113
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1114
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1115
+        });
1116
+
1117
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1118
+            return new CloudIdManager();
1119
+        });
1120
+
1121
+        $this->registerService(IConfig::class, function (Server $c) {
1122
+            return new GlobalScale\Config($c->getConfig());
1123
+        });
1124
+
1125
+        $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1126
+            return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1127
+        });
1128
+
1129
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1130
+            return new CloudFederationFactory();
1131
+        });
1132
+
1133
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1134
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1135
+
1136
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1137
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1138
+
1139
+        $this->registerService(Defaults::class, function (Server $c) {
1140
+            return new Defaults(
1141
+                $c->getThemingDefaults()
1142
+            );
1143
+        });
1144
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1145
+
1146
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1147
+            return $c->query(\OCP\IUserSession::class)->getSession();
1148
+        });
1149
+
1150
+        $this->registerService(IShareHelper::class, function (Server $c) {
1151
+            return new ShareHelper(
1152
+                $c->query(\OCP\Share\IManager::class)
1153
+            );
1154
+        });
1155
+
1156
+        $this->registerService(Installer::class, function(Server $c) {
1157
+            return new Installer(
1158
+                $c->getAppFetcher(),
1159
+                $c->getHTTPClientService(),
1160
+                $c->getTempManager(),
1161
+                $c->getLogger(),
1162
+                $c->getConfig()
1163
+            );
1164
+        });
1165
+
1166
+        $this->registerService(IApiFactory::class, function(Server $c) {
1167
+            return new ApiFactory($c->getHTTPClientService());
1168
+        });
1169
+
1170
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1171
+            $memcacheFactory = $c->getMemCacheFactory();
1172
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1173
+        });
1174
+
1175
+        $this->registerService(IContactsStore::class, function(Server $c) {
1176
+            return new ContactsStore(
1177
+                $c->getContactsManager(),
1178
+                $c->getConfig(),
1179
+                $c->getUserManager(),
1180
+                $c->getGroupManager()
1181
+            );
1182
+        });
1183
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1184
+        $this->registerAlias(IAccountManager::class, AccountManager::class);
1185
+
1186
+        $this->registerService(IStorageFactory::class, function() {
1187
+            return new StorageFactory();
1188
+        });
1189
+
1190
+        $this->registerAlias(IDashboardManager::class, DashboardManager::class);
1191
+        $this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1192
+
1193
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1194
+            return new \OC\Security\IdentityProof\Manager(
1195
+                $c->query(\OC\Files\AppData\Factory::class),
1196
+                $c->getCrypto(),
1197
+                $c->getConfig()
1198
+            );
1199
+        });
1200
+
1201
+        $this->registerAlias(ISubAdmin::class, SubAdmin::class);
1202
+
1203
+        $this->registerAlias(IInitialStateService::class, InitialStateService::class);
1204
+
1205
+        $this->connectDispatcher();
1206
+    }
1207
+
1208
+    /**
1209
+     * @return \OCP\Calendar\IManager
1210
+     */
1211
+    public function getCalendarManager() {
1212
+        return $this->query('CalendarManager');
1213
+    }
1214
+
1215
+    /**
1216
+     * @return \OCP\Calendar\Resource\IManager
1217
+     */
1218
+    public function getCalendarResourceBackendManager() {
1219
+        return $this->query('CalendarResourceBackendManager');
1220
+    }
1221
+
1222
+    /**
1223
+     * @return \OCP\Calendar\Room\IManager
1224
+     */
1225
+    public function getCalendarRoomBackendManager() {
1226
+        return $this->query('CalendarRoomBackendManager');
1227
+    }
1228
+
1229
+    private function connectDispatcher() {
1230
+        $dispatcher = $this->getEventDispatcher();
1231
+
1232
+        // Delete avatar on user deletion
1233
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1234
+            $logger = $this->getLogger();
1235
+            $manager = $this->getAvatarManager();
1236
+            /** @var IUser $user */
1237
+            $user = $e->getSubject();
1238
+
1239
+            try {
1240
+                $avatar = $manager->getAvatar($user->getUID());
1241
+                $avatar->remove();
1242
+            } catch (NotFoundException $e) {
1243
+                // no avatar to remove
1244
+            } catch (\Exception $e) {
1245
+                // Ignore exceptions
1246
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1247
+            }
1248
+        });
1249
+
1250
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1251
+            $manager = $this->getAvatarManager();
1252
+            /** @var IUser $user */
1253
+            $user = $e->getSubject();
1254
+            $feature = $e->getArgument('feature');
1255
+            $oldValue = $e->getArgument('oldValue');
1256
+            $value = $e->getArgument('value');
1257
+
1258
+            // We only change the avatar on display name changes
1259
+            if ($feature !== 'displayName') {
1260
+                return;
1261
+            }
1262
+
1263
+            try {
1264
+                $avatar = $manager->getAvatar($user->getUID());
1265
+                $avatar->userChanged($feature, $oldValue, $value);
1266
+            } catch (NotFoundException $e) {
1267
+                // no avatar to remove
1268
+            }
1269
+        });
1270
+    }
1271
+
1272
+    /**
1273
+     * @return \OCP\Contacts\IManager
1274
+     */
1275
+    public function getContactsManager() {
1276
+        return $this->query('ContactsManager');
1277
+    }
1278
+
1279
+    /**
1280
+     * @return \OC\Encryption\Manager
1281
+     */
1282
+    public function getEncryptionManager() {
1283
+        return $this->query('EncryptionManager');
1284
+    }
1285
+
1286
+    /**
1287
+     * @return \OC\Encryption\File
1288
+     */
1289
+    public function getEncryptionFilesHelper() {
1290
+        return $this->query('EncryptionFileHelper');
1291
+    }
1292
+
1293
+    /**
1294
+     * @return \OCP\Encryption\Keys\IStorage
1295
+     */
1296
+    public function getEncryptionKeyStorage() {
1297
+        return $this->query('EncryptionKeyStorage');
1298
+    }
1299
+
1300
+    /**
1301
+     * The current request object holding all information about the request
1302
+     * currently being processed is returned from this method.
1303
+     * In case the current execution was not initiated by a web request null is returned
1304
+     *
1305
+     * @return \OCP\IRequest
1306
+     */
1307
+    public function getRequest() {
1308
+        return $this->query('Request');
1309
+    }
1310
+
1311
+    /**
1312
+     * Returns the preview manager which can create preview images for a given file
1313
+     *
1314
+     * @return \OCP\IPreview
1315
+     */
1316
+    public function getPreviewManager() {
1317
+        return $this->query('PreviewManager');
1318
+    }
1319
+
1320
+    /**
1321
+     * Returns the tag manager which can get and set tags for different object types
1322
+     *
1323
+     * @see \OCP\ITagManager::load()
1324
+     * @return \OCP\ITagManager
1325
+     */
1326
+    public function getTagManager() {
1327
+        return $this->query('TagManager');
1328
+    }
1329
+
1330
+    /**
1331
+     * Returns the system-tag manager
1332
+     *
1333
+     * @return \OCP\SystemTag\ISystemTagManager
1334
+     *
1335
+     * @since 9.0.0
1336
+     */
1337
+    public function getSystemTagManager() {
1338
+        return $this->query('SystemTagManager');
1339
+    }
1340
+
1341
+    /**
1342
+     * Returns the system-tag object mapper
1343
+     *
1344
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1345
+     *
1346
+     * @since 9.0.0
1347
+     */
1348
+    public function getSystemTagObjectMapper() {
1349
+        return $this->query('SystemTagObjectMapper');
1350
+    }
1351
+
1352
+    /**
1353
+     * Returns the avatar manager, used for avatar functionality
1354
+     *
1355
+     * @return \OCP\IAvatarManager
1356
+     */
1357
+    public function getAvatarManager() {
1358
+        return $this->query('AvatarManager');
1359
+    }
1360
+
1361
+    /**
1362
+     * Returns the root folder of ownCloud's data directory
1363
+     *
1364
+     * @return \OCP\Files\IRootFolder
1365
+     */
1366
+    public function getRootFolder() {
1367
+        return $this->query('LazyRootFolder');
1368
+    }
1369
+
1370
+    /**
1371
+     * Returns the root folder of ownCloud's data directory
1372
+     * This is the lazy variant so this gets only initialized once it
1373
+     * is actually used.
1374
+     *
1375
+     * @return \OCP\Files\IRootFolder
1376
+     */
1377
+    public function getLazyRootFolder() {
1378
+        return $this->query('LazyRootFolder');
1379
+    }
1380
+
1381
+    /**
1382
+     * Returns a view to ownCloud's files folder
1383
+     *
1384
+     * @param string $userId user ID
1385
+     * @return \OCP\Files\Folder|null
1386
+     */
1387
+    public function getUserFolder($userId = null) {
1388
+        if ($userId === null) {
1389
+            $user = $this->getUserSession()->getUser();
1390
+            if (!$user) {
1391
+                return null;
1392
+            }
1393
+            $userId = $user->getUID();
1394
+        }
1395
+        $root = $this->getRootFolder();
1396
+        return $root->getUserFolder($userId);
1397
+    }
1398
+
1399
+    /**
1400
+     * Returns an app-specific view in ownClouds data directory
1401
+     *
1402
+     * @return \OCP\Files\Folder
1403
+     * @deprecated since 9.2.0 use IAppData
1404
+     */
1405
+    public function getAppFolder() {
1406
+        $dir = '/' . \OC_App::getCurrentApp();
1407
+        $root = $this->getRootFolder();
1408
+        if (!$root->nodeExists($dir)) {
1409
+            $folder = $root->newFolder($dir);
1410
+        } else {
1411
+            $folder = $root->get($dir);
1412
+        }
1413
+        return $folder;
1414
+    }
1415
+
1416
+    /**
1417
+     * @return \OC\User\Manager
1418
+     */
1419
+    public function getUserManager() {
1420
+        return $this->query('UserManager');
1421
+    }
1422
+
1423
+    /**
1424
+     * @return \OC\Group\Manager
1425
+     */
1426
+    public function getGroupManager() {
1427
+        return $this->query('GroupManager');
1428
+    }
1429
+
1430
+    /**
1431
+     * @return \OC\User\Session
1432
+     */
1433
+    public function getUserSession() {
1434
+        return $this->query('UserSession');
1435
+    }
1436
+
1437
+    /**
1438
+     * @return \OCP\ISession
1439
+     */
1440
+    public function getSession() {
1441
+        return $this->query('UserSession')->getSession();
1442
+    }
1443
+
1444
+    /**
1445
+     * @param \OCP\ISession $session
1446
+     */
1447
+    public function setSession(\OCP\ISession $session) {
1448
+        $this->query(SessionStorage::class)->setSession($session);
1449
+        $this->query('UserSession')->setSession($session);
1450
+        $this->query(Store::class)->setSession($session);
1451
+    }
1452
+
1453
+    /**
1454
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1455
+     */
1456
+    public function getTwoFactorAuthManager() {
1457
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1458
+    }
1459
+
1460
+    /**
1461
+     * @return \OC\NavigationManager
1462
+     */
1463
+    public function getNavigationManager() {
1464
+        return $this->query('NavigationManager');
1465
+    }
1466
+
1467
+    /**
1468
+     * @return \OCP\IConfig
1469
+     */
1470
+    public function getConfig() {
1471
+        return $this->query('AllConfig');
1472
+    }
1473
+
1474
+    /**
1475
+     * @return \OC\SystemConfig
1476
+     */
1477
+    public function getSystemConfig() {
1478
+        return $this->query('SystemConfig');
1479
+    }
1480
+
1481
+    /**
1482
+     * Returns the app config manager
1483
+     *
1484
+     * @return \OCP\IAppConfig
1485
+     */
1486
+    public function getAppConfig() {
1487
+        return $this->query('AppConfig');
1488
+    }
1489
+
1490
+    /**
1491
+     * @return \OCP\L10N\IFactory
1492
+     */
1493
+    public function getL10NFactory() {
1494
+        return $this->query('L10NFactory');
1495
+    }
1496
+
1497
+    /**
1498
+     * get an L10N instance
1499
+     *
1500
+     * @param string $app appid
1501
+     * @param string $lang
1502
+     * @return IL10N
1503
+     */
1504
+    public function getL10N($app, $lang = null) {
1505
+        return $this->getL10NFactory()->get($app, $lang);
1506
+    }
1507
+
1508
+    /**
1509
+     * @return \OCP\IURLGenerator
1510
+     */
1511
+    public function getURLGenerator() {
1512
+        return $this->query('URLGenerator');
1513
+    }
1514
+
1515
+    /**
1516
+     * @return AppFetcher
1517
+     */
1518
+    public function getAppFetcher() {
1519
+        return $this->query(AppFetcher::class);
1520
+    }
1521
+
1522
+    /**
1523
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1524
+     * getMemCacheFactory() instead.
1525
+     *
1526
+     * @return \OCP\ICache
1527
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1528
+     */
1529
+    public function getCache() {
1530
+        return $this->query('UserCache');
1531
+    }
1532
+
1533
+    /**
1534
+     * Returns an \OCP\CacheFactory instance
1535
+     *
1536
+     * @return \OCP\ICacheFactory
1537
+     */
1538
+    public function getMemCacheFactory() {
1539
+        return $this->query('MemCacheFactory');
1540
+    }
1541
+
1542
+    /**
1543
+     * Returns an \OC\RedisFactory instance
1544
+     *
1545
+     * @return \OC\RedisFactory
1546
+     */
1547
+    public function getGetRedisFactory() {
1548
+        return $this->query('RedisFactory');
1549
+    }
1550
+
1551
+
1552
+    /**
1553
+     * Returns the current session
1554
+     *
1555
+     * @return \OCP\IDBConnection
1556
+     */
1557
+    public function getDatabaseConnection() {
1558
+        return $this->query('DatabaseConnection');
1559
+    }
1560
+
1561
+    /**
1562
+     * Returns the activity manager
1563
+     *
1564
+     * @return \OCP\Activity\IManager
1565
+     */
1566
+    public function getActivityManager() {
1567
+        return $this->query('ActivityManager');
1568
+    }
1569
+
1570
+    /**
1571
+     * Returns an job list for controlling background jobs
1572
+     *
1573
+     * @return \OCP\BackgroundJob\IJobList
1574
+     */
1575
+    public function getJobList() {
1576
+        return $this->query('JobList');
1577
+    }
1578
+
1579
+    /**
1580
+     * Returns a logger instance
1581
+     *
1582
+     * @return \OCP\ILogger
1583
+     */
1584
+    public function getLogger() {
1585
+        return $this->query('Logger');
1586
+    }
1587
+
1588
+    /**
1589
+     * @return ILogFactory
1590
+     * @throws \OCP\AppFramework\QueryException
1591
+     */
1592
+    public function getLogFactory() {
1593
+        return $this->query(ILogFactory::class);
1594
+    }
1595
+
1596
+    /**
1597
+     * Returns a router for generating and matching urls
1598
+     *
1599
+     * @return \OCP\Route\IRouter
1600
+     */
1601
+    public function getRouter() {
1602
+        return $this->query('Router');
1603
+    }
1604
+
1605
+    /**
1606
+     * Returns a search instance
1607
+     *
1608
+     * @return \OCP\ISearch
1609
+     */
1610
+    public function getSearch() {
1611
+        return $this->query('Search');
1612
+    }
1613
+
1614
+    /**
1615
+     * Returns a SecureRandom instance
1616
+     *
1617
+     * @return \OCP\Security\ISecureRandom
1618
+     */
1619
+    public function getSecureRandom() {
1620
+        return $this->query('SecureRandom');
1621
+    }
1622
+
1623
+    /**
1624
+     * Returns a Crypto instance
1625
+     *
1626
+     * @return \OCP\Security\ICrypto
1627
+     */
1628
+    public function getCrypto() {
1629
+        return $this->query('Crypto');
1630
+    }
1631
+
1632
+    /**
1633
+     * Returns a Hasher instance
1634
+     *
1635
+     * @return \OCP\Security\IHasher
1636
+     */
1637
+    public function getHasher() {
1638
+        return $this->query('Hasher');
1639
+    }
1640
+
1641
+    /**
1642
+     * Returns a CredentialsManager instance
1643
+     *
1644
+     * @return \OCP\Security\ICredentialsManager
1645
+     */
1646
+    public function getCredentialsManager() {
1647
+        return $this->query('CredentialsManager');
1648
+    }
1649
+
1650
+    /**
1651
+     * Get the certificate manager for the user
1652
+     *
1653
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1654
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1655
+     */
1656
+    public function getCertificateManager($userId = '') {
1657
+        if ($userId === '') {
1658
+            $userSession = $this->getUserSession();
1659
+            $user = $userSession->getUser();
1660
+            if (is_null($user)) {
1661
+                return null;
1662
+            }
1663
+            $userId = $user->getUID();
1664
+        }
1665
+        return new CertificateManager(
1666
+            $userId,
1667
+            new View(),
1668
+            $this->getConfig(),
1669
+            $this->getLogger(),
1670
+            $this->getSecureRandom()
1671
+        );
1672
+    }
1673
+
1674
+    /**
1675
+     * Returns an instance of the HTTP client service
1676
+     *
1677
+     * @return \OCP\Http\Client\IClientService
1678
+     */
1679
+    public function getHTTPClientService() {
1680
+        return $this->query('HttpClientService');
1681
+    }
1682
+
1683
+    /**
1684
+     * Create a new event source
1685
+     *
1686
+     * @return \OCP\IEventSource
1687
+     */
1688
+    public function createEventSource() {
1689
+        return new \OC_EventSource();
1690
+    }
1691
+
1692
+    /**
1693
+     * Get the active event logger
1694
+     *
1695
+     * The returned logger only logs data when debug mode is enabled
1696
+     *
1697
+     * @return \OCP\Diagnostics\IEventLogger
1698
+     */
1699
+    public function getEventLogger() {
1700
+        return $this->query('EventLogger');
1701
+    }
1702
+
1703
+    /**
1704
+     * Get the active query logger
1705
+     *
1706
+     * The returned logger only logs data when debug mode is enabled
1707
+     *
1708
+     * @return \OCP\Diagnostics\IQueryLogger
1709
+     */
1710
+    public function getQueryLogger() {
1711
+        return $this->query('QueryLogger');
1712
+    }
1713
+
1714
+    /**
1715
+     * Get the manager for temporary files and folders
1716
+     *
1717
+     * @return \OCP\ITempManager
1718
+     */
1719
+    public function getTempManager() {
1720
+        return $this->query('TempManager');
1721
+    }
1722
+
1723
+    /**
1724
+     * Get the app manager
1725
+     *
1726
+     * @return \OCP\App\IAppManager
1727
+     */
1728
+    public function getAppManager() {
1729
+        return $this->query('AppManager');
1730
+    }
1731
+
1732
+    /**
1733
+     * Creates a new mailer
1734
+     *
1735
+     * @return \OCP\Mail\IMailer
1736
+     */
1737
+    public function getMailer() {
1738
+        return $this->query('Mailer');
1739
+    }
1740
+
1741
+    /**
1742
+     * Get the webroot
1743
+     *
1744
+     * @return string
1745
+     */
1746
+    public function getWebRoot() {
1747
+        return $this->webRoot;
1748
+    }
1749
+
1750
+    /**
1751
+     * @return \OC\OCSClient
1752
+     */
1753
+    public function getOcsClient() {
1754
+        return $this->query('OcsClient');
1755
+    }
1756
+
1757
+    /**
1758
+     * @return \OCP\IDateTimeZone
1759
+     */
1760
+    public function getDateTimeZone() {
1761
+        return $this->query('DateTimeZone');
1762
+    }
1763
+
1764
+    /**
1765
+     * @return \OCP\IDateTimeFormatter
1766
+     */
1767
+    public function getDateTimeFormatter() {
1768
+        return $this->query('DateTimeFormatter');
1769
+    }
1770
+
1771
+    /**
1772
+     * @return \OCP\Files\Config\IMountProviderCollection
1773
+     */
1774
+    public function getMountProviderCollection() {
1775
+        return $this->query('MountConfigManager');
1776
+    }
1777
+
1778
+    /**
1779
+     * Get the IniWrapper
1780
+     *
1781
+     * @return IniGetWrapper
1782
+     */
1783
+    public function getIniWrapper() {
1784
+        return $this->query('IniWrapper');
1785
+    }
1786
+
1787
+    /**
1788
+     * @return \OCP\Command\IBus
1789
+     */
1790
+    public function getCommandBus() {
1791
+        return $this->query('AsyncCommandBus');
1792
+    }
1793
+
1794
+    /**
1795
+     * Get the trusted domain helper
1796
+     *
1797
+     * @return TrustedDomainHelper
1798
+     */
1799
+    public function getTrustedDomainHelper() {
1800
+        return $this->query('TrustedDomainHelper');
1801
+    }
1802
+
1803
+    /**
1804
+     * Get the locking provider
1805
+     *
1806
+     * @return \OCP\Lock\ILockingProvider
1807
+     * @since 8.1.0
1808
+     */
1809
+    public function getLockingProvider() {
1810
+        return $this->query('LockingProvider');
1811
+    }
1812
+
1813
+    /**
1814
+     * @return \OCP\Files\Mount\IMountManager
1815
+     **/
1816
+    function getMountManager() {
1817
+        return $this->query('MountManager');
1818
+    }
1819
+
1820
+    /** @return \OCP\Files\Config\IUserMountCache */
1821
+    function getUserMountCache() {
1822
+        return $this->query('UserMountCache');
1823
+    }
1824
+
1825
+    /**
1826
+     * Get the MimeTypeDetector
1827
+     *
1828
+     * @return \OCP\Files\IMimeTypeDetector
1829
+     */
1830
+    public function getMimeTypeDetector() {
1831
+        return $this->query('MimeTypeDetector');
1832
+    }
1833
+
1834
+    /**
1835
+     * Get the MimeTypeLoader
1836
+     *
1837
+     * @return \OCP\Files\IMimeTypeLoader
1838
+     */
1839
+    public function getMimeTypeLoader() {
1840
+        return $this->query('MimeTypeLoader');
1841
+    }
1842
+
1843
+    /**
1844
+     * Get the manager of all the capabilities
1845
+     *
1846
+     * @return \OC\CapabilitiesManager
1847
+     */
1848
+    public function getCapabilitiesManager() {
1849
+        return $this->query('CapabilitiesManager');
1850
+    }
1851
+
1852
+    /**
1853
+     * Get the EventDispatcher
1854
+     *
1855
+     * @return EventDispatcherInterface
1856
+     * @since 8.2.0
1857
+     */
1858
+    public function getEventDispatcher() {
1859
+        return $this->query(\OC\EventDispatcher\SymfonyAdapter::class);
1860
+    }
1861
+
1862
+    /**
1863
+     * Get the Notification Manager
1864
+     *
1865
+     * @return \OCP\Notification\IManager
1866
+     * @since 8.2.0
1867
+     */
1868
+    public function getNotificationManager() {
1869
+        return $this->query('NotificationManager');
1870
+    }
1871
+
1872
+    /**
1873
+     * @return \OCP\Comments\ICommentsManager
1874
+     */
1875
+    public function getCommentsManager() {
1876
+        return $this->query('CommentsManager');
1877
+    }
1878
+
1879
+    /**
1880
+     * @return \OCA\Theming\ThemingDefaults
1881
+     */
1882
+    public function getThemingDefaults() {
1883
+        return $this->query('ThemingDefaults');
1884
+    }
1885
+
1886
+    /**
1887
+     * @return \OC\IntegrityCheck\Checker
1888
+     */
1889
+    public function getIntegrityCodeChecker() {
1890
+        return $this->query('IntegrityCodeChecker');
1891
+    }
1892
+
1893
+    /**
1894
+     * @return \OC\Session\CryptoWrapper
1895
+     */
1896
+    public function getSessionCryptoWrapper() {
1897
+        return $this->query('CryptoWrapper');
1898
+    }
1899
+
1900
+    /**
1901
+     * @return CsrfTokenManager
1902
+     */
1903
+    public function getCsrfTokenManager() {
1904
+        return $this->query('CsrfTokenManager');
1905
+    }
1906
+
1907
+    /**
1908
+     * @return Throttler
1909
+     */
1910
+    public function getBruteForceThrottler() {
1911
+        return $this->query('Throttler');
1912
+    }
1913
+
1914
+    /**
1915
+     * @return IContentSecurityPolicyManager
1916
+     */
1917
+    public function getContentSecurityPolicyManager() {
1918
+        return $this->query('ContentSecurityPolicyManager');
1919
+    }
1920
+
1921
+    /**
1922
+     * @return ContentSecurityPolicyNonceManager
1923
+     */
1924
+    public function getContentSecurityPolicyNonceManager() {
1925
+        return $this->query('ContentSecurityPolicyNonceManager');
1926
+    }
1927
+
1928
+    /**
1929
+     * Not a public API as of 8.2, wait for 9.0
1930
+     *
1931
+     * @return \OCA\Files_External\Service\BackendService
1932
+     */
1933
+    public function getStoragesBackendService() {
1934
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1935
+    }
1936
+
1937
+    /**
1938
+     * Not a public API as of 8.2, wait for 9.0
1939
+     *
1940
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1941
+     */
1942
+    public function getGlobalStoragesService() {
1943
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1944
+    }
1945
+
1946
+    /**
1947
+     * Not a public API as of 8.2, wait for 9.0
1948
+     *
1949
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1950
+     */
1951
+    public function getUserGlobalStoragesService() {
1952
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1953
+    }
1954
+
1955
+    /**
1956
+     * Not a public API as of 8.2, wait for 9.0
1957
+     *
1958
+     * @return \OCA\Files_External\Service\UserStoragesService
1959
+     */
1960
+    public function getUserStoragesService() {
1961
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1962
+    }
1963
+
1964
+    /**
1965
+     * @return \OCP\Share\IManager
1966
+     */
1967
+    public function getShareManager() {
1968
+        return $this->query('ShareManager');
1969
+    }
1970
+
1971
+    /**
1972
+     * @return \OCP\Collaboration\Collaborators\ISearch
1973
+     */
1974
+    public function getCollaboratorSearch() {
1975
+        return $this->query('CollaboratorSearch');
1976
+    }
1977
+
1978
+    /**
1979
+     * @return \OCP\Collaboration\AutoComplete\IManager
1980
+     */
1981
+    public function getAutoCompleteManager(){
1982
+        return $this->query(IManager::class);
1983
+    }
1984
+
1985
+    /**
1986
+     * Returns the LDAP Provider
1987
+     *
1988
+     * @return \OCP\LDAP\ILDAPProvider
1989
+     */
1990
+    public function getLDAPProvider() {
1991
+        return $this->query('LDAPProvider');
1992
+    }
1993
+
1994
+    /**
1995
+     * @return \OCP\Settings\IManager
1996
+     */
1997
+    public function getSettingsManager() {
1998
+        return $this->query('SettingsManager');
1999
+    }
2000
+
2001
+    /**
2002
+     * @return \OCP\Files\IAppData
2003
+     */
2004
+    public function getAppDataDir($app) {
2005
+        /** @var \OC\Files\AppData\Factory $factory */
2006
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
2007
+        return $factory->get($app);
2008
+    }
2009
+
2010
+    /**
2011
+     * @return \OCP\Lockdown\ILockdownManager
2012
+     */
2013
+    public function getLockdownManager() {
2014
+        return $this->query('LockdownManager');
2015
+    }
2016
+
2017
+    /**
2018
+     * @return \OCP\Federation\ICloudIdManager
2019
+     */
2020
+    public function getCloudIdManager() {
2021
+        return $this->query(ICloudIdManager::class);
2022
+    }
2023
+
2024
+    /**
2025
+     * @return \OCP\GlobalScale\IConfig
2026
+     */
2027
+    public function getGlobalScaleConfig() {
2028
+        return $this->query(IConfig::class);
2029
+    }
2030
+
2031
+    /**
2032
+     * @return \OCP\Federation\ICloudFederationProviderManager
2033
+     */
2034
+    public function getCloudFederationProviderManager() {
2035
+        return $this->query(ICloudFederationProviderManager::class);
2036
+    }
2037
+
2038
+    /**
2039
+     * @return \OCP\Remote\Api\IApiFactory
2040
+     */
2041
+    public function getRemoteApiFactory() {
2042
+        return $this->query(IApiFactory::class);
2043
+    }
2044
+
2045
+    /**
2046
+     * @return \OCP\Federation\ICloudFederationFactory
2047
+     */
2048
+    public function getCloudFederationFactory() {
2049
+        return $this->query(ICloudFederationFactory::class);
2050
+    }
2051
+
2052
+    /**
2053
+     * @return \OCP\Remote\IInstanceFactory
2054
+     */
2055
+    public function getRemoteInstanceFactory() {
2056
+        return $this->query(IInstanceFactory::class);
2057
+    }
2058
+
2059
+    /**
2060
+     * @return IStorageFactory
2061
+     */
2062
+    public function getStorageFactory() {
2063
+        return $this->query(IStorageFactory::class);
2064
+    }
2065
+
2066
+    /**
2067
+     * Get the Preview GeneratorHelper
2068
+     *
2069
+     * @return GeneratorHelper
2070
+     * @since 17.0.0
2071
+     */
2072
+    public function getGeneratorHelper() {
2073
+        return $this->query(\OC\Preview\GeneratorHelper::class);
2074
+    }
2075 2075
 }
Please login to merge, or discard this patch.
Spacing   +114 added lines, -114 removed lines patch added patch discarded remove patch
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 		// To find out if we are running from CLI or not
183 183
 		$this->registerParameter('isCLI', \OC::$CLI);
184 184
 
185
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
185
+		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
186 186
 			return $c;
187 187
 		});
188 188
 
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
202 202
 
203 203
 
204
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
204
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
205 205
 			return new PreviewManager(
206 206
 				$c->getConfig(),
207 207
 				$c->getRootFolder(),
@@ -213,13 +213,13 @@  discard block
 block discarded – undo
213 213
 		});
214 214
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
215 215
 
216
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
216
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
217 217
 			return new \OC\Preview\Watcher(
218 218
 				$c->getAppDataDir('preview')
219 219
 			);
220 220
 		});
221 221
 
222
-		$this->registerService(\OCP\Encryption\IManager::class, function (Server $c) {
222
+		$this->registerService(\OCP\Encryption\IManager::class, function(Server $c) {
223 223
 			$view = new View();
224 224
 			$util = new Encryption\Util(
225 225
 				$view,
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 		});
239 239
 		$this->registerAlias('EncryptionManager', \OCP\Encryption\IManager::class);
240 240
 
241
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
241
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
242 242
 			$util = new Encryption\Util(
243 243
 				new View(),
244 244
 				$c->getUserManager(),
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 			);
253 253
 		});
254 254
 
255
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
255
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
256 256
 			$view = new View();
257 257
 			$util = new Encryption\Util(
258 258
 				$view,
@@ -263,30 +263,30 @@  discard block
 block discarded – undo
263 263
 
264 264
 			return new Encryption\Keys\Storage($view, $util);
265 265
 		});
266
-		$this->registerService('TagMapper', function (Server $c) {
266
+		$this->registerService('TagMapper', function(Server $c) {
267 267
 			return new TagMapper($c->getDatabaseConnection());
268 268
 		});
269 269
 
270
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
270
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
271 271
 			$tagMapper = $c->query('TagMapper');
272 272
 			return new TagManager($tagMapper, $c->getUserSession());
273 273
 		});
274 274
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
275 275
 
276
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
276
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
277 277
 			$config = $c->getConfig();
278 278
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
279 279
 			return new $factoryClass($this);
280 280
 		});
281
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
281
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
282 282
 			return $c->query('SystemTagManagerFactory')->getManager();
283 283
 		});
284 284
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
285 285
 
286
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
286
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
287 287
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
288 288
 		});
289
-		$this->registerService('RootFolder', function (Server $c) {
289
+		$this->registerService('RootFolder', function(Server $c) {
290 290
 			$manager = \OC\Files\Filesystem::getMountManager(null);
291 291
 			$view = new View();
292 292
 			$root = new Root(
@@ -307,37 +307,37 @@  discard block
 block discarded – undo
307 307
 		});
308 308
 		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
309 309
 
310
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
311
-			return new LazyRoot(function () use ($c) {
310
+		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
311
+			return new LazyRoot(function() use ($c) {
312 312
 				return $c->query('RootFolder');
313 313
 			});
314 314
 		});
315 315
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
316 316
 
317
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
317
+		$this->registerService(\OC\User\Manager::class, function(Server $c) {
318 318
 			return new \OC\User\Manager($c->getConfig(), $c->getEventDispatcher());
319 319
 		});
320 320
 		$this->registerAlias('UserManager', \OC\User\Manager::class);
321 321
 		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
322 322
 
323
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
323
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
324 324
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $c->getEventDispatcher(), $this->getLogger());
325
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
325
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
326 326
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
327 327
 			});
328
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
328
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
329 329
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
330 330
 			});
331
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
331
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
332 332
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
333 333
 			});
334
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
334
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
335 335
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
336 336
 			});
337
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
337
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
338 338
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
339 339
 			});
340
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
340
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
341 341
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
342 342
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
343 343
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -346,7 +346,7 @@  discard block
 block discarded – undo
346 346
 		});
347 347
 		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
348 348
 
349
-		$this->registerService(Store::class, function (Server $c) {
349
+		$this->registerService(Store::class, function(Server $c) {
350 350
 			$session = $c->getSession();
351 351
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
352 352
 				$tokenProvider = $c->query(IProvider::class);
@@ -357,13 +357,13 @@  discard block
 block discarded – undo
357 357
 			return new Store($session, $logger, $tokenProvider);
358 358
 		});
359 359
 		$this->registerAlias(IStore::class, Store::class);
360
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
360
+		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) {
361 361
 			$dbConnection = $c->getDatabaseConnection();
362 362
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
363 363
 		});
364 364
 		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
365 365
 
366
-		$this->registerService(\OC\User\Session::class, function (Server $c) {
366
+		$this->registerService(\OC\User\Session::class, function(Server $c) {
367 367
 			$manager = $c->getUserManager();
368 368
 			$session = new \OC\Session\Memory('');
369 369
 			$timeFactory = new TimeFactory();
@@ -387,45 +387,45 @@  discard block
 block discarded – undo
387 387
 				$c->getLockdownManager(),
388 388
 				$c->getLogger()
389 389
 			);
390
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
390
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
391 391
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
392 392
 			});
393
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
393
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
394 394
 				/** @var $user \OC\User\User */
395 395
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
396 396
 			});
397
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
397
+			$userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) {
398 398
 				/** @var $user \OC\User\User */
399 399
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
400 400
 				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
401 401
 			});
402
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
402
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
403 403
 				/** @var $user \OC\User\User */
404 404
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
405 405
 			});
406
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
406
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
407 407
 				/** @var $user \OC\User\User */
408 408
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
409 409
 			});
410
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
410
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
411 411
 				/** @var $user \OC\User\User */
412 412
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
413 413
 			});
414
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
414
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
415 415
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
416 416
 			});
417
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
417
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password, $isTokenLogin) {
418 418
 				/** @var $user \OC\User\User */
419 419
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin));
420 420
 			});
421
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
421
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
422 422
 				/** @var $user \OC\User\User */
423 423
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
424 424
 			});
425
-			$userSession->listen('\OC\User', 'logout', function () {
425
+			$userSession->listen('\OC\User', 'logout', function() {
426 426
 				\OC_Hook::emit('OC_User', 'logout', array());
427 427
 			});
428
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
428
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
429 429
 				/** @var $user \OC\User\User */
430 430
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
431 431
 			});
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
440 440
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
441 441
 
442
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
442
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
443 443
 			return new \OC\AllConfig(
444 444
 				$c->getSystemConfig()
445 445
 			);
@@ -447,17 +447,17 @@  discard block
 block discarded – undo
447 447
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
448 448
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
449 449
 
450
-		$this->registerService('SystemConfig', function ($c) use ($config) {
450
+		$this->registerService('SystemConfig', function($c) use ($config) {
451 451
 			return new \OC\SystemConfig($config);
452 452
 		});
453 453
 
454
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
454
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
455 455
 			return new \OC\AppConfig($c->getDatabaseConnection());
456 456
 		});
457 457
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
458 458
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
459 459
 
460
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
460
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
461 461
 			return new \OC\L10N\Factory(
462 462
 				$c->getConfig(),
463 463
 				$c->getRequest(),
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 		});
468 468
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
469 469
 
470
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
470
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
471 471
 			$config = $c->getConfig();
472 472
 			$cacheFactory = $c->getMemCacheFactory();
473 473
 			$request = $c->getRequest();
@@ -482,12 +482,12 @@  discard block
 block discarded – undo
482 482
 		$this->registerAlias('AppFetcher', AppFetcher::class);
483 483
 		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
484 484
 
485
-		$this->registerService(\OCP\ICache::class, function ($c) {
485
+		$this->registerService(\OCP\ICache::class, function($c) {
486 486
 			return new Cache\File();
487 487
 		});
488 488
 		$this->registerAlias('UserCache', \OCP\ICache::class);
489 489
 
490
-		$this->registerService(Factory::class, function (Server $c) {
490
+		$this->registerService(Factory::class, function(Server $c) {
491 491
 
492 492
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
493 493
 				ArrayCache::class,
@@ -502,7 +502,7 @@  discard block
 block discarded – undo
502 502
 				$version = implode(',', $v);
503 503
 				$instanceId = \OC_Util::getInstanceId();
504 504
 				$path = \OC::$SERVERROOT;
505
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
505
+				$prefix = md5($instanceId.'-'.$version.'-'.$path);
506 506
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
507 507
 					$config->getSystemValue('memcache.local', null),
508 508
 					$config->getSystemValue('memcache.distributed', null),
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
 		$this->registerAlias('MemCacheFactory', Factory::class);
516 516
 		$this->registerAlias(ICacheFactory::class, Factory::class);
517 517
 
518
-		$this->registerService('RedisFactory', function (Server $c) {
518
+		$this->registerService('RedisFactory', function(Server $c) {
519 519
 			$systemConfig = $c->getSystemConfig();
520 520
 			return new RedisFactory($systemConfig);
521 521
 		});
522 522
 
523
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
523
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
524 524
 			return new \OC\Activity\Manager(
525 525
 				$c->getRequest(),
526 526
 				$c->getUserSession(),
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 		});
531 531
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
532 532
 
533
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
533
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
534 534
 			return new \OC\Activity\EventMerger(
535 535
 				$c->getL10N('lib')
536 536
 			);
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
553 553
 		$this->registerAlias(\OCP\Support\Subscription\IRegistry::class, \OC\Support\Subscription\Registry::class);
554 554
 
555
-		$this->registerService(\OC\Log::class, function (Server $c) {
555
+		$this->registerService(\OC\Log::class, function(Server $c) {
556 556
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
557 557
 			$factory = new LogFactory($c, $this->getSystemConfig());
558 558
 			$logger = $factory->get($logType);
@@ -563,11 +563,11 @@  discard block
 block discarded – undo
563 563
 		$this->registerAlias(\OCP\ILogger::class, \OC\Log::class);
564 564
 		$this->registerAlias('Logger', \OC\Log::class);
565 565
 
566
-		$this->registerService(ILogFactory::class, function (Server $c) {
566
+		$this->registerService(ILogFactory::class, function(Server $c) {
567 567
 			return new LogFactory($c, $this->getSystemConfig());
568 568
 		});
569 569
 
570
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
570
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
571 571
 			$config = $c->getConfig();
572 572
 			return new \OC\BackgroundJob\JobList(
573 573
 				$c->getDatabaseConnection(),
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 		});
578 578
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
579 579
 
580
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
580
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
581 581
 			$cacheFactory = $c->getMemCacheFactory();
582 582
 			$logger = $c->getLogger();
583 583
 			if ($cacheFactory->isLocalCacheAvailable()) {
@@ -589,12 +589,12 @@  discard block
 block discarded – undo
589 589
 		});
590 590
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
591 591
 
592
-		$this->registerService(\OCP\ISearch::class, function ($c) {
592
+		$this->registerService(\OCP\ISearch::class, function($c) {
593 593
 			return new Search();
594 594
 		});
595 595
 		$this->registerAlias('Search', \OCP\ISearch::class);
596 596
 
597
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
597
+		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) {
598 598
 			return new \OC\Security\RateLimiting\Limiter(
599 599
 				$this->getUserSession(),
600 600
 				$this->getRequest(),
@@ -602,34 +602,34 @@  discard block
 block discarded – undo
602 602
 				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
603 603
 			);
604 604
 		});
605
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
605
+		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
606 606
 			return new \OC\Security\RateLimiting\Backend\MemoryCache(
607 607
 				$this->getMemCacheFactory(),
608 608
 				new \OC\AppFramework\Utility\TimeFactory()
609 609
 			);
610 610
 		});
611 611
 
612
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
612
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
613 613
 			return new SecureRandom();
614 614
 		});
615 615
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
616 616
 
617
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
617
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
618 618
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
619 619
 		});
620 620
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
621 621
 
622
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
622
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
623 623
 			return new Hasher($c->getConfig());
624 624
 		});
625 625
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
626 626
 
627
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
627
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
628 628
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
629 629
 		});
630 630
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
631 631
 
632
-		$this->registerService(IDBConnection::class, function (Server $c) {
632
+		$this->registerService(IDBConnection::class, function(Server $c) {
633 633
 			$systemConfig = $c->getSystemConfig();
634 634
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
635 635
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
645 645
 
646 646
 
647
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
647
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
648 648
 			$user = \OC_User::getUser();
649 649
 			$uid = $user ? $user : null;
650 650
 			return new ClientService(
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 			);
660 660
 		});
661 661
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
662
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
662
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
663 663
 			$eventLogger = new EventLogger();
664 664
 			if ($c->getSystemConfig()->getValue('debug', false)) {
665 665
 				// In debug mode, module is being activated by default
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 		});
670 670
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
671 671
 
672
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
672
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
673 673
 			$queryLogger = new QueryLogger();
674 674
 			if ($c->getSystemConfig()->getValue('debug', false)) {
675 675
 				// In debug mode, module is being activated by default
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
 		});
680 680
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
681 681
 
682
-		$this->registerService(TempManager::class, function (Server $c) {
682
+		$this->registerService(TempManager::class, function(Server $c) {
683 683
 			return new TempManager(
684 684
 				$c->getLogger(),
685 685
 				$c->getConfig()
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
 		$this->registerAlias('TempManager', TempManager::class);
689 689
 		$this->registerAlias(ITempManager::class, TempManager::class);
690 690
 
691
-		$this->registerService(AppManager::class, function (Server $c) {
691
+		$this->registerService(AppManager::class, function(Server $c) {
692 692
 			return new \OC\App\AppManager(
693 693
 				$c->getUserSession(),
694 694
 				$c->query(\OC\AppConfig::class),
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 		$this->registerAlias('AppManager', AppManager::class);
701 701
 		$this->registerAlias(IAppManager::class, AppManager::class);
702 702
 
703
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
703
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
704 704
 			return new DateTimeZone(
705 705
 				$c->getConfig(),
706 706
 				$c->getSession()
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
 		});
709 709
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
710 710
 
711
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
711
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
712 712
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
713 713
 
714 714
 			return new DateTimeFormatter(
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 		});
719 719
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
720 720
 
721
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
721
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
722 722
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
723 723
 			$listener = new UserMountCacheListener($mountCache);
724 724
 			$listener->listen($c->getUserManager());
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 		});
727 727
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
728 728
 
729
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
729
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
730 730
 			$loader = \OC\Files\Filesystem::getLoader();
731 731
 			$mountCache = $c->query('UserMountCache');
732 732
 			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
@@ -742,10 +742,10 @@  discard block
 block discarded – undo
742 742
 		});
743 743
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
744 744
 
745
-		$this->registerService('IniWrapper', function ($c) {
745
+		$this->registerService('IniWrapper', function($c) {
746 746
 			return new IniGetWrapper();
747 747
 		});
748
-		$this->registerService('AsyncCommandBus', function (Server $c) {
748
+		$this->registerService('AsyncCommandBus', function(Server $c) {
749 749
 			$busClass = $c->getConfig()->getSystemValue('commandbus');
750 750
 			if ($busClass) {
751 751
 				list($app, $class) = explode('::', $busClass, 2);
@@ -760,10 +760,10 @@  discard block
 block discarded – undo
760 760
 				return new CronBus($jobList);
761 761
 			}
762 762
 		});
763
-		$this->registerService('TrustedDomainHelper', function ($c) {
763
+		$this->registerService('TrustedDomainHelper', function($c) {
764 764
 			return new TrustedDomainHelper($this->getConfig());
765 765
 		});
766
-		$this->registerService(Throttler::class, function (Server $c) {
766
+		$this->registerService(Throttler::class, function(Server $c) {
767 767
 			return new Throttler(
768 768
 				$c->getDatabaseConnection(),
769 769
 				new TimeFactory(),
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 			);
773 773
 		});
774 774
 		$this->registerAlias('Throttler', Throttler::class);
775
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
775
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
776 776
 			// IConfig and IAppManager requires a working database. This code
777 777
 			// might however be called when ownCloud is not yet setup.
778 778
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
 				$c->getMimeTypeDetector()
795 795
 			);
796 796
 		});
797
-		$this->registerService(\OCP\IRequest::class, function ($c) {
797
+		$this->registerService(\OCP\IRequest::class, function($c) {
798 798
 			if (isset($this['urlParams'])) {
799 799
 				$urlParams = $this['urlParams'];
800 800
 			} else {
@@ -830,7 +830,7 @@  discard block
 block discarded – undo
830 830
 		});
831 831
 		$this->registerAlias('Request', \OCP\IRequest::class);
832 832
 
833
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
833
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
834 834
 			return new Mailer(
835 835
 				$c->getConfig(),
836 836
 				$c->getLogger(),
@@ -841,7 +841,7 @@  discard block
 block discarded – undo
841 841
 		});
842 842
 		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
843 843
 
844
-		$this->registerService('LDAPProvider', function (Server $c) {
844
+		$this->registerService('LDAPProvider', function(Server $c) {
845 845
 			$config = $c->getConfig();
846 846
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
847 847
 			if (is_null($factoryClass)) {
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 			$factory = new $factoryClass($this);
852 852
 			return $factory->getLDAPProvider();
853 853
 		});
854
-		$this->registerService(ILockingProvider::class, function (Server $c) {
854
+		$this->registerService(ILockingProvider::class, function(Server $c) {
855 855
 			$ini = $c->getIniWrapper();
856 856
 			$config = $c->getConfig();
857 857
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -874,49 +874,49 @@  discard block
 block discarded – undo
874 874
 		});
875 875
 		$this->registerAlias('LockingProvider', ILockingProvider::class);
876 876
 
877
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
877
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
878 878
 			return new \OC\Files\Mount\Manager();
879 879
 		});
880 880
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
881 881
 
882
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
882
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
883 883
 			return new \OC\Files\Type\Detection(
884 884
 				$c->getURLGenerator(),
885 885
 				\OC::$configDir,
886
-				\OC::$SERVERROOT . '/resources/config/'
886
+				\OC::$SERVERROOT.'/resources/config/'
887 887
 			);
888 888
 		});
889 889
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
890 890
 
891
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
891
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
892 892
 			return new \OC\Files\Type\Loader(
893 893
 				$c->getDatabaseConnection()
894 894
 			);
895 895
 		});
896 896
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
897
-		$this->registerService(BundleFetcher::class, function () {
897
+		$this->registerService(BundleFetcher::class, function() {
898 898
 			return new BundleFetcher($this->getL10N('lib'));
899 899
 		});
900
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
900
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
901 901
 			return new Manager(
902 902
 				$c->query(IValidator::class)
903 903
 			);
904 904
 		});
905 905
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
906 906
 
907
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
907
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
908 908
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
909
-			$manager->registerCapability(function () use ($c) {
909
+			$manager->registerCapability(function() use ($c) {
910 910
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
911 911
 			});
912
-			$manager->registerCapability(function () use ($c) {
912
+			$manager->registerCapability(function() use ($c) {
913 913
 				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
914 914
 			});
915 915
 			return $manager;
916 916
 		});
917 917
 		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
918 918
 
919
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
919
+		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
920 920
 			$config = $c->getConfig();
921 921
 			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
922 922
 			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
@@ -926,7 +926,7 @@  discard block
 block discarded – undo
926 926
 			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
927 927
 				$manager = $c->getUserManager();
928 928
 				$user = $manager->get($id);
929
-				if(is_null($user)) {
929
+				if (is_null($user)) {
930 930
 					$l = $c->getL10N('core');
931 931
 					$displayName = $l->t('Unknown user');
932 932
 				} else {
@@ -939,7 +939,7 @@  discard block
 block discarded – undo
939 939
 		});
940 940
 		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
941 941
 
942
-		$this->registerService('ThemingDefaults', function (Server $c) {
942
+		$this->registerService('ThemingDefaults', function(Server $c) {
943 943
 			/*
944 944
 			 * Dark magic for autoloader.
945 945
 			 * If we do a class_exists it will try to load the class which will
@@ -967,7 +967,7 @@  discard block
 block discarded – undo
967 967
 			}
968 968
 			return new \OC_Defaults();
969 969
 		});
970
-		$this->registerService(SCSSCacher::class, function (Server $c) {
970
+		$this->registerService(SCSSCacher::class, function(Server $c) {
971 971
 			return new SCSSCacher(
972 972
 				$c->getLogger(),
973 973
 				$c->query(\OC\Files\AppData\Factory::class),
@@ -980,7 +980,7 @@  discard block
 block discarded – undo
980 980
 				new TimeFactory()
981 981
 			);
982 982
 		});
983
-		$this->registerService(JSCombiner::class, function (Server $c) {
983
+		$this->registerService(JSCombiner::class, function(Server $c) {
984 984
 			return new JSCombiner(
985 985
 				$c->getAppDataDir('js'),
986 986
 				$c->getURLGenerator(),
@@ -993,7 +993,7 @@  discard block
 block discarded – undo
993 993
 		$this->registerAlias('EventDispatcher', \OC\EventDispatcher\SymfonyAdapter::class);
994 994
 		$this->registerAlias(EventDispatcherInterface::class, \OC\EventDispatcher\SymfonyAdapter::class);
995 995
 
996
-		$this->registerService('CryptoWrapper', function (Server $c) {
996
+		$this->registerService('CryptoWrapper', function(Server $c) {
997 997
 			// FIXME: Instantiiated here due to cyclic dependency
998 998
 			$request = new Request(
999 999
 				[
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
 				$request
1019 1019
 			);
1020 1020
 		});
1021
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1021
+		$this->registerService('CsrfTokenManager', function(Server $c) {
1022 1022
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1023 1023
 
1024 1024
 			return new CsrfTokenManager(
@@ -1026,22 +1026,22 @@  discard block
 block discarded – undo
1026 1026
 				$c->query(SessionStorage::class)
1027 1027
 			);
1028 1028
 		});
1029
-		$this->registerService(SessionStorage::class, function (Server $c) {
1029
+		$this->registerService(SessionStorage::class, function(Server $c) {
1030 1030
 			return new SessionStorage($c->getSession());
1031 1031
 		});
1032
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1032
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
1033 1033
 			return new ContentSecurityPolicyManager();
1034 1034
 		});
1035 1035
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1036 1036
 
1037
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1037
+		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
1038 1038
 			return new ContentSecurityPolicyNonceManager(
1039 1039
 				$c->getCsrfTokenManager(),
1040 1040
 				$c->getRequest()
1041 1041
 			);
1042 1042
 		});
1043 1043
 
1044
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1044
+		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
1045 1045
 			$config = $c->getConfig();
1046 1046
 			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1047 1047
 			/** @var \OCP\Share\IProviderFactory $factory */
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 
1089 1089
 		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, \OC\Collaboration\Resources\Manager::class);
1090 1090
 
1091
-		$this->registerService('SettingsManager', function (Server $c) {
1091
+		$this->registerService('SettingsManager', function(Server $c) {
1092 1092
 			$manager = new \OC\Settings\Manager(
1093 1093
 				$c->getLogger(),
1094 1094
 				$c->getL10NFactory(),
@@ -1097,36 +1097,36 @@  discard block
 block discarded – undo
1097 1097
 			);
1098 1098
 			return $manager;
1099 1099
 		});
1100
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1100
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
1101 1101
 			return new \OC\Files\AppData\Factory(
1102 1102
 				$c->getRootFolder(),
1103 1103
 				$c->getSystemConfig()
1104 1104
 			);
1105 1105
 		});
1106 1106
 
1107
-		$this->registerService('LockdownManager', function (Server $c) {
1108
-			return new LockdownManager(function () use ($c) {
1107
+		$this->registerService('LockdownManager', function(Server $c) {
1108
+			return new LockdownManager(function() use ($c) {
1109 1109
 				return $c->getSession();
1110 1110
 			});
1111 1111
 		});
1112 1112
 
1113
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1113
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
1114 1114
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1115 1115
 		});
1116 1116
 
1117
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1117
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
1118 1118
 			return new CloudIdManager();
1119 1119
 		});
1120 1120
 
1121
-		$this->registerService(IConfig::class, function (Server $c) {
1121
+		$this->registerService(IConfig::class, function(Server $c) {
1122 1122
 			return new GlobalScale\Config($c->getConfig());
1123 1123
 		});
1124 1124
 
1125
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1125
+		$this->registerService(ICloudFederationProviderManager::class, function(Server $c) {
1126 1126
 			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1127 1127
 		});
1128 1128
 
1129
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1129
+		$this->registerService(ICloudFederationFactory::class, function(Server $c) {
1130 1130
 			return new CloudFederationFactory();
1131 1131
 		});
1132 1132
 
@@ -1136,18 +1136,18 @@  discard block
 block discarded – undo
1136 1136
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1137 1137
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1138 1138
 
1139
-		$this->registerService(Defaults::class, function (Server $c) {
1139
+		$this->registerService(Defaults::class, function(Server $c) {
1140 1140
 			return new Defaults(
1141 1141
 				$c->getThemingDefaults()
1142 1142
 			);
1143 1143
 		});
1144 1144
 		$this->registerAlias('Defaults', \OCP\Defaults::class);
1145 1145
 
1146
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1146
+		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1147 1147
 			return $c->query(\OCP\IUserSession::class)->getSession();
1148 1148
 		});
1149 1149
 
1150
-		$this->registerService(IShareHelper::class, function (Server $c) {
1150
+		$this->registerService(IShareHelper::class, function(Server $c) {
1151 1151
 			return new ShareHelper(
1152 1152
 				$c->query(\OCP\Share\IManager::class)
1153 1153
 			);
@@ -1190,7 +1190,7 @@  discard block
 block discarded – undo
1190 1190
 		$this->registerAlias(IDashboardManager::class, DashboardManager::class);
1191 1191
 		$this->registerAlias(IFullTextSearchManager::class, FullTextSearchManager::class);
1192 1192
 
1193
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function (Server $c) {
1193
+		$this->registerService(\OC\Security\IdentityProof\Manager::class, function(Server $c) {
1194 1194
 			return new \OC\Security\IdentityProof\Manager(
1195 1195
 				$c->query(\OC\Files\AppData\Factory::class),
1196 1196
 				$c->getCrypto(),
@@ -1243,11 +1243,11 @@  discard block
 block discarded – undo
1243 1243
 				// no avatar to remove
1244 1244
 			} catch (\Exception $e) {
1245 1245
 				// Ignore exceptions
1246
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1246
+				$logger->info('Could not cleanup avatar of '.$user->getUID());
1247 1247
 			}
1248 1248
 		});
1249 1249
 
1250
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1250
+		$dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) {
1251 1251
 			$manager = $this->getAvatarManager();
1252 1252
 			/** @var IUser $user */
1253 1253
 			$user = $e->getSubject();
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
 	 * @deprecated since 9.2.0 use IAppData
1404 1404
 	 */
1405 1405
 	public function getAppFolder() {
1406
-		$dir = '/' . \OC_App::getCurrentApp();
1406
+		$dir = '/'.\OC_App::getCurrentApp();
1407 1407
 		$root = $this->getRootFolder();
1408 1408
 		if (!$root->nodeExists($dir)) {
1409 1409
 			$folder = $root->newFolder($dir);
@@ -1978,7 +1978,7 @@  discard block
 block discarded – undo
1978 1978
 	/**
1979 1979
 	 * @return \OCP\Collaboration\AutoComplete\IManager
1980 1980
 	 */
1981
-	public function getAutoCompleteManager(){
1981
+	public function getAutoCompleteManager() {
1982 1982
 		return $this->query(IManager::class);
1983 1983
 	}
1984 1984
 
Please login to merge, or discard this patch.
lib/private/Files/Type/Detection.php 2 patches
Indentation   +293 added lines, -293 removed lines patch added patch discarded remove patch
@@ -44,297 +44,297 @@
 block discarded – undo
44 44
  * @package OC\Files\Type
45 45
  */
46 46
 class Detection implements IMimeTypeDetector {
47
-	protected $mimetypes = [];
48
-	protected $secureMimeTypes = [];
49
-
50
-	protected $mimetypeIcons = [];
51
-	/** @var string[] */
52
-	protected $mimeTypeAlias = [];
53
-
54
-	/** @var IURLGenerator */
55
-	private $urlGenerator;
56
-
57
-	/** @var string */
58
-	private $customConfigDir;
59
-
60
-	/** @var string */
61
-	private $defaultConfigDir;
62
-
63
-	/**
64
-	 * @param IURLGenerator $urlGenerator
65
-	 * @param string $customConfigDir
66
-	 * @param string $defaultConfigDir
67
-	 */
68
-	public function __construct(IURLGenerator $urlGenerator,
69
-								$customConfigDir,
70
-								$defaultConfigDir) {
71
-		$this->urlGenerator = $urlGenerator;
72
-		$this->customConfigDir = $customConfigDir;
73
-		$this->defaultConfigDir = $defaultConfigDir;
74
-	}
75
-
76
-	/**
77
-	 * Add an extension -> mimetype mapping
78
-	 *
79
-	 * $mimetype is the assumed correct mime type
80
-	 * The optional $secureMimeType is an alternative to send to send
81
-	 * to avoid potential XSS.
82
-	 *
83
-	 * @param string $extension
84
-	 * @param string $mimetype
85
-	 * @param string|null $secureMimeType
86
-	 */
87
-	public function registerType($extension,
88
-								 $mimetype,
89
-								 $secureMimeType = null) {
90
-		$this->mimetypes[$extension] = array($mimetype, $secureMimeType);
91
-		$this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype;
92
-	}
93
-
94
-	/**
95
-	 * Add an array of extension -> mimetype mappings
96
-	 *
97
-	 * The mimetype value is in itself an array where the first index is
98
-	 * the assumed correct mimetype and the second is either a secure alternative
99
-	 * or null if the correct is considered secure.
100
-	 *
101
-	 * @param array $types
102
-	 */
103
-	public function registerTypeArray($types) {
104
-		$this->mimetypes = array_merge($this->mimetypes, $types);
105
-
106
-		// Update the alternative mimetypes to avoid having to look them up each time.
107
-		foreach ($this->mimetypes as $mimeType) {
108
-			$this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0];
109
-		}
110
-	}
111
-
112
-	/**
113
-	 * Add the mimetype aliases if they are not yet present
114
-	 */
115
-	private function loadAliases() {
116
-		if (!empty($this->mimeTypeAlias)) {
117
-			return;
118
-		}
119
-
120
-		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
121
-
122
-		if (file_exists($this->customConfigDir . '/mimetypealiases.json')) {
123
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true);
124
-			$this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
125
-		}
126
-	}
127
-
128
-	/**
129
-	 * @return string[]
130
-	 */
131
-	public function getAllAliases() {
132
-		$this->loadAliases();
133
-		return $this->mimeTypeAlias;
134
-	}
135
-
136
-	public function getOnlyDefaultAliases() {
137
-		$this->loadMappings();
138
-		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
139
-		return $this->mimeTypeAlias;
140
-	}
141
-
142
-	/**
143
-	 * Add mimetype mappings if they are not yet present
144
-	 */
145
-	private function loadMappings() {
146
-		if (!empty($this->mimetypes)) {
147
-			return;
148
-		}
149
-
150
-		$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
151
-
152
-		//Check if need to load custom mappings
153
-		if (file_exists($this->customConfigDir . '/mimetypemapping.json')) {
154
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true);
155
-			$mimetypeMapping = array_merge($mimetypeMapping, $custom);
156
-		}
157
-
158
-		$this->registerTypeArray($mimetypeMapping);
159
-	}
160
-
161
-	/**
162
-	 * @return array
163
-	 */
164
-	public function getAllMappings() {
165
-		$this->loadMappings();
166
-		return $this->mimetypes;
167
-	}
168
-
169
-	/**
170
-	 * detect mimetype only based on filename, content of file is not used
171
-	 *
172
-	 * @param string $path
173
-	 * @return string
174
-	 */
175
-	public function detectPath($path) {
176
-		$this->loadMappings();
177
-
178
-		$fileName = basename($path);
179
-
180
-		// remove leading dot on hidden files with a file extension
181
-		$fileName = ltrim($fileName, '.');
182
-
183
-		// note: leading dot doesn't qualify as extension
184
-		if (strpos($fileName, '.') > 0) {
185
-
186
-			// remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part
187
-			$fileName = preg_replace('!((\.v\d+)|((.ocTransferId\d+)?.part))$!', '', $fileName);
188
-
189
-			//try to guess the type by the file extension
190
-			$extension = strtolower(strrchr($fileName, '.'));
191
-			$extension = substr($extension, 1); //remove leading .
192
-			return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0]))
193
-				? $this->mimetypes[$extension][0]
194
-				: 'application/octet-stream';
195
-		} else {
196
-			return 'application/octet-stream';
197
-		}
198
-	}
199
-
200
-	/**
201
-	 * detect mimetype based on both filename and content
202
-	 *
203
-	 * @param string $path
204
-	 * @return string
205
-	 */
206
-	public function detect($path) {
207
-		$this->loadMappings();
208
-
209
-		if (@is_dir($path)) {
210
-			// directories are easy
211
-			return "httpd/unix-directory";
212
-		}
213
-
214
-		$mimeType = $this->detectPath($path);
215
-
216
-		if ($mimeType === 'application/octet-stream' and function_exists('finfo_open')
217
-			and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)
218
-		) {
219
-			$info = @strtolower(finfo_file($finfo, $path));
220
-			finfo_close($finfo);
221
-			if ($info) {
222
-				$mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
223
-				return empty($mimeType) ? 'application/octet-stream' : $mimeType;
224
-			}
225
-
226
-		}
227
-		$isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://');
228
-		if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) {
229
-			// use mime magic extension if available
230
-			$mimeType = mime_content_type($path);
231
-		}
232
-		if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) {
233
-			// it looks like we have a 'file' command,
234
-			// lets see if it does have mime support
235
-			$path = escapeshellarg($path);
236
-			$fp = popen("file -b --mime-type $path 2>/dev/null", "r");
237
-			$reply = fgets($fp);
238
-			pclose($fp);
239
-
240
-			//trim the newline
241
-			$mimeType = trim($reply);
242
-
243
-			if (empty($mimeType)) {
244
-				$mimeType = 'application/octet-stream';
245
-			}
246
-
247
-		}
248
-		return $mimeType;
249
-	}
250
-
251
-	/**
252
-	 * detect mimetype based on the content of a string
253
-	 *
254
-	 * @param string $data
255
-	 * @return string
256
-	 */
257
-	public function detectString($data) {
258
-		if (function_exists('finfo_open') and function_exists('finfo_file')) {
259
-			$finfo = finfo_open(FILEINFO_MIME);
260
-			$info = finfo_buffer($finfo, $data);
261
-			return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
262
-		} else {
263
-			$tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
264
-			$fh = fopen($tmpFile, 'wb');
265
-			fwrite($fh, $data, 8024);
266
-			fclose($fh);
267
-			$mime = $this->detect($tmpFile);
268
-			unset($tmpFile);
269
-			return $mime;
270
-		}
271
-	}
272
-
273
-	/**
274
-	 * Get a secure mimetype that won't expose potential XSS.
275
-	 *
276
-	 * @param string $mimeType
277
-	 * @return string
278
-	 */
279
-	public function getSecureMimeType($mimeType) {
280
-		$this->loadMappings();
281
-
282
-		return isset($this->secureMimeTypes[$mimeType])
283
-			? $this->secureMimeTypes[$mimeType]
284
-			: 'application/octet-stream';
285
-	}
286
-
287
-	/**
288
-	 * Get path to the icon of a file type
289
-	 * @param string $mimetype the MIME type
290
-	 * @return string the url
291
-	 */
292
-	public function mimeTypeIcon($mimetype) {
293
-		$this->loadAliases();
294
-
295
-		while (isset($this->mimeTypeAlias[$mimetype])) {
296
-			$mimetype = $this->mimeTypeAlias[$mimetype];
297
-		}
298
-		if (isset($this->mimetypeIcons[$mimetype])) {
299
-			return $this->mimetypeIcons[$mimetype];
300
-		}
301
-
302
-		// Replace slash and backslash with a minus
303
-		$icon = str_replace('/', '-', $mimetype);
304
-		$icon = str_replace('\\', '-', $icon);
305
-
306
-		// Is it a dir?
307
-		if ($mimetype === 'dir') {
308
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg');
309
-			return $this->mimetypeIcons[$mimetype];
310
-		}
311
-		if ($mimetype === 'dir-shared') {
312
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg');
313
-			return $this->mimetypeIcons[$mimetype];
314
-		}
315
-		if ($mimetype === 'dir-external') {
316
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg');
317
-			return $this->mimetypeIcons[$mimetype];
318
-		}
319
-
320
-		// Icon exists?
321
-		try {
322
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg');
323
-			return $this->mimetypeIcons[$mimetype];
324
-		} catch (\RuntimeException $e) {
325
-			// Specified image not found
326
-		}
327
-
328
-		// Try only the first part of the filetype
329
-		$mimePart = substr($icon, 0, strpos($icon, '-'));
330
-		try {
331
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
332
-			return $this->mimetypeIcons[$mimetype];
333
-		} catch (\RuntimeException $e) {
334
-			// Image for the first part of the mimetype not found
335
-		}
336
-
337
-		$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg');
338
-		return $this->mimetypeIcons[$mimetype];
339
-	}
47
+    protected $mimetypes = [];
48
+    protected $secureMimeTypes = [];
49
+
50
+    protected $mimetypeIcons = [];
51
+    /** @var string[] */
52
+    protected $mimeTypeAlias = [];
53
+
54
+    /** @var IURLGenerator */
55
+    private $urlGenerator;
56
+
57
+    /** @var string */
58
+    private $customConfigDir;
59
+
60
+    /** @var string */
61
+    private $defaultConfigDir;
62
+
63
+    /**
64
+     * @param IURLGenerator $urlGenerator
65
+     * @param string $customConfigDir
66
+     * @param string $defaultConfigDir
67
+     */
68
+    public function __construct(IURLGenerator $urlGenerator,
69
+                                $customConfigDir,
70
+                                $defaultConfigDir) {
71
+        $this->urlGenerator = $urlGenerator;
72
+        $this->customConfigDir = $customConfigDir;
73
+        $this->defaultConfigDir = $defaultConfigDir;
74
+    }
75
+
76
+    /**
77
+     * Add an extension -> mimetype mapping
78
+     *
79
+     * $mimetype is the assumed correct mime type
80
+     * The optional $secureMimeType is an alternative to send to send
81
+     * to avoid potential XSS.
82
+     *
83
+     * @param string $extension
84
+     * @param string $mimetype
85
+     * @param string|null $secureMimeType
86
+     */
87
+    public function registerType($extension,
88
+                                    $mimetype,
89
+                                    $secureMimeType = null) {
90
+        $this->mimetypes[$extension] = array($mimetype, $secureMimeType);
91
+        $this->secureMimeTypes[$mimetype] = $secureMimeType ?: $mimetype;
92
+    }
93
+
94
+    /**
95
+     * Add an array of extension -> mimetype mappings
96
+     *
97
+     * The mimetype value is in itself an array where the first index is
98
+     * the assumed correct mimetype and the second is either a secure alternative
99
+     * or null if the correct is considered secure.
100
+     *
101
+     * @param array $types
102
+     */
103
+    public function registerTypeArray($types) {
104
+        $this->mimetypes = array_merge($this->mimetypes, $types);
105
+
106
+        // Update the alternative mimetypes to avoid having to look them up each time.
107
+        foreach ($this->mimetypes as $mimeType) {
108
+            $this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0];
109
+        }
110
+    }
111
+
112
+    /**
113
+     * Add the mimetype aliases if they are not yet present
114
+     */
115
+    private function loadAliases() {
116
+        if (!empty($this->mimeTypeAlias)) {
117
+            return;
118
+        }
119
+
120
+        $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
121
+
122
+        if (file_exists($this->customConfigDir . '/mimetypealiases.json')) {
123
+            $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true);
124
+            $this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
125
+        }
126
+    }
127
+
128
+    /**
129
+     * @return string[]
130
+     */
131
+    public function getAllAliases() {
132
+        $this->loadAliases();
133
+        return $this->mimeTypeAlias;
134
+    }
135
+
136
+    public function getOnlyDefaultAliases() {
137
+        $this->loadMappings();
138
+        $this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
139
+        return $this->mimeTypeAlias;
140
+    }
141
+
142
+    /**
143
+     * Add mimetype mappings if they are not yet present
144
+     */
145
+    private function loadMappings() {
146
+        if (!empty($this->mimetypes)) {
147
+            return;
148
+        }
149
+
150
+        $mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
151
+
152
+        //Check if need to load custom mappings
153
+        if (file_exists($this->customConfigDir . '/mimetypemapping.json')) {
154
+            $custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true);
155
+            $mimetypeMapping = array_merge($mimetypeMapping, $custom);
156
+        }
157
+
158
+        $this->registerTypeArray($mimetypeMapping);
159
+    }
160
+
161
+    /**
162
+     * @return array
163
+     */
164
+    public function getAllMappings() {
165
+        $this->loadMappings();
166
+        return $this->mimetypes;
167
+    }
168
+
169
+    /**
170
+     * detect mimetype only based on filename, content of file is not used
171
+     *
172
+     * @param string $path
173
+     * @return string
174
+     */
175
+    public function detectPath($path) {
176
+        $this->loadMappings();
177
+
178
+        $fileName = basename($path);
179
+
180
+        // remove leading dot on hidden files with a file extension
181
+        $fileName = ltrim($fileName, '.');
182
+
183
+        // note: leading dot doesn't qualify as extension
184
+        if (strpos($fileName, '.') > 0) {
185
+
186
+            // remove versioning extension: name.v1508946057 and transfer extension: name.ocTransferId2057600214.part
187
+            $fileName = preg_replace('!((\.v\d+)|((.ocTransferId\d+)?.part))$!', '', $fileName);
188
+
189
+            //try to guess the type by the file extension
190
+            $extension = strtolower(strrchr($fileName, '.'));
191
+            $extension = substr($extension, 1); //remove leading .
192
+            return (isset($this->mimetypes[$extension]) && isset($this->mimetypes[$extension][0]))
193
+                ? $this->mimetypes[$extension][0]
194
+                : 'application/octet-stream';
195
+        } else {
196
+            return 'application/octet-stream';
197
+        }
198
+    }
199
+
200
+    /**
201
+     * detect mimetype based on both filename and content
202
+     *
203
+     * @param string $path
204
+     * @return string
205
+     */
206
+    public function detect($path) {
207
+        $this->loadMappings();
208
+
209
+        if (@is_dir($path)) {
210
+            // directories are easy
211
+            return "httpd/unix-directory";
212
+        }
213
+
214
+        $mimeType = $this->detectPath($path);
215
+
216
+        if ($mimeType === 'application/octet-stream' and function_exists('finfo_open')
217
+            and function_exists('finfo_file') and $finfo = finfo_open(FILEINFO_MIME)
218
+        ) {
219
+            $info = @strtolower(finfo_file($finfo, $path));
220
+            finfo_close($finfo);
221
+            if ($info) {
222
+                $mimeType = strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
223
+                return empty($mimeType) ? 'application/octet-stream' : $mimeType;
224
+            }
225
+
226
+        }
227
+        $isWrapped = (strpos($path, '://') !== false) and (substr($path, 0, 7) === 'file://');
228
+        if (!$isWrapped and $mimeType === 'application/octet-stream' && function_exists("mime_content_type")) {
229
+            // use mime magic extension if available
230
+            $mimeType = mime_content_type($path);
231
+        }
232
+        if (!$isWrapped and $mimeType === 'application/octet-stream' && \OC_Helper::canExecute("file")) {
233
+            // it looks like we have a 'file' command,
234
+            // lets see if it does have mime support
235
+            $path = escapeshellarg($path);
236
+            $fp = popen("file -b --mime-type $path 2>/dev/null", "r");
237
+            $reply = fgets($fp);
238
+            pclose($fp);
239
+
240
+            //trim the newline
241
+            $mimeType = trim($reply);
242
+
243
+            if (empty($mimeType)) {
244
+                $mimeType = 'application/octet-stream';
245
+            }
246
+
247
+        }
248
+        return $mimeType;
249
+    }
250
+
251
+    /**
252
+     * detect mimetype based on the content of a string
253
+     *
254
+     * @param string $data
255
+     * @return string
256
+     */
257
+    public function detectString($data) {
258
+        if (function_exists('finfo_open') and function_exists('finfo_file')) {
259
+            $finfo = finfo_open(FILEINFO_MIME);
260
+            $info = finfo_buffer($finfo, $data);
261
+            return strpos($info, ';') !== false ? substr($info, 0, strpos($info, ';')) : $info;
262
+        } else {
263
+            $tmpFile = \OC::$server->getTempManager()->getTemporaryFile();
264
+            $fh = fopen($tmpFile, 'wb');
265
+            fwrite($fh, $data, 8024);
266
+            fclose($fh);
267
+            $mime = $this->detect($tmpFile);
268
+            unset($tmpFile);
269
+            return $mime;
270
+        }
271
+    }
272
+
273
+    /**
274
+     * Get a secure mimetype that won't expose potential XSS.
275
+     *
276
+     * @param string $mimeType
277
+     * @return string
278
+     */
279
+    public function getSecureMimeType($mimeType) {
280
+        $this->loadMappings();
281
+
282
+        return isset($this->secureMimeTypes[$mimeType])
283
+            ? $this->secureMimeTypes[$mimeType]
284
+            : 'application/octet-stream';
285
+    }
286
+
287
+    /**
288
+     * Get path to the icon of a file type
289
+     * @param string $mimetype the MIME type
290
+     * @return string the url
291
+     */
292
+    public function mimeTypeIcon($mimetype) {
293
+        $this->loadAliases();
294
+
295
+        while (isset($this->mimeTypeAlias[$mimetype])) {
296
+            $mimetype = $this->mimeTypeAlias[$mimetype];
297
+        }
298
+        if (isset($this->mimetypeIcons[$mimetype])) {
299
+            return $this->mimetypeIcons[$mimetype];
300
+        }
301
+
302
+        // Replace slash and backslash with a minus
303
+        $icon = str_replace('/', '-', $mimetype);
304
+        $icon = str_replace('\\', '-', $icon);
305
+
306
+        // Is it a dir?
307
+        if ($mimetype === 'dir') {
308
+            $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder.svg');
309
+            return $this->mimetypeIcons[$mimetype];
310
+        }
311
+        if ($mimetype === 'dir-shared') {
312
+            $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-shared.svg');
313
+            return $this->mimetypeIcons[$mimetype];
314
+        }
315
+        if ($mimetype === 'dir-external') {
316
+            $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/folder-external.svg');
317
+            return $this->mimetypeIcons[$mimetype];
318
+        }
319
+
320
+        // Icon exists?
321
+        try {
322
+            $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg');
323
+            return $this->mimetypeIcons[$mimetype];
324
+        } catch (\RuntimeException $e) {
325
+            // Specified image not found
326
+        }
327
+
328
+        // Try only the first part of the filetype
329
+        $mimePart = substr($icon, 0, strpos($icon, '-'));
330
+        try {
331
+            $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
332
+            return $this->mimetypeIcons[$mimetype];
333
+        } catch (\RuntimeException $e) {
334
+            // Image for the first part of the mimetype not found
335
+        }
336
+
337
+        $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg');
338
+        return $this->mimetypeIcons[$mimetype];
339
+    }
340 340
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 
106 106
 		// Update the alternative mimetypes to avoid having to look them up each time.
107 107
 		foreach ($this->mimetypes as $mimeType) {
108
-			$this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1]: $mimeType[0];
108
+			$this->secureMimeTypes[$mimeType[0]] = isset($mimeType[1]) ? $mimeType[1] : $mimeType[0];
109 109
 		}
110 110
 	}
111 111
 
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 			return;
118 118
 		}
119 119
 
120
-		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
120
+		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir.'/mimetypealiases.dist.json'), true);
121 121
 
122
-		if (file_exists($this->customConfigDir . '/mimetypealiases.json')) {
123
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypealiases.json'), true);
122
+		if (file_exists($this->customConfigDir.'/mimetypealiases.json')) {
123
+			$custom = json_decode(file_get_contents($this->customConfigDir.'/mimetypealiases.json'), true);
124 124
 			$this->mimeTypeAlias = array_merge($this->mimeTypeAlias, $custom);
125 125
 		}
126 126
 	}
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
 
136 136
 	public function getOnlyDefaultAliases() {
137 137
 		$this->loadMappings();
138
-		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypealiases.dist.json'), true);
138
+		$this->mimeTypeAlias = json_decode(file_get_contents($this->defaultConfigDir.'/mimetypealiases.dist.json'), true);
139 139
 		return $this->mimeTypeAlias;
140 140
 	}
141 141
 
@@ -147,11 +147,11 @@  discard block
 block discarded – undo
147 147
 			return;
148 148
 		}
149 149
 
150
-		$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir . '/mimetypemapping.dist.json'), true);
150
+		$mimetypeMapping = json_decode(file_get_contents($this->defaultConfigDir.'/mimetypemapping.dist.json'), true);
151 151
 
152 152
 		//Check if need to load custom mappings
153
-		if (file_exists($this->customConfigDir . '/mimetypemapping.json')) {
154
-			$custom = json_decode(file_get_contents($this->customConfigDir . '/mimetypemapping.json'), true);
153
+		if (file_exists($this->customConfigDir.'/mimetypemapping.json')) {
154
+			$custom = json_decode(file_get_contents($this->customConfigDir.'/mimetypemapping.json'), true);
155 155
 			$mimetypeMapping = array_merge($mimetypeMapping, $custom);
156 156
 		}
157 157
 
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
 
320 320
 		// Icon exists?
321 321
 		try {
322
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $icon . '.svg');
322
+			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/'.$icon.'.svg');
323 323
 			return $this->mimetypeIcons[$mimetype];
324 324
 		} catch (\RuntimeException $e) {
325 325
 			// Specified image not found
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 		// Try only the first part of the filetype
329 329
 		$mimePart = substr($icon, 0, strpos($icon, '-'));
330 330
 		try {
331
-			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');
331
+			$this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/'.$mimePart.'.svg');
332 332
 			return $this->mimetypeIcons[$mimetype];
333 333
 		} catch (\RuntimeException $e) {
334 334
 			// Image for the first part of the mimetype not found
Please login to merge, or discard this patch.