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