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