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