Completed
Pull Request — master (#3233)
by Christoph
13:23
created
lib/private/legacy/template.php 1 patch
Indentation   +343 added lines, -343 removed lines patch added patch discarded remove patch
@@ -44,347 +44,347 @@
 block discarded – undo
44 44
  */
45 45
 class OC_Template extends \OC\Template\Base {
46 46
 
47
-	/** @var string */
48
-	private $renderAs; // Create a full page?
49
-
50
-	/** @var string */
51
-	private $path; // The path to the template
52
-
53
-	/** @var array */
54
-	private $headers = array(); //custom headers
55
-
56
-	/** @var string */
57
-	protected $app; // app id
58
-
59
-	protected static $initTemplateEngineFirstRun = true;
60
-
61
-	/**
62
-	 * Constructor
63
-	 *
64
-	 * @param string $app app providing the template
65
-	 * @param string $name of the template file (without suffix)
66
-	 * @param string $renderAs If $renderAs is set, OC_Template will try to
67
-	 *                         produce a full page in the according layout. For
68
-	 *                         now, $renderAs can be set to "guest", "user" or
69
-	 *                         "admin".
70
-	 * @param bool $registerCall = true
71
-	 */
72
-	public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
73
-		// Read the selected theme from the config file
74
-		self::initTemplateEngine($renderAs);
75
-
76
-		$theme = OC_Util::getTheme();
77
-
78
-		$requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
79
-
80
-		$parts = explode('/', $app); // fix translation when app is something like core/lostpassword
81
-		$l10n = \OC::$server->getL10N($parts[0]);
82
-		$themeDefaults = \OC::$server->getThemingDefaults();
83
-
84
-		list($path, $template) = $this->findTemplate($theme, $app, $name);
85
-
86
-		// Set the private data
87
-		$this->renderAs = $renderAs;
88
-		$this->path = $path;
89
-		$this->app = $app;
90
-
91
-		parent::__construct($template, $requestToken, $l10n, $themeDefaults);
92
-	}
93
-
94
-	/**
95
-	 * @param string $renderAs
96
-	 */
97
-	public static function initTemplateEngine($renderAs) {
98
-		if (self::$initTemplateEngineFirstRun){
99
-
100
-			//apps that started before the template initialization can load their own scripts/styles
101
-			//so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
102
-			//meaning the last script/style in this list will be loaded first
103
-			if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
104
-				if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
105
-					OC_Util::addScript ( 'backgroundjobs', null, true );
106
-				}
107
-			}
108
-
109
-			OC_Util::addStyle('jquery-ui-fixes',null,true);
110
-			OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
111
-			OC_Util::addStyle('server', null, true);
112
-
113
-			// avatars
114
-			\OC_Util::addScript('jquery.avatar', null, true);
115
-			\OC_Util::addScript('placeholder', null, true);
116
-
117
-			OC_Util::addVendorScript('select2/select2');
118
-			OC_Util::addVendorStyle('select2/select2', null, true);
119
-			OC_Util::addScript('select2-toggleselect');
120
-
121
-			OC_Util::addScript('oc-backbone', null, true);
122
-			OC_Util::addVendorScript('core', 'backbone/backbone', true);
123
-			OC_Util::addVendorScript('snapjs/dist/latest/snap', null, true);
124
-			OC_Util::addScript('mimetypelist', null, true);
125
-			OC_Util::addScript('mimetype', null, true);
126
-			OC_Util::addScript("apps", null, true);
127
-			OC_Util::addScript("oc-requesttoken", null, true);
128
-			OC_Util::addScript('search', 'search', true);
129
-			OC_Util::addScript("config", null, true);
130
-			OC_Util::addScript("public/appconfig", null, true);
131
-			OC_Util::addScript("eventsource", null, true);
132
-			OC_Util::addScript("octemplate", null, true);
133
-			OC_Util::addTranslations("core", null, true);
134
-			OC_Util::addScript("l10n", null, true);
135
-			OC_Util::addScript("js", null, true);
136
-			OC_Util::addScript("oc-dialogs", null, true);
137
-			OC_Util::addScript("jquery.ocdialog", null, true);
138
-			OC_Util::addScript("jquery-ui-fixes");
139
-			OC_Util::addStyle("jquery.ocdialog");
140
-			OC_Util::addScript('files/fileinfo');
141
-			OC_Util::addScript('files/client');
142
-			OC_Util::addScript('contactsmenu');
143
-
144
-			// Add the stuff we need always
145
-			// following logic will import all vendor libraries that are
146
-			// specified in core/js/core.json
147
-			$fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
148
-			if($fileContent !== false) {
149
-				$coreDependencies = json_decode($fileContent, true);
150
-				foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
151
-					// remove trailing ".js" as addVendorScript will append it
152
-					OC_Util::addVendorScript(
153
-							substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true);
154
-				}
155
-			} else {
156
-				throw new \Exception('Cannot read core/js/core.json');
157
-			}
158
-
159
-			if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
160
-				// polyfill for btoa/atob for IE friends
161
-				OC_Util::addVendorScript('base64/base64');
162
-				// shim for the davclient.js library
163
-				\OCP\Util::addScript('files/iedavclient');
164
-			}
165
-
166
-			self::$initTemplateEngineFirstRun = false;
167
-		}
168
-
169
-	}
170
-
171
-
172
-	/**
173
-	 * find the template with the given name
174
-	 * @param string $name of the template file (without suffix)
175
-	 *
176
-	 * Will select the template file for the selected theme.
177
-	 * Checking all the possible locations.
178
-	 * @param string $theme
179
-	 * @param string $app
180
-	 * @return string[]
181
-	 */
182
-	protected function findTemplate($theme, $app, $name) {
183
-		// Check if it is a app template or not.
184
-		if( $app !== '' ) {
185
-			$dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
186
-		} else {
187
-			$dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
188
-		}
189
-		$locator = new \OC\Template\TemplateFileLocator( $dirs );
190
-		$template = $locator->find($name);
191
-		$path = $locator->getPath();
192
-		return array($path, $template);
193
-	}
194
-
195
-	/**
196
-	 * Add a custom element to the header
197
-	 * @param string $tag tag name of the element
198
-	 * @param array $attributes array of attributes for the element
199
-	 * @param string $text the text content for the element. If $text is null then the
200
-	 * element will be written as empty element. So use "" to get a closing tag.
201
-	 */
202
-	public function addHeader($tag, $attributes, $text=null) {
203
-		$this->headers[]= array(
204
-			'tag' => $tag,
205
-			'attributes' => $attributes,
206
-			'text' => $text
207
-		);
208
-	}
209
-
210
-	/**
211
-	 * Process the template
212
-	 * @return boolean|string
213
-	 *
214
-	 * This function process the template. If $this->renderAs is set, it
215
-	 * will produce a full page.
216
-	 */
217
-	public function fetchPage($additionalParams = null) {
218
-		$data = parent::fetchPage($additionalParams);
219
-
220
-		if( $this->renderAs ) {
221
-			$page = new TemplateLayout($this->renderAs, $this->app);
222
-
223
-			// Add custom headers
224
-			$headers = '';
225
-			foreach(OC_Util::$headers as $header) {
226
-				$headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
227
-				foreach($header['attributes'] as $name=>$value) {
228
-					$headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
229
-				}
230
-				if ($header['text'] !== null) {
231
-					$headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
232
-				} else {
233
-					$headers .= '/>';
234
-				}
235
-			}
236
-
237
-			$page->assign('headers', $headers);
238
-
239
-			$page->assign('content', $data);
240
-			return $page->fetchPage();
241
-		}
242
-
243
-		return $data;
244
-	}
245
-
246
-	/**
247
-	 * Include template
248
-	 *
249
-	 * @param string $file
250
-	 * @param array|null $additionalParams
251
-	 * @return string returns content of included template
252
-	 *
253
-	 * Includes another template. use <?php echo $this->inc('template'); ?> to
254
-	 * do this.
255
-	 */
256
-	public function inc( $file, $additionalParams = null ) {
257
-		return $this->load($this->path.$file.'.php', $additionalParams);
258
-	}
259
-
260
-	/**
261
-	 * Shortcut to print a simple page for users
262
-	 * @param string $application The application we render the template for
263
-	 * @param string $name Name of the template
264
-	 * @param array $parameters Parameters for the template
265
-	 * @return boolean|null
266
-	 */
267
-	public static function printUserPage( $application, $name, $parameters = array() ) {
268
-		$content = new OC_Template( $application, $name, "user" );
269
-		foreach( $parameters as $key => $value ) {
270
-			$content->assign( $key, $value );
271
-		}
272
-		print $content->printPage();
273
-	}
274
-
275
-	/**
276
-	 * Shortcut to print a simple page for admins
277
-	 * @param string $application The application we render the template for
278
-	 * @param string $name Name of the template
279
-	 * @param array $parameters Parameters for the template
280
-	 * @return bool
281
-	 */
282
-	public static function printAdminPage( $application, $name, $parameters = array() ) {
283
-		$content = new OC_Template( $application, $name, "admin" );
284
-		foreach( $parameters as $key => $value ) {
285
-			$content->assign( $key, $value );
286
-		}
287
-		return $content->printPage();
288
-	}
289
-
290
-	/**
291
-	 * Shortcut to print a simple page for guests
292
-	 * @param string $application The application we render the template for
293
-	 * @param string $name Name of the template
294
-	 * @param array|string $parameters Parameters for the template
295
-	 * @return bool
296
-	 */
297
-	public static function printGuestPage( $application, $name, $parameters = array() ) {
298
-		$content = new OC_Template( $application, $name, "guest" );
299
-		foreach( $parameters as $key => $value ) {
300
-			$content->assign( $key, $value );
301
-		}
302
-		return $content->printPage();
303
-	}
304
-
305
-	/**
306
-		* Print a fatal error page and terminates the script
307
-		* @param string $error_msg The error message to show
308
-		* @param string $hint An optional hint message - needs to be properly escaped
309
-		*/
310
-	public static function printErrorPage( $error_msg, $hint = '' ) {
311
-		if ($error_msg === $hint) {
312
-			// If the hint is the same as the message there is no need to display it twice.
313
-			$hint = '';
314
-		}
315
-
316
-		try {
317
-			$content = new \OC_Template( '', 'error', 'error', false );
318
-			$errors = array(array('error' => $error_msg, 'hint' => $hint));
319
-			$content->assign( 'errors', $errors );
320
-			$content->printPage();
321
-		} catch (\Exception $e) {
322
-			$logger = \OC::$server->getLogger();
323
-			$logger->error("$error_msg $hint", ['app' => 'core']);
324
-			$logger->logException($e, ['app' => 'core']);
325
-
326
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
327
-			header('Content-Type: text/plain; charset=utf-8');
328
-			print("$error_msg $hint");
329
-		}
330
-		die();
331
-	}
332
-
333
-	/**
334
-	 * print error page using Exception details
335
-	 * @param Exception | Throwable $exception
336
-	 */
337
-	public static function printExceptionErrorPage($exception, $fetchPage = false) {
338
-		try {
339
-			$request = \OC::$server->getRequest();
340
-			$content = new \OC_Template('', 'exception', 'error', false);
341
-			$content->assign('errorClass', get_class($exception));
342
-			$content->assign('errorMsg', $exception->getMessage());
343
-			$content->assign('errorCode', $exception->getCode());
344
-			$content->assign('file', $exception->getFile());
345
-			$content->assign('line', $exception->getLine());
346
-			$content->assign('trace', $exception->getTraceAsString());
347
-			$content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
348
-			$content->assign('remoteAddr', $request->getRemoteAddress());
349
-			$content->assign('requestID', $request->getId());
350
-			if ($fetchPage) {
351
-				return $content->fetchPage();
352
-			}
353
-			$content->printPage();
354
-		} catch (\Exception $e) {
355
-			$logger = \OC::$server->getLogger();
356
-			$logger->logException($exception, ['app' => 'core']);
357
-			$logger->logException($e, ['app' => 'core']);
358
-
359
-			header(self::getHttpProtocol() . ' 500 Internal Server Error');
360
-			header('Content-Type: text/plain; charset=utf-8');
361
-			print("Internal Server Error\n\n");
362
-			print("The server encountered an internal error and was unable to complete your request.\n");
363
-			print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
364
-			print("More details can be found in the server log.\n");
365
-		}
366
-		die();
367
-	}
368
-
369
-	/**
370
-	 * This is only here to reduce the dependencies in case of an exception to
371
-	 * still be able to print a plain error message.
372
-	 *
373
-	 * Returns the used HTTP protocol.
374
-	 *
375
-	 * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
376
-	 * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
377
-	 */
378
-	protected static function getHttpProtocol() {
379
-		$claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
380
-		$validProtocols = [
381
-			'HTTP/1.0',
382
-			'HTTP/1.1',
383
-			'HTTP/2',
384
-		];
385
-		if(in_array($claimedProtocol, $validProtocols, true)) {
386
-			return $claimedProtocol;
387
-		}
388
-		return 'HTTP/1.1';
389
-	}
47
+    /** @var string */
48
+    private $renderAs; // Create a full page?
49
+
50
+    /** @var string */
51
+    private $path; // The path to the template
52
+
53
+    /** @var array */
54
+    private $headers = array(); //custom headers
55
+
56
+    /** @var string */
57
+    protected $app; // app id
58
+
59
+    protected static $initTemplateEngineFirstRun = true;
60
+
61
+    /**
62
+     * Constructor
63
+     *
64
+     * @param string $app app providing the template
65
+     * @param string $name of the template file (without suffix)
66
+     * @param string $renderAs If $renderAs is set, OC_Template will try to
67
+     *                         produce a full page in the according layout. For
68
+     *                         now, $renderAs can be set to "guest", "user" or
69
+     *                         "admin".
70
+     * @param bool $registerCall = true
71
+     */
72
+    public function __construct( $app, $name, $renderAs = "", $registerCall = true ) {
73
+        // Read the selected theme from the config file
74
+        self::initTemplateEngine($renderAs);
75
+
76
+        $theme = OC_Util::getTheme();
77
+
78
+        $requestToken = (OC::$server->getSession() && $registerCall) ? \OCP\Util::callRegister() : '';
79
+
80
+        $parts = explode('/', $app); // fix translation when app is something like core/lostpassword
81
+        $l10n = \OC::$server->getL10N($parts[0]);
82
+        $themeDefaults = \OC::$server->getThemingDefaults();
83
+
84
+        list($path, $template) = $this->findTemplate($theme, $app, $name);
85
+
86
+        // Set the private data
87
+        $this->renderAs = $renderAs;
88
+        $this->path = $path;
89
+        $this->app = $app;
90
+
91
+        parent::__construct($template, $requestToken, $l10n, $themeDefaults);
92
+    }
93
+
94
+    /**
95
+     * @param string $renderAs
96
+     */
97
+    public static function initTemplateEngine($renderAs) {
98
+        if (self::$initTemplateEngineFirstRun){
99
+
100
+            //apps that started before the template initialization can load their own scripts/styles
101
+            //so to make sure this scripts/styles here are loaded first we use OC_Util::addScript() with $prepend=true
102
+            //meaning the last script/style in this list will be loaded first
103
+            if (\OC::$server->getSystemConfig()->getValue ('installed', false) && $renderAs !== 'error' && !\OCP\Util::needUpgrade()) {
104
+                if (\OC::$server->getConfig ()->getAppValue ( 'core', 'backgroundjobs_mode', 'ajax' ) == 'ajax') {
105
+                    OC_Util::addScript ( 'backgroundjobs', null, true );
106
+                }
107
+            }
108
+
109
+            OC_Util::addStyle('jquery-ui-fixes',null,true);
110
+            OC_Util::addVendorStyle('jquery-ui/themes/base/jquery-ui',null,true);
111
+            OC_Util::addStyle('server', null, true);
112
+
113
+            // avatars
114
+            \OC_Util::addScript('jquery.avatar', null, true);
115
+            \OC_Util::addScript('placeholder', null, true);
116
+
117
+            OC_Util::addVendorScript('select2/select2');
118
+            OC_Util::addVendorStyle('select2/select2', null, true);
119
+            OC_Util::addScript('select2-toggleselect');
120
+
121
+            OC_Util::addScript('oc-backbone', null, true);
122
+            OC_Util::addVendorScript('core', 'backbone/backbone', true);
123
+            OC_Util::addVendorScript('snapjs/dist/latest/snap', null, true);
124
+            OC_Util::addScript('mimetypelist', null, true);
125
+            OC_Util::addScript('mimetype', null, true);
126
+            OC_Util::addScript("apps", null, true);
127
+            OC_Util::addScript("oc-requesttoken", null, true);
128
+            OC_Util::addScript('search', 'search', true);
129
+            OC_Util::addScript("config", null, true);
130
+            OC_Util::addScript("public/appconfig", null, true);
131
+            OC_Util::addScript("eventsource", null, true);
132
+            OC_Util::addScript("octemplate", null, true);
133
+            OC_Util::addTranslations("core", null, true);
134
+            OC_Util::addScript("l10n", null, true);
135
+            OC_Util::addScript("js", null, true);
136
+            OC_Util::addScript("oc-dialogs", null, true);
137
+            OC_Util::addScript("jquery.ocdialog", null, true);
138
+            OC_Util::addScript("jquery-ui-fixes");
139
+            OC_Util::addStyle("jquery.ocdialog");
140
+            OC_Util::addScript('files/fileinfo');
141
+            OC_Util::addScript('files/client');
142
+            OC_Util::addScript('contactsmenu');
143
+
144
+            // Add the stuff we need always
145
+            // following logic will import all vendor libraries that are
146
+            // specified in core/js/core.json
147
+            $fileContent = file_get_contents(OC::$SERVERROOT . '/core/js/core.json');
148
+            if($fileContent !== false) {
149
+                $coreDependencies = json_decode($fileContent, true);
150
+                foreach(array_reverse($coreDependencies['vendor']) as $vendorLibrary) {
151
+                    // remove trailing ".js" as addVendorScript will append it
152
+                    OC_Util::addVendorScript(
153
+                            substr($vendorLibrary, 0, strlen($vendorLibrary) - 3),null,true);
154
+                }
155
+            } else {
156
+                throw new \Exception('Cannot read core/js/core.json');
157
+            }
158
+
159
+            if (\OC::$server->getRequest()->isUserAgent([\OC\AppFramework\Http\Request::USER_AGENT_IE])) {
160
+                // polyfill for btoa/atob for IE friends
161
+                OC_Util::addVendorScript('base64/base64');
162
+                // shim for the davclient.js library
163
+                \OCP\Util::addScript('files/iedavclient');
164
+            }
165
+
166
+            self::$initTemplateEngineFirstRun = false;
167
+        }
168
+
169
+    }
170
+
171
+
172
+    /**
173
+     * find the template with the given name
174
+     * @param string $name of the template file (without suffix)
175
+     *
176
+     * Will select the template file for the selected theme.
177
+     * Checking all the possible locations.
178
+     * @param string $theme
179
+     * @param string $app
180
+     * @return string[]
181
+     */
182
+    protected function findTemplate($theme, $app, $name) {
183
+        // Check if it is a app template or not.
184
+        if( $app !== '' ) {
185
+            $dirs = $this->getAppTemplateDirs($theme, $app, OC::$SERVERROOT, OC_App::getAppPath($app));
186
+        } else {
187
+            $dirs = $this->getCoreTemplateDirs($theme, OC::$SERVERROOT);
188
+        }
189
+        $locator = new \OC\Template\TemplateFileLocator( $dirs );
190
+        $template = $locator->find($name);
191
+        $path = $locator->getPath();
192
+        return array($path, $template);
193
+    }
194
+
195
+    /**
196
+     * Add a custom element to the header
197
+     * @param string $tag tag name of the element
198
+     * @param array $attributes array of attributes for the element
199
+     * @param string $text the text content for the element. If $text is null then the
200
+     * element will be written as empty element. So use "" to get a closing tag.
201
+     */
202
+    public function addHeader($tag, $attributes, $text=null) {
203
+        $this->headers[]= array(
204
+            'tag' => $tag,
205
+            'attributes' => $attributes,
206
+            'text' => $text
207
+        );
208
+    }
209
+
210
+    /**
211
+     * Process the template
212
+     * @return boolean|string
213
+     *
214
+     * This function process the template. If $this->renderAs is set, it
215
+     * will produce a full page.
216
+     */
217
+    public function fetchPage($additionalParams = null) {
218
+        $data = parent::fetchPage($additionalParams);
219
+
220
+        if( $this->renderAs ) {
221
+            $page = new TemplateLayout($this->renderAs, $this->app);
222
+
223
+            // Add custom headers
224
+            $headers = '';
225
+            foreach(OC_Util::$headers as $header) {
226
+                $headers .= '<'.\OCP\Util::sanitizeHTML($header['tag']);
227
+                foreach($header['attributes'] as $name=>$value) {
228
+                    $headers .= ' '.\OCP\Util::sanitizeHTML($name).'="'.\OCP\Util::sanitizeHTML($value).'"';
229
+                }
230
+                if ($header['text'] !== null) {
231
+                    $headers .= '>'.\OCP\Util::sanitizeHTML($header['text']).'</'.\OCP\Util::sanitizeHTML($header['tag']).'>';
232
+                } else {
233
+                    $headers .= '/>';
234
+                }
235
+            }
236
+
237
+            $page->assign('headers', $headers);
238
+
239
+            $page->assign('content', $data);
240
+            return $page->fetchPage();
241
+        }
242
+
243
+        return $data;
244
+    }
245
+
246
+    /**
247
+     * Include template
248
+     *
249
+     * @param string $file
250
+     * @param array|null $additionalParams
251
+     * @return string returns content of included template
252
+     *
253
+     * Includes another template. use <?php echo $this->inc('template'); ?> to
254
+     * do this.
255
+     */
256
+    public function inc( $file, $additionalParams = null ) {
257
+        return $this->load($this->path.$file.'.php', $additionalParams);
258
+    }
259
+
260
+    /**
261
+     * Shortcut to print a simple page for users
262
+     * @param string $application The application we render the template for
263
+     * @param string $name Name of the template
264
+     * @param array $parameters Parameters for the template
265
+     * @return boolean|null
266
+     */
267
+    public static function printUserPage( $application, $name, $parameters = array() ) {
268
+        $content = new OC_Template( $application, $name, "user" );
269
+        foreach( $parameters as $key => $value ) {
270
+            $content->assign( $key, $value );
271
+        }
272
+        print $content->printPage();
273
+    }
274
+
275
+    /**
276
+     * Shortcut to print a simple page for admins
277
+     * @param string $application The application we render the template for
278
+     * @param string $name Name of the template
279
+     * @param array $parameters Parameters for the template
280
+     * @return bool
281
+     */
282
+    public static function printAdminPage( $application, $name, $parameters = array() ) {
283
+        $content = new OC_Template( $application, $name, "admin" );
284
+        foreach( $parameters as $key => $value ) {
285
+            $content->assign( $key, $value );
286
+        }
287
+        return $content->printPage();
288
+    }
289
+
290
+    /**
291
+     * Shortcut to print a simple page for guests
292
+     * @param string $application The application we render the template for
293
+     * @param string $name Name of the template
294
+     * @param array|string $parameters Parameters for the template
295
+     * @return bool
296
+     */
297
+    public static function printGuestPage( $application, $name, $parameters = array() ) {
298
+        $content = new OC_Template( $application, $name, "guest" );
299
+        foreach( $parameters as $key => $value ) {
300
+            $content->assign( $key, $value );
301
+        }
302
+        return $content->printPage();
303
+    }
304
+
305
+    /**
306
+     * Print a fatal error page and terminates the script
307
+     * @param string $error_msg The error message to show
308
+     * @param string $hint An optional hint message - needs to be properly escaped
309
+     */
310
+    public static function printErrorPage( $error_msg, $hint = '' ) {
311
+        if ($error_msg === $hint) {
312
+            // If the hint is the same as the message there is no need to display it twice.
313
+            $hint = '';
314
+        }
315
+
316
+        try {
317
+            $content = new \OC_Template( '', 'error', 'error', false );
318
+            $errors = array(array('error' => $error_msg, 'hint' => $hint));
319
+            $content->assign( 'errors', $errors );
320
+            $content->printPage();
321
+        } catch (\Exception $e) {
322
+            $logger = \OC::$server->getLogger();
323
+            $logger->error("$error_msg $hint", ['app' => 'core']);
324
+            $logger->logException($e, ['app' => 'core']);
325
+
326
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
327
+            header('Content-Type: text/plain; charset=utf-8');
328
+            print("$error_msg $hint");
329
+        }
330
+        die();
331
+    }
332
+
333
+    /**
334
+     * print error page using Exception details
335
+     * @param Exception | Throwable $exception
336
+     */
337
+    public static function printExceptionErrorPage($exception, $fetchPage = false) {
338
+        try {
339
+            $request = \OC::$server->getRequest();
340
+            $content = new \OC_Template('', 'exception', 'error', false);
341
+            $content->assign('errorClass', get_class($exception));
342
+            $content->assign('errorMsg', $exception->getMessage());
343
+            $content->assign('errorCode', $exception->getCode());
344
+            $content->assign('file', $exception->getFile());
345
+            $content->assign('line', $exception->getLine());
346
+            $content->assign('trace', $exception->getTraceAsString());
347
+            $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false));
348
+            $content->assign('remoteAddr', $request->getRemoteAddress());
349
+            $content->assign('requestID', $request->getId());
350
+            if ($fetchPage) {
351
+                return $content->fetchPage();
352
+            }
353
+            $content->printPage();
354
+        } catch (\Exception $e) {
355
+            $logger = \OC::$server->getLogger();
356
+            $logger->logException($exception, ['app' => 'core']);
357
+            $logger->logException($e, ['app' => 'core']);
358
+
359
+            header(self::getHttpProtocol() . ' 500 Internal Server Error');
360
+            header('Content-Type: text/plain; charset=utf-8');
361
+            print("Internal Server Error\n\n");
362
+            print("The server encountered an internal error and was unable to complete your request.\n");
363
+            print("Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.\n");
364
+            print("More details can be found in the server log.\n");
365
+        }
366
+        die();
367
+    }
368
+
369
+    /**
370
+     * This is only here to reduce the dependencies in case of an exception to
371
+     * still be able to print a plain error message.
372
+     *
373
+     * Returns the used HTTP protocol.
374
+     *
375
+     * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0.
376
+     * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead
377
+     */
378
+    protected static function getHttpProtocol() {
379
+        $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']);
380
+        $validProtocols = [
381
+            'HTTP/1.0',
382
+            'HTTP/1.1',
383
+            'HTTP/2',
384
+        ];
385
+        if(in_array($claimedProtocol, $validProtocols, true)) {
386
+            return $claimedProtocol;
387
+        }
388
+        return 'HTTP/1.1';
389
+    }
390 390
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ActionProviderStore.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
 
33 33
 class ActionProviderStore {
34 34
 
35
-	/** @var IServerContainer */
36
-	private $serverContainer;
35
+    /** @var IServerContainer */
36
+    private $serverContainer;
37 37
 
38
-	/** @var ILogger */
39
-	private $logger;
38
+    /** @var ILogger */
39
+    private $logger;
40 40
 
41
-	/**
42
-	 * @param IServerContainer $serverContainer
43
-	 */
44
-	public function __construct(IServerContainer $serverContainer, ILogger $logger) {
45
-		$this->serverContainer = $serverContainer;
46
-		$this->logger = $logger;
47
-	}
41
+    /**
42
+     * @param IServerContainer $serverContainer
43
+     */
44
+    public function __construct(IServerContainer $serverContainer, ILogger $logger) {
45
+        $this->serverContainer = $serverContainer;
46
+        $this->logger = $logger;
47
+    }
48 48
 
49
-	/**
50
-	 * @return IProvider[]
51
-	 * @throws Exception
52
-	 */
53
-	public function getProviders() {
54
-		// TODO: include apps
55
-		$providerClasses = $this->getServerProviderClasses();
56
-		$providers = [];
49
+    /**
50
+     * @return IProvider[]
51
+     * @throws Exception
52
+     */
53
+    public function getProviders() {
54
+        // TODO: include apps
55
+        $providerClasses = $this->getServerProviderClasses();
56
+        $providers = [];
57 57
 
58
-		foreach ($providerClasses as $class) {
59
-			try {
60
-				$providers[] = $this->serverContainer->query($class);
61
-			} catch (QueryException $ex) {
62
-				$this->logger->logException($ex, [
63
-					'message' => "Could not load contacts menu action provider $class",
64
-					'app' => 'core',
65
-				]);
66
-				throw new \Exception("Could not load contacts menu action provider");
67
-			}
68
-		}
58
+        foreach ($providerClasses as $class) {
59
+            try {
60
+                $providers[] = $this->serverContainer->query($class);
61
+            } catch (QueryException $ex) {
62
+                $this->logger->logException($ex, [
63
+                    'message' => "Could not load contacts menu action provider $class",
64
+                    'app' => 'core',
65
+                ]);
66
+                throw new \Exception("Could not load contacts menu action provider");
67
+            }
68
+        }
69 69
 
70
-		return $providers;
71
-	}
70
+        return $providers;
71
+    }
72 72
 
73
-	/**
74
-	 * @return string[]
75
-	 */
76
-	private function getServerProviderClasses() {
77
-		return [
78
-			EMailProvider::class,
79
-		];
80
-	}
73
+    /**
74
+     * @return string[]
75
+     */
76
+    private function getServerProviderClasses() {
77
+        return [
78
+            EMailProvider::class,
79
+        ];
80
+    }
81 81
 
82 82
 }
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +1474 added lines, -1474 removed lines patch added patch discarded remove patch
@@ -111,1483 +111,1483 @@
 block discarded – undo
111 111
  * TODO: hookup all manager classes
112 112
  */
113 113
 class Server extends ServerContainer implements IServerContainer {
114
-	/** @var string */
115
-	private $webRoot;
116
-
117
-	/**
118
-	 * @param string $webRoot
119
-	 * @param \OC\Config $config
120
-	 */
121
-	public function __construct($webRoot, \OC\Config $config) {
122
-		parent::__construct();
123
-		$this->webRoot = $webRoot;
124
-
125
-		$this->registerService('ContactsManager', function ($c) {
126
-			return new ContactsManager();
127
-		});
128
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
129
-
130
-		$this->registerService('PreviewManager', function (Server $c) {
131
-			return new PreviewManager(
132
-				$c->getConfig(),
133
-				$c->getRootFolder(),
134
-				$c->getAppDataDir('preview'),
135
-				$c->getEventDispatcher(),
136
-				$c->getSession()->get('user_id')
137
-			);
138
-		});
139
-
140
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
141
-			return new \OC\Preview\Watcher(
142
-				$c->getAppDataDir('preview')
143
-			);
144
-		});
145
-
146
-		$this->registerService('EncryptionManager', function (Server $c) {
147
-			$view = new View();
148
-			$util = new Encryption\Util(
149
-				$view,
150
-				$c->getUserManager(),
151
-				$c->getGroupManager(),
152
-				$c->getConfig()
153
-			);
154
-			return new Encryption\Manager(
155
-				$c->getConfig(),
156
-				$c->getLogger(),
157
-				$c->getL10N('core'),
158
-				new View(),
159
-				$util,
160
-				new ArrayCache()
161
-			);
162
-		});
163
-
164
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
165
-			$util = new Encryption\Util(
166
-				new View(),
167
-				$c->getUserManager(),
168
-				$c->getGroupManager(),
169
-				$c->getConfig()
170
-			);
171
-			return new Encryption\File($util);
172
-		});
173
-
174
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
175
-			$view = new View();
176
-			$util = new Encryption\Util(
177
-				$view,
178
-				$c->getUserManager(),
179
-				$c->getGroupManager(),
180
-				$c->getConfig()
181
-			);
182
-
183
-			return new Encryption\Keys\Storage($view, $util);
184
-		});
185
-		$this->registerService('TagMapper', function (Server $c) {
186
-			return new TagMapper($c->getDatabaseConnection());
187
-		});
188
-		$this->registerService('TagManager', function (Server $c) {
189
-			$tagMapper = $c->query('TagMapper');
190
-			return new TagManager($tagMapper, $c->getUserSession());
191
-		});
192
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
193
-			$config = $c->getConfig();
194
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
195
-			/** @var \OC\SystemTag\ManagerFactory $factory */
196
-			$factory = new $factoryClass($this);
197
-			return $factory;
198
-		});
199
-		$this->registerService('SystemTagManager', function (Server $c) {
200
-			return $c->query('SystemTagManagerFactory')->getManager();
201
-		});
202
-		$this->registerService('SystemTagObjectMapper', function (Server $c) {
203
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
204
-		});
205
-		$this->registerService('RootFolder', function (Server $c) {
206
-			$manager = \OC\Files\Filesystem::getMountManager(null);
207
-			$view = new View();
208
-			$root = new Root(
209
-				$manager,
210
-				$view,
211
-				null,
212
-				$c->getUserMountCache(),
213
-				$this->getLogger(),
214
-				$this->getUserManager()
215
-			);
216
-			$connector = new HookConnector($root, $view);
217
-			$connector->viewToNode();
218
-
219
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
220
-			$previewConnector->connectWatcher();
221
-
222
-			return $root;
223
-		});
224
-		$this->registerService('LazyRootFolder', function(Server $c) {
225
-			return new LazyRoot(function() use ($c) {
226
-				return $c->query('RootFolder');
227
-			});
228
-		});
229
-		$this->registerService('UserManager', function (Server $c) {
230
-			$config = $c->getConfig();
231
-			return new \OC\User\Manager($config);
232
-		});
233
-		$this->registerService('GroupManager', function (Server $c) {
234
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
235
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
236
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
237
-			});
238
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
239
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
240
-			});
241
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
242
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
243
-			});
244
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
245
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
246
-			});
247
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
248
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
249
-			});
250
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
251
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
252
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
253
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
254
-			});
255
-			return $groupManager;
256
-		});
257
-		$this->registerService(Store::class, function(Server $c) {
258
-			$session = $c->getSession();
259
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
260
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
261
-			} else {
262
-				$tokenProvider = null;
263
-			}
264
-			$logger = $c->getLogger();
265
-			return new Store($session, $logger, $tokenProvider);
266
-		});
267
-		$this->registerAlias(IStore::class, Store::class);
268
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
269
-			$dbConnection = $c->getDatabaseConnection();
270
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
271
-		});
272
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
273
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
274
-			$crypto = $c->getCrypto();
275
-			$config = $c->getConfig();
276
-			$logger = $c->getLogger();
277
-			$timeFactory = new TimeFactory();
278
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
279
-		});
280
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
281
-		$this->registerService('UserSession', function (Server $c) {
282
-			$manager = $c->getUserManager();
283
-			$session = new \OC\Session\Memory('');
284
-			$timeFactory = new TimeFactory();
285
-			// Token providers might require a working database. This code
286
-			// might however be called when ownCloud is not yet setup.
287
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
288
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
289
-			} else {
290
-				$defaultTokenProvider = null;
291
-			}
292
-
293
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
294
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
295
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
296
-			});
297
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
298
-				/** @var $user \OC\User\User */
299
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
300
-			});
301
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
302
-				/** @var $user \OC\User\User */
303
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
304
-			});
305
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
306
-				/** @var $user \OC\User\User */
307
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
308
-			});
309
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
310
-				/** @var $user \OC\User\User */
311
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
312
-			});
313
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
314
-				/** @var $user \OC\User\User */
315
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
316
-			});
317
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
318
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
319
-			});
320
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
321
-				/** @var $user \OC\User\User */
322
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
323
-			});
324
-			$userSession->listen('\OC\User', 'logout', function () {
325
-				\OC_Hook::emit('OC_User', 'logout', array());
326
-			});
327
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
328
-				/** @var $user \OC\User\User */
329
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
330
-			});
331
-			return $userSession;
332
-		});
333
-
334
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
335
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
336
-		});
337
-
338
-		$this->registerService('NavigationManager', function (Server $c) {
339
-			return new \OC\NavigationManager($c->getAppManager(),
340
-				$c->getURLGenerator(),
341
-				$c->getL10NFactory(),
342
-				$c->getUserSession(),
343
-				$c->getGroupManager());
344
-		});
345
-		$this->registerService('AllConfig', function (Server $c) {
346
-			return new \OC\AllConfig(
347
-				$c->getSystemConfig()
348
-			);
349
-		});
350
-		$this->registerAlias(\OCP\IConfig::class, 'AllConfig');
351
-		$this->registerService('SystemConfig', function ($c) use ($config) {
352
-			return new \OC\SystemConfig($config);
353
-		});
354
-		$this->registerService('AppConfig', function (Server $c) {
355
-			return new \OC\AppConfig($c->getDatabaseConnection());
356
-		});
357
-		$this->registerService('L10NFactory', function (Server $c) {
358
-			return new \OC\L10N\Factory(
359
-				$c->getConfig(),
360
-				$c->getRequest(),
361
-				$c->getUserSession(),
362
-				\OC::$SERVERROOT
363
-			);
364
-		});
365
-		$this->registerService('URLGenerator', function (Server $c) {
366
-			$config = $c->getConfig();
367
-			$cacheFactory = $c->getMemCacheFactory();
368
-			return new \OC\URLGenerator(
369
-				$config,
370
-				$cacheFactory
371
-			);
372
-		});
373
-		$this->registerAlias(IURLGenerator::class, 'URLGenerator');
374
-		$this->registerService('AppHelper', function ($c) {
375
-			return new \OC\AppHelper();
376
-		});
377
-		$this->registerService('AppFetcher', function ($c) {
378
-			return new AppFetcher(
379
-				$this->getAppDataDir('appstore'),
380
-				$this->getHTTPClientService(),
381
-				$this->query(TimeFactory::class),
382
-				$this->getConfig()
383
-			);
384
-		});
385
-		$this->registerService('CategoryFetcher', function ($c) {
386
-			return new CategoryFetcher(
387
-				$this->getAppDataDir('appstore'),
388
-				$this->getHTTPClientService(),
389
-				$this->query(TimeFactory::class),
390
-				$this->getConfig()
391
-			);
392
-		});
393
-		$this->registerService('UserCache', function ($c) {
394
-			return new Cache\File();
395
-		});
396
-		$this->registerService('MemCacheFactory', function (Server $c) {
397
-			$config = $c->getConfig();
398
-
399
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
400
-				$v = \OC_App::getAppVersions();
401
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
402
-				$version = implode(',', $v);
403
-				$instanceId = \OC_Util::getInstanceId();
404
-				$path = \OC::$SERVERROOT;
405
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
406
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
407
-					$config->getSystemValue('memcache.local', null),
408
-					$config->getSystemValue('memcache.distributed', null),
409
-					$config->getSystemValue('memcache.locking', null)
410
-				);
411
-			}
412
-
413
-			return new \OC\Memcache\Factory('', $c->getLogger(),
414
-				'\\OC\\Memcache\\ArrayCache',
415
-				'\\OC\\Memcache\\ArrayCache',
416
-				'\\OC\\Memcache\\ArrayCache'
417
-			);
418
-		});
419
-		$this->registerService('RedisFactory', function (Server $c) {
420
-			$systemConfig = $c->getSystemConfig();
421
-			return new RedisFactory($systemConfig);
422
-		});
423
-		$this->registerService('ActivityManager', function (Server $c) {
424
-			return new \OC\Activity\Manager(
425
-				$c->getRequest(),
426
-				$c->getUserSession(),
427
-				$c->getConfig(),
428
-				$c->query(IValidator::class)
429
-			);
430
-		});
431
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
432
-			return new \OC\Activity\EventMerger(
433
-				$c->getL10N('lib')
434
-			);
435
-		});
436
-		$this->registerAlias(IValidator::class, Validator::class);
437
-		$this->registerService('AvatarManager', function (Server $c) {
438
-			return new AvatarManager(
439
-				$c->getUserManager(),
440
-				$c->getAppDataDir('avatar'),
441
-				$c->getL10N('lib'),
442
-				$c->getLogger(),
443
-				$c->getConfig()
444
-			);
445
-		});
446
-		$this->registerService('Logger', function (Server $c) {
447
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
448
-			$logger = Log::getLogClass($logType);
449
-			call_user_func(array($logger, 'init'));
450
-
451
-			return new Log($logger);
452
-		});
453
-		$this->registerService('JobList', function (Server $c) {
454
-			$config = $c->getConfig();
455
-			return new \OC\BackgroundJob\JobList(
456
-				$c->getDatabaseConnection(),
457
-				$config,
458
-				new TimeFactory()
459
-			);
460
-		});
461
-		$this->registerService('Router', function (Server $c) {
462
-			$cacheFactory = $c->getMemCacheFactory();
463
-			$logger = $c->getLogger();
464
-			if ($cacheFactory->isAvailable()) {
465
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
466
-			} else {
467
-				$router = new \OC\Route\Router($logger);
468
-			}
469
-			return $router;
470
-		});
471
-		$this->registerService('Search', function ($c) {
472
-			return new Search();
473
-		});
474
-		$this->registerService('SecureRandom', function ($c) {
475
-			return new SecureRandom();
476
-		});
477
-		$this->registerService('Crypto', function (Server $c) {
478
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
479
-		});
480
-		$this->registerService('Hasher', function (Server $c) {
481
-			return new Hasher($c->getConfig());
482
-		});
483
-		$this->registerService('CredentialsManager', function (Server $c) {
484
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
485
-		});
486
-		$this->registerService('DatabaseConnection', function (Server $c) {
487
-			$systemConfig = $c->getSystemConfig();
488
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
489
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
490
-			if (!$factory->isValidType($type)) {
491
-				throw new \OC\DatabaseException('Invalid database type');
492
-			}
493
-			$connectionParams = $factory->createConnectionParams();
494
-			$connection = $factory->getConnection($type, $connectionParams);
495
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
496
-			return $connection;
497
-		});
498
-		$this->registerService('HTTPHelper', function (Server $c) {
499
-			$config = $c->getConfig();
500
-			return new HTTPHelper(
501
-				$config,
502
-				$c->getHTTPClientService()
503
-			);
504
-		});
505
-		$this->registerService('HttpClientService', function (Server $c) {
506
-			$user = \OC_User::getUser();
507
-			$uid = $user ? $user : null;
508
-			return new ClientService(
509
-				$c->getConfig(),
510
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
511
-			);
512
-		});
513
-		$this->registerService('EventLogger', function (Server $c) {
514
-			if ($c->getSystemConfig()->getValue('debug', false)) {
515
-				return new EventLogger();
516
-			} else {
517
-				return new NullEventLogger();
518
-			}
519
-		});
520
-		$this->registerService('QueryLogger', function (Server $c) {
521
-			if ($c->getSystemConfig()->getValue('debug', false)) {
522
-				return new QueryLogger();
523
-			} else {
524
-				return new NullQueryLogger();
525
-			}
526
-		});
527
-		$this->registerService('TempManager', function (Server $c) {
528
-			return new TempManager(
529
-				$c->getLogger(),
530
-				$c->getConfig()
531
-			);
532
-		});
533
-		$this->registerService('AppManager', function (Server $c) {
534
-			return new \OC\App\AppManager(
535
-				$c->getUserSession(),
536
-				$c->getAppConfig(),
537
-				$c->getGroupManager(),
538
-				$c->getMemCacheFactory(),
539
-				$c->getEventDispatcher()
540
-			);
541
-		});
542
-		$this->registerService('DateTimeZone', function (Server $c) {
543
-			return new DateTimeZone(
544
-				$c->getConfig(),
545
-				$c->getSession()
546
-			);
547
-		});
548
-		$this->registerService('DateTimeFormatter', function (Server $c) {
549
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
550
-
551
-			return new DateTimeFormatter(
552
-				$c->getDateTimeZone()->getTimeZone(),
553
-				$c->getL10N('lib', $language)
554
-			);
555
-		});
556
-		$this->registerService('UserMountCache', function (Server $c) {
557
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
558
-			$listener = new UserMountCacheListener($mountCache);
559
-			$listener->listen($c->getUserManager());
560
-			return $mountCache;
561
-		});
562
-		$this->registerService('MountConfigManager', function (Server $c) {
563
-			$loader = \OC\Files\Filesystem::getLoader();
564
-			$mountCache = $c->query('UserMountCache');
565
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
566
-
567
-			// builtin providers
568
-
569
-			$config = $c->getConfig();
570
-			$manager->registerProvider(new CacheMountProvider($config));
571
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
572
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
573
-
574
-			return $manager;
575
-		});
576
-		$this->registerService('IniWrapper', function ($c) {
577
-			return new IniGetWrapper();
578
-		});
579
-		$this->registerService('AsyncCommandBus', function (Server $c) {
580
-			$jobList = $c->getJobList();
581
-			return new AsyncBus($jobList);
582
-		});
583
-		$this->registerService('TrustedDomainHelper', function ($c) {
584
-			return new TrustedDomainHelper($this->getConfig());
585
-		});
586
-		$this->registerService('Throttler', function(Server $c) {
587
-			return new Throttler(
588
-				$c->getDatabaseConnection(),
589
-				new TimeFactory(),
590
-				$c->getLogger(),
591
-				$c->getConfig()
592
-			);
593
-		});
594
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
595
-			// IConfig and IAppManager requires a working database. This code
596
-			// might however be called when ownCloud is not yet setup.
597
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
598
-				$config = $c->getConfig();
599
-				$appManager = $c->getAppManager();
600
-			} else {
601
-				$config = null;
602
-				$appManager = null;
603
-			}
604
-
605
-			return new Checker(
606
-					new EnvironmentHelper(),
607
-					new FileAccessHelper(),
608
-					new AppLocator(),
609
-					$config,
610
-					$c->getMemCacheFactory(),
611
-					$appManager,
612
-					$c->getTempManager()
613
-			);
614
-		});
615
-		$this->registerService('Request', function ($c) {
616
-			if (isset($this['urlParams'])) {
617
-				$urlParams = $this['urlParams'];
618
-			} else {
619
-				$urlParams = [];
620
-			}
621
-
622
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
623
-				&& in_array('fakeinput', stream_get_wrappers())
624
-			) {
625
-				$stream = 'fakeinput://data';
626
-			} else {
627
-				$stream = 'php://input';
628
-			}
629
-
630
-			return new Request(
631
-				[
632
-					'get' => $_GET,
633
-					'post' => $_POST,
634
-					'files' => $_FILES,
635
-					'server' => $_SERVER,
636
-					'env' => $_ENV,
637
-					'cookies' => $_COOKIE,
638
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
639
-						? $_SERVER['REQUEST_METHOD']
640
-						: null,
641
-					'urlParams' => $urlParams,
642
-				],
643
-				$this->getSecureRandom(),
644
-				$this->getConfig(),
645
-				$this->getCsrfTokenManager(),
646
-				$stream
647
-			);
648
-		});
649
-		$this->registerService('Mailer', function (Server $c) {
650
-			return new Mailer(
651
-				$c->getConfig(),
652
-				$c->getLogger(),
653
-				$c->getThemingDefaults()
654
-			);
655
-		});
656
-		$this->registerService('LDAPProvider', function(Server $c) {
657
-			$config = $c->getConfig();
658
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
659
-			if(is_null($factoryClass)) {
660
-				throw new \Exception('ldapProviderFactory not set');
661
-			}
662
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
663
-			$factory = new $factoryClass($this);
664
-			return $factory->getLDAPProvider();
665
-		});
666
-		$this->registerService('LockingProvider', function (Server $c) {
667
-			$ini = $c->getIniWrapper();
668
-			$config = $c->getConfig();
669
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
670
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
671
-				/** @var \OC\Memcache\Factory $memcacheFactory */
672
-				$memcacheFactory = $c->getMemCacheFactory();
673
-				$memcache = $memcacheFactory->createLocking('lock');
674
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
675
-					return new MemcacheLockingProvider($memcache, $ttl);
676
-				}
677
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
678
-			}
679
-			return new NoopLockingProvider();
680
-		});
681
-		$this->registerService('MountManager', function () {
682
-			return new \OC\Files\Mount\Manager();
683
-		});
684
-		$this->registerService('MimeTypeDetector', function (Server $c) {
685
-			return new \OC\Files\Type\Detection(
686
-				$c->getURLGenerator(),
687
-				\OC::$configDir,
688
-				\OC::$SERVERROOT . '/resources/config/'
689
-			);
690
-		});
691
-		$this->registerService('MimeTypeLoader', function (Server $c) {
692
-			return new \OC\Files\Type\Loader(
693
-				$c->getDatabaseConnection()
694
-			);
695
-		});
696
-		$this->registerService('NotificationManager', function (Server $c) {
697
-			return new Manager(
698
-				$c->query(IValidator::class)
699
-			);
700
-		});
701
-		$this->registerService('CapabilitiesManager', function (Server $c) {
702
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
703
-			$manager->registerCapability(function () use ($c) {
704
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
705
-			});
706
-			return $manager;
707
-		});
708
-		$this->registerService('CommentsManager', function(Server $c) {
709
-			$config = $c->getConfig();
710
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
711
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
712
-			$factory = new $factoryClass($this);
713
-			return $factory->getManager();
714
-		});
715
-		$this->registerService('ThemingDefaults', function(Server $c) {
716
-			/*
114
+    /** @var string */
115
+    private $webRoot;
116
+
117
+    /**
118
+     * @param string $webRoot
119
+     * @param \OC\Config $config
120
+     */
121
+    public function __construct($webRoot, \OC\Config $config) {
122
+        parent::__construct();
123
+        $this->webRoot = $webRoot;
124
+
125
+        $this->registerService('ContactsManager', function ($c) {
126
+            return new ContactsManager();
127
+        });
128
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
129
+
130
+        $this->registerService('PreviewManager', function (Server $c) {
131
+            return new PreviewManager(
132
+                $c->getConfig(),
133
+                $c->getRootFolder(),
134
+                $c->getAppDataDir('preview'),
135
+                $c->getEventDispatcher(),
136
+                $c->getSession()->get('user_id')
137
+            );
138
+        });
139
+
140
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
141
+            return new \OC\Preview\Watcher(
142
+                $c->getAppDataDir('preview')
143
+            );
144
+        });
145
+
146
+        $this->registerService('EncryptionManager', function (Server $c) {
147
+            $view = new View();
148
+            $util = new Encryption\Util(
149
+                $view,
150
+                $c->getUserManager(),
151
+                $c->getGroupManager(),
152
+                $c->getConfig()
153
+            );
154
+            return new Encryption\Manager(
155
+                $c->getConfig(),
156
+                $c->getLogger(),
157
+                $c->getL10N('core'),
158
+                new View(),
159
+                $util,
160
+                new ArrayCache()
161
+            );
162
+        });
163
+
164
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
165
+            $util = new Encryption\Util(
166
+                new View(),
167
+                $c->getUserManager(),
168
+                $c->getGroupManager(),
169
+                $c->getConfig()
170
+            );
171
+            return new Encryption\File($util);
172
+        });
173
+
174
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
175
+            $view = new View();
176
+            $util = new Encryption\Util(
177
+                $view,
178
+                $c->getUserManager(),
179
+                $c->getGroupManager(),
180
+                $c->getConfig()
181
+            );
182
+
183
+            return new Encryption\Keys\Storage($view, $util);
184
+        });
185
+        $this->registerService('TagMapper', function (Server $c) {
186
+            return new TagMapper($c->getDatabaseConnection());
187
+        });
188
+        $this->registerService('TagManager', function (Server $c) {
189
+            $tagMapper = $c->query('TagMapper');
190
+            return new TagManager($tagMapper, $c->getUserSession());
191
+        });
192
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
193
+            $config = $c->getConfig();
194
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
195
+            /** @var \OC\SystemTag\ManagerFactory $factory */
196
+            $factory = new $factoryClass($this);
197
+            return $factory;
198
+        });
199
+        $this->registerService('SystemTagManager', function (Server $c) {
200
+            return $c->query('SystemTagManagerFactory')->getManager();
201
+        });
202
+        $this->registerService('SystemTagObjectMapper', function (Server $c) {
203
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
204
+        });
205
+        $this->registerService('RootFolder', function (Server $c) {
206
+            $manager = \OC\Files\Filesystem::getMountManager(null);
207
+            $view = new View();
208
+            $root = new Root(
209
+                $manager,
210
+                $view,
211
+                null,
212
+                $c->getUserMountCache(),
213
+                $this->getLogger(),
214
+                $this->getUserManager()
215
+            );
216
+            $connector = new HookConnector($root, $view);
217
+            $connector->viewToNode();
218
+
219
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
220
+            $previewConnector->connectWatcher();
221
+
222
+            return $root;
223
+        });
224
+        $this->registerService('LazyRootFolder', function(Server $c) {
225
+            return new LazyRoot(function() use ($c) {
226
+                return $c->query('RootFolder');
227
+            });
228
+        });
229
+        $this->registerService('UserManager', function (Server $c) {
230
+            $config = $c->getConfig();
231
+            return new \OC\User\Manager($config);
232
+        });
233
+        $this->registerService('GroupManager', function (Server $c) {
234
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
235
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
236
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
237
+            });
238
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
239
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
240
+            });
241
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
242
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
243
+            });
244
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
245
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
246
+            });
247
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
248
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
249
+            });
250
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
251
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
252
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
253
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
254
+            });
255
+            return $groupManager;
256
+        });
257
+        $this->registerService(Store::class, function(Server $c) {
258
+            $session = $c->getSession();
259
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
260
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
261
+            } else {
262
+                $tokenProvider = null;
263
+            }
264
+            $logger = $c->getLogger();
265
+            return new Store($session, $logger, $tokenProvider);
266
+        });
267
+        $this->registerAlias(IStore::class, Store::class);
268
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
269
+            $dbConnection = $c->getDatabaseConnection();
270
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
271
+        });
272
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
273
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
274
+            $crypto = $c->getCrypto();
275
+            $config = $c->getConfig();
276
+            $logger = $c->getLogger();
277
+            $timeFactory = new TimeFactory();
278
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
279
+        });
280
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
281
+        $this->registerService('UserSession', function (Server $c) {
282
+            $manager = $c->getUserManager();
283
+            $session = new \OC\Session\Memory('');
284
+            $timeFactory = new TimeFactory();
285
+            // Token providers might require a working database. This code
286
+            // might however be called when ownCloud is not yet setup.
287
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
288
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
289
+            } else {
290
+                $defaultTokenProvider = null;
291
+            }
292
+
293
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
294
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
295
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
296
+            });
297
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
298
+                /** @var $user \OC\User\User */
299
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
300
+            });
301
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
302
+                /** @var $user \OC\User\User */
303
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
304
+            });
305
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
306
+                /** @var $user \OC\User\User */
307
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
308
+            });
309
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
310
+                /** @var $user \OC\User\User */
311
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
312
+            });
313
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
314
+                /** @var $user \OC\User\User */
315
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
316
+            });
317
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
318
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
319
+            });
320
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
321
+                /** @var $user \OC\User\User */
322
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
323
+            });
324
+            $userSession->listen('\OC\User', 'logout', function () {
325
+                \OC_Hook::emit('OC_User', 'logout', array());
326
+            });
327
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
328
+                /** @var $user \OC\User\User */
329
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
330
+            });
331
+            return $userSession;
332
+        });
333
+
334
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
335
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
336
+        });
337
+
338
+        $this->registerService('NavigationManager', function (Server $c) {
339
+            return new \OC\NavigationManager($c->getAppManager(),
340
+                $c->getURLGenerator(),
341
+                $c->getL10NFactory(),
342
+                $c->getUserSession(),
343
+                $c->getGroupManager());
344
+        });
345
+        $this->registerService('AllConfig', function (Server $c) {
346
+            return new \OC\AllConfig(
347
+                $c->getSystemConfig()
348
+            );
349
+        });
350
+        $this->registerAlias(\OCP\IConfig::class, 'AllConfig');
351
+        $this->registerService('SystemConfig', function ($c) use ($config) {
352
+            return new \OC\SystemConfig($config);
353
+        });
354
+        $this->registerService('AppConfig', function (Server $c) {
355
+            return new \OC\AppConfig($c->getDatabaseConnection());
356
+        });
357
+        $this->registerService('L10NFactory', function (Server $c) {
358
+            return new \OC\L10N\Factory(
359
+                $c->getConfig(),
360
+                $c->getRequest(),
361
+                $c->getUserSession(),
362
+                \OC::$SERVERROOT
363
+            );
364
+        });
365
+        $this->registerService('URLGenerator', function (Server $c) {
366
+            $config = $c->getConfig();
367
+            $cacheFactory = $c->getMemCacheFactory();
368
+            return new \OC\URLGenerator(
369
+                $config,
370
+                $cacheFactory
371
+            );
372
+        });
373
+        $this->registerAlias(IURLGenerator::class, 'URLGenerator');
374
+        $this->registerService('AppHelper', function ($c) {
375
+            return new \OC\AppHelper();
376
+        });
377
+        $this->registerService('AppFetcher', function ($c) {
378
+            return new AppFetcher(
379
+                $this->getAppDataDir('appstore'),
380
+                $this->getHTTPClientService(),
381
+                $this->query(TimeFactory::class),
382
+                $this->getConfig()
383
+            );
384
+        });
385
+        $this->registerService('CategoryFetcher', function ($c) {
386
+            return new CategoryFetcher(
387
+                $this->getAppDataDir('appstore'),
388
+                $this->getHTTPClientService(),
389
+                $this->query(TimeFactory::class),
390
+                $this->getConfig()
391
+            );
392
+        });
393
+        $this->registerService('UserCache', function ($c) {
394
+            return new Cache\File();
395
+        });
396
+        $this->registerService('MemCacheFactory', function (Server $c) {
397
+            $config = $c->getConfig();
398
+
399
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
400
+                $v = \OC_App::getAppVersions();
401
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
402
+                $version = implode(',', $v);
403
+                $instanceId = \OC_Util::getInstanceId();
404
+                $path = \OC::$SERVERROOT;
405
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
406
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
407
+                    $config->getSystemValue('memcache.local', null),
408
+                    $config->getSystemValue('memcache.distributed', null),
409
+                    $config->getSystemValue('memcache.locking', null)
410
+                );
411
+            }
412
+
413
+            return new \OC\Memcache\Factory('', $c->getLogger(),
414
+                '\\OC\\Memcache\\ArrayCache',
415
+                '\\OC\\Memcache\\ArrayCache',
416
+                '\\OC\\Memcache\\ArrayCache'
417
+            );
418
+        });
419
+        $this->registerService('RedisFactory', function (Server $c) {
420
+            $systemConfig = $c->getSystemConfig();
421
+            return new RedisFactory($systemConfig);
422
+        });
423
+        $this->registerService('ActivityManager', function (Server $c) {
424
+            return new \OC\Activity\Manager(
425
+                $c->getRequest(),
426
+                $c->getUserSession(),
427
+                $c->getConfig(),
428
+                $c->query(IValidator::class)
429
+            );
430
+        });
431
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
432
+            return new \OC\Activity\EventMerger(
433
+                $c->getL10N('lib')
434
+            );
435
+        });
436
+        $this->registerAlias(IValidator::class, Validator::class);
437
+        $this->registerService('AvatarManager', function (Server $c) {
438
+            return new AvatarManager(
439
+                $c->getUserManager(),
440
+                $c->getAppDataDir('avatar'),
441
+                $c->getL10N('lib'),
442
+                $c->getLogger(),
443
+                $c->getConfig()
444
+            );
445
+        });
446
+        $this->registerService('Logger', function (Server $c) {
447
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
448
+            $logger = Log::getLogClass($logType);
449
+            call_user_func(array($logger, 'init'));
450
+
451
+            return new Log($logger);
452
+        });
453
+        $this->registerService('JobList', function (Server $c) {
454
+            $config = $c->getConfig();
455
+            return new \OC\BackgroundJob\JobList(
456
+                $c->getDatabaseConnection(),
457
+                $config,
458
+                new TimeFactory()
459
+            );
460
+        });
461
+        $this->registerService('Router', function (Server $c) {
462
+            $cacheFactory = $c->getMemCacheFactory();
463
+            $logger = $c->getLogger();
464
+            if ($cacheFactory->isAvailable()) {
465
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
466
+            } else {
467
+                $router = new \OC\Route\Router($logger);
468
+            }
469
+            return $router;
470
+        });
471
+        $this->registerService('Search', function ($c) {
472
+            return new Search();
473
+        });
474
+        $this->registerService('SecureRandom', function ($c) {
475
+            return new SecureRandom();
476
+        });
477
+        $this->registerService('Crypto', function (Server $c) {
478
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
479
+        });
480
+        $this->registerService('Hasher', function (Server $c) {
481
+            return new Hasher($c->getConfig());
482
+        });
483
+        $this->registerService('CredentialsManager', function (Server $c) {
484
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
485
+        });
486
+        $this->registerService('DatabaseConnection', function (Server $c) {
487
+            $systemConfig = $c->getSystemConfig();
488
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
489
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
490
+            if (!$factory->isValidType($type)) {
491
+                throw new \OC\DatabaseException('Invalid database type');
492
+            }
493
+            $connectionParams = $factory->createConnectionParams();
494
+            $connection = $factory->getConnection($type, $connectionParams);
495
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
496
+            return $connection;
497
+        });
498
+        $this->registerService('HTTPHelper', function (Server $c) {
499
+            $config = $c->getConfig();
500
+            return new HTTPHelper(
501
+                $config,
502
+                $c->getHTTPClientService()
503
+            );
504
+        });
505
+        $this->registerService('HttpClientService', function (Server $c) {
506
+            $user = \OC_User::getUser();
507
+            $uid = $user ? $user : null;
508
+            return new ClientService(
509
+                $c->getConfig(),
510
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
511
+            );
512
+        });
513
+        $this->registerService('EventLogger', function (Server $c) {
514
+            if ($c->getSystemConfig()->getValue('debug', false)) {
515
+                return new EventLogger();
516
+            } else {
517
+                return new NullEventLogger();
518
+            }
519
+        });
520
+        $this->registerService('QueryLogger', function (Server $c) {
521
+            if ($c->getSystemConfig()->getValue('debug', false)) {
522
+                return new QueryLogger();
523
+            } else {
524
+                return new NullQueryLogger();
525
+            }
526
+        });
527
+        $this->registerService('TempManager', function (Server $c) {
528
+            return new TempManager(
529
+                $c->getLogger(),
530
+                $c->getConfig()
531
+            );
532
+        });
533
+        $this->registerService('AppManager', function (Server $c) {
534
+            return new \OC\App\AppManager(
535
+                $c->getUserSession(),
536
+                $c->getAppConfig(),
537
+                $c->getGroupManager(),
538
+                $c->getMemCacheFactory(),
539
+                $c->getEventDispatcher()
540
+            );
541
+        });
542
+        $this->registerService('DateTimeZone', function (Server $c) {
543
+            return new DateTimeZone(
544
+                $c->getConfig(),
545
+                $c->getSession()
546
+            );
547
+        });
548
+        $this->registerService('DateTimeFormatter', function (Server $c) {
549
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
550
+
551
+            return new DateTimeFormatter(
552
+                $c->getDateTimeZone()->getTimeZone(),
553
+                $c->getL10N('lib', $language)
554
+            );
555
+        });
556
+        $this->registerService('UserMountCache', function (Server $c) {
557
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
558
+            $listener = new UserMountCacheListener($mountCache);
559
+            $listener->listen($c->getUserManager());
560
+            return $mountCache;
561
+        });
562
+        $this->registerService('MountConfigManager', function (Server $c) {
563
+            $loader = \OC\Files\Filesystem::getLoader();
564
+            $mountCache = $c->query('UserMountCache');
565
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
566
+
567
+            // builtin providers
568
+
569
+            $config = $c->getConfig();
570
+            $manager->registerProvider(new CacheMountProvider($config));
571
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
572
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
573
+
574
+            return $manager;
575
+        });
576
+        $this->registerService('IniWrapper', function ($c) {
577
+            return new IniGetWrapper();
578
+        });
579
+        $this->registerService('AsyncCommandBus', function (Server $c) {
580
+            $jobList = $c->getJobList();
581
+            return new AsyncBus($jobList);
582
+        });
583
+        $this->registerService('TrustedDomainHelper', function ($c) {
584
+            return new TrustedDomainHelper($this->getConfig());
585
+        });
586
+        $this->registerService('Throttler', function(Server $c) {
587
+            return new Throttler(
588
+                $c->getDatabaseConnection(),
589
+                new TimeFactory(),
590
+                $c->getLogger(),
591
+                $c->getConfig()
592
+            );
593
+        });
594
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
595
+            // IConfig and IAppManager requires a working database. This code
596
+            // might however be called when ownCloud is not yet setup.
597
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
598
+                $config = $c->getConfig();
599
+                $appManager = $c->getAppManager();
600
+            } else {
601
+                $config = null;
602
+                $appManager = null;
603
+            }
604
+
605
+            return new Checker(
606
+                    new EnvironmentHelper(),
607
+                    new FileAccessHelper(),
608
+                    new AppLocator(),
609
+                    $config,
610
+                    $c->getMemCacheFactory(),
611
+                    $appManager,
612
+                    $c->getTempManager()
613
+            );
614
+        });
615
+        $this->registerService('Request', function ($c) {
616
+            if (isset($this['urlParams'])) {
617
+                $urlParams = $this['urlParams'];
618
+            } else {
619
+                $urlParams = [];
620
+            }
621
+
622
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
623
+                && in_array('fakeinput', stream_get_wrappers())
624
+            ) {
625
+                $stream = 'fakeinput://data';
626
+            } else {
627
+                $stream = 'php://input';
628
+            }
629
+
630
+            return new Request(
631
+                [
632
+                    'get' => $_GET,
633
+                    'post' => $_POST,
634
+                    'files' => $_FILES,
635
+                    'server' => $_SERVER,
636
+                    'env' => $_ENV,
637
+                    'cookies' => $_COOKIE,
638
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
639
+                        ? $_SERVER['REQUEST_METHOD']
640
+                        : null,
641
+                    'urlParams' => $urlParams,
642
+                ],
643
+                $this->getSecureRandom(),
644
+                $this->getConfig(),
645
+                $this->getCsrfTokenManager(),
646
+                $stream
647
+            );
648
+        });
649
+        $this->registerService('Mailer', function (Server $c) {
650
+            return new Mailer(
651
+                $c->getConfig(),
652
+                $c->getLogger(),
653
+                $c->getThemingDefaults()
654
+            );
655
+        });
656
+        $this->registerService('LDAPProvider', function(Server $c) {
657
+            $config = $c->getConfig();
658
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
659
+            if(is_null($factoryClass)) {
660
+                throw new \Exception('ldapProviderFactory not set');
661
+            }
662
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
663
+            $factory = new $factoryClass($this);
664
+            return $factory->getLDAPProvider();
665
+        });
666
+        $this->registerService('LockingProvider', function (Server $c) {
667
+            $ini = $c->getIniWrapper();
668
+            $config = $c->getConfig();
669
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
670
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
671
+                /** @var \OC\Memcache\Factory $memcacheFactory */
672
+                $memcacheFactory = $c->getMemCacheFactory();
673
+                $memcache = $memcacheFactory->createLocking('lock');
674
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
675
+                    return new MemcacheLockingProvider($memcache, $ttl);
676
+                }
677
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
678
+            }
679
+            return new NoopLockingProvider();
680
+        });
681
+        $this->registerService('MountManager', function () {
682
+            return new \OC\Files\Mount\Manager();
683
+        });
684
+        $this->registerService('MimeTypeDetector', function (Server $c) {
685
+            return new \OC\Files\Type\Detection(
686
+                $c->getURLGenerator(),
687
+                \OC::$configDir,
688
+                \OC::$SERVERROOT . '/resources/config/'
689
+            );
690
+        });
691
+        $this->registerService('MimeTypeLoader', function (Server $c) {
692
+            return new \OC\Files\Type\Loader(
693
+                $c->getDatabaseConnection()
694
+            );
695
+        });
696
+        $this->registerService('NotificationManager', function (Server $c) {
697
+            return new Manager(
698
+                $c->query(IValidator::class)
699
+            );
700
+        });
701
+        $this->registerService('CapabilitiesManager', function (Server $c) {
702
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
703
+            $manager->registerCapability(function () use ($c) {
704
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
705
+            });
706
+            return $manager;
707
+        });
708
+        $this->registerService('CommentsManager', function(Server $c) {
709
+            $config = $c->getConfig();
710
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
711
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
712
+            $factory = new $factoryClass($this);
713
+            return $factory->getManager();
714
+        });
715
+        $this->registerService('ThemingDefaults', function(Server $c) {
716
+            /*
717 717
 			 * Dark magic for autoloader.
718 718
 			 * If we do a class_exists it will try to load the class which will
719 719
 			 * make composer cache the result. Resulting in errors when enabling
720 720
 			 * the theming app.
721 721
 			 */
722
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
723
-			if (isset($prefixes['OCA\\Theming\\'])) {
724
-				$classExists = true;
725
-			} else {
726
-				$classExists = false;
727
-			}
728
-
729
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
730
-				return new ThemingDefaults(
731
-					$c->getConfig(),
732
-					$c->getL10N('theming'),
733
-					$c->getURLGenerator(),
734
-					new \OC_Defaults(),
735
-					$c->getLazyRootFolder(),
736
-					$c->getMemCacheFactory()
737
-				);
738
-			}
739
-			return new \OC_Defaults();
740
-		});
741
-		$this->registerService('EventDispatcher', function () {
742
-			return new EventDispatcher();
743
-		});
744
-		$this->registerService('CryptoWrapper', function (Server $c) {
745
-			// FIXME: Instantiiated here due to cyclic dependency
746
-			$request = new Request(
747
-				[
748
-					'get' => $_GET,
749
-					'post' => $_POST,
750
-					'files' => $_FILES,
751
-					'server' => $_SERVER,
752
-					'env' => $_ENV,
753
-					'cookies' => $_COOKIE,
754
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
755
-						? $_SERVER['REQUEST_METHOD']
756
-						: null,
757
-				],
758
-				$c->getSecureRandom(),
759
-				$c->getConfig()
760
-			);
761
-
762
-			return new CryptoWrapper(
763
-				$c->getConfig(),
764
-				$c->getCrypto(),
765
-				$c->getSecureRandom(),
766
-				$request
767
-			);
768
-		});
769
-		$this->registerService('CsrfTokenManager', function (Server $c) {
770
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
771
-
772
-			return new CsrfTokenManager(
773
-				$tokenGenerator,
774
-				$c->query(SessionStorage::class)
775
-			);
776
-		});
777
-		$this->registerService(SessionStorage::class, function (Server $c) {
778
-			return new SessionStorage($c->getSession());
779
-		});
780
-		$this->registerService('ContentSecurityPolicyManager', function (Server $c) {
781
-			return new ContentSecurityPolicyManager();
782
-		});
783
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
784
-			return new ContentSecurityPolicyNonceManager(
785
-				$c->getCsrfTokenManager(),
786
-				$c->getRequest()
787
-			);
788
-		});
789
-		$this->registerService('ShareManager', function(Server $c) {
790
-			$config = $c->getConfig();
791
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
792
-			/** @var \OCP\Share\IProviderFactory $factory */
793
-			$factory = new $factoryClass($this);
794
-
795
-			$manager = new \OC\Share20\Manager(
796
-				$c->getLogger(),
797
-				$c->getConfig(),
798
-				$c->getSecureRandom(),
799
-				$c->getHasher(),
800
-				$c->getMountManager(),
801
-				$c->getGroupManager(),
802
-				$c->getL10N('core'),
803
-				$factory,
804
-				$c->getUserManager(),
805
-				$c->getLazyRootFolder(),
806
-				$c->getEventDispatcher()
807
-			);
808
-
809
-			return $manager;
810
-		});
811
-		$this->registerService('SettingsManager', function(Server $c) {
812
-			$manager = new \OC\Settings\Manager(
813
-				$c->getLogger(),
814
-				$c->getDatabaseConnection(),
815
-				$c->getL10N('lib'),
816
-				$c->getConfig(),
817
-				$c->getEncryptionManager(),
818
-				$c->getUserManager(),
819
-				$c->getLockingProvider(),
820
-				$c->getRequest(),
821
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
822
-				$c->getURLGenerator()
823
-			);
824
-			return $manager;
825
-		});
826
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
827
-			return new \OC\Files\AppData\Factory(
828
-				$c->getRootFolder(),
829
-				$c->getSystemConfig()
830
-			);
831
-		});
832
-
833
-		$this->registerService('LockdownManager', function (Server $c) {
834
-			return new LockdownManager();
835
-		});
836
-
837
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
838
-			return new CloudIdManager();
839
-		});
840
-
841
-		/* To trick DI since we don't extend the DIContainer here */
842
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
843
-			return new CleanPreviewsBackgroundJob(
844
-				$c->getRootFolder(),
845
-				$c->getLogger(),
846
-				$c->getJobList(),
847
-				new TimeFactory()
848
-			);
849
-		});
850
-	}
851
-
852
-	/**
853
-	 * @return \OCP\Contacts\IManager
854
-	 */
855
-	public function getContactsManager() {
856
-		return $this->query('ContactsManager');
857
-	}
858
-
859
-	/**
860
-	 * @return \OC\Encryption\Manager
861
-	 */
862
-	public function getEncryptionManager() {
863
-		return $this->query('EncryptionManager');
864
-	}
865
-
866
-	/**
867
-	 * @return \OC\Encryption\File
868
-	 */
869
-	public function getEncryptionFilesHelper() {
870
-		return $this->query('EncryptionFileHelper');
871
-	}
872
-
873
-	/**
874
-	 * @return \OCP\Encryption\Keys\IStorage
875
-	 */
876
-	public function getEncryptionKeyStorage() {
877
-		return $this->query('EncryptionKeyStorage');
878
-	}
879
-
880
-	/**
881
-	 * The current request object holding all information about the request
882
-	 * currently being processed is returned from this method.
883
-	 * In case the current execution was not initiated by a web request null is returned
884
-	 *
885
-	 * @return \OCP\IRequest
886
-	 */
887
-	public function getRequest() {
888
-		return $this->query('Request');
889
-	}
890
-
891
-	/**
892
-	 * Returns the preview manager which can create preview images for a given file
893
-	 *
894
-	 * @return \OCP\IPreview
895
-	 */
896
-	public function getPreviewManager() {
897
-		return $this->query('PreviewManager');
898
-	}
899
-
900
-	/**
901
-	 * Returns the tag manager which can get and set tags for different object types
902
-	 *
903
-	 * @see \OCP\ITagManager::load()
904
-	 * @return \OCP\ITagManager
905
-	 */
906
-	public function getTagManager() {
907
-		return $this->query('TagManager');
908
-	}
909
-
910
-	/**
911
-	 * Returns the system-tag manager
912
-	 *
913
-	 * @return \OCP\SystemTag\ISystemTagManager
914
-	 *
915
-	 * @since 9.0.0
916
-	 */
917
-	public function getSystemTagManager() {
918
-		return $this->query('SystemTagManager');
919
-	}
920
-
921
-	/**
922
-	 * Returns the system-tag object mapper
923
-	 *
924
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
925
-	 *
926
-	 * @since 9.0.0
927
-	 */
928
-	public function getSystemTagObjectMapper() {
929
-		return $this->query('SystemTagObjectMapper');
930
-	}
931
-
932
-	/**
933
-	 * Returns the avatar manager, used for avatar functionality
934
-	 *
935
-	 * @return \OCP\IAvatarManager
936
-	 */
937
-	public function getAvatarManager() {
938
-		return $this->query('AvatarManager');
939
-	}
940
-
941
-	/**
942
-	 * Returns the root folder of ownCloud's data directory
943
-	 *
944
-	 * @return \OCP\Files\IRootFolder
945
-	 */
946
-	public function getRootFolder() {
947
-		return $this->query('LazyRootFolder');
948
-	}
949
-
950
-	/**
951
-	 * Returns the root folder of ownCloud's data directory
952
-	 * This is the lazy variant so this gets only initialized once it
953
-	 * is actually used.
954
-	 *
955
-	 * @return \OCP\Files\IRootFolder
956
-	 */
957
-	public function getLazyRootFolder() {
958
-		return $this->query('LazyRootFolder');
959
-	}
960
-
961
-	/**
962
-	 * Returns a view to ownCloud's files folder
963
-	 *
964
-	 * @param string $userId user ID
965
-	 * @return \OCP\Files\Folder|null
966
-	 */
967
-	public function getUserFolder($userId = null) {
968
-		if ($userId === null) {
969
-			$user = $this->getUserSession()->getUser();
970
-			if (!$user) {
971
-				return null;
972
-			}
973
-			$userId = $user->getUID();
974
-		}
975
-		$root = $this->getRootFolder();
976
-		return $root->getUserFolder($userId);
977
-	}
978
-
979
-	/**
980
-	 * Returns an app-specific view in ownClouds data directory
981
-	 *
982
-	 * @return \OCP\Files\Folder
983
-	 * @deprecated since 9.2.0 use IAppData
984
-	 */
985
-	public function getAppFolder() {
986
-		$dir = '/' . \OC_App::getCurrentApp();
987
-		$root = $this->getRootFolder();
988
-		if (!$root->nodeExists($dir)) {
989
-			$folder = $root->newFolder($dir);
990
-		} else {
991
-			$folder = $root->get($dir);
992
-		}
993
-		return $folder;
994
-	}
995
-
996
-	/**
997
-	 * @return \OC\User\Manager
998
-	 */
999
-	public function getUserManager() {
1000
-		return $this->query('UserManager');
1001
-	}
1002
-
1003
-	/**
1004
-	 * @return \OC\Group\Manager
1005
-	 */
1006
-	public function getGroupManager() {
1007
-		return $this->query('GroupManager');
1008
-	}
1009
-
1010
-	/**
1011
-	 * @return \OC\User\Session
1012
-	 */
1013
-	public function getUserSession() {
1014
-		return $this->query('UserSession');
1015
-	}
1016
-
1017
-	/**
1018
-	 * @return \OCP\ISession
1019
-	 */
1020
-	public function getSession() {
1021
-		return $this->query('UserSession')->getSession();
1022
-	}
1023
-
1024
-	/**
1025
-	 * @param \OCP\ISession $session
1026
-	 */
1027
-	public function setSession(\OCP\ISession $session) {
1028
-		$this->query(SessionStorage::class)->setSession($session);
1029
-		$this->query('UserSession')->setSession($session);
1030
-		$this->query(Store::class)->setSession($session);
1031
-	}
1032
-
1033
-	/**
1034
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1035
-	 */
1036
-	public function getTwoFactorAuthManager() {
1037
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1038
-	}
1039
-
1040
-	/**
1041
-	 * @return \OC\NavigationManager
1042
-	 */
1043
-	public function getNavigationManager() {
1044
-		return $this->query('NavigationManager');
1045
-	}
1046
-
1047
-	/**
1048
-	 * @return \OCP\IConfig
1049
-	 */
1050
-	public function getConfig() {
1051
-		return $this->query('AllConfig');
1052
-	}
1053
-
1054
-	/**
1055
-	 * @internal For internal use only
1056
-	 * @return \OC\SystemConfig
1057
-	 */
1058
-	public function getSystemConfig() {
1059
-		return $this->query('SystemConfig');
1060
-	}
1061
-
1062
-	/**
1063
-	 * Returns the app config manager
1064
-	 *
1065
-	 * @return \OCP\IAppConfig
1066
-	 */
1067
-	public function getAppConfig() {
1068
-		return $this->query('AppConfig');
1069
-	}
1070
-
1071
-	/**
1072
-	 * @return \OCP\L10N\IFactory
1073
-	 */
1074
-	public function getL10NFactory() {
1075
-		return $this->query('L10NFactory');
1076
-	}
1077
-
1078
-	/**
1079
-	 * get an L10N instance
1080
-	 *
1081
-	 * @param string $app appid
1082
-	 * @param string $lang
1083
-	 * @return IL10N
1084
-	 */
1085
-	public function getL10N($app, $lang = null) {
1086
-		return $this->getL10NFactory()->get($app, $lang);
1087
-	}
1088
-
1089
-	/**
1090
-	 * @return \OCP\IURLGenerator
1091
-	 */
1092
-	public function getURLGenerator() {
1093
-		return $this->query('URLGenerator');
1094
-	}
1095
-
1096
-	/**
1097
-	 * @return \OCP\IHelper
1098
-	 */
1099
-	public function getHelper() {
1100
-		return $this->query('AppHelper');
1101
-	}
1102
-
1103
-	/**
1104
-	 * @return AppFetcher
1105
-	 */
1106
-	public function getAppFetcher() {
1107
-		return $this->query('AppFetcher');
1108
-	}
1109
-
1110
-	/**
1111
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1112
-	 * getMemCacheFactory() instead.
1113
-	 *
1114
-	 * @return \OCP\ICache
1115
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1116
-	 */
1117
-	public function getCache() {
1118
-		return $this->query('UserCache');
1119
-	}
1120
-
1121
-	/**
1122
-	 * Returns an \OCP\CacheFactory instance
1123
-	 *
1124
-	 * @return \OCP\ICacheFactory
1125
-	 */
1126
-	public function getMemCacheFactory() {
1127
-		return $this->query('MemCacheFactory');
1128
-	}
1129
-
1130
-	/**
1131
-	 * Returns an \OC\RedisFactory instance
1132
-	 *
1133
-	 * @return \OC\RedisFactory
1134
-	 */
1135
-	public function getGetRedisFactory() {
1136
-		return $this->query('RedisFactory');
1137
-	}
1138
-
1139
-
1140
-	/**
1141
-	 * Returns the current session
1142
-	 *
1143
-	 * @return \OCP\IDBConnection
1144
-	 */
1145
-	public function getDatabaseConnection() {
1146
-		return $this->query('DatabaseConnection');
1147
-	}
1148
-
1149
-	/**
1150
-	 * Returns the activity manager
1151
-	 *
1152
-	 * @return \OCP\Activity\IManager
1153
-	 */
1154
-	public function getActivityManager() {
1155
-		return $this->query('ActivityManager');
1156
-	}
1157
-
1158
-	/**
1159
-	 * Returns an job list for controlling background jobs
1160
-	 *
1161
-	 * @return \OCP\BackgroundJob\IJobList
1162
-	 */
1163
-	public function getJobList() {
1164
-		return $this->query('JobList');
1165
-	}
1166
-
1167
-	/**
1168
-	 * Returns a logger instance
1169
-	 *
1170
-	 * @return \OCP\ILogger
1171
-	 */
1172
-	public function getLogger() {
1173
-		return $this->query('Logger');
1174
-	}
1175
-
1176
-	/**
1177
-	 * Returns a router for generating and matching urls
1178
-	 *
1179
-	 * @return \OCP\Route\IRouter
1180
-	 */
1181
-	public function getRouter() {
1182
-		return $this->query('Router');
1183
-	}
1184
-
1185
-	/**
1186
-	 * Returns a search instance
1187
-	 *
1188
-	 * @return \OCP\ISearch
1189
-	 */
1190
-	public function getSearch() {
1191
-		return $this->query('Search');
1192
-	}
1193
-
1194
-	/**
1195
-	 * Returns a SecureRandom instance
1196
-	 *
1197
-	 * @return \OCP\Security\ISecureRandom
1198
-	 */
1199
-	public function getSecureRandom() {
1200
-		return $this->query('SecureRandom');
1201
-	}
1202
-
1203
-	/**
1204
-	 * Returns a Crypto instance
1205
-	 *
1206
-	 * @return \OCP\Security\ICrypto
1207
-	 */
1208
-	public function getCrypto() {
1209
-		return $this->query('Crypto');
1210
-	}
1211
-
1212
-	/**
1213
-	 * Returns a Hasher instance
1214
-	 *
1215
-	 * @return \OCP\Security\IHasher
1216
-	 */
1217
-	public function getHasher() {
1218
-		return $this->query('Hasher');
1219
-	}
1220
-
1221
-	/**
1222
-	 * Returns a CredentialsManager instance
1223
-	 *
1224
-	 * @return \OCP\Security\ICredentialsManager
1225
-	 */
1226
-	public function getCredentialsManager() {
1227
-		return $this->query('CredentialsManager');
1228
-	}
1229
-
1230
-	/**
1231
-	 * Returns an instance of the HTTP helper class
1232
-	 *
1233
-	 * @deprecated Use getHTTPClientService()
1234
-	 * @return \OC\HTTPHelper
1235
-	 */
1236
-	public function getHTTPHelper() {
1237
-		return $this->query('HTTPHelper');
1238
-	}
1239
-
1240
-	/**
1241
-	 * Get the certificate manager for the user
1242
-	 *
1243
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1244
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1245
-	 */
1246
-	public function getCertificateManager($userId = '') {
1247
-		if ($userId === '') {
1248
-			$userSession = $this->getUserSession();
1249
-			$user = $userSession->getUser();
1250
-			if (is_null($user)) {
1251
-				return null;
1252
-			}
1253
-			$userId = $user->getUID();
1254
-		}
1255
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1256
-	}
1257
-
1258
-	/**
1259
-	 * Returns an instance of the HTTP client service
1260
-	 *
1261
-	 * @return \OCP\Http\Client\IClientService
1262
-	 */
1263
-	public function getHTTPClientService() {
1264
-		return $this->query('HttpClientService');
1265
-	}
1266
-
1267
-	/**
1268
-	 * Create a new event source
1269
-	 *
1270
-	 * @return \OCP\IEventSource
1271
-	 */
1272
-	public function createEventSource() {
1273
-		return new \OC_EventSource();
1274
-	}
1275
-
1276
-	/**
1277
-	 * Get the active event logger
1278
-	 *
1279
-	 * The returned logger only logs data when debug mode is enabled
1280
-	 *
1281
-	 * @return \OCP\Diagnostics\IEventLogger
1282
-	 */
1283
-	public function getEventLogger() {
1284
-		return $this->query('EventLogger');
1285
-	}
1286
-
1287
-	/**
1288
-	 * Get the active query logger
1289
-	 *
1290
-	 * The returned logger only logs data when debug mode is enabled
1291
-	 *
1292
-	 * @return \OCP\Diagnostics\IQueryLogger
1293
-	 */
1294
-	public function getQueryLogger() {
1295
-		return $this->query('QueryLogger');
1296
-	}
1297
-
1298
-	/**
1299
-	 * Get the manager for temporary files and folders
1300
-	 *
1301
-	 * @return \OCP\ITempManager
1302
-	 */
1303
-	public function getTempManager() {
1304
-		return $this->query('TempManager');
1305
-	}
1306
-
1307
-	/**
1308
-	 * Get the app manager
1309
-	 *
1310
-	 * @return \OCP\App\IAppManager
1311
-	 */
1312
-	public function getAppManager() {
1313
-		return $this->query('AppManager');
1314
-	}
1315
-
1316
-	/**
1317
-	 * Creates a new mailer
1318
-	 *
1319
-	 * @return \OCP\Mail\IMailer
1320
-	 */
1321
-	public function getMailer() {
1322
-		return $this->query('Mailer');
1323
-	}
1324
-
1325
-	/**
1326
-	 * Get the webroot
1327
-	 *
1328
-	 * @return string
1329
-	 */
1330
-	public function getWebRoot() {
1331
-		return $this->webRoot;
1332
-	}
1333
-
1334
-	/**
1335
-	 * @return \OC\OCSClient
1336
-	 */
1337
-	public function getOcsClient() {
1338
-		return $this->query('OcsClient');
1339
-	}
1340
-
1341
-	/**
1342
-	 * @return \OCP\IDateTimeZone
1343
-	 */
1344
-	public function getDateTimeZone() {
1345
-		return $this->query('DateTimeZone');
1346
-	}
1347
-
1348
-	/**
1349
-	 * @return \OCP\IDateTimeFormatter
1350
-	 */
1351
-	public function getDateTimeFormatter() {
1352
-		return $this->query('DateTimeFormatter');
1353
-	}
1354
-
1355
-	/**
1356
-	 * @return \OCP\Files\Config\IMountProviderCollection
1357
-	 */
1358
-	public function getMountProviderCollection() {
1359
-		return $this->query('MountConfigManager');
1360
-	}
1361
-
1362
-	/**
1363
-	 * Get the IniWrapper
1364
-	 *
1365
-	 * @return IniGetWrapper
1366
-	 */
1367
-	public function getIniWrapper() {
1368
-		return $this->query('IniWrapper');
1369
-	}
1370
-
1371
-	/**
1372
-	 * @return \OCP\Command\IBus
1373
-	 */
1374
-	public function getCommandBus() {
1375
-		return $this->query('AsyncCommandBus');
1376
-	}
1377
-
1378
-	/**
1379
-	 * Get the trusted domain helper
1380
-	 *
1381
-	 * @return TrustedDomainHelper
1382
-	 */
1383
-	public function getTrustedDomainHelper() {
1384
-		return $this->query('TrustedDomainHelper');
1385
-	}
1386
-
1387
-	/**
1388
-	 * Get the locking provider
1389
-	 *
1390
-	 * @return \OCP\Lock\ILockingProvider
1391
-	 * @since 8.1.0
1392
-	 */
1393
-	public function getLockingProvider() {
1394
-		return $this->query('LockingProvider');
1395
-	}
1396
-
1397
-	/**
1398
-	 * @return \OCP\Files\Mount\IMountManager
1399
-	 **/
1400
-	function getMountManager() {
1401
-		return $this->query('MountManager');
1402
-	}
1403
-
1404
-	/** @return \OCP\Files\Config\IUserMountCache */
1405
-	function getUserMountCache() {
1406
-		return $this->query('UserMountCache');
1407
-	}
1408
-
1409
-	/**
1410
-	 * Get the MimeTypeDetector
1411
-	 *
1412
-	 * @return \OCP\Files\IMimeTypeDetector
1413
-	 */
1414
-	public function getMimeTypeDetector() {
1415
-		return $this->query('MimeTypeDetector');
1416
-	}
1417
-
1418
-	/**
1419
-	 * Get the MimeTypeLoader
1420
-	 *
1421
-	 * @return \OCP\Files\IMimeTypeLoader
1422
-	 */
1423
-	public function getMimeTypeLoader() {
1424
-		return $this->query('MimeTypeLoader');
1425
-	}
1426
-
1427
-	/**
1428
-	 * Get the manager of all the capabilities
1429
-	 *
1430
-	 * @return \OC\CapabilitiesManager
1431
-	 */
1432
-	public function getCapabilitiesManager() {
1433
-		return $this->query('CapabilitiesManager');
1434
-	}
1435
-
1436
-	/**
1437
-	 * Get the EventDispatcher
1438
-	 *
1439
-	 * @return EventDispatcherInterface
1440
-	 * @since 8.2.0
1441
-	 */
1442
-	public function getEventDispatcher() {
1443
-		return $this->query('EventDispatcher');
1444
-	}
1445
-
1446
-	/**
1447
-	 * Get the Notification Manager
1448
-	 *
1449
-	 * @return \OCP\Notification\IManager
1450
-	 * @since 8.2.0
1451
-	 */
1452
-	public function getNotificationManager() {
1453
-		return $this->query('NotificationManager');
1454
-	}
1455
-
1456
-	/**
1457
-	 * @return \OCP\Comments\ICommentsManager
1458
-	 */
1459
-	public function getCommentsManager() {
1460
-		return $this->query('CommentsManager');
1461
-	}
1462
-
1463
-	/**
1464
-	 * @return \OC_Defaults
1465
-	 */
1466
-	public function getThemingDefaults() {
1467
-		return $this->query('ThemingDefaults');
1468
-	}
1469
-
1470
-	/**
1471
-	 * @return \OC\IntegrityCheck\Checker
1472
-	 */
1473
-	public function getIntegrityCodeChecker() {
1474
-		return $this->query('IntegrityCodeChecker');
1475
-	}
1476
-
1477
-	/**
1478
-	 * @return \OC\Session\CryptoWrapper
1479
-	 */
1480
-	public function getSessionCryptoWrapper() {
1481
-		return $this->query('CryptoWrapper');
1482
-	}
1483
-
1484
-	/**
1485
-	 * @return CsrfTokenManager
1486
-	 */
1487
-	public function getCsrfTokenManager() {
1488
-		return $this->query('CsrfTokenManager');
1489
-	}
1490
-
1491
-	/**
1492
-	 * @return Throttler
1493
-	 */
1494
-	public function getBruteForceThrottler() {
1495
-		return $this->query('Throttler');
1496
-	}
1497
-
1498
-	/**
1499
-	 * @return IContentSecurityPolicyManager
1500
-	 */
1501
-	public function getContentSecurityPolicyManager() {
1502
-		return $this->query('ContentSecurityPolicyManager');
1503
-	}
1504
-
1505
-	/**
1506
-	 * @return ContentSecurityPolicyNonceManager
1507
-	 */
1508
-	public function getContentSecurityPolicyNonceManager() {
1509
-		return $this->query('ContentSecurityPolicyNonceManager');
1510
-	}
1511
-
1512
-	/**
1513
-	 * Not a public API as of 8.2, wait for 9.0
1514
-	 *
1515
-	 * @return \OCA\Files_External\Service\BackendService
1516
-	 */
1517
-	public function getStoragesBackendService() {
1518
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1519
-	}
1520
-
1521
-	/**
1522
-	 * Not a public API as of 8.2, wait for 9.0
1523
-	 *
1524
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1525
-	 */
1526
-	public function getGlobalStoragesService() {
1527
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1528
-	}
1529
-
1530
-	/**
1531
-	 * Not a public API as of 8.2, wait for 9.0
1532
-	 *
1533
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1534
-	 */
1535
-	public function getUserGlobalStoragesService() {
1536
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1537
-	}
1538
-
1539
-	/**
1540
-	 * Not a public API as of 8.2, wait for 9.0
1541
-	 *
1542
-	 * @return \OCA\Files_External\Service\UserStoragesService
1543
-	 */
1544
-	public function getUserStoragesService() {
1545
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1546
-	}
1547
-
1548
-	/**
1549
-	 * @return \OCP\Share\IManager
1550
-	 */
1551
-	public function getShareManager() {
1552
-		return $this->query('ShareManager');
1553
-	}
1554
-
1555
-	/**
1556
-	 * Returns the LDAP Provider
1557
-	 *
1558
-	 * @return \OCP\LDAP\ILDAPProvider
1559
-	 */
1560
-	public function getLDAPProvider() {
1561
-		return $this->query('LDAPProvider');
1562
-	}
1563
-
1564
-	/**
1565
-	 * @return \OCP\Settings\IManager
1566
-	 */
1567
-	public function getSettingsManager() {
1568
-		return $this->query('SettingsManager');
1569
-	}
1570
-
1571
-	/**
1572
-	 * @return \OCP\Files\IAppData
1573
-	 */
1574
-	public function getAppDataDir($app) {
1575
-		/** @var \OC\Files\AppData\Factory $factory */
1576
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1577
-		return $factory->get($app);
1578
-	}
1579
-
1580
-	/**
1581
-	 * @return \OCP\Lockdown\ILockdownManager
1582
-	 */
1583
-	public function getLockdownManager() {
1584
-		return $this->query('LockdownManager');
1585
-	}
1586
-
1587
-	/**
1588
-	 * @return \OCP\Federation\ICloudIdManager
1589
-	 */
1590
-	public function getCloudIdManager() {
1591
-		return $this->query(ICloudIdManager::class);
1592
-	}
722
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
723
+            if (isset($prefixes['OCA\\Theming\\'])) {
724
+                $classExists = true;
725
+            } else {
726
+                $classExists = false;
727
+            }
728
+
729
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
730
+                return new ThemingDefaults(
731
+                    $c->getConfig(),
732
+                    $c->getL10N('theming'),
733
+                    $c->getURLGenerator(),
734
+                    new \OC_Defaults(),
735
+                    $c->getLazyRootFolder(),
736
+                    $c->getMemCacheFactory()
737
+                );
738
+            }
739
+            return new \OC_Defaults();
740
+        });
741
+        $this->registerService('EventDispatcher', function () {
742
+            return new EventDispatcher();
743
+        });
744
+        $this->registerService('CryptoWrapper', function (Server $c) {
745
+            // FIXME: Instantiiated here due to cyclic dependency
746
+            $request = new Request(
747
+                [
748
+                    'get' => $_GET,
749
+                    'post' => $_POST,
750
+                    'files' => $_FILES,
751
+                    'server' => $_SERVER,
752
+                    'env' => $_ENV,
753
+                    'cookies' => $_COOKIE,
754
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
755
+                        ? $_SERVER['REQUEST_METHOD']
756
+                        : null,
757
+                ],
758
+                $c->getSecureRandom(),
759
+                $c->getConfig()
760
+            );
761
+
762
+            return new CryptoWrapper(
763
+                $c->getConfig(),
764
+                $c->getCrypto(),
765
+                $c->getSecureRandom(),
766
+                $request
767
+            );
768
+        });
769
+        $this->registerService('CsrfTokenManager', function (Server $c) {
770
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
771
+
772
+            return new CsrfTokenManager(
773
+                $tokenGenerator,
774
+                $c->query(SessionStorage::class)
775
+            );
776
+        });
777
+        $this->registerService(SessionStorage::class, function (Server $c) {
778
+            return new SessionStorage($c->getSession());
779
+        });
780
+        $this->registerService('ContentSecurityPolicyManager', function (Server $c) {
781
+            return new ContentSecurityPolicyManager();
782
+        });
783
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
784
+            return new ContentSecurityPolicyNonceManager(
785
+                $c->getCsrfTokenManager(),
786
+                $c->getRequest()
787
+            );
788
+        });
789
+        $this->registerService('ShareManager', function(Server $c) {
790
+            $config = $c->getConfig();
791
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
792
+            /** @var \OCP\Share\IProviderFactory $factory */
793
+            $factory = new $factoryClass($this);
794
+
795
+            $manager = new \OC\Share20\Manager(
796
+                $c->getLogger(),
797
+                $c->getConfig(),
798
+                $c->getSecureRandom(),
799
+                $c->getHasher(),
800
+                $c->getMountManager(),
801
+                $c->getGroupManager(),
802
+                $c->getL10N('core'),
803
+                $factory,
804
+                $c->getUserManager(),
805
+                $c->getLazyRootFolder(),
806
+                $c->getEventDispatcher()
807
+            );
808
+
809
+            return $manager;
810
+        });
811
+        $this->registerService('SettingsManager', function(Server $c) {
812
+            $manager = new \OC\Settings\Manager(
813
+                $c->getLogger(),
814
+                $c->getDatabaseConnection(),
815
+                $c->getL10N('lib'),
816
+                $c->getConfig(),
817
+                $c->getEncryptionManager(),
818
+                $c->getUserManager(),
819
+                $c->getLockingProvider(),
820
+                $c->getRequest(),
821
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
822
+                $c->getURLGenerator()
823
+            );
824
+            return $manager;
825
+        });
826
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
827
+            return new \OC\Files\AppData\Factory(
828
+                $c->getRootFolder(),
829
+                $c->getSystemConfig()
830
+            );
831
+        });
832
+
833
+        $this->registerService('LockdownManager', function (Server $c) {
834
+            return new LockdownManager();
835
+        });
836
+
837
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
838
+            return new CloudIdManager();
839
+        });
840
+
841
+        /* To trick DI since we don't extend the DIContainer here */
842
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
843
+            return new CleanPreviewsBackgroundJob(
844
+                $c->getRootFolder(),
845
+                $c->getLogger(),
846
+                $c->getJobList(),
847
+                new TimeFactory()
848
+            );
849
+        });
850
+    }
851
+
852
+    /**
853
+     * @return \OCP\Contacts\IManager
854
+     */
855
+    public function getContactsManager() {
856
+        return $this->query('ContactsManager');
857
+    }
858
+
859
+    /**
860
+     * @return \OC\Encryption\Manager
861
+     */
862
+    public function getEncryptionManager() {
863
+        return $this->query('EncryptionManager');
864
+    }
865
+
866
+    /**
867
+     * @return \OC\Encryption\File
868
+     */
869
+    public function getEncryptionFilesHelper() {
870
+        return $this->query('EncryptionFileHelper');
871
+    }
872
+
873
+    /**
874
+     * @return \OCP\Encryption\Keys\IStorage
875
+     */
876
+    public function getEncryptionKeyStorage() {
877
+        return $this->query('EncryptionKeyStorage');
878
+    }
879
+
880
+    /**
881
+     * The current request object holding all information about the request
882
+     * currently being processed is returned from this method.
883
+     * In case the current execution was not initiated by a web request null is returned
884
+     *
885
+     * @return \OCP\IRequest
886
+     */
887
+    public function getRequest() {
888
+        return $this->query('Request');
889
+    }
890
+
891
+    /**
892
+     * Returns the preview manager which can create preview images for a given file
893
+     *
894
+     * @return \OCP\IPreview
895
+     */
896
+    public function getPreviewManager() {
897
+        return $this->query('PreviewManager');
898
+    }
899
+
900
+    /**
901
+     * Returns the tag manager which can get and set tags for different object types
902
+     *
903
+     * @see \OCP\ITagManager::load()
904
+     * @return \OCP\ITagManager
905
+     */
906
+    public function getTagManager() {
907
+        return $this->query('TagManager');
908
+    }
909
+
910
+    /**
911
+     * Returns the system-tag manager
912
+     *
913
+     * @return \OCP\SystemTag\ISystemTagManager
914
+     *
915
+     * @since 9.0.0
916
+     */
917
+    public function getSystemTagManager() {
918
+        return $this->query('SystemTagManager');
919
+    }
920
+
921
+    /**
922
+     * Returns the system-tag object mapper
923
+     *
924
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
925
+     *
926
+     * @since 9.0.0
927
+     */
928
+    public function getSystemTagObjectMapper() {
929
+        return $this->query('SystemTagObjectMapper');
930
+    }
931
+
932
+    /**
933
+     * Returns the avatar manager, used for avatar functionality
934
+     *
935
+     * @return \OCP\IAvatarManager
936
+     */
937
+    public function getAvatarManager() {
938
+        return $this->query('AvatarManager');
939
+    }
940
+
941
+    /**
942
+     * Returns the root folder of ownCloud's data directory
943
+     *
944
+     * @return \OCP\Files\IRootFolder
945
+     */
946
+    public function getRootFolder() {
947
+        return $this->query('LazyRootFolder');
948
+    }
949
+
950
+    /**
951
+     * Returns the root folder of ownCloud's data directory
952
+     * This is the lazy variant so this gets only initialized once it
953
+     * is actually used.
954
+     *
955
+     * @return \OCP\Files\IRootFolder
956
+     */
957
+    public function getLazyRootFolder() {
958
+        return $this->query('LazyRootFolder');
959
+    }
960
+
961
+    /**
962
+     * Returns a view to ownCloud's files folder
963
+     *
964
+     * @param string $userId user ID
965
+     * @return \OCP\Files\Folder|null
966
+     */
967
+    public function getUserFolder($userId = null) {
968
+        if ($userId === null) {
969
+            $user = $this->getUserSession()->getUser();
970
+            if (!$user) {
971
+                return null;
972
+            }
973
+            $userId = $user->getUID();
974
+        }
975
+        $root = $this->getRootFolder();
976
+        return $root->getUserFolder($userId);
977
+    }
978
+
979
+    /**
980
+     * Returns an app-specific view in ownClouds data directory
981
+     *
982
+     * @return \OCP\Files\Folder
983
+     * @deprecated since 9.2.0 use IAppData
984
+     */
985
+    public function getAppFolder() {
986
+        $dir = '/' . \OC_App::getCurrentApp();
987
+        $root = $this->getRootFolder();
988
+        if (!$root->nodeExists($dir)) {
989
+            $folder = $root->newFolder($dir);
990
+        } else {
991
+            $folder = $root->get($dir);
992
+        }
993
+        return $folder;
994
+    }
995
+
996
+    /**
997
+     * @return \OC\User\Manager
998
+     */
999
+    public function getUserManager() {
1000
+        return $this->query('UserManager');
1001
+    }
1002
+
1003
+    /**
1004
+     * @return \OC\Group\Manager
1005
+     */
1006
+    public function getGroupManager() {
1007
+        return $this->query('GroupManager');
1008
+    }
1009
+
1010
+    /**
1011
+     * @return \OC\User\Session
1012
+     */
1013
+    public function getUserSession() {
1014
+        return $this->query('UserSession');
1015
+    }
1016
+
1017
+    /**
1018
+     * @return \OCP\ISession
1019
+     */
1020
+    public function getSession() {
1021
+        return $this->query('UserSession')->getSession();
1022
+    }
1023
+
1024
+    /**
1025
+     * @param \OCP\ISession $session
1026
+     */
1027
+    public function setSession(\OCP\ISession $session) {
1028
+        $this->query(SessionStorage::class)->setSession($session);
1029
+        $this->query('UserSession')->setSession($session);
1030
+        $this->query(Store::class)->setSession($session);
1031
+    }
1032
+
1033
+    /**
1034
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1035
+     */
1036
+    public function getTwoFactorAuthManager() {
1037
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1038
+    }
1039
+
1040
+    /**
1041
+     * @return \OC\NavigationManager
1042
+     */
1043
+    public function getNavigationManager() {
1044
+        return $this->query('NavigationManager');
1045
+    }
1046
+
1047
+    /**
1048
+     * @return \OCP\IConfig
1049
+     */
1050
+    public function getConfig() {
1051
+        return $this->query('AllConfig');
1052
+    }
1053
+
1054
+    /**
1055
+     * @internal For internal use only
1056
+     * @return \OC\SystemConfig
1057
+     */
1058
+    public function getSystemConfig() {
1059
+        return $this->query('SystemConfig');
1060
+    }
1061
+
1062
+    /**
1063
+     * Returns the app config manager
1064
+     *
1065
+     * @return \OCP\IAppConfig
1066
+     */
1067
+    public function getAppConfig() {
1068
+        return $this->query('AppConfig');
1069
+    }
1070
+
1071
+    /**
1072
+     * @return \OCP\L10N\IFactory
1073
+     */
1074
+    public function getL10NFactory() {
1075
+        return $this->query('L10NFactory');
1076
+    }
1077
+
1078
+    /**
1079
+     * get an L10N instance
1080
+     *
1081
+     * @param string $app appid
1082
+     * @param string $lang
1083
+     * @return IL10N
1084
+     */
1085
+    public function getL10N($app, $lang = null) {
1086
+        return $this->getL10NFactory()->get($app, $lang);
1087
+    }
1088
+
1089
+    /**
1090
+     * @return \OCP\IURLGenerator
1091
+     */
1092
+    public function getURLGenerator() {
1093
+        return $this->query('URLGenerator');
1094
+    }
1095
+
1096
+    /**
1097
+     * @return \OCP\IHelper
1098
+     */
1099
+    public function getHelper() {
1100
+        return $this->query('AppHelper');
1101
+    }
1102
+
1103
+    /**
1104
+     * @return AppFetcher
1105
+     */
1106
+    public function getAppFetcher() {
1107
+        return $this->query('AppFetcher');
1108
+    }
1109
+
1110
+    /**
1111
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1112
+     * getMemCacheFactory() instead.
1113
+     *
1114
+     * @return \OCP\ICache
1115
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1116
+     */
1117
+    public function getCache() {
1118
+        return $this->query('UserCache');
1119
+    }
1120
+
1121
+    /**
1122
+     * Returns an \OCP\CacheFactory instance
1123
+     *
1124
+     * @return \OCP\ICacheFactory
1125
+     */
1126
+    public function getMemCacheFactory() {
1127
+        return $this->query('MemCacheFactory');
1128
+    }
1129
+
1130
+    /**
1131
+     * Returns an \OC\RedisFactory instance
1132
+     *
1133
+     * @return \OC\RedisFactory
1134
+     */
1135
+    public function getGetRedisFactory() {
1136
+        return $this->query('RedisFactory');
1137
+    }
1138
+
1139
+
1140
+    /**
1141
+     * Returns the current session
1142
+     *
1143
+     * @return \OCP\IDBConnection
1144
+     */
1145
+    public function getDatabaseConnection() {
1146
+        return $this->query('DatabaseConnection');
1147
+    }
1148
+
1149
+    /**
1150
+     * Returns the activity manager
1151
+     *
1152
+     * @return \OCP\Activity\IManager
1153
+     */
1154
+    public function getActivityManager() {
1155
+        return $this->query('ActivityManager');
1156
+    }
1157
+
1158
+    /**
1159
+     * Returns an job list for controlling background jobs
1160
+     *
1161
+     * @return \OCP\BackgroundJob\IJobList
1162
+     */
1163
+    public function getJobList() {
1164
+        return $this->query('JobList');
1165
+    }
1166
+
1167
+    /**
1168
+     * Returns a logger instance
1169
+     *
1170
+     * @return \OCP\ILogger
1171
+     */
1172
+    public function getLogger() {
1173
+        return $this->query('Logger');
1174
+    }
1175
+
1176
+    /**
1177
+     * Returns a router for generating and matching urls
1178
+     *
1179
+     * @return \OCP\Route\IRouter
1180
+     */
1181
+    public function getRouter() {
1182
+        return $this->query('Router');
1183
+    }
1184
+
1185
+    /**
1186
+     * Returns a search instance
1187
+     *
1188
+     * @return \OCP\ISearch
1189
+     */
1190
+    public function getSearch() {
1191
+        return $this->query('Search');
1192
+    }
1193
+
1194
+    /**
1195
+     * Returns a SecureRandom instance
1196
+     *
1197
+     * @return \OCP\Security\ISecureRandom
1198
+     */
1199
+    public function getSecureRandom() {
1200
+        return $this->query('SecureRandom');
1201
+    }
1202
+
1203
+    /**
1204
+     * Returns a Crypto instance
1205
+     *
1206
+     * @return \OCP\Security\ICrypto
1207
+     */
1208
+    public function getCrypto() {
1209
+        return $this->query('Crypto');
1210
+    }
1211
+
1212
+    /**
1213
+     * Returns a Hasher instance
1214
+     *
1215
+     * @return \OCP\Security\IHasher
1216
+     */
1217
+    public function getHasher() {
1218
+        return $this->query('Hasher');
1219
+    }
1220
+
1221
+    /**
1222
+     * Returns a CredentialsManager instance
1223
+     *
1224
+     * @return \OCP\Security\ICredentialsManager
1225
+     */
1226
+    public function getCredentialsManager() {
1227
+        return $this->query('CredentialsManager');
1228
+    }
1229
+
1230
+    /**
1231
+     * Returns an instance of the HTTP helper class
1232
+     *
1233
+     * @deprecated Use getHTTPClientService()
1234
+     * @return \OC\HTTPHelper
1235
+     */
1236
+    public function getHTTPHelper() {
1237
+        return $this->query('HTTPHelper');
1238
+    }
1239
+
1240
+    /**
1241
+     * Get the certificate manager for the user
1242
+     *
1243
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1244
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1245
+     */
1246
+    public function getCertificateManager($userId = '') {
1247
+        if ($userId === '') {
1248
+            $userSession = $this->getUserSession();
1249
+            $user = $userSession->getUser();
1250
+            if (is_null($user)) {
1251
+                return null;
1252
+            }
1253
+            $userId = $user->getUID();
1254
+        }
1255
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1256
+    }
1257
+
1258
+    /**
1259
+     * Returns an instance of the HTTP client service
1260
+     *
1261
+     * @return \OCP\Http\Client\IClientService
1262
+     */
1263
+    public function getHTTPClientService() {
1264
+        return $this->query('HttpClientService');
1265
+    }
1266
+
1267
+    /**
1268
+     * Create a new event source
1269
+     *
1270
+     * @return \OCP\IEventSource
1271
+     */
1272
+    public function createEventSource() {
1273
+        return new \OC_EventSource();
1274
+    }
1275
+
1276
+    /**
1277
+     * Get the active event logger
1278
+     *
1279
+     * The returned logger only logs data when debug mode is enabled
1280
+     *
1281
+     * @return \OCP\Diagnostics\IEventLogger
1282
+     */
1283
+    public function getEventLogger() {
1284
+        return $this->query('EventLogger');
1285
+    }
1286
+
1287
+    /**
1288
+     * Get the active query logger
1289
+     *
1290
+     * The returned logger only logs data when debug mode is enabled
1291
+     *
1292
+     * @return \OCP\Diagnostics\IQueryLogger
1293
+     */
1294
+    public function getQueryLogger() {
1295
+        return $this->query('QueryLogger');
1296
+    }
1297
+
1298
+    /**
1299
+     * Get the manager for temporary files and folders
1300
+     *
1301
+     * @return \OCP\ITempManager
1302
+     */
1303
+    public function getTempManager() {
1304
+        return $this->query('TempManager');
1305
+    }
1306
+
1307
+    /**
1308
+     * Get the app manager
1309
+     *
1310
+     * @return \OCP\App\IAppManager
1311
+     */
1312
+    public function getAppManager() {
1313
+        return $this->query('AppManager');
1314
+    }
1315
+
1316
+    /**
1317
+     * Creates a new mailer
1318
+     *
1319
+     * @return \OCP\Mail\IMailer
1320
+     */
1321
+    public function getMailer() {
1322
+        return $this->query('Mailer');
1323
+    }
1324
+
1325
+    /**
1326
+     * Get the webroot
1327
+     *
1328
+     * @return string
1329
+     */
1330
+    public function getWebRoot() {
1331
+        return $this->webRoot;
1332
+    }
1333
+
1334
+    /**
1335
+     * @return \OC\OCSClient
1336
+     */
1337
+    public function getOcsClient() {
1338
+        return $this->query('OcsClient');
1339
+    }
1340
+
1341
+    /**
1342
+     * @return \OCP\IDateTimeZone
1343
+     */
1344
+    public function getDateTimeZone() {
1345
+        return $this->query('DateTimeZone');
1346
+    }
1347
+
1348
+    /**
1349
+     * @return \OCP\IDateTimeFormatter
1350
+     */
1351
+    public function getDateTimeFormatter() {
1352
+        return $this->query('DateTimeFormatter');
1353
+    }
1354
+
1355
+    /**
1356
+     * @return \OCP\Files\Config\IMountProviderCollection
1357
+     */
1358
+    public function getMountProviderCollection() {
1359
+        return $this->query('MountConfigManager');
1360
+    }
1361
+
1362
+    /**
1363
+     * Get the IniWrapper
1364
+     *
1365
+     * @return IniGetWrapper
1366
+     */
1367
+    public function getIniWrapper() {
1368
+        return $this->query('IniWrapper');
1369
+    }
1370
+
1371
+    /**
1372
+     * @return \OCP\Command\IBus
1373
+     */
1374
+    public function getCommandBus() {
1375
+        return $this->query('AsyncCommandBus');
1376
+    }
1377
+
1378
+    /**
1379
+     * Get the trusted domain helper
1380
+     *
1381
+     * @return TrustedDomainHelper
1382
+     */
1383
+    public function getTrustedDomainHelper() {
1384
+        return $this->query('TrustedDomainHelper');
1385
+    }
1386
+
1387
+    /**
1388
+     * Get the locking provider
1389
+     *
1390
+     * @return \OCP\Lock\ILockingProvider
1391
+     * @since 8.1.0
1392
+     */
1393
+    public function getLockingProvider() {
1394
+        return $this->query('LockingProvider');
1395
+    }
1396
+
1397
+    /**
1398
+     * @return \OCP\Files\Mount\IMountManager
1399
+     **/
1400
+    function getMountManager() {
1401
+        return $this->query('MountManager');
1402
+    }
1403
+
1404
+    /** @return \OCP\Files\Config\IUserMountCache */
1405
+    function getUserMountCache() {
1406
+        return $this->query('UserMountCache');
1407
+    }
1408
+
1409
+    /**
1410
+     * Get the MimeTypeDetector
1411
+     *
1412
+     * @return \OCP\Files\IMimeTypeDetector
1413
+     */
1414
+    public function getMimeTypeDetector() {
1415
+        return $this->query('MimeTypeDetector');
1416
+    }
1417
+
1418
+    /**
1419
+     * Get the MimeTypeLoader
1420
+     *
1421
+     * @return \OCP\Files\IMimeTypeLoader
1422
+     */
1423
+    public function getMimeTypeLoader() {
1424
+        return $this->query('MimeTypeLoader');
1425
+    }
1426
+
1427
+    /**
1428
+     * Get the manager of all the capabilities
1429
+     *
1430
+     * @return \OC\CapabilitiesManager
1431
+     */
1432
+    public function getCapabilitiesManager() {
1433
+        return $this->query('CapabilitiesManager');
1434
+    }
1435
+
1436
+    /**
1437
+     * Get the EventDispatcher
1438
+     *
1439
+     * @return EventDispatcherInterface
1440
+     * @since 8.2.0
1441
+     */
1442
+    public function getEventDispatcher() {
1443
+        return $this->query('EventDispatcher');
1444
+    }
1445
+
1446
+    /**
1447
+     * Get the Notification Manager
1448
+     *
1449
+     * @return \OCP\Notification\IManager
1450
+     * @since 8.2.0
1451
+     */
1452
+    public function getNotificationManager() {
1453
+        return $this->query('NotificationManager');
1454
+    }
1455
+
1456
+    /**
1457
+     * @return \OCP\Comments\ICommentsManager
1458
+     */
1459
+    public function getCommentsManager() {
1460
+        return $this->query('CommentsManager');
1461
+    }
1462
+
1463
+    /**
1464
+     * @return \OC_Defaults
1465
+     */
1466
+    public function getThemingDefaults() {
1467
+        return $this->query('ThemingDefaults');
1468
+    }
1469
+
1470
+    /**
1471
+     * @return \OC\IntegrityCheck\Checker
1472
+     */
1473
+    public function getIntegrityCodeChecker() {
1474
+        return $this->query('IntegrityCodeChecker');
1475
+    }
1476
+
1477
+    /**
1478
+     * @return \OC\Session\CryptoWrapper
1479
+     */
1480
+    public function getSessionCryptoWrapper() {
1481
+        return $this->query('CryptoWrapper');
1482
+    }
1483
+
1484
+    /**
1485
+     * @return CsrfTokenManager
1486
+     */
1487
+    public function getCsrfTokenManager() {
1488
+        return $this->query('CsrfTokenManager');
1489
+    }
1490
+
1491
+    /**
1492
+     * @return Throttler
1493
+     */
1494
+    public function getBruteForceThrottler() {
1495
+        return $this->query('Throttler');
1496
+    }
1497
+
1498
+    /**
1499
+     * @return IContentSecurityPolicyManager
1500
+     */
1501
+    public function getContentSecurityPolicyManager() {
1502
+        return $this->query('ContentSecurityPolicyManager');
1503
+    }
1504
+
1505
+    /**
1506
+     * @return ContentSecurityPolicyNonceManager
1507
+     */
1508
+    public function getContentSecurityPolicyNonceManager() {
1509
+        return $this->query('ContentSecurityPolicyNonceManager');
1510
+    }
1511
+
1512
+    /**
1513
+     * Not a public API as of 8.2, wait for 9.0
1514
+     *
1515
+     * @return \OCA\Files_External\Service\BackendService
1516
+     */
1517
+    public function getStoragesBackendService() {
1518
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1519
+    }
1520
+
1521
+    /**
1522
+     * Not a public API as of 8.2, wait for 9.0
1523
+     *
1524
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1525
+     */
1526
+    public function getGlobalStoragesService() {
1527
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1528
+    }
1529
+
1530
+    /**
1531
+     * Not a public API as of 8.2, wait for 9.0
1532
+     *
1533
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1534
+     */
1535
+    public function getUserGlobalStoragesService() {
1536
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1537
+    }
1538
+
1539
+    /**
1540
+     * Not a public API as of 8.2, wait for 9.0
1541
+     *
1542
+     * @return \OCA\Files_External\Service\UserStoragesService
1543
+     */
1544
+    public function getUserStoragesService() {
1545
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1546
+    }
1547
+
1548
+    /**
1549
+     * @return \OCP\Share\IManager
1550
+     */
1551
+    public function getShareManager() {
1552
+        return $this->query('ShareManager');
1553
+    }
1554
+
1555
+    /**
1556
+     * Returns the LDAP Provider
1557
+     *
1558
+     * @return \OCP\LDAP\ILDAPProvider
1559
+     */
1560
+    public function getLDAPProvider() {
1561
+        return $this->query('LDAPProvider');
1562
+    }
1563
+
1564
+    /**
1565
+     * @return \OCP\Settings\IManager
1566
+     */
1567
+    public function getSettingsManager() {
1568
+        return $this->query('SettingsManager');
1569
+    }
1570
+
1571
+    /**
1572
+     * @return \OCP\Files\IAppData
1573
+     */
1574
+    public function getAppDataDir($app) {
1575
+        /** @var \OC\Files\AppData\Factory $factory */
1576
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1577
+        return $factory->get($app);
1578
+    }
1579
+
1580
+    /**
1581
+     * @return \OCP\Lockdown\ILockdownManager
1582
+     */
1583
+    public function getLockdownManager() {
1584
+        return $this->query('LockdownManager');
1585
+    }
1586
+
1587
+    /**
1588
+     * @return \OCP\Federation\ICloudIdManager
1589
+     */
1590
+    public function getCloudIdManager() {
1591
+        return $this->query(ICloudIdManager::class);
1592
+    }
1593 1593
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -122,12 +122,12 @@  discard block
 block discarded – undo
122 122
 		parent::__construct();
123 123
 		$this->webRoot = $webRoot;
124 124
 
125
-		$this->registerService('ContactsManager', function ($c) {
125
+		$this->registerService('ContactsManager', function($c) {
126 126
 			return new ContactsManager();
127 127
 		});
128 128
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
129 129
 
130
-		$this->registerService('PreviewManager', function (Server $c) {
130
+		$this->registerService('PreviewManager', function(Server $c) {
131 131
 			return new PreviewManager(
132 132
 				$c->getConfig(),
133 133
 				$c->getRootFolder(),
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
 			);
138 138
 		});
139 139
 
140
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
140
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
141 141
 			return new \OC\Preview\Watcher(
142 142
 				$c->getAppDataDir('preview')
143 143
 			);
144 144
 		});
145 145
 
146
-		$this->registerService('EncryptionManager', function (Server $c) {
146
+		$this->registerService('EncryptionManager', function(Server $c) {
147 147
 			$view = new View();
148 148
 			$util = new Encryption\Util(
149 149
 				$view,
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
 			);
162 162
 		});
163 163
 
164
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
164
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
165 165
 			$util = new Encryption\Util(
166 166
 				new View(),
167 167
 				$c->getUserManager(),
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 			return new Encryption\File($util);
172 172
 		});
173 173
 
174
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
174
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
175 175
 			$view = new View();
176 176
 			$util = new Encryption\Util(
177 177
 				$view,
@@ -182,27 +182,27 @@  discard block
 block discarded – undo
182 182
 
183 183
 			return new Encryption\Keys\Storage($view, $util);
184 184
 		});
185
-		$this->registerService('TagMapper', function (Server $c) {
185
+		$this->registerService('TagMapper', function(Server $c) {
186 186
 			return new TagMapper($c->getDatabaseConnection());
187 187
 		});
188
-		$this->registerService('TagManager', function (Server $c) {
188
+		$this->registerService('TagManager', function(Server $c) {
189 189
 			$tagMapper = $c->query('TagMapper');
190 190
 			return new TagManager($tagMapper, $c->getUserSession());
191 191
 		});
192
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
192
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
193 193
 			$config = $c->getConfig();
194 194
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
195 195
 			/** @var \OC\SystemTag\ManagerFactory $factory */
196 196
 			$factory = new $factoryClass($this);
197 197
 			return $factory;
198 198
 		});
199
-		$this->registerService('SystemTagManager', function (Server $c) {
199
+		$this->registerService('SystemTagManager', function(Server $c) {
200 200
 			return $c->query('SystemTagManagerFactory')->getManager();
201 201
 		});
202
-		$this->registerService('SystemTagObjectMapper', function (Server $c) {
202
+		$this->registerService('SystemTagObjectMapper', function(Server $c) {
203 203
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
204 204
 		});
205
-		$this->registerService('RootFolder', function (Server $c) {
205
+		$this->registerService('RootFolder', function(Server $c) {
206 206
 			$manager = \OC\Files\Filesystem::getMountManager(null);
207 207
 			$view = new View();
208 208
 			$root = new Root(
@@ -226,28 +226,28 @@  discard block
 block discarded – undo
226 226
 				return $c->query('RootFolder');
227 227
 			});
228 228
 		});
229
-		$this->registerService('UserManager', function (Server $c) {
229
+		$this->registerService('UserManager', function(Server $c) {
230 230
 			$config = $c->getConfig();
231 231
 			return new \OC\User\Manager($config);
232 232
 		});
233
-		$this->registerService('GroupManager', function (Server $c) {
233
+		$this->registerService('GroupManager', function(Server $c) {
234 234
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
235
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
235
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
236 236
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
237 237
 			});
238
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
238
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
239 239
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
240 240
 			});
241
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
241
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
242 242
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
243 243
 			});
244
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
244
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
245 245
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
246 246
 			});
247
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
247
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
248 248
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
249 249
 			});
250
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
250
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
251 251
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
252 252
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
253 253
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -265,11 +265,11 @@  discard block
 block discarded – undo
265 265
 			return new Store($session, $logger, $tokenProvider);
266 266
 		});
267 267
 		$this->registerAlias(IStore::class, Store::class);
268
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
268
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
269 269
 			$dbConnection = $c->getDatabaseConnection();
270 270
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
271 271
 		});
272
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
272
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
273 273
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
274 274
 			$crypto = $c->getCrypto();
275 275
 			$config = $c->getConfig();
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
279 279
 		});
280 280
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
281
-		$this->registerService('UserSession', function (Server $c) {
281
+		$this->registerService('UserSession', function(Server $c) {
282 282
 			$manager = $c->getUserManager();
283 283
 			$session = new \OC\Session\Memory('');
284 284
 			$timeFactory = new TimeFactory();
@@ -291,70 +291,70 @@  discard block
 block discarded – undo
291 291
 			}
292 292
 
293 293
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
294
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
294
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
295 295
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
296 296
 			});
297
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
297
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
298 298
 				/** @var $user \OC\User\User */
299 299
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
300 300
 			});
301
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
301
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
302 302
 				/** @var $user \OC\User\User */
303 303
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
304 304
 			});
305
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
305
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
306 306
 				/** @var $user \OC\User\User */
307 307
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
308 308
 			});
309
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
309
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
310 310
 				/** @var $user \OC\User\User */
311 311
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
312 312
 			});
313
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
313
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
314 314
 				/** @var $user \OC\User\User */
315 315
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
316 316
 			});
317
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
317
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
318 318
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
319 319
 			});
320
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
320
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
321 321
 				/** @var $user \OC\User\User */
322 322
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
323 323
 			});
324
-			$userSession->listen('\OC\User', 'logout', function () {
324
+			$userSession->listen('\OC\User', 'logout', function() {
325 325
 				\OC_Hook::emit('OC_User', 'logout', array());
326 326
 			});
327
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
327
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) {
328 328
 				/** @var $user \OC\User\User */
329 329
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
330 330
 			});
331 331
 			return $userSession;
332 332
 		});
333 333
 
334
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
334
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
335 335
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
336 336
 		});
337 337
 
338
-		$this->registerService('NavigationManager', function (Server $c) {
338
+		$this->registerService('NavigationManager', function(Server $c) {
339 339
 			return new \OC\NavigationManager($c->getAppManager(),
340 340
 				$c->getURLGenerator(),
341 341
 				$c->getL10NFactory(),
342 342
 				$c->getUserSession(),
343 343
 				$c->getGroupManager());
344 344
 		});
345
-		$this->registerService('AllConfig', function (Server $c) {
345
+		$this->registerService('AllConfig', function(Server $c) {
346 346
 			return new \OC\AllConfig(
347 347
 				$c->getSystemConfig()
348 348
 			);
349 349
 		});
350 350
 		$this->registerAlias(\OCP\IConfig::class, 'AllConfig');
351
-		$this->registerService('SystemConfig', function ($c) use ($config) {
351
+		$this->registerService('SystemConfig', function($c) use ($config) {
352 352
 			return new \OC\SystemConfig($config);
353 353
 		});
354
-		$this->registerService('AppConfig', function (Server $c) {
354
+		$this->registerService('AppConfig', function(Server $c) {
355 355
 			return new \OC\AppConfig($c->getDatabaseConnection());
356 356
 		});
357
-		$this->registerService('L10NFactory', function (Server $c) {
357
+		$this->registerService('L10NFactory', function(Server $c) {
358 358
 			return new \OC\L10N\Factory(
359 359
 				$c->getConfig(),
360 360
 				$c->getRequest(),
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 				\OC::$SERVERROOT
363 363
 			);
364 364
 		});
365
-		$this->registerService('URLGenerator', function (Server $c) {
365
+		$this->registerService('URLGenerator', function(Server $c) {
366 366
 			$config = $c->getConfig();
367 367
 			$cacheFactory = $c->getMemCacheFactory();
368 368
 			return new \OC\URLGenerator(
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
 			);
372 372
 		});
373 373
 		$this->registerAlias(IURLGenerator::class, 'URLGenerator');
374
-		$this->registerService('AppHelper', function ($c) {
374
+		$this->registerService('AppHelper', function($c) {
375 375
 			return new \OC\AppHelper();
376 376
 		});
377
-		$this->registerService('AppFetcher', function ($c) {
377
+		$this->registerService('AppFetcher', function($c) {
378 378
 			return new AppFetcher(
379 379
 				$this->getAppDataDir('appstore'),
380 380
 				$this->getHTTPClientService(),
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 				$this->getConfig()
383 383
 			);
384 384
 		});
385
-		$this->registerService('CategoryFetcher', function ($c) {
385
+		$this->registerService('CategoryFetcher', function($c) {
386 386
 			return new CategoryFetcher(
387 387
 				$this->getAppDataDir('appstore'),
388 388
 				$this->getHTTPClientService(),
@@ -390,19 +390,19 @@  discard block
 block discarded – undo
390 390
 				$this->getConfig()
391 391
 			);
392 392
 		});
393
-		$this->registerService('UserCache', function ($c) {
393
+		$this->registerService('UserCache', function($c) {
394 394
 			return new Cache\File();
395 395
 		});
396
-		$this->registerService('MemCacheFactory', function (Server $c) {
396
+		$this->registerService('MemCacheFactory', function(Server $c) {
397 397
 			$config = $c->getConfig();
398 398
 
399 399
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
400 400
 				$v = \OC_App::getAppVersions();
401
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
401
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
402 402
 				$version = implode(',', $v);
403 403
 				$instanceId = \OC_Util::getInstanceId();
404 404
 				$path = \OC::$SERVERROOT;
405
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
405
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
406 406
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
407 407
 					$config->getSystemValue('memcache.local', null),
408 408
 					$config->getSystemValue('memcache.distributed', null),
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 				'\\OC\\Memcache\\ArrayCache'
417 417
 			);
418 418
 		});
419
-		$this->registerService('RedisFactory', function (Server $c) {
419
+		$this->registerService('RedisFactory', function(Server $c) {
420 420
 			$systemConfig = $c->getSystemConfig();
421 421
 			return new RedisFactory($systemConfig);
422 422
 		});
423
-		$this->registerService('ActivityManager', function (Server $c) {
423
+		$this->registerService('ActivityManager', function(Server $c) {
424 424
 			return new \OC\Activity\Manager(
425 425
 				$c->getRequest(),
426 426
 				$c->getUserSession(),
@@ -428,13 +428,13 @@  discard block
 block discarded – undo
428 428
 				$c->query(IValidator::class)
429 429
 			);
430 430
 		});
431
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
431
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
432 432
 			return new \OC\Activity\EventMerger(
433 433
 				$c->getL10N('lib')
434 434
 			);
435 435
 		});
436 436
 		$this->registerAlias(IValidator::class, Validator::class);
437
-		$this->registerService('AvatarManager', function (Server $c) {
437
+		$this->registerService('AvatarManager', function(Server $c) {
438 438
 			return new AvatarManager(
439 439
 				$c->getUserManager(),
440 440
 				$c->getAppDataDir('avatar'),
@@ -443,14 +443,14 @@  discard block
 block discarded – undo
443 443
 				$c->getConfig()
444 444
 			);
445 445
 		});
446
-		$this->registerService('Logger', function (Server $c) {
446
+		$this->registerService('Logger', function(Server $c) {
447 447
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
448 448
 			$logger = Log::getLogClass($logType);
449 449
 			call_user_func(array($logger, 'init'));
450 450
 
451 451
 			return new Log($logger);
452 452
 		});
453
-		$this->registerService('JobList', function (Server $c) {
453
+		$this->registerService('JobList', function(Server $c) {
454 454
 			$config = $c->getConfig();
455 455
 			return new \OC\BackgroundJob\JobList(
456 456
 				$c->getDatabaseConnection(),
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 				new TimeFactory()
459 459
 			);
460 460
 		});
461
-		$this->registerService('Router', function (Server $c) {
461
+		$this->registerService('Router', function(Server $c) {
462 462
 			$cacheFactory = $c->getMemCacheFactory();
463 463
 			$logger = $c->getLogger();
464 464
 			if ($cacheFactory->isAvailable()) {
@@ -468,22 +468,22 @@  discard block
 block discarded – undo
468 468
 			}
469 469
 			return $router;
470 470
 		});
471
-		$this->registerService('Search', function ($c) {
471
+		$this->registerService('Search', function($c) {
472 472
 			return new Search();
473 473
 		});
474
-		$this->registerService('SecureRandom', function ($c) {
474
+		$this->registerService('SecureRandom', function($c) {
475 475
 			return new SecureRandom();
476 476
 		});
477
-		$this->registerService('Crypto', function (Server $c) {
477
+		$this->registerService('Crypto', function(Server $c) {
478 478
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
479 479
 		});
480
-		$this->registerService('Hasher', function (Server $c) {
480
+		$this->registerService('Hasher', function(Server $c) {
481 481
 			return new Hasher($c->getConfig());
482 482
 		});
483
-		$this->registerService('CredentialsManager', function (Server $c) {
483
+		$this->registerService('CredentialsManager', function(Server $c) {
484 484
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
485 485
 		});
486
-		$this->registerService('DatabaseConnection', function (Server $c) {
486
+		$this->registerService('DatabaseConnection', function(Server $c) {
487 487
 			$systemConfig = $c->getSystemConfig();
488 488
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
489 489
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -495,14 +495,14 @@  discard block
 block discarded – undo
495 495
 			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
496 496
 			return $connection;
497 497
 		});
498
-		$this->registerService('HTTPHelper', function (Server $c) {
498
+		$this->registerService('HTTPHelper', function(Server $c) {
499 499
 			$config = $c->getConfig();
500 500
 			return new HTTPHelper(
501 501
 				$config,
502 502
 				$c->getHTTPClientService()
503 503
 			);
504 504
 		});
505
-		$this->registerService('HttpClientService', function (Server $c) {
505
+		$this->registerService('HttpClientService', function(Server $c) {
506 506
 			$user = \OC_User::getUser();
507 507
 			$uid = $user ? $user : null;
508 508
 			return new ClientService(
@@ -510,27 +510,27 @@  discard block
 block discarded – undo
510 510
 				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
511 511
 			);
512 512
 		});
513
-		$this->registerService('EventLogger', function (Server $c) {
513
+		$this->registerService('EventLogger', function(Server $c) {
514 514
 			if ($c->getSystemConfig()->getValue('debug', false)) {
515 515
 				return new EventLogger();
516 516
 			} else {
517 517
 				return new NullEventLogger();
518 518
 			}
519 519
 		});
520
-		$this->registerService('QueryLogger', function (Server $c) {
520
+		$this->registerService('QueryLogger', function(Server $c) {
521 521
 			if ($c->getSystemConfig()->getValue('debug', false)) {
522 522
 				return new QueryLogger();
523 523
 			} else {
524 524
 				return new NullQueryLogger();
525 525
 			}
526 526
 		});
527
-		$this->registerService('TempManager', function (Server $c) {
527
+		$this->registerService('TempManager', function(Server $c) {
528 528
 			return new TempManager(
529 529
 				$c->getLogger(),
530 530
 				$c->getConfig()
531 531
 			);
532 532
 		});
533
-		$this->registerService('AppManager', function (Server $c) {
533
+		$this->registerService('AppManager', function(Server $c) {
534 534
 			return new \OC\App\AppManager(
535 535
 				$c->getUserSession(),
536 536
 				$c->getAppConfig(),
@@ -539,13 +539,13 @@  discard block
 block discarded – undo
539 539
 				$c->getEventDispatcher()
540 540
 			);
541 541
 		});
542
-		$this->registerService('DateTimeZone', function (Server $c) {
542
+		$this->registerService('DateTimeZone', function(Server $c) {
543 543
 			return new DateTimeZone(
544 544
 				$c->getConfig(),
545 545
 				$c->getSession()
546 546
 			);
547 547
 		});
548
-		$this->registerService('DateTimeFormatter', function (Server $c) {
548
+		$this->registerService('DateTimeFormatter', function(Server $c) {
549 549
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
550 550
 
551 551
 			return new DateTimeFormatter(
@@ -553,16 +553,16 @@  discard block
 block discarded – undo
553 553
 				$c->getL10N('lib', $language)
554 554
 			);
555 555
 		});
556
-		$this->registerService('UserMountCache', function (Server $c) {
556
+		$this->registerService('UserMountCache', function(Server $c) {
557 557
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
558 558
 			$listener = new UserMountCacheListener($mountCache);
559 559
 			$listener->listen($c->getUserManager());
560 560
 			return $mountCache;
561 561
 		});
562
-		$this->registerService('MountConfigManager', function (Server $c) {
562
+		$this->registerService('MountConfigManager', function(Server $c) {
563 563
 			$loader = \OC\Files\Filesystem::getLoader();
564 564
 			$mountCache = $c->query('UserMountCache');
565
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
565
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
566 566
 
567 567
 			// builtin providers
568 568
 
@@ -573,14 +573,14 @@  discard block
 block discarded – undo
573 573
 
574 574
 			return $manager;
575 575
 		});
576
-		$this->registerService('IniWrapper', function ($c) {
576
+		$this->registerService('IniWrapper', function($c) {
577 577
 			return new IniGetWrapper();
578 578
 		});
579
-		$this->registerService('AsyncCommandBus', function (Server $c) {
579
+		$this->registerService('AsyncCommandBus', function(Server $c) {
580 580
 			$jobList = $c->getJobList();
581 581
 			return new AsyncBus($jobList);
582 582
 		});
583
-		$this->registerService('TrustedDomainHelper', function ($c) {
583
+		$this->registerService('TrustedDomainHelper', function($c) {
584 584
 			return new TrustedDomainHelper($this->getConfig());
585 585
 		});
586 586
 		$this->registerService('Throttler', function(Server $c) {
@@ -591,10 +591,10 @@  discard block
 block discarded – undo
591 591
 				$c->getConfig()
592 592
 			);
593 593
 		});
594
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
594
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
595 595
 			// IConfig and IAppManager requires a working database. This code
596 596
 			// might however be called when ownCloud is not yet setup.
597
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
597
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
598 598
 				$config = $c->getConfig();
599 599
 				$appManager = $c->getAppManager();
600 600
 			} else {
@@ -612,7 +612,7 @@  discard block
 block discarded – undo
612 612
 					$c->getTempManager()
613 613
 			);
614 614
 		});
615
-		$this->registerService('Request', function ($c) {
615
+		$this->registerService('Request', function($c) {
616 616
 			if (isset($this['urlParams'])) {
617 617
 				$urlParams = $this['urlParams'];
618 618
 			} else {
@@ -646,7 +646,7 @@  discard block
 block discarded – undo
646 646
 				$stream
647 647
 			);
648 648
 		});
649
-		$this->registerService('Mailer', function (Server $c) {
649
+		$this->registerService('Mailer', function(Server $c) {
650 650
 			return new Mailer(
651 651
 				$c->getConfig(),
652 652
 				$c->getLogger(),
@@ -656,14 +656,14 @@  discard block
 block discarded – undo
656 656
 		$this->registerService('LDAPProvider', function(Server $c) {
657 657
 			$config = $c->getConfig();
658 658
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
659
-			if(is_null($factoryClass)) {
659
+			if (is_null($factoryClass)) {
660 660
 				throw new \Exception('ldapProviderFactory not set');
661 661
 			}
662 662
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
663 663
 			$factory = new $factoryClass($this);
664 664
 			return $factory->getLDAPProvider();
665 665
 		});
666
-		$this->registerService('LockingProvider', function (Server $c) {
666
+		$this->registerService('LockingProvider', function(Server $c) {
667 667
 			$ini = $c->getIniWrapper();
668 668
 			$config = $c->getConfig();
669 669
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -678,29 +678,29 @@  discard block
 block discarded – undo
678 678
 			}
679 679
 			return new NoopLockingProvider();
680 680
 		});
681
-		$this->registerService('MountManager', function () {
681
+		$this->registerService('MountManager', function() {
682 682
 			return new \OC\Files\Mount\Manager();
683 683
 		});
684
-		$this->registerService('MimeTypeDetector', function (Server $c) {
684
+		$this->registerService('MimeTypeDetector', function(Server $c) {
685 685
 			return new \OC\Files\Type\Detection(
686 686
 				$c->getURLGenerator(),
687 687
 				\OC::$configDir,
688
-				\OC::$SERVERROOT . '/resources/config/'
688
+				\OC::$SERVERROOT.'/resources/config/'
689 689
 			);
690 690
 		});
691
-		$this->registerService('MimeTypeLoader', function (Server $c) {
691
+		$this->registerService('MimeTypeLoader', function(Server $c) {
692 692
 			return new \OC\Files\Type\Loader(
693 693
 				$c->getDatabaseConnection()
694 694
 			);
695 695
 		});
696
-		$this->registerService('NotificationManager', function (Server $c) {
696
+		$this->registerService('NotificationManager', function(Server $c) {
697 697
 			return new Manager(
698 698
 				$c->query(IValidator::class)
699 699
 			);
700 700
 		});
701
-		$this->registerService('CapabilitiesManager', function (Server $c) {
701
+		$this->registerService('CapabilitiesManager', function(Server $c) {
702 702
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
703
-			$manager->registerCapability(function () use ($c) {
703
+			$manager->registerCapability(function() use ($c) {
704 704
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
705 705
 			});
706 706
 			return $manager;
@@ -738,10 +738,10 @@  discard block
 block discarded – undo
738 738
 			}
739 739
 			return new \OC_Defaults();
740 740
 		});
741
-		$this->registerService('EventDispatcher', function () {
741
+		$this->registerService('EventDispatcher', function() {
742 742
 			return new EventDispatcher();
743 743
 		});
744
-		$this->registerService('CryptoWrapper', function (Server $c) {
744
+		$this->registerService('CryptoWrapper', function(Server $c) {
745 745
 			// FIXME: Instantiiated here due to cyclic dependency
746 746
 			$request = new Request(
747 747
 				[
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 				$request
767 767
 			);
768 768
 		});
769
-		$this->registerService('CsrfTokenManager', function (Server $c) {
769
+		$this->registerService('CsrfTokenManager', function(Server $c) {
770 770
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
771 771
 
772 772
 			return new CsrfTokenManager(
@@ -774,10 +774,10 @@  discard block
 block discarded – undo
774 774
 				$c->query(SessionStorage::class)
775 775
 			);
776 776
 		});
777
-		$this->registerService(SessionStorage::class, function (Server $c) {
777
+		$this->registerService(SessionStorage::class, function(Server $c) {
778 778
 			return new SessionStorage($c->getSession());
779 779
 		});
780
-		$this->registerService('ContentSecurityPolicyManager', function (Server $c) {
780
+		$this->registerService('ContentSecurityPolicyManager', function(Server $c) {
781 781
 			return new ContentSecurityPolicyManager();
782 782
 		});
783 783
 		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
@@ -823,23 +823,23 @@  discard block
 block discarded – undo
823 823
 			);
824 824
 			return $manager;
825 825
 		});
826
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
826
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
827 827
 			return new \OC\Files\AppData\Factory(
828 828
 				$c->getRootFolder(),
829 829
 				$c->getSystemConfig()
830 830
 			);
831 831
 		});
832 832
 
833
-		$this->registerService('LockdownManager', function (Server $c) {
833
+		$this->registerService('LockdownManager', function(Server $c) {
834 834
 			return new LockdownManager();
835 835
 		});
836 836
 
837
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
837
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
838 838
 			return new CloudIdManager();
839 839
 		});
840 840
 
841 841
 		/* To trick DI since we don't extend the DIContainer here */
842
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
842
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
843 843
 			return new CleanPreviewsBackgroundJob(
844 844
 				$c->getRootFolder(),
845 845
 				$c->getLogger(),
@@ -983,7 +983,7 @@  discard block
 block discarded – undo
983 983
 	 * @deprecated since 9.2.0 use IAppData
984 984
 	 */
985 985
 	public function getAppFolder() {
986
-		$dir = '/' . \OC_App::getCurrentApp();
986
+		$dir = '/'.\OC_App::getCurrentApp();
987 987
 		$root = $this->getRootFolder();
988 988
 		if (!$root->nodeExists($dir)) {
989 989
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/ContactsStore.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -29,61 +29,61 @@
 block discarded – undo
29 29
 
30 30
 class ContactsStore {
31 31
 
32
-	/** @var IManager */
33
-	private $contactsManager;
34
-
35
-	/**
36
-	 * @param IManager $contactsManager
37
-	 */
38
-	public function __construct(IManager $contactsManager) {
39
-		$this->contactsManager = $contactsManager;
40
-	}
41
-
42
-	/**
43
-	 * @param string|null $filter
44
-	 * @return IEntry[]
45
-	 */
46
-	public function getContacts($filter) {
47
-		$allContacts = $this->contactsManager->search($filter ?: '', [
48
-			'FN',
49
-		]);
50
-
51
-		return array_map(function(array $contact) {
52
-			return $this->contactArrayToEntry($contact);
53
-		}, $allContacts);
54
-	}
55
-
56
-	/**
57
-	 * @param array $contact
58
-	 * @return Entry
59
-	 */
60
-	private function contactArrayToEntry(array $contact) {
61
-		$entry = new Entry();
62
-
63
-		if (isset($contact['id'])) {
64
-			$entry->setId($contact['id']);
65
-		}
66
-
67
-		if (isset($contact['FN'])) {
68
-			$entry->setFullName($contact['FN']);
69
-		}
70
-
71
-		$avatarPrefix = "VALUE=uri:";
72
-		if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
73
-			$entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
74
-		}
75
-
76
-		if (isset($contact['EMAIL'])) {
77
-			foreach ($contact['EMAIL'] as $email) {
78
-				$entry->addEMailAddress($email);
79
-			}
80
-		}
81
-
82
-		// Attach all other properties to the entry too because some
83
-		// providers might make use of it.
84
-		$entry->setProperties($contact);
85
-
86
-		return $entry;
87
-	}
32
+    /** @var IManager */
33
+    private $contactsManager;
34
+
35
+    /**
36
+     * @param IManager $contactsManager
37
+     */
38
+    public function __construct(IManager $contactsManager) {
39
+        $this->contactsManager = $contactsManager;
40
+    }
41
+
42
+    /**
43
+     * @param string|null $filter
44
+     * @return IEntry[]
45
+     */
46
+    public function getContacts($filter) {
47
+        $allContacts = $this->contactsManager->search($filter ?: '', [
48
+            'FN',
49
+        ]);
50
+
51
+        return array_map(function(array $contact) {
52
+            return $this->contactArrayToEntry($contact);
53
+        }, $allContacts);
54
+    }
55
+
56
+    /**
57
+     * @param array $contact
58
+     * @return Entry
59
+     */
60
+    private function contactArrayToEntry(array $contact) {
61
+        $entry = new Entry();
62
+
63
+        if (isset($contact['id'])) {
64
+            $entry->setId($contact['id']);
65
+        }
66
+
67
+        if (isset($contact['FN'])) {
68
+            $entry->setFullName($contact['FN']);
69
+        }
70
+
71
+        $avatarPrefix = "VALUE=uri:";
72
+        if (isset($contact['PHOTO']) && strpos($contact['PHOTO'], $avatarPrefix) === 0) {
73
+            $entry->setAvatar(substr($contact['PHOTO'], strlen($avatarPrefix)));
74
+        }
75
+
76
+        if (isset($contact['EMAIL'])) {
77
+            foreach ($contact['EMAIL'] as $email) {
78
+                $entry->addEMailAddress($email);
79
+            }
80
+        }
81
+
82
+        // Attach all other properties to the entry too because some
83
+        // providers might make use of it.
84
+        $entry->setProperties($contact);
85
+
86
+        return $entry;
87
+    }
88 88
 
89 89
 }
Please login to merge, or discard this patch.
lib/private/Contacts/ContactsMenu/Entry.php 1 patch
Indentation   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -29,141 +29,141 @@
 block discarded – undo
29 29
 
30 30
 class Entry implements IEntry {
31 31
 
32
-	/** @var string|int|null */
33
-	private $id = null;
34
-
35
-	/** @var string */
36
-	private $fullName = '';
37
-
38
-	/** @var string[] */
39
-	private $emailAddresses = [];
40
-
41
-	/** @var string|null */
42
-	private $avatar;
43
-
44
-	/** @var IAction[] */
45
-	private $actions = [];
46
-
47
-	/** @var array */
48
-	private $properties = [];
49
-
50
-	/**
51
-	 * @param string $id
52
-	 */
53
-	public function setId($id) {
54
-		$this->id = $id;
55
-	}
56
-
57
-	/**
58
-	 * @param string $displayName
59
-	 */
60
-	public function setFullName($displayName) {
61
-		$this->fullName = $displayName;
62
-	}
63
-
64
-	/**
65
-	 * @return string
66
-	 */
67
-	public function getFullName() {
68
-		return $this->fullName;
69
-	}
70
-
71
-	/**
72
-	 * @param string $address
73
-	 */
74
-	public function addEMailAddress($address) {
75
-		$this->emailAddresses[] = $address;
76
-	}
77
-
78
-	/**
79
-	 * @return string
80
-	 */
81
-	public function getEMailAddresses() {
82
-		return $this->emailAddresses;
83
-	}
84
-
85
-	/**
86
-	 * @param string $avatar
87
-	 */
88
-	public function setAvatar($avatar) {
89
-		$this->avatar = $avatar;
90
-	}
91
-
92
-	/**
93
-	 * @return string
94
-	 */
95
-	public function getAvatar() {
96
-		return $this->avatar;
97
-	}
98
-
99
-	/**
100
-	 * @param IAction $action
101
-	 */
102
-	public function addAction(IAction $action) {
103
-		$this->actions[] = $action;
104
-		$this->sortActions();
105
-	}
106
-
107
-	/**
108
-	 * @return IAction[]
109
-	 */
110
-	public function getActions() {
111
-		return $this->actions;
112
-	}
113
-
114
-	/**
115
-	 * sort the actions by priority and name
116
-	 */
117
-	private function sortActions() {
118
-		usort($this->actions, function(IAction $action1, IAction $action2) {
119
-			$prio1 = $action1->getPriority();
120
-			$prio2 = $action2->getPriority();
121
-
122
-			if ($prio1 === $prio2) {
123
-				// Ascending order for same priority
124
-				return strcasecmp($action1->getName(), $action2->getName());
125
-			}
126
-
127
-			// Descending order when priority differs
128
-			return $prio2 - $prio1;
129
-		});
130
-	}
131
-
132
-	/**
133
-	 * @param array $contact key-value array containing additional properties
134
-	 */
135
-	public function setProperties(array $contact) {
136
-		$this->properties = $contact;
137
-	}
138
-
139
-	/**
140
-	 * @param string $key
141
-	 * @return mixed
142
-	 */
143
-	public function getProperty($key) {
144
-		if (!isset($this->properties[$key])) {
145
-			return null;
146
-		}
147
-		return $this->properties[$key];
148
-	}
149
-
150
-	/**
151
-	 * @return array
152
-	 */
153
-	public function jsonSerialize() {
154
-		$topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
155
-		$otherActions = array_map(function(IAction $action) {
156
-			return $action->jsonSerialize();
157
-		}, array_slice($this->actions, 1));
158
-
159
-		return [
160
-			'id' => $this->id,
161
-			'fullName' => $this->fullName,
162
-			'avatar' => $this->getAvatar(),
163
-			'topAction' => $topAction,
164
-			'actions' => $otherActions,
165
-			'lastMessage' => '',
166
-		];
167
-	}
32
+    /** @var string|int|null */
33
+    private $id = null;
34
+
35
+    /** @var string */
36
+    private $fullName = '';
37
+
38
+    /** @var string[] */
39
+    private $emailAddresses = [];
40
+
41
+    /** @var string|null */
42
+    private $avatar;
43
+
44
+    /** @var IAction[] */
45
+    private $actions = [];
46
+
47
+    /** @var array */
48
+    private $properties = [];
49
+
50
+    /**
51
+     * @param string $id
52
+     */
53
+    public function setId($id) {
54
+        $this->id = $id;
55
+    }
56
+
57
+    /**
58
+     * @param string $displayName
59
+     */
60
+    public function setFullName($displayName) {
61
+        $this->fullName = $displayName;
62
+    }
63
+
64
+    /**
65
+     * @return string
66
+     */
67
+    public function getFullName() {
68
+        return $this->fullName;
69
+    }
70
+
71
+    /**
72
+     * @param string $address
73
+     */
74
+    public function addEMailAddress($address) {
75
+        $this->emailAddresses[] = $address;
76
+    }
77
+
78
+    /**
79
+     * @return string
80
+     */
81
+    public function getEMailAddresses() {
82
+        return $this->emailAddresses;
83
+    }
84
+
85
+    /**
86
+     * @param string $avatar
87
+     */
88
+    public function setAvatar($avatar) {
89
+        $this->avatar = $avatar;
90
+    }
91
+
92
+    /**
93
+     * @return string
94
+     */
95
+    public function getAvatar() {
96
+        return $this->avatar;
97
+    }
98
+
99
+    /**
100
+     * @param IAction $action
101
+     */
102
+    public function addAction(IAction $action) {
103
+        $this->actions[] = $action;
104
+        $this->sortActions();
105
+    }
106
+
107
+    /**
108
+     * @return IAction[]
109
+     */
110
+    public function getActions() {
111
+        return $this->actions;
112
+    }
113
+
114
+    /**
115
+     * sort the actions by priority and name
116
+     */
117
+    private function sortActions() {
118
+        usort($this->actions, function(IAction $action1, IAction $action2) {
119
+            $prio1 = $action1->getPriority();
120
+            $prio2 = $action2->getPriority();
121
+
122
+            if ($prio1 === $prio2) {
123
+                // Ascending order for same priority
124
+                return strcasecmp($action1->getName(), $action2->getName());
125
+            }
126
+
127
+            // Descending order when priority differs
128
+            return $prio2 - $prio1;
129
+        });
130
+    }
131
+
132
+    /**
133
+     * @param array $contact key-value array containing additional properties
134
+     */
135
+    public function setProperties(array $contact) {
136
+        $this->properties = $contact;
137
+    }
138
+
139
+    /**
140
+     * @param string $key
141
+     * @return mixed
142
+     */
143
+    public function getProperty($key) {
144
+        if (!isset($this->properties[$key])) {
145
+            return null;
146
+        }
147
+        return $this->properties[$key];
148
+    }
149
+
150
+    /**
151
+     * @return array
152
+     */
153
+    public function jsonSerialize() {
154
+        $topAction = !empty($this->actions) ? $this->actions[0]->jsonSerialize() : null;
155
+        $otherActions = array_map(function(IAction $action) {
156
+            return $action->jsonSerialize();
157
+        }, array_slice($this->actions, 1));
158
+
159
+        return [
160
+            'id' => $this->id,
161
+            'fullName' => $this->fullName,
162
+            'avatar' => $this->getAvatar(),
163
+            'topAction' => $topAction,
164
+            'actions' => $otherActions,
165
+            'lastMessage' => '',
166
+        ];
167
+    }
168 168
 
169 169
 }
Please login to merge, or discard this patch.
lib/public/Contacts/ContactsMenu/IEntry.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -31,36 +31,36 @@
 block discarded – undo
31 31
  */
32 32
 interface IEntry extends JsonSerializable {
33 33
 
34
-	/**
35
-	 * @since 12.0
36
-	 * @return string
37
-	 */
38
-	public function getFullName();
34
+    /**
35
+     * @since 12.0
36
+     * @return string
37
+     */
38
+    public function getFullName();
39 39
 
40
-	/**
41
-	 * @since 12.0
42
-	 * @return string[]
43
-	 */
44
-	public function getEMailAddresses();
40
+    /**
41
+     * @since 12.0
42
+     * @return string[]
43
+     */
44
+    public function getEMailAddresses();
45 45
 
46
-	/**
47
-	 * @since 12.0
48
-	 * @return string|null image URI
49
-	 */
50
-	public function getAvatar();
46
+    /**
47
+     * @since 12.0
48
+     * @return string|null image URI
49
+     */
50
+    public function getAvatar();
51 51
 
52
-	/**
53
-	 * @since 12.0
54
-	 * @param IAction $action an action to show in the contacts menu
55
-	 */
56
-	public function addAction(IAction $action);
52
+    /**
53
+     * @since 12.0
54
+     * @param IAction $action an action to show in the contacts menu
55
+     */
56
+    public function addAction(IAction $action);
57 57
 
58
-	/**
59
-	 * Get an arbitrary property from the contact
60
-	 *
61
-	 * @since 12.0
62
-	 * @param string $key
63
-	 * @return mixed the value of the property or null
64
-	 */
65
-	public function getProperty($key);
58
+    /**
59
+     * Get an arbitrary property from the contact
60
+     *
61
+     * @since 12.0
62
+     * @param string $key
63
+     * @return mixed the value of the property or null
64
+     */
65
+    public function getProperty($key);
66 66
 }
Please login to merge, or discard this patch.