Completed
Pull Request — master (#3531)
by Julius
15:36
created
apps/dav/lib/CalDAV/PublicCalendarRoot.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,6 @@
 block discarded – undo
21 21
 namespace OCA\DAV\CalDAV;
22 22
 
23 23
 use Sabre\DAV\Collection;
24
-use Sabre\DAV\Exception\NotFound;
25 24
 
26 25
 class PublicCalendarRoot extends Collection {
27 26
 
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,43 +25,43 @@
 block discarded – undo
25 25
 
26 26
 class PublicCalendarRoot extends Collection {
27 27
 
28
-	/** @var CalDavBackend */
29
-	protected $caldavBackend;
28
+    /** @var CalDavBackend */
29
+    protected $caldavBackend;
30 30
 
31
-	/** @var \OCP\IL10N */
32
-	protected $l10n;
31
+    /** @var \OCP\IL10N */
32
+    protected $l10n;
33 33
 
34
-	function __construct(CalDavBackend $caldavBackend) {
35
-		$this->caldavBackend = $caldavBackend;
36
-		$this->l10n = \OC::$server->getL10N('dav');
37
-	}
34
+    function __construct(CalDavBackend $caldavBackend) {
35
+        $this->caldavBackend = $caldavBackend;
36
+        $this->l10n = \OC::$server->getL10N('dav');
37
+    }
38 38
 
39
-	/**
40
-	 * @inheritdoc
41
-	 */
42
-	function getName() {
43
-		return 'public-calendars';
44
-	}
39
+    /**
40
+     * @inheritdoc
41
+     */
42
+    function getName() {
43
+        return 'public-calendars';
44
+    }
45 45
 
46
-	/**
47
-	 * @inheritdoc
48
-	 */
49
-	function getChild($name) {
50
-		$calendar = $this->caldavBackend->getPublicCalendar($name);
51
-		return new Calendar($this->caldavBackend, $calendar, $this->l10n);
52
-	}
46
+    /**
47
+     * @inheritdoc
48
+     */
49
+    function getChild($name) {
50
+        $calendar = $this->caldavBackend->getPublicCalendar($name);
51
+        return new Calendar($this->caldavBackend, $calendar, $this->l10n);
52
+    }
53 53
 
54
-	/**
55
-	 * @inheritdoc
56
-	 */
57
-	function getChildren() {
58
-		$calendars = $this->caldavBackend->getPublicCalendars();
59
-		$children = [];
60
-		foreach ($calendars as $calendar) {
61
-			// TODO: maybe implement a new class PublicCalendar ???
62
-			$children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
63
-		}
54
+    /**
55
+     * @inheritdoc
56
+     */
57
+    function getChildren() {
58
+        $calendars = $this->caldavBackend->getPublicCalendars();
59
+        $children = [];
60
+        foreach ($calendars as $calendar) {
61
+            // TODO: maybe implement a new class PublicCalendar ???
62
+            $children[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
63
+        }
64 64
 
65
-		return $children;
66
-	}
65
+        return $children;
66
+    }
67 67
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Http/Output.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
 	private $webRoot;
35 35
 
36 36
 	/**
37
-	 * @param $webRoot
37
+	 * @param string $webRoot
38 38
 	 */
39 39
 	public function __construct($webRoot) {
40 40
 		$this->webRoot = $webRoot;
Please login to merge, or discard this patch.
Indentation   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -30,70 +30,70 @@
 block discarded – undo
30 30
  * Very thin wrapper class to make output testable
31 31
  */
32 32
 class Output implements IOutput {
33
-	/** @var string */
34
-	private $webRoot;
33
+    /** @var string */
34
+    private $webRoot;
35 35
 
36
-	/**
37
-	 * @param $webRoot
38
-	 */
39
-	public function __construct($webRoot) {
40
-		$this->webRoot = $webRoot;
41
-	}
36
+    /**
37
+     * @param $webRoot
38
+     */
39
+    public function __construct($webRoot) {
40
+        $this->webRoot = $webRoot;
41
+    }
42 42
 
43
-	/**
44
-	 * @param string $out
45
-	 */
46
-	public function setOutput($out) {
47
-		print($out);
48
-	}
43
+    /**
44
+     * @param string $out
45
+     */
46
+    public function setOutput($out) {
47
+        print($out);
48
+    }
49 49
 
50
-	/**
51
-	 * @param string|resource $path or file handle
52
-	 *
53
-	 * @return bool false if an error occurred
54
-	 */
55
-	public function setReadfile($path) {
56
-		if (is_resource($path)) {
57
-			$output = fopen('php://output', 'w');
58
-			return stream_copy_to_stream($path, $output) > 0;
59
-		} else {
60
-			return @readfile($path);
61
-		}
62
-	}
50
+    /**
51
+     * @param string|resource $path or file handle
52
+     *
53
+     * @return bool false if an error occurred
54
+     */
55
+    public function setReadfile($path) {
56
+        if (is_resource($path)) {
57
+            $output = fopen('php://output', 'w');
58
+            return stream_copy_to_stream($path, $output) > 0;
59
+        } else {
60
+            return @readfile($path);
61
+        }
62
+    }
63 63
 
64
-	/**
65
-	 * @param string $header
66
-	 */
67
-	public function setHeader($header) {
68
-		header($header);
69
-	}
64
+    /**
65
+     * @param string $header
66
+     */
67
+    public function setHeader($header) {
68
+        header($header);
69
+    }
70 70
 
71
-	/**
72
-	 * @param int $code sets the http status code
73
-	 */
74
-	public function setHttpResponseCode($code) {
75
-		http_response_code($code);
76
-	}
71
+    /**
72
+     * @param int $code sets the http status code
73
+     */
74
+    public function setHttpResponseCode($code) {
75
+        http_response_code($code);
76
+    }
77 77
 
78
-	/**
79
-	 * @return int returns the current http response code
80
-	 */
81
-	public function getHttpResponseCode() {
82
-		return http_response_code();
83
-	}
78
+    /**
79
+     * @return int returns the current http response code
80
+     */
81
+    public function getHttpResponseCode() {
82
+        return http_response_code();
83
+    }
84 84
 
85
-	/**
86
-	 * @param string $name
87
-	 * @param string $value
88
-	 * @param int $expire
89
-	 * @param string $path
90
-	 * @param string $domain
91
-	 * @param bool $secure
92
-	 * @param bool $httpOnly
93
-	 */
94
-	public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
95
-		$path = $this->webRoot ? : '/';
96
-		setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
97
-	}
85
+    /**
86
+     * @param string $name
87
+     * @param string $value
88
+     * @param int $expire
89
+     * @param string $path
90
+     * @param string $domain
91
+     * @param bool $secure
92
+     * @param bool $httpOnly
93
+     */
94
+    public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
95
+        $path = $this->webRoot ? : '/';
96
+        setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
97
+    }
98 98
 
99 99
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -92,7 +92,7 @@
 block discarded – undo
92 92
 	 * @param bool $httpOnly
93 93
 	 */
94 94
 	public function setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly) {
95
-		$path = $this->webRoot ? : '/';
95
+		$path = $this->webRoot ?: '/';
96 96
 		setcookie($name, $value, $expire, $path, $domain, $secure, $httpOnly);
97 97
 	}
98 98
 
Please login to merge, or discard this patch.
apps/files_external/lib/Service/DBConfigService.php 3 patches
Doc Comments   +16 added lines patch added patch discarded remove patch
@@ -89,6 +89,9 @@  discard block
 block discarded – undo
89 89
 		return $this->getMountsFromQuery($query);
90 90
 	}
91 91
 
92
+	/**
93
+	 * @param string $userId
94
+	 */
92 95
 	public function getMountsForUser($userId, $groupIds) {
93 96
 		$builder = $this->connection->getQueryBuilder();
94 97
 		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
@@ -125,6 +128,10 @@  discard block
 block discarded – undo
125 128
 		return $this->getMountsFromQuery($query);
126 129
 	}
127 130
 
131
+	/**
132
+	 * @param integer $type
133
+	 * @param string|null $value
134
+	 */
128 135
 	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
129 136
 		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
130 137
 			->from('external_mounts', 'm')
@@ -332,6 +339,9 @@  discard block
 block discarded – undo
332 339
 		}
333 340
 	}
334 341
 
342
+	/**
343
+	 * @param integer $mountId
344
+	 */
335 345
 	public function addApplicable($mountId, $type, $value) {
336 346
 		$this->connection->insertIfNotExist('*PREFIX*external_applicable', [
337 347
 			'mount_id' => $mountId,
@@ -340,6 +350,9 @@  discard block
 block discarded – undo
340 350
 		], ['mount_id', 'type', 'value']);
341 351
 	}
342 352
 
353
+	/**
354
+	 * @param integer $mountId
355
+	 */
343 356
 	public function removeApplicable($mountId, $type, $value) {
344 357
 		$builder = $this->connection->getQueryBuilder();
345 358
 		$query = $builder->delete('external_applicable')
@@ -473,6 +486,9 @@  discard block
 block discarded – undo
473 486
 		return array_combine($keys, $values);
474 487
 	}
475 488
 
489
+	/**
490
+	 * @param string $value
491
+	 */
476 492
 	private function encryptValue($value) {
477 493
 		return $this->crypto->encrypt($value);
478 494
 	}
Please login to merge, or discard this patch.
Indentation   +452 added lines, -452 removed lines patch added patch discarded remove patch
@@ -32,456 +32,456 @@
 block discarded – undo
32 32
  * Stores the mount config in the database
33 33
  */
34 34
 class DBConfigService {
35
-	const MOUNT_TYPE_ADMIN = 1;
36
-	const MOUNT_TYPE_PERSONAl = 2;
37
-
38
-	const APPLICABLE_TYPE_GLOBAL = 1;
39
-	const APPLICABLE_TYPE_GROUP = 2;
40
-	const APPLICABLE_TYPE_USER = 3;
41
-
42
-	/**
43
-	 * @var IDBConnection
44
-	 */
45
-	private $connection;
46
-
47
-	/**
48
-	 * @var ICrypto
49
-	 */
50
-	private $crypto;
51
-
52
-	/**
53
-	 * DBConfigService constructor.
54
-	 *
55
-	 * @param IDBConnection $connection
56
-	 * @param ICrypto $crypto
57
-	 */
58
-	public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
-		$this->connection = $connection;
60
-		$this->crypto = $crypto;
61
-	}
62
-
63
-	/**
64
-	 * @param int $mountId
65
-	 * @return array
66
-	 */
67
-	public function getMountById($mountId) {
68
-		$builder = $this->connection->getQueryBuilder();
69
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
70
-			->from('external_mounts', 'm')
71
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
72
-		$mounts = $this->getMountsFromQuery($query);
73
-		if (count($mounts) > 0) {
74
-			return $mounts[0];
75
-		} else {
76
-			return null;
77
-		}
78
-	}
79
-
80
-	/**
81
-	 * Get all configured mounts
82
-	 *
83
-	 * @return array
84
-	 */
85
-	public function getAllMounts() {
86
-		$builder = $this->connection->getQueryBuilder();
87
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
88
-			->from('external_mounts');
89
-		return $this->getMountsFromQuery($query);
90
-	}
91
-
92
-	public function getMountsForUser($userId, $groupIds) {
93
-		$builder = $this->connection->getQueryBuilder();
94
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
95
-			->from('external_mounts', 'm')
96
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
97
-			->where($builder->expr()->orX(
98
-				$builder->expr()->andX( // global mounts
99
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
100
-					$builder->expr()->isNull('a.value')
101
-				),
102
-				$builder->expr()->andX( // mounts for user
103
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
104
-					$builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
105
-				),
106
-				$builder->expr()->andX( // mounts for group
107
-					$builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
108
-					$builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_INT_ARRAY))
109
-				)
110
-			));
111
-
112
-		return $this->getMountsFromQuery($query);
113
-	}
114
-
115
-	/**
116
-	 * Get admin defined mounts
117
-	 *
118
-	 * @return array
119
-	 */
120
-	public function getAdminMounts() {
121
-		$builder = $this->connection->getQueryBuilder();
122
-		$query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
123
-			->from('external_mounts')
124
-			->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
125
-		return $this->getMountsFromQuery($query);
126
-	}
127
-
128
-	protected function getForQuery(IQueryBuilder $builder, $type, $value) {
129
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
130
-			->from('external_mounts', 'm')
131
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
132
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
133
-
134
-		if (is_null($value)) {
135
-			$query = $query->andWhere($builder->expr()->isNull('a.value'));
136
-		} else {
137
-			$query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
138
-		}
139
-
140
-		return $query;
141
-	}
142
-
143
-	/**
144
-	 * Get mounts by applicable
145
-	 *
146
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
147
-	 * @param string|null $value user_id, group_id or null for global mounts
148
-	 * @return array
149
-	 */
150
-	public function getMountsFor($type, $value) {
151
-		$builder = $this->connection->getQueryBuilder();
152
-		$query = $this->getForQuery($builder, $type, $value);
153
-
154
-		return $this->getMountsFromQuery($query);
155
-	}
156
-
157
-	/**
158
-	 * Get admin defined mounts by applicable
159
-	 *
160
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
161
-	 * @param string|null $value user_id, group_id or null for global mounts
162
-	 * @return array
163
-	 */
164
-	public function getAdminMountsFor($type, $value) {
165
-		$builder = $this->connection->getQueryBuilder();
166
-		$query = $this->getForQuery($builder, $type, $value);
167
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
168
-
169
-		return $this->getMountsFromQuery($query);
170
-	}
171
-
172
-	/**
173
-	 * Get admin defined mounts for multiple applicable
174
-	 *
175
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
176
-	 * @param string[] $values user_ids or group_ids
177
-	 * @return array
178
-	 */
179
-	public function getAdminMountsForMultiple($type, array $values) {
180
-		$builder = $this->connection->getQueryBuilder();
181
-		$params = array_map(function ($value) use ($builder) {
182
-			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
183
-		}, $values);
184
-
185
-		$query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
186
-			->from('external_mounts', 'm')
187
-			->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
188
-			->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
189
-			->andWhere($builder->expr()->in('a.value', $params));
190
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
191
-
192
-		return $this->getMountsFromQuery($query);
193
-	}
194
-
195
-	/**
196
-	 * Get user defined mounts by applicable
197
-	 *
198
-	 * @param int $type any of the self::APPLICABLE_TYPE_ constants
199
-	 * @param string|null $value user_id, group_id or null for global mounts
200
-	 * @return array
201
-	 */
202
-	public function getUserMountsFor($type, $value) {
203
-		$builder = $this->connection->getQueryBuilder();
204
-		$query = $this->getForQuery($builder, $type, $value);
205
-		$query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
206
-
207
-		return $this->getMountsFromQuery($query);
208
-	}
209
-
210
-	/**
211
-	 * Add a mount to the database
212
-	 *
213
-	 * @param string $mountPoint
214
-	 * @param string $storageBackend
215
-	 * @param string $authBackend
216
-	 * @param int $priority
217
-	 * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
218
-	 * @return int the id of the new mount
219
-	 */
220
-	public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
221
-		if (!$priority) {
222
-			$priority = 100;
223
-		}
224
-		$builder = $this->connection->getQueryBuilder();
225
-		$query = $builder->insert('external_mounts')
226
-			->values([
227
-				'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
228
-				'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
229
-				'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
230
-				'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
231
-				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
232
-			]);
233
-		$query->execute();
234
-		return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
235
-	}
236
-
237
-	/**
238
-	 * Remove a mount from the database
239
-	 *
240
-	 * @param int $mountId
241
-	 */
242
-	public function removeMount($mountId) {
243
-		$builder = $this->connection->getQueryBuilder();
244
-		$query = $builder->delete('external_mounts')
245
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
246
-		$query->execute();
247
-
248
-		$query = $builder->delete('external_applicable')
249
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
-		$query->execute();
251
-
252
-		$query = $builder->delete('external_config')
253
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
-		$query->execute();
255
-
256
-		$query = $builder->delete('external_options')
257
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
258
-		$query->execute();
259
-	}
260
-
261
-	/**
262
-	 * @param int $mountId
263
-	 * @param string $newMountPoint
264
-	 */
265
-	public function setMountPoint($mountId, $newMountPoint) {
266
-		$builder = $this->connection->getQueryBuilder();
267
-
268
-		$query = $builder->update('external_mounts')
269
-			->set('mount_point', $builder->createNamedParameter($newMountPoint))
270
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
271
-
272
-		$query->execute();
273
-	}
274
-
275
-	/**
276
-	 * @param int $mountId
277
-	 * @param string $newAuthBackend
278
-	 */
279
-	public function setAuthBackend($mountId, $newAuthBackend) {
280
-		$builder = $this->connection->getQueryBuilder();
281
-
282
-		$query = $builder->update('external_mounts')
283
-			->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
284
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
285
-
286
-		$query->execute();
287
-	}
288
-
289
-	/**
290
-	 * @param int $mountId
291
-	 * @param string $key
292
-	 * @param string $value
293
-	 */
294
-	public function setConfig($mountId, $key, $value) {
295
-		if ($key === 'password') {
296
-			$value = $this->encryptValue($value);
297
-		}
298
-		$count = $this->connection->insertIfNotExist('*PREFIX*external_config', [
299
-			'mount_id' => $mountId,
300
-			'key' => $key,
301
-			'value' => $value
302
-		], ['mount_id', 'key']);
303
-		if ($count === 0) {
304
-			$builder = $this->connection->getQueryBuilder();
305
-			$query = $builder->update('external_config')
306
-				->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
307
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
308
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
309
-			$query->execute();
310
-		}
311
-	}
312
-
313
-	/**
314
-	 * @param int $mountId
315
-	 * @param string $key
316
-	 * @param string $value
317
-	 */
318
-	public function setOption($mountId, $key, $value) {
319
-
320
-		$count = $this->connection->insertIfNotExist('*PREFIX*external_options', [
321
-			'mount_id' => $mountId,
322
-			'key' => $key,
323
-			'value' => json_encode($value)
324
-		], ['mount_id', 'key']);
325
-		if ($count === 0) {
326
-			$builder = $this->connection->getQueryBuilder();
327
-			$query = $builder->update('external_options')
328
-				->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
329
-				->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
330
-				->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
331
-			$query->execute();
332
-		}
333
-	}
334
-
335
-	public function addApplicable($mountId, $type, $value) {
336
-		$this->connection->insertIfNotExist('*PREFIX*external_applicable', [
337
-			'mount_id' => $mountId,
338
-			'type' => $type,
339
-			'value' => $value
340
-		], ['mount_id', 'type', 'value']);
341
-	}
342
-
343
-	public function removeApplicable($mountId, $type, $value) {
344
-		$builder = $this->connection->getQueryBuilder();
345
-		$query = $builder->delete('external_applicable')
346
-			->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
347
-			->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
348
-
349
-		if (is_null($value)) {
350
-			$query = $query->andWhere($builder->expr()->isNull('value'));
351
-		} else {
352
-			$query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
353
-		}
354
-
355
-		$query->execute();
356
-	}
357
-
358
-	private function getMountsFromQuery(IQueryBuilder $query) {
359
-		$result = $query->execute();
360
-		$mounts = $result->fetchAll();
361
-		$uniqueMounts = [];
362
-		foreach ($mounts as $mount) {
363
-			$id = $mount['mount_id'];
364
-			if (!isset($uniqueMounts[$id])) {
365
-				$uniqueMounts[$id] = $mount;
366
-			}
367
-		}
368
-		$uniqueMounts = array_values($uniqueMounts);
369
-
370
-		$mountIds = array_map(function ($mount) {
371
-			return $mount['mount_id'];
372
-		}, $uniqueMounts);
373
-		$mountIds = array_values(array_unique($mountIds));
374
-
375
-		$applicable = $this->getApplicableForMounts($mountIds);
376
-		$config = $this->getConfigForMounts($mountIds);
377
-		$options = $this->getOptionsForMounts($mountIds);
378
-
379
-		return array_map(function ($mount, $applicable, $config, $options) {
380
-			$mount['type'] = (int)$mount['type'];
381
-			$mount['priority'] = (int)$mount['priority'];
382
-			$mount['applicable'] = $applicable;
383
-			$mount['config'] = $config;
384
-			$mount['options'] = $options;
385
-			return $mount;
386
-		}, $uniqueMounts, $applicable, $config, $options);
387
-	}
388
-
389
-	/**
390
-	 * Get mount options from a table grouped by mount id
391
-	 *
392
-	 * @param string $table
393
-	 * @param string[] $fields
394
-	 * @param int[] $mountIds
395
-	 * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
396
-	 */
397
-	private function selectForMounts($table, array $fields, array $mountIds) {
398
-		if (count($mountIds) === 0) {
399
-			return [];
400
-		}
401
-		$builder = $this->connection->getQueryBuilder();
402
-		$fields[] = 'mount_id';
403
-		$placeHolders = array_map(function ($id) use ($builder) {
404
-			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
405
-		}, $mountIds);
406
-		$query = $builder->select($fields)
407
-			->from($table)
408
-			->where($builder->expr()->in('mount_id', $placeHolders));
409
-		$rows = $query->execute()->fetchAll();
410
-
411
-		$result = [];
412
-		foreach ($mountIds as $mountId) {
413
-			$result[$mountId] = [];
414
-		}
415
-		foreach ($rows as $row) {
416
-			if (isset($row['type'])) {
417
-				$row['type'] = (int)$row['type'];
418
-			}
419
-			$result[$row['mount_id']][] = $row;
420
-		}
421
-		return $result;
422
-	}
423
-
424
-	/**
425
-	 * @param int[] $mountIds
426
-	 * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
427
-	 */
428
-	public function getApplicableForMounts($mountIds) {
429
-		return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
430
-	}
431
-
432
-	/**
433
-	 * @param int[] $mountIds
434
-	 * @return array [$id => ['key1' => $value1, ...], ...]
435
-	 */
436
-	public function getConfigForMounts($mountIds) {
437
-		$mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
438
-		return array_map([$this, 'createKeyValueMap'], $mountConfigs);
439
-	}
440
-
441
-	/**
442
-	 * @param int[] $mountIds
443
-	 * @return array [$id => ['key1' => $value1, ...], ...]
444
-	 */
445
-	public function getOptionsForMounts($mountIds) {
446
-		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
447
-		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
448
-		return array_map(function (array $options) {
449
-			return array_map(function ($option) {
450
-				return json_decode($option);
451
-			}, $options);
452
-		}, $optionsMap);
453
-	}
454
-
455
-	/**
456
-	 * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
457
-	 * @return array ['key1' => $value1, ...]
458
-	 */
459
-	private function createKeyValueMap(array $keyValuePairs) {
460
-		$decryptedPairts = array_map(function ($pair) {
461
-			if ($pair['key'] === 'password') {
462
-				$pair['value'] = $this->decryptValue($pair['value']);
463
-			}
464
-			return $pair;
465
-		}, $keyValuePairs);
466
-		$keys = array_map(function ($pair) {
467
-			return $pair['key'];
468
-		}, $decryptedPairts);
469
-		$values = array_map(function ($pair) {
470
-			return $pair['value'];
471
-		}, $decryptedPairts);
472
-
473
-		return array_combine($keys, $values);
474
-	}
475
-
476
-	private function encryptValue($value) {
477
-		return $this->crypto->encrypt($value);
478
-	}
479
-
480
-	private function decryptValue($value) {
481
-		try {
482
-			return $this->crypto->decrypt($value);
483
-		} catch (\Exception $e) {
484
-			return $value;
485
-		}
486
-	}
35
+    const MOUNT_TYPE_ADMIN = 1;
36
+    const MOUNT_TYPE_PERSONAl = 2;
37
+
38
+    const APPLICABLE_TYPE_GLOBAL = 1;
39
+    const APPLICABLE_TYPE_GROUP = 2;
40
+    const APPLICABLE_TYPE_USER = 3;
41
+
42
+    /**
43
+     * @var IDBConnection
44
+     */
45
+    private $connection;
46
+
47
+    /**
48
+     * @var ICrypto
49
+     */
50
+    private $crypto;
51
+
52
+    /**
53
+     * DBConfigService constructor.
54
+     *
55
+     * @param IDBConnection $connection
56
+     * @param ICrypto $crypto
57
+     */
58
+    public function __construct(IDBConnection $connection, ICrypto $crypto) {
59
+        $this->connection = $connection;
60
+        $this->crypto = $crypto;
61
+    }
62
+
63
+    /**
64
+     * @param int $mountId
65
+     * @return array
66
+     */
67
+    public function getMountById($mountId) {
68
+        $builder = $this->connection->getQueryBuilder();
69
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
70
+            ->from('external_mounts', 'm')
71
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
72
+        $mounts = $this->getMountsFromQuery($query);
73
+        if (count($mounts) > 0) {
74
+            return $mounts[0];
75
+        } else {
76
+            return null;
77
+        }
78
+    }
79
+
80
+    /**
81
+     * Get all configured mounts
82
+     *
83
+     * @return array
84
+     */
85
+    public function getAllMounts() {
86
+        $builder = $this->connection->getQueryBuilder();
87
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
88
+            ->from('external_mounts');
89
+        return $this->getMountsFromQuery($query);
90
+    }
91
+
92
+    public function getMountsForUser($userId, $groupIds) {
93
+        $builder = $this->connection->getQueryBuilder();
94
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
95
+            ->from('external_mounts', 'm')
96
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
97
+            ->where($builder->expr()->orX(
98
+                $builder->expr()->andX( // global mounts
99
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)),
100
+                    $builder->expr()->isNull('a.value')
101
+                ),
102
+                $builder->expr()->andX( // mounts for user
103
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)),
104
+                    $builder->expr()->eq('a.value', $builder->createNamedParameter($userId))
105
+                ),
106
+                $builder->expr()->andX( // mounts for group
107
+                    $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)),
108
+                    $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_INT_ARRAY))
109
+                )
110
+            ));
111
+
112
+        return $this->getMountsFromQuery($query);
113
+    }
114
+
115
+    /**
116
+     * Get admin defined mounts
117
+     *
118
+     * @return array
119
+     */
120
+    public function getAdminMounts() {
121
+        $builder = $this->connection->getQueryBuilder();
122
+        $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type'])
123
+            ->from('external_mounts')
124
+            ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
125
+        return $this->getMountsFromQuery($query);
126
+    }
127
+
128
+    protected function getForQuery(IQueryBuilder $builder, $type, $value) {
129
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
130
+            ->from('external_mounts', 'm')
131
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
132
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
133
+
134
+        if (is_null($value)) {
135
+            $query = $query->andWhere($builder->expr()->isNull('a.value'));
136
+        } else {
137
+            $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value)));
138
+        }
139
+
140
+        return $query;
141
+    }
142
+
143
+    /**
144
+     * Get mounts by applicable
145
+     *
146
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
147
+     * @param string|null $value user_id, group_id or null for global mounts
148
+     * @return array
149
+     */
150
+    public function getMountsFor($type, $value) {
151
+        $builder = $this->connection->getQueryBuilder();
152
+        $query = $this->getForQuery($builder, $type, $value);
153
+
154
+        return $this->getMountsFromQuery($query);
155
+    }
156
+
157
+    /**
158
+     * Get admin defined mounts by applicable
159
+     *
160
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
161
+     * @param string|null $value user_id, group_id or null for global mounts
162
+     * @return array
163
+     */
164
+    public function getAdminMountsFor($type, $value) {
165
+        $builder = $this->connection->getQueryBuilder();
166
+        $query = $this->getForQuery($builder, $type, $value);
167
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
168
+
169
+        return $this->getMountsFromQuery($query);
170
+    }
171
+
172
+    /**
173
+     * Get admin defined mounts for multiple applicable
174
+     *
175
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
176
+     * @param string[] $values user_ids or group_ids
177
+     * @return array
178
+     */
179
+    public function getAdminMountsForMultiple($type, array $values) {
180
+        $builder = $this->connection->getQueryBuilder();
181
+        $params = array_map(function ($value) use ($builder) {
182
+            return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
183
+        }, $values);
184
+
185
+        $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type'])
186
+            ->from('external_mounts', 'm')
187
+            ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id'))
188
+            ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)))
189
+            ->andWhere($builder->expr()->in('a.value', $params));
190
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT)));
191
+
192
+        return $this->getMountsFromQuery($query);
193
+    }
194
+
195
+    /**
196
+     * Get user defined mounts by applicable
197
+     *
198
+     * @param int $type any of the self::APPLICABLE_TYPE_ constants
199
+     * @param string|null $value user_id, group_id or null for global mounts
200
+     * @return array
201
+     */
202
+    public function getUserMountsFor($type, $value) {
203
+        $builder = $this->connection->getQueryBuilder();
204
+        $query = $this->getForQuery($builder, $type, $value);
205
+        $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT)));
206
+
207
+        return $this->getMountsFromQuery($query);
208
+    }
209
+
210
+    /**
211
+     * Add a mount to the database
212
+     *
213
+     * @param string $mountPoint
214
+     * @param string $storageBackend
215
+     * @param string $authBackend
216
+     * @param int $priority
217
+     * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL
218
+     * @return int the id of the new mount
219
+     */
220
+    public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) {
221
+        if (!$priority) {
222
+            $priority = 100;
223
+        }
224
+        $builder = $this->connection->getQueryBuilder();
225
+        $query = $builder->insert('external_mounts')
226
+            ->values([
227
+                'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR),
228
+                'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR),
229
+                'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR),
230
+                'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT),
231
+                'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
232
+            ]);
233
+        $query->execute();
234
+        return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
235
+    }
236
+
237
+    /**
238
+     * Remove a mount from the database
239
+     *
240
+     * @param int $mountId
241
+     */
242
+    public function removeMount($mountId) {
243
+        $builder = $this->connection->getQueryBuilder();
244
+        $query = $builder->delete('external_mounts')
245
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
246
+        $query->execute();
247
+
248
+        $query = $builder->delete('external_applicable')
249
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
250
+        $query->execute();
251
+
252
+        $query = $builder->delete('external_config')
253
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
254
+        $query->execute();
255
+
256
+        $query = $builder->delete('external_options')
257
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
258
+        $query->execute();
259
+    }
260
+
261
+    /**
262
+     * @param int $mountId
263
+     * @param string $newMountPoint
264
+     */
265
+    public function setMountPoint($mountId, $newMountPoint) {
266
+        $builder = $this->connection->getQueryBuilder();
267
+
268
+        $query = $builder->update('external_mounts')
269
+            ->set('mount_point', $builder->createNamedParameter($newMountPoint))
270
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
271
+
272
+        $query->execute();
273
+    }
274
+
275
+    /**
276
+     * @param int $mountId
277
+     * @param string $newAuthBackend
278
+     */
279
+    public function setAuthBackend($mountId, $newAuthBackend) {
280
+        $builder = $this->connection->getQueryBuilder();
281
+
282
+        $query = $builder->update('external_mounts')
283
+            ->set('auth_backend', $builder->createNamedParameter($newAuthBackend))
284
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)));
285
+
286
+        $query->execute();
287
+    }
288
+
289
+    /**
290
+     * @param int $mountId
291
+     * @param string $key
292
+     * @param string $value
293
+     */
294
+    public function setConfig($mountId, $key, $value) {
295
+        if ($key === 'password') {
296
+            $value = $this->encryptValue($value);
297
+        }
298
+        $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [
299
+            'mount_id' => $mountId,
300
+            'key' => $key,
301
+            'value' => $value
302
+        ], ['mount_id', 'key']);
303
+        if ($count === 0) {
304
+            $builder = $this->connection->getQueryBuilder();
305
+            $query = $builder->update('external_config')
306
+                ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))
307
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
308
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
309
+            $query->execute();
310
+        }
311
+    }
312
+
313
+    /**
314
+     * @param int $mountId
315
+     * @param string $key
316
+     * @param string $value
317
+     */
318
+    public function setOption($mountId, $key, $value) {
319
+
320
+        $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [
321
+            'mount_id' => $mountId,
322
+            'key' => $key,
323
+            'value' => json_encode($value)
324
+        ], ['mount_id', 'key']);
325
+        if ($count === 0) {
326
+            $builder = $this->connection->getQueryBuilder();
327
+            $query = $builder->update('external_options')
328
+                ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR))
329
+                ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
330
+                ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR)));
331
+            $query->execute();
332
+        }
333
+    }
334
+
335
+    public function addApplicable($mountId, $type, $value) {
336
+        $this->connection->insertIfNotExist('*PREFIX*external_applicable', [
337
+            'mount_id' => $mountId,
338
+            'type' => $type,
339
+            'value' => $value
340
+        ], ['mount_id', 'type', 'value']);
341
+    }
342
+
343
+    public function removeApplicable($mountId, $type, $value) {
344
+        $builder = $this->connection->getQueryBuilder();
345
+        $query = $builder->delete('external_applicable')
346
+            ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT)))
347
+            ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)));
348
+
349
+        if (is_null($value)) {
350
+            $query = $query->andWhere($builder->expr()->isNull('value'));
351
+        } else {
352
+            $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)));
353
+        }
354
+
355
+        $query->execute();
356
+    }
357
+
358
+    private function getMountsFromQuery(IQueryBuilder $query) {
359
+        $result = $query->execute();
360
+        $mounts = $result->fetchAll();
361
+        $uniqueMounts = [];
362
+        foreach ($mounts as $mount) {
363
+            $id = $mount['mount_id'];
364
+            if (!isset($uniqueMounts[$id])) {
365
+                $uniqueMounts[$id] = $mount;
366
+            }
367
+        }
368
+        $uniqueMounts = array_values($uniqueMounts);
369
+
370
+        $mountIds = array_map(function ($mount) {
371
+            return $mount['mount_id'];
372
+        }, $uniqueMounts);
373
+        $mountIds = array_values(array_unique($mountIds));
374
+
375
+        $applicable = $this->getApplicableForMounts($mountIds);
376
+        $config = $this->getConfigForMounts($mountIds);
377
+        $options = $this->getOptionsForMounts($mountIds);
378
+
379
+        return array_map(function ($mount, $applicable, $config, $options) {
380
+            $mount['type'] = (int)$mount['type'];
381
+            $mount['priority'] = (int)$mount['priority'];
382
+            $mount['applicable'] = $applicable;
383
+            $mount['config'] = $config;
384
+            $mount['options'] = $options;
385
+            return $mount;
386
+        }, $uniqueMounts, $applicable, $config, $options);
387
+    }
388
+
389
+    /**
390
+     * Get mount options from a table grouped by mount id
391
+     *
392
+     * @param string $table
393
+     * @param string[] $fields
394
+     * @param int[] $mountIds
395
+     * @return array [$mountId => [['field1' => $value1, ...], ...], ...]
396
+     */
397
+    private function selectForMounts($table, array $fields, array $mountIds) {
398
+        if (count($mountIds) === 0) {
399
+            return [];
400
+        }
401
+        $builder = $this->connection->getQueryBuilder();
402
+        $fields[] = 'mount_id';
403
+        $placeHolders = array_map(function ($id) use ($builder) {
404
+            return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
405
+        }, $mountIds);
406
+        $query = $builder->select($fields)
407
+            ->from($table)
408
+            ->where($builder->expr()->in('mount_id', $placeHolders));
409
+        $rows = $query->execute()->fetchAll();
410
+
411
+        $result = [];
412
+        foreach ($mountIds as $mountId) {
413
+            $result[$mountId] = [];
414
+        }
415
+        foreach ($rows as $row) {
416
+            if (isset($row['type'])) {
417
+                $row['type'] = (int)$row['type'];
418
+            }
419
+            $result[$row['mount_id']][] = $row;
420
+        }
421
+        return $result;
422
+    }
423
+
424
+    /**
425
+     * @param int[] $mountIds
426
+     * @return array [$id => [['type' => $type, 'value' => $value], ...], ...]
427
+     */
428
+    public function getApplicableForMounts($mountIds) {
429
+        return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds);
430
+    }
431
+
432
+    /**
433
+     * @param int[] $mountIds
434
+     * @return array [$id => ['key1' => $value1, ...], ...]
435
+     */
436
+    public function getConfigForMounts($mountIds) {
437
+        $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds);
438
+        return array_map([$this, 'createKeyValueMap'], $mountConfigs);
439
+    }
440
+
441
+    /**
442
+     * @param int[] $mountIds
443
+     * @return array [$id => ['key1' => $value1, ...], ...]
444
+     */
445
+    public function getOptionsForMounts($mountIds) {
446
+        $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
447
+        $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
448
+        return array_map(function (array $options) {
449
+            return array_map(function ($option) {
450
+                return json_decode($option);
451
+            }, $options);
452
+        }, $optionsMap);
453
+    }
454
+
455
+    /**
456
+     * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...]
457
+     * @return array ['key1' => $value1, ...]
458
+     */
459
+    private function createKeyValueMap(array $keyValuePairs) {
460
+        $decryptedPairts = array_map(function ($pair) {
461
+            if ($pair['key'] === 'password') {
462
+                $pair['value'] = $this->decryptValue($pair['value']);
463
+            }
464
+            return $pair;
465
+        }, $keyValuePairs);
466
+        $keys = array_map(function ($pair) {
467
+            return $pair['key'];
468
+        }, $decryptedPairts);
469
+        $values = array_map(function ($pair) {
470
+            return $pair['value'];
471
+        }, $decryptedPairts);
472
+
473
+        return array_combine($keys, $values);
474
+    }
475
+
476
+    private function encryptValue($value) {
477
+        return $this->crypto->encrypt($value);
478
+    }
479
+
480
+    private function decryptValue($value) {
481
+        try {
482
+            return $this->crypto->decrypt($value);
483
+        } catch (\Exception $e) {
484
+            return $value;
485
+        }
486
+    }
487 487
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
 	 */
179 179
 	public function getAdminMountsForMultiple($type, array $values) {
180 180
 		$builder = $this->connection->getQueryBuilder();
181
-		$params = array_map(function ($value) use ($builder) {
181
+		$params = array_map(function($value) use ($builder) {
182 182
 			return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR);
183 183
 		}, $values);
184 184
 
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 				'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT)
232 232
 			]);
233 233
 		$query->execute();
234
-		return (int)$this->connection->lastInsertId('*PREFIX*external_mounts');
234
+		return (int) $this->connection->lastInsertId('*PREFIX*external_mounts');
235 235
 	}
236 236
 
237 237
 	/**
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 		$uniqueMounts = array_values($uniqueMounts);
369 369
 
370
-		$mountIds = array_map(function ($mount) {
370
+		$mountIds = array_map(function($mount) {
371 371
 			return $mount['mount_id'];
372 372
 		}, $uniqueMounts);
373 373
 		$mountIds = array_values(array_unique($mountIds));
@@ -376,9 +376,9 @@  discard block
 block discarded – undo
376 376
 		$config = $this->getConfigForMounts($mountIds);
377 377
 		$options = $this->getOptionsForMounts($mountIds);
378 378
 
379
-		return array_map(function ($mount, $applicable, $config, $options) {
380
-			$mount['type'] = (int)$mount['type'];
381
-			$mount['priority'] = (int)$mount['priority'];
379
+		return array_map(function($mount, $applicable, $config, $options) {
380
+			$mount['type'] = (int) $mount['type'];
381
+			$mount['priority'] = (int) $mount['priority'];
382 382
 			$mount['applicable'] = $applicable;
383 383
 			$mount['config'] = $config;
384 384
 			$mount['options'] = $options;
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		}
401 401
 		$builder = $this->connection->getQueryBuilder();
402 402
 		$fields[] = 'mount_id';
403
-		$placeHolders = array_map(function ($id) use ($builder) {
403
+		$placeHolders = array_map(function($id) use ($builder) {
404 404
 			return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT);
405 405
 		}, $mountIds);
406 406
 		$query = $builder->select($fields)
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 		}
415 415
 		foreach ($rows as $row) {
416 416
 			if (isset($row['type'])) {
417
-				$row['type'] = (int)$row['type'];
417
+				$row['type'] = (int) $row['type'];
418 418
 			}
419 419
 			$result[$row['mount_id']][] = $row;
420 420
 		}
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	public function getOptionsForMounts($mountIds) {
446 446
 		$mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds);
447 447
 		$optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions);
448
-		return array_map(function (array $options) {
449
-			return array_map(function ($option) {
448
+		return array_map(function(array $options) {
449
+			return array_map(function($option) {
450 450
 				return json_decode($option);
451 451
 			}, $options);
452 452
 		}, $optionsMap);
@@ -457,16 +457,16 @@  discard block
 block discarded – undo
457 457
 	 * @return array ['key1' => $value1, ...]
458 458
 	 */
459 459
 	private function createKeyValueMap(array $keyValuePairs) {
460
-		$decryptedPairts = array_map(function ($pair) {
460
+		$decryptedPairts = array_map(function($pair) {
461 461
 			if ($pair['key'] === 'password') {
462 462
 				$pair['value'] = $this->decryptValue($pair['value']);
463 463
 			}
464 464
 			return $pair;
465 465
 		}, $keyValuePairs);
466
-		$keys = array_map(function ($pair) {
466
+		$keys = array_map(function($pair) {
467 467
 			return $pair['key'];
468 468
 		}, $decryptedPairts);
469
-		$values = array_map(function ($pair) {
469
+		$values = array_map(function($pair) {
470 470
 			return $pair['value'];
471 471
 		}, $decryptedPairts);
472 472
 
Please login to merge, or discard this patch.
apps/federation/lib/AppInfo/Application.php 3 patches
Unused Use Statements   -3 removed lines patch added patch discarded remove patch
@@ -24,16 +24,13 @@
 block discarded – undo
24 24
 
25 25
 namespace OCA\Federation\AppInfo;
26 26
 
27
-use OCA\Federation\API\OCSAuthAPI;
28 27
 use OCA\Federation\Controller\SettingsController;
29 28
 use OCA\Federation\DAV\FedAuth;
30 29
 use OCA\Federation\DbHandler;
31 30
 use OCA\Federation\Hooks;
32 31
 use OCA\Federation\Middleware\AddServerMiddleware;
33 32
 use OCA\Federation\SyncFederationAddressBooks;
34
-use OCA\Federation\SyncJob;
35 33
 use OCA\Federation\TrustedServers;
36
-use OCP\API;
37 34
 use OCP\App;
38 35
 use OCP\AppFramework\IAppContainer;
39 36
 use OCP\SabrePluginEvent;
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -42,100 +42,100 @@
 block discarded – undo
42 42
 
43 43
 class Application extends \OCP\AppFramework\App {
44 44
 
45
-	/**
46
-	 * @param array $urlParams
47
-	 */
48
-	public function __construct($urlParams = array()) {
49
-		parent::__construct('federation', $urlParams);
50
-		$this->registerService();
51
-		$this->registerMiddleware();
52
-	}
53
-
54
-	private function registerService() {
55
-		$container = $this->getContainer();
56
-
57
-		$container->registerService('addServerMiddleware', function(IAppContainer $c) {
58
-			return new AddServerMiddleware(
59
-				$c->getAppName(),
60
-				\OC::$server->getL10N($c->getAppName()),
61
-				\OC::$server->getLogger()
62
-			);
63
-		});
64
-
65
-		$container->registerService('DbHandler', function(IAppContainer $c) {
66
-			return new DbHandler(
67
-				\OC::$server->getDatabaseConnection(),
68
-				\OC::$server->getL10N($c->getAppName())
69
-			);
70
-		});
71
-
72
-		$container->registerService('TrustedServers', function(IAppContainer $c) {
73
-			$server = $c->getServer();
74
-			return new TrustedServers(
75
-				$c->query('DbHandler'),
76
-				$server->getHTTPClientService(),
77
-				$server->getLogger(),
78
-				$server->getJobList(),
79
-				$server->getSecureRandom(),
80
-				$server->getConfig(),
81
-				$server->getEventDispatcher()
82
-			);
83
-		});
84
-
85
-		$container->registerService('SettingsController', function (IAppContainer $c) {
86
-			$server = $c->getServer();
87
-			return new SettingsController(
88
-				$c->getAppName(),
89
-				$server->getRequest(),
90
-				$server->getL10N($c->getAppName()),
91
-				$c->query('TrustedServers')
92
-			);
93
-		});
94
-
95
-	}
96
-
97
-	private function registerMiddleware() {
98
-		$container = $this->getContainer();
99
-		$container->registerMiddleware('addServerMiddleware');
100
-	}
101
-
102
-	/**
103
-	 * listen to federated_share_added hooks to auto-add new servers to the
104
-	 * list of trusted servers.
105
-	 */
106
-	public function registerHooks() {
107
-
108
-		$container = $this->getContainer();
109
-		$hooksManager = new Hooks($container->query('TrustedServers'));
110
-
111
-		Util::connectHook(
112
-				'OCP\Share',
113
-				'federated_share_added',
114
-				$hooksManager,
115
-				'addServerHook'
116
-		);
117
-
118
-		$dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
119
-		$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) {
120
-			if ($event instanceof SabrePluginEvent) {
121
-				$authPlugin = $event->getServer()->getPlugin('auth');
122
-				if ($authPlugin instanceof Plugin) {
123
-					$h = new DbHandler($container->getServer()->getDatabaseConnection(),
124
-							$container->getServer()->getL10N('federation')
125
-					);
126
-					$authPlugin->addBackend(new FedAuth($h));
127
-				}
128
-			}
129
-		});
130
-	}
131
-
132
-	/**
133
-	 * @return SyncFederationAddressBooks
134
-	 */
135
-	public function getSyncService() {
136
-		$syncService = \OC::$server->query('CardDAVSyncService');
137
-		$dbHandler = $this->getContainer()->query('DbHandler');
138
-		return new SyncFederationAddressBooks($dbHandler, $syncService);
139
-	}
45
+    /**
46
+     * @param array $urlParams
47
+     */
48
+    public function __construct($urlParams = array()) {
49
+        parent::__construct('federation', $urlParams);
50
+        $this->registerService();
51
+        $this->registerMiddleware();
52
+    }
53
+
54
+    private function registerService() {
55
+        $container = $this->getContainer();
56
+
57
+        $container->registerService('addServerMiddleware', function(IAppContainer $c) {
58
+            return new AddServerMiddleware(
59
+                $c->getAppName(),
60
+                \OC::$server->getL10N($c->getAppName()),
61
+                \OC::$server->getLogger()
62
+            );
63
+        });
64
+
65
+        $container->registerService('DbHandler', function(IAppContainer $c) {
66
+            return new DbHandler(
67
+                \OC::$server->getDatabaseConnection(),
68
+                \OC::$server->getL10N($c->getAppName())
69
+            );
70
+        });
71
+
72
+        $container->registerService('TrustedServers', function(IAppContainer $c) {
73
+            $server = $c->getServer();
74
+            return new TrustedServers(
75
+                $c->query('DbHandler'),
76
+                $server->getHTTPClientService(),
77
+                $server->getLogger(),
78
+                $server->getJobList(),
79
+                $server->getSecureRandom(),
80
+                $server->getConfig(),
81
+                $server->getEventDispatcher()
82
+            );
83
+        });
84
+
85
+        $container->registerService('SettingsController', function (IAppContainer $c) {
86
+            $server = $c->getServer();
87
+            return new SettingsController(
88
+                $c->getAppName(),
89
+                $server->getRequest(),
90
+                $server->getL10N($c->getAppName()),
91
+                $c->query('TrustedServers')
92
+            );
93
+        });
94
+
95
+    }
96
+
97
+    private function registerMiddleware() {
98
+        $container = $this->getContainer();
99
+        $container->registerMiddleware('addServerMiddleware');
100
+    }
101
+
102
+    /**
103
+     * listen to federated_share_added hooks to auto-add new servers to the
104
+     * list of trusted servers.
105
+     */
106
+    public function registerHooks() {
107
+
108
+        $container = $this->getContainer();
109
+        $hooksManager = new Hooks($container->query('TrustedServers'));
110
+
111
+        Util::connectHook(
112
+                'OCP\Share',
113
+                'federated_share_added',
114
+                $hooksManager,
115
+                'addServerHook'
116
+        );
117
+
118
+        $dispatcher = $this->getContainer()->getServer()->getEventDispatcher();
119
+        $dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) {
120
+            if ($event instanceof SabrePluginEvent) {
121
+                $authPlugin = $event->getServer()->getPlugin('auth');
122
+                if ($authPlugin instanceof Plugin) {
123
+                    $h = new DbHandler($container->getServer()->getDatabaseConnection(),
124
+                            $container->getServer()->getL10N('federation')
125
+                    );
126
+                    $authPlugin->addBackend(new FedAuth($h));
127
+                }
128
+            }
129
+        });
130
+    }
131
+
132
+    /**
133
+     * @return SyncFederationAddressBooks
134
+     */
135
+    public function getSyncService() {
136
+        $syncService = \OC::$server->query('CardDAVSyncService');
137
+        $dbHandler = $this->getContainer()->query('DbHandler');
138
+        return new SyncFederationAddressBooks($dbHandler, $syncService);
139
+    }
140 140
 
141 141
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -82,7 +82,7 @@
 block discarded – undo
82 82
 			);
83 83
 		});
84 84
 
85
-		$container->registerService('SettingsController', function (IAppContainer $c) {
85
+		$container->registerService('SettingsController', function(IAppContainer $c) {
86 86
 			$server = $c->getServer();
87 87
 			return new SettingsController(
88 88
 				$c->getAppName(),
Please login to merge, or discard this patch.
lib/private/AppFramework/OCS/BaseResponse.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 	/**
25 25
 	 * BaseResponse constructor.
26 26
 	 *
27
-	 * @param DataResponse|null $dataResponse
27
+	 * @param DataResponse $dataResponse
28 28
 	 * @param string $format
29 29
 	 * @param string|null $statusMessage
30 30
 	 * @param int|null $itemsCount
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -27,70 +27,70 @@
 block discarded – undo
27 27
 use OCP\AppFramework\Http\Response;
28 28
 
29 29
 abstract class BaseResponse extends Response   {
30
-	/** @var array */
31
-	protected $data;
30
+    /** @var array */
31
+    protected $data;
32 32
 
33
-	/** @var string */
34
-	protected $format;
33
+    /** @var string */
34
+    protected $format;
35 35
 
36
-	/** @var string */
37
-	protected $statusMessage;
36
+    /** @var string */
37
+    protected $statusMessage;
38 38
 
39
-	/** @var int */
40
-	protected $itemsCount;
39
+    /** @var int */
40
+    protected $itemsCount;
41 41
 
42
-	/** @var int */
43
-	protected $itemsPerPage;
42
+    /** @var int */
43
+    protected $itemsPerPage;
44 44
 
45
-	/**
46
-	 * BaseResponse constructor.
47
-	 *
48
-	 * @param DataResponse|null $dataResponse
49
-	 * @param string $format
50
-	 * @param string|null $statusMessage
51
-	 * @param int|null $itemsCount
52
-	 * @param int|null $itemsPerPage
53
-	 */
54
-	public function __construct(DataResponse $dataResponse,
55
-								$format = 'xml',
56
-								$statusMessage = null,
57
-								$itemsCount = null,
58
-								$itemsPerPage = null) {
59
-		$this->format = $format;
60
-		$this->statusMessage = $statusMessage;
61
-		$this->itemsCount = $itemsCount;
62
-		$this->itemsPerPage = $itemsPerPage;
45
+    /**
46
+     * BaseResponse constructor.
47
+     *
48
+     * @param DataResponse|null $dataResponse
49
+     * @param string $format
50
+     * @param string|null $statusMessage
51
+     * @param int|null $itemsCount
52
+     * @param int|null $itemsPerPage
53
+     */
54
+    public function __construct(DataResponse $dataResponse,
55
+                                $format = 'xml',
56
+                                $statusMessage = null,
57
+                                $itemsCount = null,
58
+                                $itemsPerPage = null) {
59
+        $this->format = $format;
60
+        $this->statusMessage = $statusMessage;
61
+        $this->itemsCount = $itemsCount;
62
+        $this->itemsPerPage = $itemsPerPage;
63 63
 
64
-		$this->data = $dataResponse->getData();
64
+        $this->data = $dataResponse->getData();
65 65
 
66
-		$this->setHeaders($dataResponse->getHeaders());
67
-		$this->setStatus($dataResponse->getStatus());
68
-		$this->setETag($dataResponse->getETag());
69
-		$this->setLastModified($dataResponse->getLastModified());
70
-		$this->setCookies($dataResponse->getCookies());
71
-		$this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
66
+        $this->setHeaders($dataResponse->getHeaders());
67
+        $this->setStatus($dataResponse->getStatus());
68
+        $this->setETag($dataResponse->getETag());
69
+        $this->setLastModified($dataResponse->getLastModified());
70
+        $this->setCookies($dataResponse->getCookies());
71
+        $this->setContentSecurityPolicy(new EmptyContentSecurityPolicy());
72 72
 
73
-		if ($format === 'json') {
74
-			$this->addHeader(
75
-				'Content-Type', 'application/json; charset=utf-8'
76
-			);
77
-		} else {
78
-			$this->addHeader(
79
-				'Content-Type', 'application/xml; charset=utf-8'
80
-			);
81
-		}
82
-	}
73
+        if ($format === 'json') {
74
+            $this->addHeader(
75
+                'Content-Type', 'application/json; charset=utf-8'
76
+            );
77
+        } else {
78
+            $this->addHeader(
79
+                'Content-Type', 'application/xml; charset=utf-8'
80
+            );
81
+        }
82
+    }
83 83
 
84
-	/**
85
-	 * @param string[] $meta
86
-	 * @return string
87
-	 */
88
-	protected function renderResult($meta) {
89
-		// TODO rewrite functions
90
-		return \OC_API::renderResult($this->format, $meta, $this->data);
91
-	}
84
+    /**
85
+     * @param string[] $meta
86
+     * @return string
87
+     */
88
+    protected function renderResult($meta) {
89
+        // TODO rewrite functions
90
+        return \OC_API::renderResult($this->format, $meta, $this->data);
91
+    }
92 92
 
93
-	public function getOCSStatus() {
94
-		return parent::getStatus();
95
-	}
93
+    public function getOCSStatus() {
94
+        return parent::getStatus();
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
27 27
 use OCP\AppFramework\Http\Response;
28 28
 
29
-abstract class BaseResponse extends Response   {
29
+abstract class BaseResponse extends Response {
30 30
 	/** @var array */
31 31
 	protected $data;
32 32
 
Please login to merge, or discard this patch.
lib/private/Server.php 4 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1143,7 +1143,7 @@  discard block
 block discarded – undo
1143 1143
 	 * Get the certificate manager for the user
1144 1144
 	 *
1145 1145
 	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1146
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1146
+	 * @return null|CertificateManager | null if $uid is null and no user is logged in
1147 1147
 	 */
1148 1148
 	public function getCertificateManager($userId = '') {
1149 1149
 		if ($userId === '') {
@@ -1464,6 +1464,7 @@  discard block
 block discarded – undo
1464 1464
 	}
1465 1465
 
1466 1466
 	/**
1467
+	 * @param string $app
1467 1468
 	 * @return \OCP\Files\IAppData
1468 1469
 	 */
1469 1470
 	public function getAppDataDir($app) {
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
130 130
 		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
131 131
 
132
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
132
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
133 133
 			return new PreviewManager(
134 134
 				$c->getConfig(),
135 135
 				$c->getRootFolder(),
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
 		});
141 141
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
142 142
 
143
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
143
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
144 144
 			return new \OC\Preview\Watcher(
145 145
 				$c->getAppDataDir('preview')
146 146
 			);
147 147
 		});
148 148
 
149
-		$this->registerService('EncryptionManager', function (Server $c) {
149
+		$this->registerService('EncryptionManager', function(Server $c) {
150 150
 			$view = new View();
151 151
 			$util = new Encryption\Util(
152 152
 				$view,
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 			);
165 165
 		});
166 166
 
167
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
167
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
168 168
 			$util = new Encryption\Util(
169 169
 				new View(),
170 170
 				$c->getUserManager(),
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 			return new Encryption\File($util);
175 175
 		});
176 176
 
177
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
177
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
178 178
 			$view = new View();
179 179
 			$util = new Encryption\Util(
180 180
 				$view,
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
 
186 186
 			return new Encryption\Keys\Storage($view, $util);
187 187
 		});
188
-		$this->registerService('TagMapper', function (Server $c) {
188
+		$this->registerService('TagMapper', function(Server $c) {
189 189
 			return new TagMapper($c->getDatabaseConnection());
190 190
 		});
191 191
 
192
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
192
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
193 193
 			$tagMapper = $c->query('TagMapper');
194 194
 			return new TagManager($tagMapper, $c->getUserSession());
195 195
 		});
196 196
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
197 197
 
198
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
198
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
199 199
 			$config = $c->getConfig();
200 200
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
201 201
 			/** @var \OC\SystemTag\ManagerFactory $factory */
202 202
 			$factory = new $factoryClass($this);
203 203
 			return $factory;
204 204
 		});
205
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
205
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
206 206
 			return $c->query('SystemTagManagerFactory')->getManager();
207 207
 		});
208 208
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
209 209
 
210
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
210
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
211 211
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
212 212
 		});
213
-		$this->registerService('RootFolder', function (Server $c) {
213
+		$this->registerService('RootFolder', function(Server $c) {
214 214
 			$manager = \OC\Files\Filesystem::getMountManager(null);
215 215
 			$view = new View();
216 216
 			$root = new Root(
@@ -238,30 +238,30 @@  discard block
 block discarded – undo
238 238
 		});
239 239
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
240 240
 
241
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
241
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
242 242
 			$config = $c->getConfig();
243 243
 			return new \OC\User\Manager($config);
244 244
 		});
245 245
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
246 246
 
247
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
247
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
248 248
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
249
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
249
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
250 250
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
251 251
 			});
252
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
252
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
253 253
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
254 254
 			});
255
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
255
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
256 256
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
257 257
 			});
258
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
258
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
259 259
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
260 260
 			});
261
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
261
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
262 262
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
263 263
 			});
264
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
265 265
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
266 266
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
267 267
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -281,11 +281,11 @@  discard block
 block discarded – undo
281 281
 			return new Store($session, $logger, $tokenProvider);
282 282
 		});
283 283
 		$this->registerAlias(IStore::class, Store::class);
284
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
284
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
285 285
 			$dbConnection = $c->getDatabaseConnection();
286 286
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
287 287
 		});
288
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
288
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
289 289
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
290 290
 			$crypto = $c->getCrypto();
291 291
 			$config = $c->getConfig();
@@ -295,7 +295,7 @@  discard block
 block discarded – undo
295 295
 		});
296 296
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
297 297
 
298
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
298
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
299 299
 			$manager = $c->getUserManager();
300 300
 			$session = new \OC\Session\Memory('');
301 301
 			$timeFactory = new TimeFactory();
@@ -308,40 +308,40 @@  discard block
 block discarded – undo
308 308
 			}
309 309
 
310 310
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
311
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
311
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
312 312
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
313 313
 			});
314
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
314
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
315 315
 				/** @var $user \OC\User\User */
316 316
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
317 317
 			});
318
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
318
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
319 319
 				/** @var $user \OC\User\User */
320 320
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
321 321
 			});
322
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
322
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
323 323
 				/** @var $user \OC\User\User */
324 324
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
325 325
 			});
326
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
326
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
327 327
 				/** @var $user \OC\User\User */
328 328
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
329 329
 			});
330
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
330
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
331 331
 				/** @var $user \OC\User\User */
332 332
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
333 333
 			});
334
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
334
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
335 335
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
336 336
 			});
337
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
337
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
338 338
 				/** @var $user \OC\User\User */
339 339
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
340 340
 			});
341
-			$userSession->listen('\OC\User', 'logout', function () {
341
+			$userSession->listen('\OC\User', 'logout', function() {
342 342
 				\OC_Hook::emit('OC_User', 'logout', array());
343 343
 			});
344
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
344
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) {
345 345
 				/** @var $user \OC\User\User */
346 346
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
347 347
 			});
@@ -349,11 +349,11 @@  discard block
 block discarded – undo
349 349
 		});
350 350
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
351 351
 
352
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
352
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
353 353
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
354 354
 		});
355 355
 
356
-		$this->registerService(\OCP\INavigationManager::class, function (Server $c) {
356
+		$this->registerService(\OCP\INavigationManager::class, function(Server $c) {
357 357
 			return new \OC\NavigationManager($c->getAppManager(),
358 358
 				$c->getURLGenerator(),
359 359
 				$c->getL10NFactory(),
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		});
363 363
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
364 364
 
365
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
365
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
366 366
 			return new \OC\AllConfig(
367 367
 				$c->getSystemConfig()
368 368
 			);
@@ -370,17 +370,17 @@  discard block
 block discarded – undo
370 370
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
371 371
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
372 372
 
373
-		$this->registerService('SystemConfig', function ($c) use ($config) {
373
+		$this->registerService('SystemConfig', function($c) use ($config) {
374 374
 			return new \OC\SystemConfig($config);
375 375
 		});
376 376
 
377
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
377
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
378 378
 			return new \OC\AppConfig($c->getDatabaseConnection());
379 379
 		});
380 380
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
381 381
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
382 382
 
383
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
383
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
384 384
 			return new \OC\L10N\Factory(
385 385
 				$c->getConfig(),
386 386
 				$c->getRequest(),
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 		});
391 391
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
392 392
 
393
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
393
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
394 394
 			$config = $c->getConfig();
395 395
 			$cacheFactory = $c->getMemCacheFactory();
396 396
 			return new \OC\URLGenerator(
@@ -400,10 +400,10 @@  discard block
 block discarded – undo
400 400
 		});
401 401
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
402 402
 
403
-		$this->registerService('AppHelper', function ($c) {
403
+		$this->registerService('AppHelper', function($c) {
404 404
 			return new \OC\AppHelper();
405 405
 		});
406
-		$this->registerService('AppFetcher', function ($c) {
406
+		$this->registerService('AppFetcher', function($c) {
407 407
 			return new AppFetcher(
408 408
 				$this->getAppDataDir('appstore'),
409 409
 				$this->getHTTPClientService(),
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
 				$this->getConfig()
412 412
 			);
413 413
 		});
414
-		$this->registerService('CategoryFetcher', function ($c) {
414
+		$this->registerService('CategoryFetcher', function($c) {
415 415
 			return new CategoryFetcher(
416 416
 				$this->getAppDataDir('appstore'),
417 417
 				$this->getHTTPClientService(),
@@ -420,21 +420,21 @@  discard block
 block discarded – undo
420 420
 			);
421 421
 		});
422 422
 
423
-		$this->registerService(\OCP\ICache::class, function ($c) {
423
+		$this->registerService(\OCP\ICache::class, function($c) {
424 424
 			return new Cache\File();
425 425
 		});
426 426
 		$this->registerAlias('UserCache', \OCP\ICache::class);
427 427
 
428
-		$this->registerService(Factory::class, function (Server $c) {
428
+		$this->registerService(Factory::class, function(Server $c) {
429 429
 			$config = $c->getConfig();
430 430
 
431 431
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
432 432
 				$v = \OC_App::getAppVersions();
433
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
433
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
434 434
 				$version = implode(',', $v);
435 435
 				$instanceId = \OC_Util::getInstanceId();
436 436
 				$path = \OC::$SERVERROOT;
437
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
437
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
438 438
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
439 439
 					$config->getSystemValue('memcache.local', null),
440 440
 					$config->getSystemValue('memcache.distributed', null),
@@ -451,12 +451,12 @@  discard block
 block discarded – undo
451 451
 		$this->registerAlias('MemCacheFactory', Factory::class);
452 452
 		$this->registerAlias(ICacheFactory::class, Factory::class);
453 453
 
454
-		$this->registerService('RedisFactory', function (Server $c) {
454
+		$this->registerService('RedisFactory', function(Server $c) {
455 455
 			$systemConfig = $c->getSystemConfig();
456 456
 			return new RedisFactory($systemConfig);
457 457
 		});
458 458
 
459
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
459
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
460 460
 			return new \OC\Activity\Manager(
461 461
 				$c->getRequest(),
462 462
 				$c->getUserSession(),
@@ -466,14 +466,14 @@  discard block
 block discarded – undo
466 466
 		});
467 467
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
468 468
 
469
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
469
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
470 470
 			return new \OC\Activity\EventMerger(
471 471
 				$c->getL10N('lib')
472 472
 			);
473 473
 		});
474 474
 		$this->registerAlias(IValidator::class, Validator::class);
475 475
 
476
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
476
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
477 477
 			return new AvatarManager(
478 478
 				$c->getUserManager(),
479 479
 				$c->getAppDataDir('avatar'),
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 		});
485 485
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
486 486
 
487
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
487
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
488 488
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
489 489
 			$logger = Log::getLogClass($logType);
490 490
 			call_user_func(array($logger, 'init'));
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 		});
494 494
 		$this->registerAlias('Logger', \OCP\ILogger::class);
495 495
 
496
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
496
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
497 497
 			$config = $c->getConfig();
498 498
 			return new \OC\BackgroundJob\JobList(
499 499
 				$c->getDatabaseConnection(),
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
 		});
504 504
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
505 505
 
506
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
506
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
507 507
 			$cacheFactory = $c->getMemCacheFactory();
508 508
 			$logger = $c->getLogger();
509 509
 			if ($cacheFactory->isAvailable()) {
@@ -515,32 +515,32 @@  discard block
 block discarded – undo
515 515
 		});
516 516
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
517 517
 
518
-		$this->registerService(\OCP\ISearch::class, function ($c) {
518
+		$this->registerService(\OCP\ISearch::class, function($c) {
519 519
 			return new Search();
520 520
 		});
521 521
 		$this->registerAlias('Search', \OCP\ISearch::class);
522 522
 
523
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
523
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
524 524
 			return new SecureRandom();
525 525
 		});
526 526
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
527 527
 
528
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
528
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
529 529
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
530 530
 		});
531 531
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
532 532
 
533
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
533
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
534 534
 			return new Hasher($c->getConfig());
535 535
 		});
536 536
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
537 537
 
538
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
538
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
539 539
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
540 540
 		});
541 541
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
542 542
 
543
-		$this->registerService(IDBConnection::class, function (Server $c) {
543
+		$this->registerService(IDBConnection::class, function(Server $c) {
544 544
 			$systemConfig = $c->getSystemConfig();
545 545
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
546 546
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -554,7 +554,7 @@  discard block
 block discarded – undo
554 554
 		});
555 555
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
556 556
 
557
-		$this->registerService('HTTPHelper', function (Server $c) {
557
+		$this->registerService('HTTPHelper', function(Server $c) {
558 558
 			$config = $c->getConfig();
559 559
 			return new HTTPHelper(
560 560
 				$config,
@@ -562,7 +562,7 @@  discard block
 block discarded – undo
562 562
 			);
563 563
 		});
564 564
 
565
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
565
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
566 566
 			$user = \OC_User::getUser();
567 567
 			$uid = $user ? $user : null;
568 568
 			return new ClientService(
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 		});
573 573
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
574 574
 
575
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
575
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
576 576
 			if ($c->getSystemConfig()->getValue('debug', false)) {
577 577
 				return new EventLogger();
578 578
 			} else {
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 		});
582 582
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
583 583
 
584
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
584
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
585 585
 			if ($c->getSystemConfig()->getValue('debug', false)) {
586 586
 				return new QueryLogger();
587 587
 			} else {
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 		});
591 591
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
592 592
 
593
-		$this->registerService(TempManager::class, function (Server $c) {
593
+		$this->registerService(TempManager::class, function(Server $c) {
594 594
 			return new TempManager(
595 595
 				$c->getLogger(),
596 596
 				$c->getConfig()
@@ -599,7 +599,7 @@  discard block
 block discarded – undo
599 599
 		$this->registerAlias('TempManager', TempManager::class);
600 600
 		$this->registerAlias(ITempManager::class, TempManager::class);
601 601
 
602
-		$this->registerService(AppManager::class, function (Server $c) {
602
+		$this->registerService(AppManager::class, function(Server $c) {
603 603
 			return new \OC\App\AppManager(
604 604
 				$c->getUserSession(),
605 605
 				$c->getAppConfig(),
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 		$this->registerAlias('AppManager', AppManager::class);
612 612
 		$this->registerAlias(IAppManager::class, AppManager::class);
613 613
 
614
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
614
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
615 615
 			return new DateTimeZone(
616 616
 				$c->getConfig(),
617 617
 				$c->getSession()
@@ -619,7 +619,7 @@  discard block
 block discarded – undo
619 619
 		});
620 620
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
621 621
 
622
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
622
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
623 623
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
624 624
 
625 625
 			return new DateTimeFormatter(
@@ -629,7 +629,7 @@  discard block
 block discarded – undo
629 629
 		});
630 630
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
631 631
 
632
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
632
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
633 633
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
634 634
 			$listener = new UserMountCacheListener($mountCache);
635 635
 			$listener->listen($c->getUserManager());
@@ -637,10 +637,10 @@  discard block
 block discarded – undo
637 637
 		});
638 638
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
639 639
 
640
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
640
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
641 641
 			$loader = \OC\Files\Filesystem::getLoader();
642 642
 			$mountCache = $c->query('UserMountCache');
643
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
643
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
644 644
 
645 645
 			// builtin providers
646 646
 
@@ -653,14 +653,14 @@  discard block
 block discarded – undo
653 653
 		});
654 654
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
655 655
 
656
-		$this->registerService('IniWrapper', function ($c) {
656
+		$this->registerService('IniWrapper', function($c) {
657 657
 			return new IniGetWrapper();
658 658
 		});
659
-		$this->registerService('AsyncCommandBus', function (Server $c) {
659
+		$this->registerService('AsyncCommandBus', function(Server $c) {
660 660
 			$jobList = $c->getJobList();
661 661
 			return new AsyncBus($jobList);
662 662
 		});
663
-		$this->registerService('TrustedDomainHelper', function ($c) {
663
+		$this->registerService('TrustedDomainHelper', function($c) {
664 664
 			return new TrustedDomainHelper($this->getConfig());
665 665
 		});
666 666
 		$this->registerService('Throttler', function(Server $c) {
@@ -671,10 +671,10 @@  discard block
 block discarded – undo
671 671
 				$c->getConfig()
672 672
 			);
673 673
 		});
674
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
674
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
675 675
 			// IConfig and IAppManager requires a working database. This code
676 676
 			// might however be called when ownCloud is not yet setup.
677
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
677
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
678 678
 				$config = $c->getConfig();
679 679
 				$appManager = $c->getAppManager();
680 680
 			} else {
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
 					$c->getTempManager()
693 693
 			);
694 694
 		});
695
-		$this->registerService(\OCP\IRequest::class, function ($c) {
695
+		$this->registerService(\OCP\IRequest::class, function($c) {
696 696
 			if (isset($this['urlParams'])) {
697 697
 				$urlParams = $this['urlParams'];
698 698
 			} else {
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 		});
729 729
 		$this->registerAlias('Request', \OCP\IRequest::class);
730 730
 
731
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
731
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
732 732
 			return new Mailer(
733 733
 				$c->getConfig(),
734 734
 				$c->getLogger(),
@@ -740,14 +740,14 @@  discard block
 block discarded – undo
740 740
 		$this->registerService('LDAPProvider', function(Server $c) {
741 741
 			$config = $c->getConfig();
742 742
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
743
-			if(is_null($factoryClass)) {
743
+			if (is_null($factoryClass)) {
744 744
 				throw new \Exception('ldapProviderFactory not set');
745 745
 			}
746 746
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
747 747
 			$factory = new $factoryClass($this);
748 748
 			return $factory->getLDAPProvider();
749 749
 		});
750
-		$this->registerService('LockingProvider', function (Server $c) {
750
+		$this->registerService('LockingProvider', function(Server $c) {
751 751
 			$ini = $c->getIniWrapper();
752 752
 			$config = $c->getConfig();
753 753
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -763,37 +763,37 @@  discard block
 block discarded – undo
763 763
 			return new NoopLockingProvider();
764 764
 		});
765 765
 
766
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
766
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
767 767
 			return new \OC\Files\Mount\Manager();
768 768
 		});
769 769
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
770 770
 
771
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
771
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
772 772
 			return new \OC\Files\Type\Detection(
773 773
 				$c->getURLGenerator(),
774 774
 				\OC::$configDir,
775
-				\OC::$SERVERROOT . '/resources/config/'
775
+				\OC::$SERVERROOT.'/resources/config/'
776 776
 			);
777 777
 		});
778 778
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
779 779
 
780
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
780
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
781 781
 			return new \OC\Files\Type\Loader(
782 782
 				$c->getDatabaseConnection()
783 783
 			);
784 784
 		});
785 785
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
786 786
 
787
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
787
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
788 788
 			return new Manager(
789 789
 				$c->query(IValidator::class)
790 790
 			);
791 791
 		});
792 792
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
793 793
 
794
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
794
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
795 795
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
796
-			$manager->registerCapability(function () use ($c) {
796
+			$manager->registerCapability(function() use ($c) {
797 797
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
798 798
 			});
799 799
 			return $manager;
@@ -835,13 +835,13 @@  discard block
 block discarded – undo
835 835
 			}
836 836
 			return new \OC_Defaults();
837 837
 		});
838
-		$this->registerService(EventDispatcher::class, function () {
838
+		$this->registerService(EventDispatcher::class, function() {
839 839
 			return new EventDispatcher();
840 840
 		});
841 841
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
842 842
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
843 843
 
844
-		$this->registerService('CryptoWrapper', function (Server $c) {
844
+		$this->registerService('CryptoWrapper', function(Server $c) {
845 845
 			// FIXME: Instantiiated here due to cyclic dependency
846 846
 			$request = new Request(
847 847
 				[
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
 				$request
867 867
 			);
868 868
 		});
869
-		$this->registerService('CsrfTokenManager', function (Server $c) {
869
+		$this->registerService('CsrfTokenManager', function(Server $c) {
870 870
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
871 871
 
872 872
 			return new CsrfTokenManager(
@@ -874,10 +874,10 @@  discard block
 block discarded – undo
874 874
 				$c->query(SessionStorage::class)
875 875
 			);
876 876
 		});
877
-		$this->registerService(SessionStorage::class, function (Server $c) {
877
+		$this->registerService(SessionStorage::class, function(Server $c) {
878 878
 			return new SessionStorage($c->getSession());
879 879
 		});
880
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
880
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
881 881
 			return new ContentSecurityPolicyManager();
882 882
 		});
883 883
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -928,23 +928,23 @@  discard block
 block discarded – undo
928 928
 			);
929 929
 			return $manager;
930 930
 		});
931
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
931
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
932 932
 			return new \OC\Files\AppData\Factory(
933 933
 				$c->getRootFolder(),
934 934
 				$c->getSystemConfig()
935 935
 			);
936 936
 		});
937 937
 
938
-		$this->registerService('LockdownManager', function (Server $c) {
938
+		$this->registerService('LockdownManager', function(Server $c) {
939 939
 			return new LockdownManager();
940 940
 		});
941 941
 
942
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
942
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
943 943
 			return new CloudIdManager();
944 944
 		});
945 945
 
946 946
 		/* To trick DI since we don't extend the DIContainer here */
947
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
947
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
948 948
 			return new CleanPreviewsBackgroundJob(
949 949
 				$c->getRootFolder(),
950 950
 				$c->getLogger(),
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
 	 * @deprecated since 9.2.0 use IAppData
1099 1099
 	 */
1100 1100
 	public function getAppFolder() {
1101
-		$dir = '/' . \OC_App::getCurrentApp();
1101
+		$dir = '/'.\OC_App::getCurrentApp();
1102 1102
 		$root = $this->getRootFolder();
1103 1103
 		if (!$root->nodeExists($dir)) {
1104 1104
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,6 @@
 block discarded – undo
94 94
 use OC\Session\CryptoWrapper;
95 95
 use OC\Tagging\TagMapper;
96 96
 use OCA\Theming\ThemingDefaults;
97
-
98 97
 use OCP\App\IAppManager;
99 98
 use OCA\Theming\Util;
100 99
 use OCP\Federation\ICloudIdManager;
Please login to merge, or discard this patch.
Indentation   +1586 added lines, -1586 removed lines patch added patch discarded remove patch
@@ -117,1595 +117,1595 @@
 block discarded – undo
117 117
  * TODO: hookup all manager classes
118 118
  */
119 119
 class Server extends ServerContainer implements IServerContainer {
120
-	/** @var string */
121
-	private $webRoot;
122
-
123
-	/**
124
-	 * @param string $webRoot
125
-	 * @param \OC\Config $config
126
-	 */
127
-	public function __construct($webRoot, \OC\Config $config) {
128
-		parent::__construct();
129
-		$this->webRoot = $webRoot;
130
-
131
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
-
134
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
135
-			return new PreviewManager(
136
-				$c->getConfig(),
137
-				$c->getRootFolder(),
138
-				$c->getAppDataDir('preview'),
139
-				$c->getEventDispatcher(),
140
-				$c->getSession()->get('user_id')
141
-			);
142
-		});
143
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
-
145
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
-			return new \OC\Preview\Watcher(
147
-				$c->getAppDataDir('preview')
148
-			);
149
-		});
150
-
151
-		$this->registerService('EncryptionManager', function (Server $c) {
152
-			$view = new View();
153
-			$util = new Encryption\Util(
154
-				$view,
155
-				$c->getUserManager(),
156
-				$c->getGroupManager(),
157
-				$c->getConfig()
158
-			);
159
-			return new Encryption\Manager(
160
-				$c->getConfig(),
161
-				$c->getLogger(),
162
-				$c->getL10N('core'),
163
-				new View(),
164
-				$util,
165
-				new ArrayCache()
166
-			);
167
-		});
168
-
169
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
170
-			$util = new Encryption\Util(
171
-				new View(),
172
-				$c->getUserManager(),
173
-				$c->getGroupManager(),
174
-				$c->getConfig()
175
-			);
176
-			return new Encryption\File($util);
177
-		});
178
-
179
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
180
-			$view = new View();
181
-			$util = new Encryption\Util(
182
-				$view,
183
-				$c->getUserManager(),
184
-				$c->getGroupManager(),
185
-				$c->getConfig()
186
-			);
187
-
188
-			return new Encryption\Keys\Storage($view, $util);
189
-		});
190
-		$this->registerService('TagMapper', function (Server $c) {
191
-			return new TagMapper($c->getDatabaseConnection());
192
-		});
193
-
194
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
-			$tagMapper = $c->query('TagMapper');
196
-			return new TagManager($tagMapper, $c->getUserSession());
197
-		});
198
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
199
-
200
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
201
-			$config = $c->getConfig();
202
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
-			/** @var \OC\SystemTag\ManagerFactory $factory */
204
-			$factory = new $factoryClass($this);
205
-			return $factory;
206
-		});
207
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
-			return $c->query('SystemTagManagerFactory')->getManager();
209
-		});
210
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
-
212
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
-		});
215
-		$this->registerService('RootFolder', function (Server $c) {
216
-			$manager = \OC\Files\Filesystem::getMountManager(null);
217
-			$view = new View();
218
-			$root = new Root(
219
-				$manager,
220
-				$view,
221
-				null,
222
-				$c->getUserMountCache(),
223
-				$this->getLogger(),
224
-				$this->getUserManager()
225
-			);
226
-			$connector = new HookConnector($root, $view);
227
-			$connector->viewToNode();
228
-
229
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
-			$previewConnector->connectWatcher();
231
-
232
-			return $root;
233
-		});
234
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
-
236
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
-			return new LazyRoot(function() use ($c) {
238
-				return $c->query('RootFolder');
239
-			});
240
-		});
241
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
-
243
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
-			$config = $c->getConfig();
245
-			return new \OC\User\Manager($config);
246
-		});
247
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
248
-
249
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
-			});
254
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
-			});
257
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
-			});
260
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
-			});
263
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
-			});
266
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
-			});
271
-			return $groupManager;
272
-		});
273
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
-
275
-		$this->registerService(Store::class, function(Server $c) {
276
-			$session = $c->getSession();
277
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
-			} else {
280
-				$tokenProvider = null;
281
-			}
282
-			$logger = $c->getLogger();
283
-			return new Store($session, $logger, $tokenProvider);
284
-		});
285
-		$this->registerAlias(IStore::class, Store::class);
286
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
-			$dbConnection = $c->getDatabaseConnection();
288
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
-		});
290
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
-			$crypto = $c->getCrypto();
293
-			$config = $c->getConfig();
294
-			$logger = $c->getLogger();
295
-			$timeFactory = new TimeFactory();
296
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
-		});
298
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
-
300
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
-			$manager = $c->getUserManager();
302
-			$session = new \OC\Session\Memory('');
303
-			$timeFactory = new TimeFactory();
304
-			// Token providers might require a working database. This code
305
-			// might however be called when ownCloud is not yet setup.
306
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
-			} else {
309
-				$defaultTokenProvider = null;
310
-			}
311
-
312
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
313
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
-			});
316
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
-				/** @var $user \OC\User\User */
318
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
-			});
320
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
321
-				/** @var $user \OC\User\User */
322
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
-			});
324
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
325
-				/** @var $user \OC\User\User */
326
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
-			});
328
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
-				/** @var $user \OC\User\User */
330
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
-			});
332
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
-				/** @var $user \OC\User\User */
334
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
-			});
336
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
-			});
339
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
-				/** @var $user \OC\User\User */
341
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
-			});
343
-			$userSession->listen('\OC\User', 'logout', function () {
344
-				\OC_Hook::emit('OC_User', 'logout', array());
345
-			});
346
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
-				/** @var $user \OC\User\User */
348
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
-			});
350
-			return $userSession;
351
-		});
352
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
353
-
354
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
-		});
357
-
358
-		$this->registerService(\OCP\INavigationManager::class, function (Server $c) {
359
-			return new \OC\NavigationManager($c->getAppManager(),
360
-				$c->getURLGenerator(),
361
-				$c->getL10NFactory(),
362
-				$c->getUserSession(),
363
-				$c->getGroupManager());
364
-		});
365
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
366
-
367
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
368
-			return new \OC\AllConfig(
369
-				$c->getSystemConfig()
370
-			);
371
-		});
372
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
373
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
374
-
375
-		$this->registerService('SystemConfig', function ($c) use ($config) {
376
-			return new \OC\SystemConfig($config);
377
-		});
378
-
379
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
380
-			return new \OC\AppConfig($c->getDatabaseConnection());
381
-		});
382
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
383
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
384
-
385
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
386
-			return new \OC\L10N\Factory(
387
-				$c->getConfig(),
388
-				$c->getRequest(),
389
-				$c->getUserSession(),
390
-				\OC::$SERVERROOT
391
-			);
392
-		});
393
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
394
-
395
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
396
-			$config = $c->getConfig();
397
-			$cacheFactory = $c->getMemCacheFactory();
398
-			return new \OC\URLGenerator(
399
-				$config,
400
-				$cacheFactory
401
-			);
402
-		});
403
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
404
-
405
-		$this->registerService('AppHelper', function ($c) {
406
-			return new \OC\AppHelper();
407
-		});
408
-		$this->registerService('AppFetcher', function ($c) {
409
-			return new AppFetcher(
410
-				$this->getAppDataDir('appstore'),
411
-				$this->getHTTPClientService(),
412
-				$this->query(TimeFactory::class),
413
-				$this->getConfig()
414
-			);
415
-		});
416
-		$this->registerService('CategoryFetcher', function ($c) {
417
-			return new CategoryFetcher(
418
-				$this->getAppDataDir('appstore'),
419
-				$this->getHTTPClientService(),
420
-				$this->query(TimeFactory::class),
421
-				$this->getConfig()
422
-			);
423
-		});
424
-
425
-		$this->registerService(\OCP\ICache::class, function ($c) {
426
-			return new Cache\File();
427
-		});
428
-		$this->registerAlias('UserCache', \OCP\ICache::class);
429
-
430
-		$this->registerService(Factory::class, function (Server $c) {
431
-			$config = $c->getConfig();
432
-
433
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
434
-				$v = \OC_App::getAppVersions();
435
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
436
-				$version = implode(',', $v);
437
-				$instanceId = \OC_Util::getInstanceId();
438
-				$path = \OC::$SERVERROOT;
439
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
440
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
441
-					$config->getSystemValue('memcache.local', null),
442
-					$config->getSystemValue('memcache.distributed', null),
443
-					$config->getSystemValue('memcache.locking', null)
444
-				);
445
-			}
446
-
447
-			return new \OC\Memcache\Factory('', $c->getLogger(),
448
-				'\\OC\\Memcache\\ArrayCache',
449
-				'\\OC\\Memcache\\ArrayCache',
450
-				'\\OC\\Memcache\\ArrayCache'
451
-			);
452
-		});
453
-		$this->registerAlias('MemCacheFactory', Factory::class);
454
-		$this->registerAlias(ICacheFactory::class, Factory::class);
455
-
456
-		$this->registerService('RedisFactory', function (Server $c) {
457
-			$systemConfig = $c->getSystemConfig();
458
-			return new RedisFactory($systemConfig);
459
-		});
460
-
461
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
462
-			return new \OC\Activity\Manager(
463
-				$c->getRequest(),
464
-				$c->getUserSession(),
465
-				$c->getConfig(),
466
-				$c->query(IValidator::class)
467
-			);
468
-		});
469
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
470
-
471
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
472
-			return new \OC\Activity\EventMerger(
473
-				$c->getL10N('lib')
474
-			);
475
-		});
476
-		$this->registerAlias(IValidator::class, Validator::class);
477
-
478
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
479
-			return new AvatarManager(
480
-				$c->getUserManager(),
481
-				$c->getAppDataDir('avatar'),
482
-				$c->getL10N('lib'),
483
-				$c->getLogger(),
484
-				$c->getConfig()
485
-			);
486
-		});
487
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
488
-
489
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
490
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
491
-			$logger = Log::getLogClass($logType);
492
-			call_user_func(array($logger, 'init'));
493
-
494
-			return new Log($logger);
495
-		});
496
-		$this->registerAlias('Logger', \OCP\ILogger::class);
497
-
498
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
499
-			$config = $c->getConfig();
500
-			return new \OC\BackgroundJob\JobList(
501
-				$c->getDatabaseConnection(),
502
-				$config,
503
-				new TimeFactory()
504
-			);
505
-		});
506
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
507
-
508
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
509
-			$cacheFactory = $c->getMemCacheFactory();
510
-			$logger = $c->getLogger();
511
-			if ($cacheFactory->isAvailable()) {
512
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
513
-			} else {
514
-				$router = new \OC\Route\Router($logger);
515
-			}
516
-			return $router;
517
-		});
518
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
519
-
520
-		$this->registerService(\OCP\ISearch::class, function ($c) {
521
-			return new Search();
522
-		});
523
-		$this->registerAlias('Search', \OCP\ISearch::class);
524
-
525
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
526
-			return new SecureRandom();
527
-		});
528
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
529
-
530
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
531
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
532
-		});
533
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
534
-
535
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
536
-			return new Hasher($c->getConfig());
537
-		});
538
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
539
-
540
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
541
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
542
-		});
543
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
544
-
545
-		$this->registerService(IDBConnection::class, function (Server $c) {
546
-			$systemConfig = $c->getSystemConfig();
547
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
548
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
549
-			if (!$factory->isValidType($type)) {
550
-				throw new \OC\DatabaseException('Invalid database type');
551
-			}
552
-			$connectionParams = $factory->createConnectionParams();
553
-			$connection = $factory->getConnection($type, $connectionParams);
554
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
555
-			return $connection;
556
-		});
557
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
558
-
559
-		$this->registerService('HTTPHelper', function (Server $c) {
560
-			$config = $c->getConfig();
561
-			return new HTTPHelper(
562
-				$config,
563
-				$c->getHTTPClientService()
564
-			);
565
-		});
566
-
567
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
568
-			$user = \OC_User::getUser();
569
-			$uid = $user ? $user : null;
570
-			return new ClientService(
571
-				$c->getConfig(),
572
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
573
-			);
574
-		});
575
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
576
-
577
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
578
-			if ($c->getSystemConfig()->getValue('debug', false)) {
579
-				return new EventLogger();
580
-			} else {
581
-				return new NullEventLogger();
582
-			}
583
-		});
584
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
585
-
586
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
587
-			if ($c->getSystemConfig()->getValue('debug', false)) {
588
-				return new QueryLogger();
589
-			} else {
590
-				return new NullQueryLogger();
591
-			}
592
-		});
593
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
594
-
595
-		$this->registerService(TempManager::class, function (Server $c) {
596
-			return new TempManager(
597
-				$c->getLogger(),
598
-				$c->getConfig()
599
-			);
600
-		});
601
-		$this->registerAlias('TempManager', TempManager::class);
602
-		$this->registerAlias(ITempManager::class, TempManager::class);
603
-
604
-		$this->registerService(AppManager::class, function (Server $c) {
605
-			return new \OC\App\AppManager(
606
-				$c->getUserSession(),
607
-				$c->getAppConfig(),
608
-				$c->getGroupManager(),
609
-				$c->getMemCacheFactory(),
610
-				$c->getEventDispatcher()
611
-			);
612
-		});
613
-		$this->registerAlias('AppManager', AppManager::class);
614
-		$this->registerAlias(IAppManager::class, AppManager::class);
615
-
616
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
617
-			return new DateTimeZone(
618
-				$c->getConfig(),
619
-				$c->getSession()
620
-			);
621
-		});
622
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
623
-
624
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
625
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
626
-
627
-			return new DateTimeFormatter(
628
-				$c->getDateTimeZone()->getTimeZone(),
629
-				$c->getL10N('lib', $language)
630
-			);
631
-		});
632
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
633
-
634
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
635
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
636
-			$listener = new UserMountCacheListener($mountCache);
637
-			$listener->listen($c->getUserManager());
638
-			return $mountCache;
639
-		});
640
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
641
-
642
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
643
-			$loader = \OC\Files\Filesystem::getLoader();
644
-			$mountCache = $c->query('UserMountCache');
645
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
646
-
647
-			// builtin providers
648
-
649
-			$config = $c->getConfig();
650
-			$manager->registerProvider(new CacheMountProvider($config));
651
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
652
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
653
-
654
-			return $manager;
655
-		});
656
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
657
-
658
-		$this->registerService('IniWrapper', function ($c) {
659
-			return new IniGetWrapper();
660
-		});
661
-		$this->registerService('AsyncCommandBus', function (Server $c) {
662
-			$jobList = $c->getJobList();
663
-			return new AsyncBus($jobList);
664
-		});
665
-		$this->registerService('TrustedDomainHelper', function ($c) {
666
-			return new TrustedDomainHelper($this->getConfig());
667
-		});
668
-		$this->registerService('Throttler', function(Server $c) {
669
-			return new Throttler(
670
-				$c->getDatabaseConnection(),
671
-				new TimeFactory(),
672
-				$c->getLogger(),
673
-				$c->getConfig()
674
-			);
675
-		});
676
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
677
-			// IConfig and IAppManager requires a working database. This code
678
-			// might however be called when ownCloud is not yet setup.
679
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
680
-				$config = $c->getConfig();
681
-				$appManager = $c->getAppManager();
682
-			} else {
683
-				$config = null;
684
-				$appManager = null;
685
-			}
686
-
687
-			return new Checker(
688
-					new EnvironmentHelper(),
689
-					new FileAccessHelper(),
690
-					new AppLocator(),
691
-					$config,
692
-					$c->getMemCacheFactory(),
693
-					$appManager,
694
-					$c->getTempManager()
695
-			);
696
-		});
697
-		$this->registerService(\OCP\IRequest::class, function ($c) {
698
-			if (isset($this['urlParams'])) {
699
-				$urlParams = $this['urlParams'];
700
-			} else {
701
-				$urlParams = [];
702
-			}
703
-
704
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
705
-				&& in_array('fakeinput', stream_get_wrappers())
706
-			) {
707
-				$stream = 'fakeinput://data';
708
-			} else {
709
-				$stream = 'php://input';
710
-			}
711
-
712
-			return new Request(
713
-				[
714
-					'get' => $_GET,
715
-					'post' => $_POST,
716
-					'files' => $_FILES,
717
-					'server' => $_SERVER,
718
-					'env' => $_ENV,
719
-					'cookies' => $_COOKIE,
720
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
721
-						? $_SERVER['REQUEST_METHOD']
722
-						: null,
723
-					'urlParams' => $urlParams,
724
-				],
725
-				$this->getSecureRandom(),
726
-				$this->getConfig(),
727
-				$this->getCsrfTokenManager(),
728
-				$stream
729
-			);
730
-		});
731
-		$this->registerAlias('Request', \OCP\IRequest::class);
732
-
733
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
734
-			return new Mailer(
735
-				$c->getConfig(),
736
-				$c->getLogger(),
737
-				$c->getThemingDefaults()
738
-			);
739
-		});
740
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
741
-
742
-		$this->registerService('LDAPProvider', function(Server $c) {
743
-			$config = $c->getConfig();
744
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
745
-			if(is_null($factoryClass)) {
746
-				throw new \Exception('ldapProviderFactory not set');
747
-			}
748
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
749
-			$factory = new $factoryClass($this);
750
-			return $factory->getLDAPProvider();
751
-		});
752
-		$this->registerService('LockingProvider', function (Server $c) {
753
-			$ini = $c->getIniWrapper();
754
-			$config = $c->getConfig();
755
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
756
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
757
-				/** @var \OC\Memcache\Factory $memcacheFactory */
758
-				$memcacheFactory = $c->getMemCacheFactory();
759
-				$memcache = $memcacheFactory->createLocking('lock');
760
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
761
-					return new MemcacheLockingProvider($memcache, $ttl);
762
-				}
763
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
764
-			}
765
-			return new NoopLockingProvider();
766
-		});
767
-
768
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
769
-			return new \OC\Files\Mount\Manager();
770
-		});
771
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
772
-
773
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
774
-			return new \OC\Files\Type\Detection(
775
-				$c->getURLGenerator(),
776
-				\OC::$configDir,
777
-				\OC::$SERVERROOT . '/resources/config/'
778
-			);
779
-		});
780
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
781
-
782
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
783
-			return new \OC\Files\Type\Loader(
784
-				$c->getDatabaseConnection()
785
-			);
786
-		});
787
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
788
-
789
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
790
-			return new Manager(
791
-				$c->query(IValidator::class)
792
-			);
793
-		});
794
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
795
-
796
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
797
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
798
-			$manager->registerCapability(function () use ($c) {
799
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
800
-			});
801
-			return $manager;
802
-		});
803
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
804
-
805
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
806
-			$config = $c->getConfig();
807
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
808
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
809
-			$factory = new $factoryClass($this);
810
-			return $factory->getManager();
811
-		});
812
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
813
-
814
-		$this->registerService('ThemingDefaults', function(Server $c) {
815
-			/*
120
+    /** @var string */
121
+    private $webRoot;
122
+
123
+    /**
124
+     * @param string $webRoot
125
+     * @param \OC\Config $config
126
+     */
127
+    public function __construct($webRoot, \OC\Config $config) {
128
+        parent::__construct();
129
+        $this->webRoot = $webRoot;
130
+
131
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
+
134
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
135
+            return new PreviewManager(
136
+                $c->getConfig(),
137
+                $c->getRootFolder(),
138
+                $c->getAppDataDir('preview'),
139
+                $c->getEventDispatcher(),
140
+                $c->getSession()->get('user_id')
141
+            );
142
+        });
143
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
+
145
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
+            return new \OC\Preview\Watcher(
147
+                $c->getAppDataDir('preview')
148
+            );
149
+        });
150
+
151
+        $this->registerService('EncryptionManager', function (Server $c) {
152
+            $view = new View();
153
+            $util = new Encryption\Util(
154
+                $view,
155
+                $c->getUserManager(),
156
+                $c->getGroupManager(),
157
+                $c->getConfig()
158
+            );
159
+            return new Encryption\Manager(
160
+                $c->getConfig(),
161
+                $c->getLogger(),
162
+                $c->getL10N('core'),
163
+                new View(),
164
+                $util,
165
+                new ArrayCache()
166
+            );
167
+        });
168
+
169
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
170
+            $util = new Encryption\Util(
171
+                new View(),
172
+                $c->getUserManager(),
173
+                $c->getGroupManager(),
174
+                $c->getConfig()
175
+            );
176
+            return new Encryption\File($util);
177
+        });
178
+
179
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
180
+            $view = new View();
181
+            $util = new Encryption\Util(
182
+                $view,
183
+                $c->getUserManager(),
184
+                $c->getGroupManager(),
185
+                $c->getConfig()
186
+            );
187
+
188
+            return new Encryption\Keys\Storage($view, $util);
189
+        });
190
+        $this->registerService('TagMapper', function (Server $c) {
191
+            return new TagMapper($c->getDatabaseConnection());
192
+        });
193
+
194
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
+            $tagMapper = $c->query('TagMapper');
196
+            return new TagManager($tagMapper, $c->getUserSession());
197
+        });
198
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
199
+
200
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
201
+            $config = $c->getConfig();
202
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
+            /** @var \OC\SystemTag\ManagerFactory $factory */
204
+            $factory = new $factoryClass($this);
205
+            return $factory;
206
+        });
207
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
+            return $c->query('SystemTagManagerFactory')->getManager();
209
+        });
210
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
+
212
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
+        });
215
+        $this->registerService('RootFolder', function (Server $c) {
216
+            $manager = \OC\Files\Filesystem::getMountManager(null);
217
+            $view = new View();
218
+            $root = new Root(
219
+                $manager,
220
+                $view,
221
+                null,
222
+                $c->getUserMountCache(),
223
+                $this->getLogger(),
224
+                $this->getUserManager()
225
+            );
226
+            $connector = new HookConnector($root, $view);
227
+            $connector->viewToNode();
228
+
229
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
+            $previewConnector->connectWatcher();
231
+
232
+            return $root;
233
+        });
234
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
+
236
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
+            return new LazyRoot(function() use ($c) {
238
+                return $c->query('RootFolder');
239
+            });
240
+        });
241
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
+
243
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
+            $config = $c->getConfig();
245
+            return new \OC\User\Manager($config);
246
+        });
247
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
248
+
249
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
+            });
254
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
+            });
257
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
+            });
260
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
+            });
263
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
+            });
266
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
+            });
271
+            return $groupManager;
272
+        });
273
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
+
275
+        $this->registerService(Store::class, function(Server $c) {
276
+            $session = $c->getSession();
277
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
+            } else {
280
+                $tokenProvider = null;
281
+            }
282
+            $logger = $c->getLogger();
283
+            return new Store($session, $logger, $tokenProvider);
284
+        });
285
+        $this->registerAlias(IStore::class, Store::class);
286
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
+            $dbConnection = $c->getDatabaseConnection();
288
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
+        });
290
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
+            $crypto = $c->getCrypto();
293
+            $config = $c->getConfig();
294
+            $logger = $c->getLogger();
295
+            $timeFactory = new TimeFactory();
296
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
+        });
298
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
+
300
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
+            $manager = $c->getUserManager();
302
+            $session = new \OC\Session\Memory('');
303
+            $timeFactory = new TimeFactory();
304
+            // Token providers might require a working database. This code
305
+            // might however be called when ownCloud is not yet setup.
306
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
+            } else {
309
+                $defaultTokenProvider = null;
310
+            }
311
+
312
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
313
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
+            });
316
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
+                /** @var $user \OC\User\User */
318
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
+            });
320
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
321
+                /** @var $user \OC\User\User */
322
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
+            });
324
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
325
+                /** @var $user \OC\User\User */
326
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
+            });
328
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
+                /** @var $user \OC\User\User */
330
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
+            });
332
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
+                /** @var $user \OC\User\User */
334
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
+            });
336
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
+            });
339
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
+                /** @var $user \OC\User\User */
341
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
+            });
343
+            $userSession->listen('\OC\User', 'logout', function () {
344
+                \OC_Hook::emit('OC_User', 'logout', array());
345
+            });
346
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
+                /** @var $user \OC\User\User */
348
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
+            });
350
+            return $userSession;
351
+        });
352
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
353
+
354
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
+        });
357
+
358
+        $this->registerService(\OCP\INavigationManager::class, function (Server $c) {
359
+            return new \OC\NavigationManager($c->getAppManager(),
360
+                $c->getURLGenerator(),
361
+                $c->getL10NFactory(),
362
+                $c->getUserSession(),
363
+                $c->getGroupManager());
364
+        });
365
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
366
+
367
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
368
+            return new \OC\AllConfig(
369
+                $c->getSystemConfig()
370
+            );
371
+        });
372
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
373
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
374
+
375
+        $this->registerService('SystemConfig', function ($c) use ($config) {
376
+            return new \OC\SystemConfig($config);
377
+        });
378
+
379
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
380
+            return new \OC\AppConfig($c->getDatabaseConnection());
381
+        });
382
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
383
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
384
+
385
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
386
+            return new \OC\L10N\Factory(
387
+                $c->getConfig(),
388
+                $c->getRequest(),
389
+                $c->getUserSession(),
390
+                \OC::$SERVERROOT
391
+            );
392
+        });
393
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
394
+
395
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
396
+            $config = $c->getConfig();
397
+            $cacheFactory = $c->getMemCacheFactory();
398
+            return new \OC\URLGenerator(
399
+                $config,
400
+                $cacheFactory
401
+            );
402
+        });
403
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
404
+
405
+        $this->registerService('AppHelper', function ($c) {
406
+            return new \OC\AppHelper();
407
+        });
408
+        $this->registerService('AppFetcher', function ($c) {
409
+            return new AppFetcher(
410
+                $this->getAppDataDir('appstore'),
411
+                $this->getHTTPClientService(),
412
+                $this->query(TimeFactory::class),
413
+                $this->getConfig()
414
+            );
415
+        });
416
+        $this->registerService('CategoryFetcher', function ($c) {
417
+            return new CategoryFetcher(
418
+                $this->getAppDataDir('appstore'),
419
+                $this->getHTTPClientService(),
420
+                $this->query(TimeFactory::class),
421
+                $this->getConfig()
422
+            );
423
+        });
424
+
425
+        $this->registerService(\OCP\ICache::class, function ($c) {
426
+            return new Cache\File();
427
+        });
428
+        $this->registerAlias('UserCache', \OCP\ICache::class);
429
+
430
+        $this->registerService(Factory::class, function (Server $c) {
431
+            $config = $c->getConfig();
432
+
433
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
434
+                $v = \OC_App::getAppVersions();
435
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
436
+                $version = implode(',', $v);
437
+                $instanceId = \OC_Util::getInstanceId();
438
+                $path = \OC::$SERVERROOT;
439
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
440
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
441
+                    $config->getSystemValue('memcache.local', null),
442
+                    $config->getSystemValue('memcache.distributed', null),
443
+                    $config->getSystemValue('memcache.locking', null)
444
+                );
445
+            }
446
+
447
+            return new \OC\Memcache\Factory('', $c->getLogger(),
448
+                '\\OC\\Memcache\\ArrayCache',
449
+                '\\OC\\Memcache\\ArrayCache',
450
+                '\\OC\\Memcache\\ArrayCache'
451
+            );
452
+        });
453
+        $this->registerAlias('MemCacheFactory', Factory::class);
454
+        $this->registerAlias(ICacheFactory::class, Factory::class);
455
+
456
+        $this->registerService('RedisFactory', function (Server $c) {
457
+            $systemConfig = $c->getSystemConfig();
458
+            return new RedisFactory($systemConfig);
459
+        });
460
+
461
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
462
+            return new \OC\Activity\Manager(
463
+                $c->getRequest(),
464
+                $c->getUserSession(),
465
+                $c->getConfig(),
466
+                $c->query(IValidator::class)
467
+            );
468
+        });
469
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
470
+
471
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
472
+            return new \OC\Activity\EventMerger(
473
+                $c->getL10N('lib')
474
+            );
475
+        });
476
+        $this->registerAlias(IValidator::class, Validator::class);
477
+
478
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
479
+            return new AvatarManager(
480
+                $c->getUserManager(),
481
+                $c->getAppDataDir('avatar'),
482
+                $c->getL10N('lib'),
483
+                $c->getLogger(),
484
+                $c->getConfig()
485
+            );
486
+        });
487
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
488
+
489
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
490
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
491
+            $logger = Log::getLogClass($logType);
492
+            call_user_func(array($logger, 'init'));
493
+
494
+            return new Log($logger);
495
+        });
496
+        $this->registerAlias('Logger', \OCP\ILogger::class);
497
+
498
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
499
+            $config = $c->getConfig();
500
+            return new \OC\BackgroundJob\JobList(
501
+                $c->getDatabaseConnection(),
502
+                $config,
503
+                new TimeFactory()
504
+            );
505
+        });
506
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
507
+
508
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
509
+            $cacheFactory = $c->getMemCacheFactory();
510
+            $logger = $c->getLogger();
511
+            if ($cacheFactory->isAvailable()) {
512
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
513
+            } else {
514
+                $router = new \OC\Route\Router($logger);
515
+            }
516
+            return $router;
517
+        });
518
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
519
+
520
+        $this->registerService(\OCP\ISearch::class, function ($c) {
521
+            return new Search();
522
+        });
523
+        $this->registerAlias('Search', \OCP\ISearch::class);
524
+
525
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
526
+            return new SecureRandom();
527
+        });
528
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
529
+
530
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
531
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
532
+        });
533
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
534
+
535
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
536
+            return new Hasher($c->getConfig());
537
+        });
538
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
539
+
540
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
541
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
542
+        });
543
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
544
+
545
+        $this->registerService(IDBConnection::class, function (Server $c) {
546
+            $systemConfig = $c->getSystemConfig();
547
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
548
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
549
+            if (!$factory->isValidType($type)) {
550
+                throw new \OC\DatabaseException('Invalid database type');
551
+            }
552
+            $connectionParams = $factory->createConnectionParams();
553
+            $connection = $factory->getConnection($type, $connectionParams);
554
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
555
+            return $connection;
556
+        });
557
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
558
+
559
+        $this->registerService('HTTPHelper', function (Server $c) {
560
+            $config = $c->getConfig();
561
+            return new HTTPHelper(
562
+                $config,
563
+                $c->getHTTPClientService()
564
+            );
565
+        });
566
+
567
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
568
+            $user = \OC_User::getUser();
569
+            $uid = $user ? $user : null;
570
+            return new ClientService(
571
+                $c->getConfig(),
572
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
573
+            );
574
+        });
575
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
576
+
577
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
578
+            if ($c->getSystemConfig()->getValue('debug', false)) {
579
+                return new EventLogger();
580
+            } else {
581
+                return new NullEventLogger();
582
+            }
583
+        });
584
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
585
+
586
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
587
+            if ($c->getSystemConfig()->getValue('debug', false)) {
588
+                return new QueryLogger();
589
+            } else {
590
+                return new NullQueryLogger();
591
+            }
592
+        });
593
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
594
+
595
+        $this->registerService(TempManager::class, function (Server $c) {
596
+            return new TempManager(
597
+                $c->getLogger(),
598
+                $c->getConfig()
599
+            );
600
+        });
601
+        $this->registerAlias('TempManager', TempManager::class);
602
+        $this->registerAlias(ITempManager::class, TempManager::class);
603
+
604
+        $this->registerService(AppManager::class, function (Server $c) {
605
+            return new \OC\App\AppManager(
606
+                $c->getUserSession(),
607
+                $c->getAppConfig(),
608
+                $c->getGroupManager(),
609
+                $c->getMemCacheFactory(),
610
+                $c->getEventDispatcher()
611
+            );
612
+        });
613
+        $this->registerAlias('AppManager', AppManager::class);
614
+        $this->registerAlias(IAppManager::class, AppManager::class);
615
+
616
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
617
+            return new DateTimeZone(
618
+                $c->getConfig(),
619
+                $c->getSession()
620
+            );
621
+        });
622
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
623
+
624
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
625
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
626
+
627
+            return new DateTimeFormatter(
628
+                $c->getDateTimeZone()->getTimeZone(),
629
+                $c->getL10N('lib', $language)
630
+            );
631
+        });
632
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
633
+
634
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
635
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
636
+            $listener = new UserMountCacheListener($mountCache);
637
+            $listener->listen($c->getUserManager());
638
+            return $mountCache;
639
+        });
640
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
641
+
642
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
643
+            $loader = \OC\Files\Filesystem::getLoader();
644
+            $mountCache = $c->query('UserMountCache');
645
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
646
+
647
+            // builtin providers
648
+
649
+            $config = $c->getConfig();
650
+            $manager->registerProvider(new CacheMountProvider($config));
651
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
652
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
653
+
654
+            return $manager;
655
+        });
656
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
657
+
658
+        $this->registerService('IniWrapper', function ($c) {
659
+            return new IniGetWrapper();
660
+        });
661
+        $this->registerService('AsyncCommandBus', function (Server $c) {
662
+            $jobList = $c->getJobList();
663
+            return new AsyncBus($jobList);
664
+        });
665
+        $this->registerService('TrustedDomainHelper', function ($c) {
666
+            return new TrustedDomainHelper($this->getConfig());
667
+        });
668
+        $this->registerService('Throttler', function(Server $c) {
669
+            return new Throttler(
670
+                $c->getDatabaseConnection(),
671
+                new TimeFactory(),
672
+                $c->getLogger(),
673
+                $c->getConfig()
674
+            );
675
+        });
676
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
677
+            // IConfig and IAppManager requires a working database. This code
678
+            // might however be called when ownCloud is not yet setup.
679
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
680
+                $config = $c->getConfig();
681
+                $appManager = $c->getAppManager();
682
+            } else {
683
+                $config = null;
684
+                $appManager = null;
685
+            }
686
+
687
+            return new Checker(
688
+                    new EnvironmentHelper(),
689
+                    new FileAccessHelper(),
690
+                    new AppLocator(),
691
+                    $config,
692
+                    $c->getMemCacheFactory(),
693
+                    $appManager,
694
+                    $c->getTempManager()
695
+            );
696
+        });
697
+        $this->registerService(\OCP\IRequest::class, function ($c) {
698
+            if (isset($this['urlParams'])) {
699
+                $urlParams = $this['urlParams'];
700
+            } else {
701
+                $urlParams = [];
702
+            }
703
+
704
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
705
+                && in_array('fakeinput', stream_get_wrappers())
706
+            ) {
707
+                $stream = 'fakeinput://data';
708
+            } else {
709
+                $stream = 'php://input';
710
+            }
711
+
712
+            return new Request(
713
+                [
714
+                    'get' => $_GET,
715
+                    'post' => $_POST,
716
+                    'files' => $_FILES,
717
+                    'server' => $_SERVER,
718
+                    'env' => $_ENV,
719
+                    'cookies' => $_COOKIE,
720
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
721
+                        ? $_SERVER['REQUEST_METHOD']
722
+                        : null,
723
+                    'urlParams' => $urlParams,
724
+                ],
725
+                $this->getSecureRandom(),
726
+                $this->getConfig(),
727
+                $this->getCsrfTokenManager(),
728
+                $stream
729
+            );
730
+        });
731
+        $this->registerAlias('Request', \OCP\IRequest::class);
732
+
733
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
734
+            return new Mailer(
735
+                $c->getConfig(),
736
+                $c->getLogger(),
737
+                $c->getThemingDefaults()
738
+            );
739
+        });
740
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
741
+
742
+        $this->registerService('LDAPProvider', function(Server $c) {
743
+            $config = $c->getConfig();
744
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
745
+            if(is_null($factoryClass)) {
746
+                throw new \Exception('ldapProviderFactory not set');
747
+            }
748
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
749
+            $factory = new $factoryClass($this);
750
+            return $factory->getLDAPProvider();
751
+        });
752
+        $this->registerService('LockingProvider', function (Server $c) {
753
+            $ini = $c->getIniWrapper();
754
+            $config = $c->getConfig();
755
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
756
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
757
+                /** @var \OC\Memcache\Factory $memcacheFactory */
758
+                $memcacheFactory = $c->getMemCacheFactory();
759
+                $memcache = $memcacheFactory->createLocking('lock');
760
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
761
+                    return new MemcacheLockingProvider($memcache, $ttl);
762
+                }
763
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
764
+            }
765
+            return new NoopLockingProvider();
766
+        });
767
+
768
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
769
+            return new \OC\Files\Mount\Manager();
770
+        });
771
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
772
+
773
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
774
+            return new \OC\Files\Type\Detection(
775
+                $c->getURLGenerator(),
776
+                \OC::$configDir,
777
+                \OC::$SERVERROOT . '/resources/config/'
778
+            );
779
+        });
780
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
781
+
782
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
783
+            return new \OC\Files\Type\Loader(
784
+                $c->getDatabaseConnection()
785
+            );
786
+        });
787
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
788
+
789
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
790
+            return new Manager(
791
+                $c->query(IValidator::class)
792
+            );
793
+        });
794
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
795
+
796
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
797
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
798
+            $manager->registerCapability(function () use ($c) {
799
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
800
+            });
801
+            return $manager;
802
+        });
803
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
804
+
805
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
806
+            $config = $c->getConfig();
807
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
808
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
809
+            $factory = new $factoryClass($this);
810
+            return $factory->getManager();
811
+        });
812
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
813
+
814
+        $this->registerService('ThemingDefaults', function(Server $c) {
815
+            /*
816 816
 			 * Dark magic for autoloader.
817 817
 			 * If we do a class_exists it will try to load the class which will
818 818
 			 * make composer cache the result. Resulting in errors when enabling
819 819
 			 * the theming app.
820 820
 			 */
821
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
822
-			if (isset($prefixes['OCA\\Theming\\'])) {
823
-				$classExists = true;
824
-			} else {
825
-				$classExists = false;
826
-			}
827
-
828
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
829
-				return new ThemingDefaults(
830
-					$c->getConfig(),
831
-					$c->getL10N('theming'),
832
-					$c->getURLGenerator(),
833
-					new \OC_Defaults(),
834
-					$c->getAppDataDir('theming'),
835
-					$c->getMemCacheFactory(),
836
-					new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
837
-				);
838
-			}
839
-			return new \OC_Defaults();
840
-		});
841
-		$this->registerService(EventDispatcher::class, function () {
842
-			return new EventDispatcher();
843
-		});
844
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
845
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
846
-
847
-		$this->registerService('CryptoWrapper', function (Server $c) {
848
-			// FIXME: Instantiiated here due to cyclic dependency
849
-			$request = new Request(
850
-				[
851
-					'get' => $_GET,
852
-					'post' => $_POST,
853
-					'files' => $_FILES,
854
-					'server' => $_SERVER,
855
-					'env' => $_ENV,
856
-					'cookies' => $_COOKIE,
857
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
858
-						? $_SERVER['REQUEST_METHOD']
859
-						: null,
860
-				],
861
-				$c->getSecureRandom(),
862
-				$c->getConfig()
863
-			);
864
-
865
-			return new CryptoWrapper(
866
-				$c->getConfig(),
867
-				$c->getCrypto(),
868
-				$c->getSecureRandom(),
869
-				$request
870
-			);
871
-		});
872
-		$this->registerService('CsrfTokenManager', function (Server $c) {
873
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
874
-
875
-			return new CsrfTokenManager(
876
-				$tokenGenerator,
877
-				$c->query(SessionStorage::class)
878
-			);
879
-		});
880
-		$this->registerService(SessionStorage::class, function (Server $c) {
881
-			return new SessionStorage($c->getSession());
882
-		});
883
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
884
-			return new ContentSecurityPolicyManager();
885
-		});
886
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
887
-
888
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
889
-			return new ContentSecurityPolicyNonceManager(
890
-				$c->getCsrfTokenManager(),
891
-				$c->getRequest()
892
-			);
893
-		});
894
-
895
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
896
-			$config = $c->getConfig();
897
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
898
-			/** @var \OCP\Share\IProviderFactory $factory */
899
-			$factory = new $factoryClass($this);
900
-
901
-			$manager = new \OC\Share20\Manager(
902
-				$c->getLogger(),
903
-				$c->getConfig(),
904
-				$c->getSecureRandom(),
905
-				$c->getHasher(),
906
-				$c->getMountManager(),
907
-				$c->getGroupManager(),
908
-				$c->getL10N('core'),
909
-				$factory,
910
-				$c->getUserManager(),
911
-				$c->getLazyRootFolder(),
912
-				$c->getEventDispatcher()
913
-			);
914
-
915
-			return $manager;
916
-		});
917
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
918
-
919
-		$this->registerService('SettingsManager', function(Server $c) {
920
-			$manager = new \OC\Settings\Manager(
921
-				$c->getLogger(),
922
-				$c->getDatabaseConnection(),
923
-				$c->getL10N('lib'),
924
-				$c->getConfig(),
925
-				$c->getEncryptionManager(),
926
-				$c->getUserManager(),
927
-				$c->getLockingProvider(),
928
-				$c->getRequest(),
929
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
930
-				$c->getURLGenerator()
931
-			);
932
-			return $manager;
933
-		});
934
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
935
-			return new \OC\Files\AppData\Factory(
936
-				$c->getRootFolder(),
937
-				$c->getSystemConfig()
938
-			);
939
-		});
940
-
941
-		$this->registerService('LockdownManager', function (Server $c) {
942
-			return new LockdownManager();
943
-		});
944
-
945
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
946
-			return new CloudIdManager();
947
-		});
948
-
949
-		/* To trick DI since we don't extend the DIContainer here */
950
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
951
-			return new CleanPreviewsBackgroundJob(
952
-				$c->getRootFolder(),
953
-				$c->getLogger(),
954
-				$c->getJobList(),
955
-				new TimeFactory()
956
-			);
957
-		});
958
-
959
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
960
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
961
-
962
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
963
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
964
-
965
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
966
-			return $c->query(\OCP\IUserSession::class)->getSession();
967
-		});
968
-	}
969
-
970
-	/**
971
-	 * @return \OCP\Contacts\IManager
972
-	 */
973
-	public function getContactsManager() {
974
-		return $this->query('ContactsManager');
975
-	}
976
-
977
-	/**
978
-	 * @return \OC\Encryption\Manager
979
-	 */
980
-	public function getEncryptionManager() {
981
-		return $this->query('EncryptionManager');
982
-	}
983
-
984
-	/**
985
-	 * @return \OC\Encryption\File
986
-	 */
987
-	public function getEncryptionFilesHelper() {
988
-		return $this->query('EncryptionFileHelper');
989
-	}
990
-
991
-	/**
992
-	 * @return \OCP\Encryption\Keys\IStorage
993
-	 */
994
-	public function getEncryptionKeyStorage() {
995
-		return $this->query('EncryptionKeyStorage');
996
-	}
997
-
998
-	/**
999
-	 * The current request object holding all information about the request
1000
-	 * currently being processed is returned from this method.
1001
-	 * In case the current execution was not initiated by a web request null is returned
1002
-	 *
1003
-	 * @return \OCP\IRequest
1004
-	 */
1005
-	public function getRequest() {
1006
-		return $this->query('Request');
1007
-	}
1008
-
1009
-	/**
1010
-	 * Returns the preview manager which can create preview images for a given file
1011
-	 *
1012
-	 * @return \OCP\IPreview
1013
-	 */
1014
-	public function getPreviewManager() {
1015
-		return $this->query('PreviewManager');
1016
-	}
1017
-
1018
-	/**
1019
-	 * Returns the tag manager which can get and set tags for different object types
1020
-	 *
1021
-	 * @see \OCP\ITagManager::load()
1022
-	 * @return \OCP\ITagManager
1023
-	 */
1024
-	public function getTagManager() {
1025
-		return $this->query('TagManager');
1026
-	}
1027
-
1028
-	/**
1029
-	 * Returns the system-tag manager
1030
-	 *
1031
-	 * @return \OCP\SystemTag\ISystemTagManager
1032
-	 *
1033
-	 * @since 9.0.0
1034
-	 */
1035
-	public function getSystemTagManager() {
1036
-		return $this->query('SystemTagManager');
1037
-	}
1038
-
1039
-	/**
1040
-	 * Returns the system-tag object mapper
1041
-	 *
1042
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1043
-	 *
1044
-	 * @since 9.0.0
1045
-	 */
1046
-	public function getSystemTagObjectMapper() {
1047
-		return $this->query('SystemTagObjectMapper');
1048
-	}
1049
-
1050
-	/**
1051
-	 * Returns the avatar manager, used for avatar functionality
1052
-	 *
1053
-	 * @return \OCP\IAvatarManager
1054
-	 */
1055
-	public function getAvatarManager() {
1056
-		return $this->query('AvatarManager');
1057
-	}
1058
-
1059
-	/**
1060
-	 * Returns the root folder of ownCloud's data directory
1061
-	 *
1062
-	 * @return \OCP\Files\IRootFolder
1063
-	 */
1064
-	public function getRootFolder() {
1065
-		return $this->query('LazyRootFolder');
1066
-	}
1067
-
1068
-	/**
1069
-	 * Returns the root folder of ownCloud's data directory
1070
-	 * This is the lazy variant so this gets only initialized once it
1071
-	 * is actually used.
1072
-	 *
1073
-	 * @return \OCP\Files\IRootFolder
1074
-	 */
1075
-	public function getLazyRootFolder() {
1076
-		return $this->query('LazyRootFolder');
1077
-	}
1078
-
1079
-	/**
1080
-	 * Returns a view to ownCloud's files folder
1081
-	 *
1082
-	 * @param string $userId user ID
1083
-	 * @return \OCP\Files\Folder|null
1084
-	 */
1085
-	public function getUserFolder($userId = null) {
1086
-		if ($userId === null) {
1087
-			$user = $this->getUserSession()->getUser();
1088
-			if (!$user) {
1089
-				return null;
1090
-			}
1091
-			$userId = $user->getUID();
1092
-		}
1093
-		$root = $this->getRootFolder();
1094
-		return $root->getUserFolder($userId);
1095
-	}
1096
-
1097
-	/**
1098
-	 * Returns an app-specific view in ownClouds data directory
1099
-	 *
1100
-	 * @return \OCP\Files\Folder
1101
-	 * @deprecated since 9.2.0 use IAppData
1102
-	 */
1103
-	public function getAppFolder() {
1104
-		$dir = '/' . \OC_App::getCurrentApp();
1105
-		$root = $this->getRootFolder();
1106
-		if (!$root->nodeExists($dir)) {
1107
-			$folder = $root->newFolder($dir);
1108
-		} else {
1109
-			$folder = $root->get($dir);
1110
-		}
1111
-		return $folder;
1112
-	}
1113
-
1114
-	/**
1115
-	 * @return \OC\User\Manager
1116
-	 */
1117
-	public function getUserManager() {
1118
-		return $this->query('UserManager');
1119
-	}
1120
-
1121
-	/**
1122
-	 * @return \OC\Group\Manager
1123
-	 */
1124
-	public function getGroupManager() {
1125
-		return $this->query('GroupManager');
1126
-	}
1127
-
1128
-	/**
1129
-	 * @return \OC\User\Session
1130
-	 */
1131
-	public function getUserSession() {
1132
-		return $this->query('UserSession');
1133
-	}
1134
-
1135
-	/**
1136
-	 * @return \OCP\ISession
1137
-	 */
1138
-	public function getSession() {
1139
-		return $this->query('UserSession')->getSession();
1140
-	}
1141
-
1142
-	/**
1143
-	 * @param \OCP\ISession $session
1144
-	 */
1145
-	public function setSession(\OCP\ISession $session) {
1146
-		$this->query(SessionStorage::class)->setSession($session);
1147
-		$this->query('UserSession')->setSession($session);
1148
-		$this->query(Store::class)->setSession($session);
1149
-	}
1150
-
1151
-	/**
1152
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1153
-	 */
1154
-	public function getTwoFactorAuthManager() {
1155
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1156
-	}
1157
-
1158
-	/**
1159
-	 * @return \OC\NavigationManager
1160
-	 */
1161
-	public function getNavigationManager() {
1162
-		return $this->query('NavigationManager');
1163
-	}
1164
-
1165
-	/**
1166
-	 * @return \OCP\IConfig
1167
-	 */
1168
-	public function getConfig() {
1169
-		return $this->query('AllConfig');
1170
-	}
1171
-
1172
-	/**
1173
-	 * @internal For internal use only
1174
-	 * @return \OC\SystemConfig
1175
-	 */
1176
-	public function getSystemConfig() {
1177
-		return $this->query('SystemConfig');
1178
-	}
1179
-
1180
-	/**
1181
-	 * Returns the app config manager
1182
-	 *
1183
-	 * @return \OCP\IAppConfig
1184
-	 */
1185
-	public function getAppConfig() {
1186
-		return $this->query('AppConfig');
1187
-	}
1188
-
1189
-	/**
1190
-	 * @return \OCP\L10N\IFactory
1191
-	 */
1192
-	public function getL10NFactory() {
1193
-		return $this->query('L10NFactory');
1194
-	}
1195
-
1196
-	/**
1197
-	 * get an L10N instance
1198
-	 *
1199
-	 * @param string $app appid
1200
-	 * @param string $lang
1201
-	 * @return IL10N
1202
-	 */
1203
-	public function getL10N($app, $lang = null) {
1204
-		return $this->getL10NFactory()->get($app, $lang);
1205
-	}
1206
-
1207
-	/**
1208
-	 * @return \OCP\IURLGenerator
1209
-	 */
1210
-	public function getURLGenerator() {
1211
-		return $this->query('URLGenerator');
1212
-	}
1213
-
1214
-	/**
1215
-	 * @return \OCP\IHelper
1216
-	 */
1217
-	public function getHelper() {
1218
-		return $this->query('AppHelper');
1219
-	}
1220
-
1221
-	/**
1222
-	 * @return AppFetcher
1223
-	 */
1224
-	public function getAppFetcher() {
1225
-		return $this->query('AppFetcher');
1226
-	}
1227
-
1228
-	/**
1229
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1230
-	 * getMemCacheFactory() instead.
1231
-	 *
1232
-	 * @return \OCP\ICache
1233
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1234
-	 */
1235
-	public function getCache() {
1236
-		return $this->query('UserCache');
1237
-	}
1238
-
1239
-	/**
1240
-	 * Returns an \OCP\CacheFactory instance
1241
-	 *
1242
-	 * @return \OCP\ICacheFactory
1243
-	 */
1244
-	public function getMemCacheFactory() {
1245
-		return $this->query('MemCacheFactory');
1246
-	}
1247
-
1248
-	/**
1249
-	 * Returns an \OC\RedisFactory instance
1250
-	 *
1251
-	 * @return \OC\RedisFactory
1252
-	 */
1253
-	public function getGetRedisFactory() {
1254
-		return $this->query('RedisFactory');
1255
-	}
1256
-
1257
-
1258
-	/**
1259
-	 * Returns the current session
1260
-	 *
1261
-	 * @return \OCP\IDBConnection
1262
-	 */
1263
-	public function getDatabaseConnection() {
1264
-		return $this->query('DatabaseConnection');
1265
-	}
1266
-
1267
-	/**
1268
-	 * Returns the activity manager
1269
-	 *
1270
-	 * @return \OCP\Activity\IManager
1271
-	 */
1272
-	public function getActivityManager() {
1273
-		return $this->query('ActivityManager');
1274
-	}
1275
-
1276
-	/**
1277
-	 * Returns an job list for controlling background jobs
1278
-	 *
1279
-	 * @return \OCP\BackgroundJob\IJobList
1280
-	 */
1281
-	public function getJobList() {
1282
-		return $this->query('JobList');
1283
-	}
1284
-
1285
-	/**
1286
-	 * Returns a logger instance
1287
-	 *
1288
-	 * @return \OCP\ILogger
1289
-	 */
1290
-	public function getLogger() {
1291
-		return $this->query('Logger');
1292
-	}
1293
-
1294
-	/**
1295
-	 * Returns a router for generating and matching urls
1296
-	 *
1297
-	 * @return \OCP\Route\IRouter
1298
-	 */
1299
-	public function getRouter() {
1300
-		return $this->query('Router');
1301
-	}
1302
-
1303
-	/**
1304
-	 * Returns a search instance
1305
-	 *
1306
-	 * @return \OCP\ISearch
1307
-	 */
1308
-	public function getSearch() {
1309
-		return $this->query('Search');
1310
-	}
1311
-
1312
-	/**
1313
-	 * Returns a SecureRandom instance
1314
-	 *
1315
-	 * @return \OCP\Security\ISecureRandom
1316
-	 */
1317
-	public function getSecureRandom() {
1318
-		return $this->query('SecureRandom');
1319
-	}
1320
-
1321
-	/**
1322
-	 * Returns a Crypto instance
1323
-	 *
1324
-	 * @return \OCP\Security\ICrypto
1325
-	 */
1326
-	public function getCrypto() {
1327
-		return $this->query('Crypto');
1328
-	}
1329
-
1330
-	/**
1331
-	 * Returns a Hasher instance
1332
-	 *
1333
-	 * @return \OCP\Security\IHasher
1334
-	 */
1335
-	public function getHasher() {
1336
-		return $this->query('Hasher');
1337
-	}
1338
-
1339
-	/**
1340
-	 * Returns a CredentialsManager instance
1341
-	 *
1342
-	 * @return \OCP\Security\ICredentialsManager
1343
-	 */
1344
-	public function getCredentialsManager() {
1345
-		return $this->query('CredentialsManager');
1346
-	}
1347
-
1348
-	/**
1349
-	 * Returns an instance of the HTTP helper class
1350
-	 *
1351
-	 * @deprecated Use getHTTPClientService()
1352
-	 * @return \OC\HTTPHelper
1353
-	 */
1354
-	public function getHTTPHelper() {
1355
-		return $this->query('HTTPHelper');
1356
-	}
1357
-
1358
-	/**
1359
-	 * Get the certificate manager for the user
1360
-	 *
1361
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1362
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1363
-	 */
1364
-	public function getCertificateManager($userId = '') {
1365
-		if ($userId === '') {
1366
-			$userSession = $this->getUserSession();
1367
-			$user = $userSession->getUser();
1368
-			if (is_null($user)) {
1369
-				return null;
1370
-			}
1371
-			$userId = $user->getUID();
1372
-		}
1373
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1374
-	}
1375
-
1376
-	/**
1377
-	 * Returns an instance of the HTTP client service
1378
-	 *
1379
-	 * @return \OCP\Http\Client\IClientService
1380
-	 */
1381
-	public function getHTTPClientService() {
1382
-		return $this->query('HttpClientService');
1383
-	}
1384
-
1385
-	/**
1386
-	 * Create a new event source
1387
-	 *
1388
-	 * @return \OCP\IEventSource
1389
-	 */
1390
-	public function createEventSource() {
1391
-		return new \OC_EventSource();
1392
-	}
1393
-
1394
-	/**
1395
-	 * Get the active event logger
1396
-	 *
1397
-	 * The returned logger only logs data when debug mode is enabled
1398
-	 *
1399
-	 * @return \OCP\Diagnostics\IEventLogger
1400
-	 */
1401
-	public function getEventLogger() {
1402
-		return $this->query('EventLogger');
1403
-	}
1404
-
1405
-	/**
1406
-	 * Get the active query logger
1407
-	 *
1408
-	 * The returned logger only logs data when debug mode is enabled
1409
-	 *
1410
-	 * @return \OCP\Diagnostics\IQueryLogger
1411
-	 */
1412
-	public function getQueryLogger() {
1413
-		return $this->query('QueryLogger');
1414
-	}
1415
-
1416
-	/**
1417
-	 * Get the manager for temporary files and folders
1418
-	 *
1419
-	 * @return \OCP\ITempManager
1420
-	 */
1421
-	public function getTempManager() {
1422
-		return $this->query('TempManager');
1423
-	}
1424
-
1425
-	/**
1426
-	 * Get the app manager
1427
-	 *
1428
-	 * @return \OCP\App\IAppManager
1429
-	 */
1430
-	public function getAppManager() {
1431
-		return $this->query('AppManager');
1432
-	}
1433
-
1434
-	/**
1435
-	 * Creates a new mailer
1436
-	 *
1437
-	 * @return \OCP\Mail\IMailer
1438
-	 */
1439
-	public function getMailer() {
1440
-		return $this->query('Mailer');
1441
-	}
1442
-
1443
-	/**
1444
-	 * Get the webroot
1445
-	 *
1446
-	 * @return string
1447
-	 */
1448
-	public function getWebRoot() {
1449
-		return $this->webRoot;
1450
-	}
1451
-
1452
-	/**
1453
-	 * @return \OC\OCSClient
1454
-	 */
1455
-	public function getOcsClient() {
1456
-		return $this->query('OcsClient');
1457
-	}
1458
-
1459
-	/**
1460
-	 * @return \OCP\IDateTimeZone
1461
-	 */
1462
-	public function getDateTimeZone() {
1463
-		return $this->query('DateTimeZone');
1464
-	}
1465
-
1466
-	/**
1467
-	 * @return \OCP\IDateTimeFormatter
1468
-	 */
1469
-	public function getDateTimeFormatter() {
1470
-		return $this->query('DateTimeFormatter');
1471
-	}
1472
-
1473
-	/**
1474
-	 * @return \OCP\Files\Config\IMountProviderCollection
1475
-	 */
1476
-	public function getMountProviderCollection() {
1477
-		return $this->query('MountConfigManager');
1478
-	}
1479
-
1480
-	/**
1481
-	 * Get the IniWrapper
1482
-	 *
1483
-	 * @return IniGetWrapper
1484
-	 */
1485
-	public function getIniWrapper() {
1486
-		return $this->query('IniWrapper');
1487
-	}
1488
-
1489
-	/**
1490
-	 * @return \OCP\Command\IBus
1491
-	 */
1492
-	public function getCommandBus() {
1493
-		return $this->query('AsyncCommandBus');
1494
-	}
1495
-
1496
-	/**
1497
-	 * Get the trusted domain helper
1498
-	 *
1499
-	 * @return TrustedDomainHelper
1500
-	 */
1501
-	public function getTrustedDomainHelper() {
1502
-		return $this->query('TrustedDomainHelper');
1503
-	}
1504
-
1505
-	/**
1506
-	 * Get the locking provider
1507
-	 *
1508
-	 * @return \OCP\Lock\ILockingProvider
1509
-	 * @since 8.1.0
1510
-	 */
1511
-	public function getLockingProvider() {
1512
-		return $this->query('LockingProvider');
1513
-	}
1514
-
1515
-	/**
1516
-	 * @return \OCP\Files\Mount\IMountManager
1517
-	 **/
1518
-	function getMountManager() {
1519
-		return $this->query('MountManager');
1520
-	}
1521
-
1522
-	/** @return \OCP\Files\Config\IUserMountCache */
1523
-	function getUserMountCache() {
1524
-		return $this->query('UserMountCache');
1525
-	}
1526
-
1527
-	/**
1528
-	 * Get the MimeTypeDetector
1529
-	 *
1530
-	 * @return \OCP\Files\IMimeTypeDetector
1531
-	 */
1532
-	public function getMimeTypeDetector() {
1533
-		return $this->query('MimeTypeDetector');
1534
-	}
1535
-
1536
-	/**
1537
-	 * Get the MimeTypeLoader
1538
-	 *
1539
-	 * @return \OCP\Files\IMimeTypeLoader
1540
-	 */
1541
-	public function getMimeTypeLoader() {
1542
-		return $this->query('MimeTypeLoader');
1543
-	}
1544
-
1545
-	/**
1546
-	 * Get the manager of all the capabilities
1547
-	 *
1548
-	 * @return \OC\CapabilitiesManager
1549
-	 */
1550
-	public function getCapabilitiesManager() {
1551
-		return $this->query('CapabilitiesManager');
1552
-	}
1553
-
1554
-	/**
1555
-	 * Get the EventDispatcher
1556
-	 *
1557
-	 * @return EventDispatcherInterface
1558
-	 * @since 8.2.0
1559
-	 */
1560
-	public function getEventDispatcher() {
1561
-		return $this->query('EventDispatcher');
1562
-	}
1563
-
1564
-	/**
1565
-	 * Get the Notification Manager
1566
-	 *
1567
-	 * @return \OCP\Notification\IManager
1568
-	 * @since 8.2.0
1569
-	 */
1570
-	public function getNotificationManager() {
1571
-		return $this->query('NotificationManager');
1572
-	}
1573
-
1574
-	/**
1575
-	 * @return \OCP\Comments\ICommentsManager
1576
-	 */
1577
-	public function getCommentsManager() {
1578
-		return $this->query('CommentsManager');
1579
-	}
1580
-
1581
-	/**
1582
-	 * @return \OC_Defaults
1583
-	 */
1584
-	public function getThemingDefaults() {
1585
-		return $this->query('ThemingDefaults');
1586
-	}
1587
-
1588
-	/**
1589
-	 * @return \OC\IntegrityCheck\Checker
1590
-	 */
1591
-	public function getIntegrityCodeChecker() {
1592
-		return $this->query('IntegrityCodeChecker');
1593
-	}
1594
-
1595
-	/**
1596
-	 * @return \OC\Session\CryptoWrapper
1597
-	 */
1598
-	public function getSessionCryptoWrapper() {
1599
-		return $this->query('CryptoWrapper');
1600
-	}
1601
-
1602
-	/**
1603
-	 * @return CsrfTokenManager
1604
-	 */
1605
-	public function getCsrfTokenManager() {
1606
-		return $this->query('CsrfTokenManager');
1607
-	}
1608
-
1609
-	/**
1610
-	 * @return Throttler
1611
-	 */
1612
-	public function getBruteForceThrottler() {
1613
-		return $this->query('Throttler');
1614
-	}
1615
-
1616
-	/**
1617
-	 * @return IContentSecurityPolicyManager
1618
-	 */
1619
-	public function getContentSecurityPolicyManager() {
1620
-		return $this->query('ContentSecurityPolicyManager');
1621
-	}
1622
-
1623
-	/**
1624
-	 * @return ContentSecurityPolicyNonceManager
1625
-	 */
1626
-	public function getContentSecurityPolicyNonceManager() {
1627
-		return $this->query('ContentSecurityPolicyNonceManager');
1628
-	}
1629
-
1630
-	/**
1631
-	 * Not a public API as of 8.2, wait for 9.0
1632
-	 *
1633
-	 * @return \OCA\Files_External\Service\BackendService
1634
-	 */
1635
-	public function getStoragesBackendService() {
1636
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1637
-	}
1638
-
1639
-	/**
1640
-	 * Not a public API as of 8.2, wait for 9.0
1641
-	 *
1642
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1643
-	 */
1644
-	public function getGlobalStoragesService() {
1645
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1646
-	}
1647
-
1648
-	/**
1649
-	 * Not a public API as of 8.2, wait for 9.0
1650
-	 *
1651
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1652
-	 */
1653
-	public function getUserGlobalStoragesService() {
1654
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1655
-	}
1656
-
1657
-	/**
1658
-	 * Not a public API as of 8.2, wait for 9.0
1659
-	 *
1660
-	 * @return \OCA\Files_External\Service\UserStoragesService
1661
-	 */
1662
-	public function getUserStoragesService() {
1663
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1664
-	}
1665
-
1666
-	/**
1667
-	 * @return \OCP\Share\IManager
1668
-	 */
1669
-	public function getShareManager() {
1670
-		return $this->query('ShareManager');
1671
-	}
1672
-
1673
-	/**
1674
-	 * Returns the LDAP Provider
1675
-	 *
1676
-	 * @return \OCP\LDAP\ILDAPProvider
1677
-	 */
1678
-	public function getLDAPProvider() {
1679
-		return $this->query('LDAPProvider');
1680
-	}
1681
-
1682
-	/**
1683
-	 * @return \OCP\Settings\IManager
1684
-	 */
1685
-	public function getSettingsManager() {
1686
-		return $this->query('SettingsManager');
1687
-	}
1688
-
1689
-	/**
1690
-	 * @return \OCP\Files\IAppData
1691
-	 */
1692
-	public function getAppDataDir($app) {
1693
-		/** @var \OC\Files\AppData\Factory $factory */
1694
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1695
-		return $factory->get($app);
1696
-	}
1697
-
1698
-	/**
1699
-	 * @return \OCP\Lockdown\ILockdownManager
1700
-	 */
1701
-	public function getLockdownManager() {
1702
-		return $this->query('LockdownManager');
1703
-	}
1704
-
1705
-	/**
1706
-	 * @return \OCP\Federation\ICloudIdManager
1707
-	 */
1708
-	public function getCloudIdManager() {
1709
-		return $this->query(ICloudIdManager::class);
1710
-	}
821
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
822
+            if (isset($prefixes['OCA\\Theming\\'])) {
823
+                $classExists = true;
824
+            } else {
825
+                $classExists = false;
826
+            }
827
+
828
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
829
+                return new ThemingDefaults(
830
+                    $c->getConfig(),
831
+                    $c->getL10N('theming'),
832
+                    $c->getURLGenerator(),
833
+                    new \OC_Defaults(),
834
+                    $c->getAppDataDir('theming'),
835
+                    $c->getMemCacheFactory(),
836
+                    new Util($c->getConfig(), $this->getRootFolder(), $this->getAppManager())
837
+                );
838
+            }
839
+            return new \OC_Defaults();
840
+        });
841
+        $this->registerService(EventDispatcher::class, function () {
842
+            return new EventDispatcher();
843
+        });
844
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
845
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
846
+
847
+        $this->registerService('CryptoWrapper', function (Server $c) {
848
+            // FIXME: Instantiiated here due to cyclic dependency
849
+            $request = new Request(
850
+                [
851
+                    'get' => $_GET,
852
+                    'post' => $_POST,
853
+                    'files' => $_FILES,
854
+                    'server' => $_SERVER,
855
+                    'env' => $_ENV,
856
+                    'cookies' => $_COOKIE,
857
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
858
+                        ? $_SERVER['REQUEST_METHOD']
859
+                        : null,
860
+                ],
861
+                $c->getSecureRandom(),
862
+                $c->getConfig()
863
+            );
864
+
865
+            return new CryptoWrapper(
866
+                $c->getConfig(),
867
+                $c->getCrypto(),
868
+                $c->getSecureRandom(),
869
+                $request
870
+            );
871
+        });
872
+        $this->registerService('CsrfTokenManager', function (Server $c) {
873
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
874
+
875
+            return new CsrfTokenManager(
876
+                $tokenGenerator,
877
+                $c->query(SessionStorage::class)
878
+            );
879
+        });
880
+        $this->registerService(SessionStorage::class, function (Server $c) {
881
+            return new SessionStorage($c->getSession());
882
+        });
883
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
884
+            return new ContentSecurityPolicyManager();
885
+        });
886
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
887
+
888
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
889
+            return new ContentSecurityPolicyNonceManager(
890
+                $c->getCsrfTokenManager(),
891
+                $c->getRequest()
892
+            );
893
+        });
894
+
895
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
896
+            $config = $c->getConfig();
897
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
898
+            /** @var \OCP\Share\IProviderFactory $factory */
899
+            $factory = new $factoryClass($this);
900
+
901
+            $manager = new \OC\Share20\Manager(
902
+                $c->getLogger(),
903
+                $c->getConfig(),
904
+                $c->getSecureRandom(),
905
+                $c->getHasher(),
906
+                $c->getMountManager(),
907
+                $c->getGroupManager(),
908
+                $c->getL10N('core'),
909
+                $factory,
910
+                $c->getUserManager(),
911
+                $c->getLazyRootFolder(),
912
+                $c->getEventDispatcher()
913
+            );
914
+
915
+            return $manager;
916
+        });
917
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
918
+
919
+        $this->registerService('SettingsManager', function(Server $c) {
920
+            $manager = new \OC\Settings\Manager(
921
+                $c->getLogger(),
922
+                $c->getDatabaseConnection(),
923
+                $c->getL10N('lib'),
924
+                $c->getConfig(),
925
+                $c->getEncryptionManager(),
926
+                $c->getUserManager(),
927
+                $c->getLockingProvider(),
928
+                $c->getRequest(),
929
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
930
+                $c->getURLGenerator()
931
+            );
932
+            return $manager;
933
+        });
934
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
935
+            return new \OC\Files\AppData\Factory(
936
+                $c->getRootFolder(),
937
+                $c->getSystemConfig()
938
+            );
939
+        });
940
+
941
+        $this->registerService('LockdownManager', function (Server $c) {
942
+            return new LockdownManager();
943
+        });
944
+
945
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
946
+            return new CloudIdManager();
947
+        });
948
+
949
+        /* To trick DI since we don't extend the DIContainer here */
950
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
951
+            return new CleanPreviewsBackgroundJob(
952
+                $c->getRootFolder(),
953
+                $c->getLogger(),
954
+                $c->getJobList(),
955
+                new TimeFactory()
956
+            );
957
+        });
958
+
959
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
960
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
961
+
962
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
963
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
964
+
965
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
966
+            return $c->query(\OCP\IUserSession::class)->getSession();
967
+        });
968
+    }
969
+
970
+    /**
971
+     * @return \OCP\Contacts\IManager
972
+     */
973
+    public function getContactsManager() {
974
+        return $this->query('ContactsManager');
975
+    }
976
+
977
+    /**
978
+     * @return \OC\Encryption\Manager
979
+     */
980
+    public function getEncryptionManager() {
981
+        return $this->query('EncryptionManager');
982
+    }
983
+
984
+    /**
985
+     * @return \OC\Encryption\File
986
+     */
987
+    public function getEncryptionFilesHelper() {
988
+        return $this->query('EncryptionFileHelper');
989
+    }
990
+
991
+    /**
992
+     * @return \OCP\Encryption\Keys\IStorage
993
+     */
994
+    public function getEncryptionKeyStorage() {
995
+        return $this->query('EncryptionKeyStorage');
996
+    }
997
+
998
+    /**
999
+     * The current request object holding all information about the request
1000
+     * currently being processed is returned from this method.
1001
+     * In case the current execution was not initiated by a web request null is returned
1002
+     *
1003
+     * @return \OCP\IRequest
1004
+     */
1005
+    public function getRequest() {
1006
+        return $this->query('Request');
1007
+    }
1008
+
1009
+    /**
1010
+     * Returns the preview manager which can create preview images for a given file
1011
+     *
1012
+     * @return \OCP\IPreview
1013
+     */
1014
+    public function getPreviewManager() {
1015
+        return $this->query('PreviewManager');
1016
+    }
1017
+
1018
+    /**
1019
+     * Returns the tag manager which can get and set tags for different object types
1020
+     *
1021
+     * @see \OCP\ITagManager::load()
1022
+     * @return \OCP\ITagManager
1023
+     */
1024
+    public function getTagManager() {
1025
+        return $this->query('TagManager');
1026
+    }
1027
+
1028
+    /**
1029
+     * Returns the system-tag manager
1030
+     *
1031
+     * @return \OCP\SystemTag\ISystemTagManager
1032
+     *
1033
+     * @since 9.0.0
1034
+     */
1035
+    public function getSystemTagManager() {
1036
+        return $this->query('SystemTagManager');
1037
+    }
1038
+
1039
+    /**
1040
+     * Returns the system-tag object mapper
1041
+     *
1042
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1043
+     *
1044
+     * @since 9.0.0
1045
+     */
1046
+    public function getSystemTagObjectMapper() {
1047
+        return $this->query('SystemTagObjectMapper');
1048
+    }
1049
+
1050
+    /**
1051
+     * Returns the avatar manager, used for avatar functionality
1052
+     *
1053
+     * @return \OCP\IAvatarManager
1054
+     */
1055
+    public function getAvatarManager() {
1056
+        return $this->query('AvatarManager');
1057
+    }
1058
+
1059
+    /**
1060
+     * Returns the root folder of ownCloud's data directory
1061
+     *
1062
+     * @return \OCP\Files\IRootFolder
1063
+     */
1064
+    public function getRootFolder() {
1065
+        return $this->query('LazyRootFolder');
1066
+    }
1067
+
1068
+    /**
1069
+     * Returns the root folder of ownCloud's data directory
1070
+     * This is the lazy variant so this gets only initialized once it
1071
+     * is actually used.
1072
+     *
1073
+     * @return \OCP\Files\IRootFolder
1074
+     */
1075
+    public function getLazyRootFolder() {
1076
+        return $this->query('LazyRootFolder');
1077
+    }
1078
+
1079
+    /**
1080
+     * Returns a view to ownCloud's files folder
1081
+     *
1082
+     * @param string $userId user ID
1083
+     * @return \OCP\Files\Folder|null
1084
+     */
1085
+    public function getUserFolder($userId = null) {
1086
+        if ($userId === null) {
1087
+            $user = $this->getUserSession()->getUser();
1088
+            if (!$user) {
1089
+                return null;
1090
+            }
1091
+            $userId = $user->getUID();
1092
+        }
1093
+        $root = $this->getRootFolder();
1094
+        return $root->getUserFolder($userId);
1095
+    }
1096
+
1097
+    /**
1098
+     * Returns an app-specific view in ownClouds data directory
1099
+     *
1100
+     * @return \OCP\Files\Folder
1101
+     * @deprecated since 9.2.0 use IAppData
1102
+     */
1103
+    public function getAppFolder() {
1104
+        $dir = '/' . \OC_App::getCurrentApp();
1105
+        $root = $this->getRootFolder();
1106
+        if (!$root->nodeExists($dir)) {
1107
+            $folder = $root->newFolder($dir);
1108
+        } else {
1109
+            $folder = $root->get($dir);
1110
+        }
1111
+        return $folder;
1112
+    }
1113
+
1114
+    /**
1115
+     * @return \OC\User\Manager
1116
+     */
1117
+    public function getUserManager() {
1118
+        return $this->query('UserManager');
1119
+    }
1120
+
1121
+    /**
1122
+     * @return \OC\Group\Manager
1123
+     */
1124
+    public function getGroupManager() {
1125
+        return $this->query('GroupManager');
1126
+    }
1127
+
1128
+    /**
1129
+     * @return \OC\User\Session
1130
+     */
1131
+    public function getUserSession() {
1132
+        return $this->query('UserSession');
1133
+    }
1134
+
1135
+    /**
1136
+     * @return \OCP\ISession
1137
+     */
1138
+    public function getSession() {
1139
+        return $this->query('UserSession')->getSession();
1140
+    }
1141
+
1142
+    /**
1143
+     * @param \OCP\ISession $session
1144
+     */
1145
+    public function setSession(\OCP\ISession $session) {
1146
+        $this->query(SessionStorage::class)->setSession($session);
1147
+        $this->query('UserSession')->setSession($session);
1148
+        $this->query(Store::class)->setSession($session);
1149
+    }
1150
+
1151
+    /**
1152
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1153
+     */
1154
+    public function getTwoFactorAuthManager() {
1155
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1156
+    }
1157
+
1158
+    /**
1159
+     * @return \OC\NavigationManager
1160
+     */
1161
+    public function getNavigationManager() {
1162
+        return $this->query('NavigationManager');
1163
+    }
1164
+
1165
+    /**
1166
+     * @return \OCP\IConfig
1167
+     */
1168
+    public function getConfig() {
1169
+        return $this->query('AllConfig');
1170
+    }
1171
+
1172
+    /**
1173
+     * @internal For internal use only
1174
+     * @return \OC\SystemConfig
1175
+     */
1176
+    public function getSystemConfig() {
1177
+        return $this->query('SystemConfig');
1178
+    }
1179
+
1180
+    /**
1181
+     * Returns the app config manager
1182
+     *
1183
+     * @return \OCP\IAppConfig
1184
+     */
1185
+    public function getAppConfig() {
1186
+        return $this->query('AppConfig');
1187
+    }
1188
+
1189
+    /**
1190
+     * @return \OCP\L10N\IFactory
1191
+     */
1192
+    public function getL10NFactory() {
1193
+        return $this->query('L10NFactory');
1194
+    }
1195
+
1196
+    /**
1197
+     * get an L10N instance
1198
+     *
1199
+     * @param string $app appid
1200
+     * @param string $lang
1201
+     * @return IL10N
1202
+     */
1203
+    public function getL10N($app, $lang = null) {
1204
+        return $this->getL10NFactory()->get($app, $lang);
1205
+    }
1206
+
1207
+    /**
1208
+     * @return \OCP\IURLGenerator
1209
+     */
1210
+    public function getURLGenerator() {
1211
+        return $this->query('URLGenerator');
1212
+    }
1213
+
1214
+    /**
1215
+     * @return \OCP\IHelper
1216
+     */
1217
+    public function getHelper() {
1218
+        return $this->query('AppHelper');
1219
+    }
1220
+
1221
+    /**
1222
+     * @return AppFetcher
1223
+     */
1224
+    public function getAppFetcher() {
1225
+        return $this->query('AppFetcher');
1226
+    }
1227
+
1228
+    /**
1229
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1230
+     * getMemCacheFactory() instead.
1231
+     *
1232
+     * @return \OCP\ICache
1233
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1234
+     */
1235
+    public function getCache() {
1236
+        return $this->query('UserCache');
1237
+    }
1238
+
1239
+    /**
1240
+     * Returns an \OCP\CacheFactory instance
1241
+     *
1242
+     * @return \OCP\ICacheFactory
1243
+     */
1244
+    public function getMemCacheFactory() {
1245
+        return $this->query('MemCacheFactory');
1246
+    }
1247
+
1248
+    /**
1249
+     * Returns an \OC\RedisFactory instance
1250
+     *
1251
+     * @return \OC\RedisFactory
1252
+     */
1253
+    public function getGetRedisFactory() {
1254
+        return $this->query('RedisFactory');
1255
+    }
1256
+
1257
+
1258
+    /**
1259
+     * Returns the current session
1260
+     *
1261
+     * @return \OCP\IDBConnection
1262
+     */
1263
+    public function getDatabaseConnection() {
1264
+        return $this->query('DatabaseConnection');
1265
+    }
1266
+
1267
+    /**
1268
+     * Returns the activity manager
1269
+     *
1270
+     * @return \OCP\Activity\IManager
1271
+     */
1272
+    public function getActivityManager() {
1273
+        return $this->query('ActivityManager');
1274
+    }
1275
+
1276
+    /**
1277
+     * Returns an job list for controlling background jobs
1278
+     *
1279
+     * @return \OCP\BackgroundJob\IJobList
1280
+     */
1281
+    public function getJobList() {
1282
+        return $this->query('JobList');
1283
+    }
1284
+
1285
+    /**
1286
+     * Returns a logger instance
1287
+     *
1288
+     * @return \OCP\ILogger
1289
+     */
1290
+    public function getLogger() {
1291
+        return $this->query('Logger');
1292
+    }
1293
+
1294
+    /**
1295
+     * Returns a router for generating and matching urls
1296
+     *
1297
+     * @return \OCP\Route\IRouter
1298
+     */
1299
+    public function getRouter() {
1300
+        return $this->query('Router');
1301
+    }
1302
+
1303
+    /**
1304
+     * Returns a search instance
1305
+     *
1306
+     * @return \OCP\ISearch
1307
+     */
1308
+    public function getSearch() {
1309
+        return $this->query('Search');
1310
+    }
1311
+
1312
+    /**
1313
+     * Returns a SecureRandom instance
1314
+     *
1315
+     * @return \OCP\Security\ISecureRandom
1316
+     */
1317
+    public function getSecureRandom() {
1318
+        return $this->query('SecureRandom');
1319
+    }
1320
+
1321
+    /**
1322
+     * Returns a Crypto instance
1323
+     *
1324
+     * @return \OCP\Security\ICrypto
1325
+     */
1326
+    public function getCrypto() {
1327
+        return $this->query('Crypto');
1328
+    }
1329
+
1330
+    /**
1331
+     * Returns a Hasher instance
1332
+     *
1333
+     * @return \OCP\Security\IHasher
1334
+     */
1335
+    public function getHasher() {
1336
+        return $this->query('Hasher');
1337
+    }
1338
+
1339
+    /**
1340
+     * Returns a CredentialsManager instance
1341
+     *
1342
+     * @return \OCP\Security\ICredentialsManager
1343
+     */
1344
+    public function getCredentialsManager() {
1345
+        return $this->query('CredentialsManager');
1346
+    }
1347
+
1348
+    /**
1349
+     * Returns an instance of the HTTP helper class
1350
+     *
1351
+     * @deprecated Use getHTTPClientService()
1352
+     * @return \OC\HTTPHelper
1353
+     */
1354
+    public function getHTTPHelper() {
1355
+        return $this->query('HTTPHelper');
1356
+    }
1357
+
1358
+    /**
1359
+     * Get the certificate manager for the user
1360
+     *
1361
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1362
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1363
+     */
1364
+    public function getCertificateManager($userId = '') {
1365
+        if ($userId === '') {
1366
+            $userSession = $this->getUserSession();
1367
+            $user = $userSession->getUser();
1368
+            if (is_null($user)) {
1369
+                return null;
1370
+            }
1371
+            $userId = $user->getUID();
1372
+        }
1373
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1374
+    }
1375
+
1376
+    /**
1377
+     * Returns an instance of the HTTP client service
1378
+     *
1379
+     * @return \OCP\Http\Client\IClientService
1380
+     */
1381
+    public function getHTTPClientService() {
1382
+        return $this->query('HttpClientService');
1383
+    }
1384
+
1385
+    /**
1386
+     * Create a new event source
1387
+     *
1388
+     * @return \OCP\IEventSource
1389
+     */
1390
+    public function createEventSource() {
1391
+        return new \OC_EventSource();
1392
+    }
1393
+
1394
+    /**
1395
+     * Get the active event logger
1396
+     *
1397
+     * The returned logger only logs data when debug mode is enabled
1398
+     *
1399
+     * @return \OCP\Diagnostics\IEventLogger
1400
+     */
1401
+    public function getEventLogger() {
1402
+        return $this->query('EventLogger');
1403
+    }
1404
+
1405
+    /**
1406
+     * Get the active query logger
1407
+     *
1408
+     * The returned logger only logs data when debug mode is enabled
1409
+     *
1410
+     * @return \OCP\Diagnostics\IQueryLogger
1411
+     */
1412
+    public function getQueryLogger() {
1413
+        return $this->query('QueryLogger');
1414
+    }
1415
+
1416
+    /**
1417
+     * Get the manager for temporary files and folders
1418
+     *
1419
+     * @return \OCP\ITempManager
1420
+     */
1421
+    public function getTempManager() {
1422
+        return $this->query('TempManager');
1423
+    }
1424
+
1425
+    /**
1426
+     * Get the app manager
1427
+     *
1428
+     * @return \OCP\App\IAppManager
1429
+     */
1430
+    public function getAppManager() {
1431
+        return $this->query('AppManager');
1432
+    }
1433
+
1434
+    /**
1435
+     * Creates a new mailer
1436
+     *
1437
+     * @return \OCP\Mail\IMailer
1438
+     */
1439
+    public function getMailer() {
1440
+        return $this->query('Mailer');
1441
+    }
1442
+
1443
+    /**
1444
+     * Get the webroot
1445
+     *
1446
+     * @return string
1447
+     */
1448
+    public function getWebRoot() {
1449
+        return $this->webRoot;
1450
+    }
1451
+
1452
+    /**
1453
+     * @return \OC\OCSClient
1454
+     */
1455
+    public function getOcsClient() {
1456
+        return $this->query('OcsClient');
1457
+    }
1458
+
1459
+    /**
1460
+     * @return \OCP\IDateTimeZone
1461
+     */
1462
+    public function getDateTimeZone() {
1463
+        return $this->query('DateTimeZone');
1464
+    }
1465
+
1466
+    /**
1467
+     * @return \OCP\IDateTimeFormatter
1468
+     */
1469
+    public function getDateTimeFormatter() {
1470
+        return $this->query('DateTimeFormatter');
1471
+    }
1472
+
1473
+    /**
1474
+     * @return \OCP\Files\Config\IMountProviderCollection
1475
+     */
1476
+    public function getMountProviderCollection() {
1477
+        return $this->query('MountConfigManager');
1478
+    }
1479
+
1480
+    /**
1481
+     * Get the IniWrapper
1482
+     *
1483
+     * @return IniGetWrapper
1484
+     */
1485
+    public function getIniWrapper() {
1486
+        return $this->query('IniWrapper');
1487
+    }
1488
+
1489
+    /**
1490
+     * @return \OCP\Command\IBus
1491
+     */
1492
+    public function getCommandBus() {
1493
+        return $this->query('AsyncCommandBus');
1494
+    }
1495
+
1496
+    /**
1497
+     * Get the trusted domain helper
1498
+     *
1499
+     * @return TrustedDomainHelper
1500
+     */
1501
+    public function getTrustedDomainHelper() {
1502
+        return $this->query('TrustedDomainHelper');
1503
+    }
1504
+
1505
+    /**
1506
+     * Get the locking provider
1507
+     *
1508
+     * @return \OCP\Lock\ILockingProvider
1509
+     * @since 8.1.0
1510
+     */
1511
+    public function getLockingProvider() {
1512
+        return $this->query('LockingProvider');
1513
+    }
1514
+
1515
+    /**
1516
+     * @return \OCP\Files\Mount\IMountManager
1517
+     **/
1518
+    function getMountManager() {
1519
+        return $this->query('MountManager');
1520
+    }
1521
+
1522
+    /** @return \OCP\Files\Config\IUserMountCache */
1523
+    function getUserMountCache() {
1524
+        return $this->query('UserMountCache');
1525
+    }
1526
+
1527
+    /**
1528
+     * Get the MimeTypeDetector
1529
+     *
1530
+     * @return \OCP\Files\IMimeTypeDetector
1531
+     */
1532
+    public function getMimeTypeDetector() {
1533
+        return $this->query('MimeTypeDetector');
1534
+    }
1535
+
1536
+    /**
1537
+     * Get the MimeTypeLoader
1538
+     *
1539
+     * @return \OCP\Files\IMimeTypeLoader
1540
+     */
1541
+    public function getMimeTypeLoader() {
1542
+        return $this->query('MimeTypeLoader');
1543
+    }
1544
+
1545
+    /**
1546
+     * Get the manager of all the capabilities
1547
+     *
1548
+     * @return \OC\CapabilitiesManager
1549
+     */
1550
+    public function getCapabilitiesManager() {
1551
+        return $this->query('CapabilitiesManager');
1552
+    }
1553
+
1554
+    /**
1555
+     * Get the EventDispatcher
1556
+     *
1557
+     * @return EventDispatcherInterface
1558
+     * @since 8.2.0
1559
+     */
1560
+    public function getEventDispatcher() {
1561
+        return $this->query('EventDispatcher');
1562
+    }
1563
+
1564
+    /**
1565
+     * Get the Notification Manager
1566
+     *
1567
+     * @return \OCP\Notification\IManager
1568
+     * @since 8.2.0
1569
+     */
1570
+    public function getNotificationManager() {
1571
+        return $this->query('NotificationManager');
1572
+    }
1573
+
1574
+    /**
1575
+     * @return \OCP\Comments\ICommentsManager
1576
+     */
1577
+    public function getCommentsManager() {
1578
+        return $this->query('CommentsManager');
1579
+    }
1580
+
1581
+    /**
1582
+     * @return \OC_Defaults
1583
+     */
1584
+    public function getThemingDefaults() {
1585
+        return $this->query('ThemingDefaults');
1586
+    }
1587
+
1588
+    /**
1589
+     * @return \OC\IntegrityCheck\Checker
1590
+     */
1591
+    public function getIntegrityCodeChecker() {
1592
+        return $this->query('IntegrityCodeChecker');
1593
+    }
1594
+
1595
+    /**
1596
+     * @return \OC\Session\CryptoWrapper
1597
+     */
1598
+    public function getSessionCryptoWrapper() {
1599
+        return $this->query('CryptoWrapper');
1600
+    }
1601
+
1602
+    /**
1603
+     * @return CsrfTokenManager
1604
+     */
1605
+    public function getCsrfTokenManager() {
1606
+        return $this->query('CsrfTokenManager');
1607
+    }
1608
+
1609
+    /**
1610
+     * @return Throttler
1611
+     */
1612
+    public function getBruteForceThrottler() {
1613
+        return $this->query('Throttler');
1614
+    }
1615
+
1616
+    /**
1617
+     * @return IContentSecurityPolicyManager
1618
+     */
1619
+    public function getContentSecurityPolicyManager() {
1620
+        return $this->query('ContentSecurityPolicyManager');
1621
+    }
1622
+
1623
+    /**
1624
+     * @return ContentSecurityPolicyNonceManager
1625
+     */
1626
+    public function getContentSecurityPolicyNonceManager() {
1627
+        return $this->query('ContentSecurityPolicyNonceManager');
1628
+    }
1629
+
1630
+    /**
1631
+     * Not a public API as of 8.2, wait for 9.0
1632
+     *
1633
+     * @return \OCA\Files_External\Service\BackendService
1634
+     */
1635
+    public function getStoragesBackendService() {
1636
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1637
+    }
1638
+
1639
+    /**
1640
+     * Not a public API as of 8.2, wait for 9.0
1641
+     *
1642
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1643
+     */
1644
+    public function getGlobalStoragesService() {
1645
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1646
+    }
1647
+
1648
+    /**
1649
+     * Not a public API as of 8.2, wait for 9.0
1650
+     *
1651
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1652
+     */
1653
+    public function getUserGlobalStoragesService() {
1654
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1655
+    }
1656
+
1657
+    /**
1658
+     * Not a public API as of 8.2, wait for 9.0
1659
+     *
1660
+     * @return \OCA\Files_External\Service\UserStoragesService
1661
+     */
1662
+    public function getUserStoragesService() {
1663
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1664
+    }
1665
+
1666
+    /**
1667
+     * @return \OCP\Share\IManager
1668
+     */
1669
+    public function getShareManager() {
1670
+        return $this->query('ShareManager');
1671
+    }
1672
+
1673
+    /**
1674
+     * Returns the LDAP Provider
1675
+     *
1676
+     * @return \OCP\LDAP\ILDAPProvider
1677
+     */
1678
+    public function getLDAPProvider() {
1679
+        return $this->query('LDAPProvider');
1680
+    }
1681
+
1682
+    /**
1683
+     * @return \OCP\Settings\IManager
1684
+     */
1685
+    public function getSettingsManager() {
1686
+        return $this->query('SettingsManager');
1687
+    }
1688
+
1689
+    /**
1690
+     * @return \OCP\Files\IAppData
1691
+     */
1692
+    public function getAppDataDir($app) {
1693
+        /** @var \OC\Files\AppData\Factory $factory */
1694
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1695
+        return $factory->get($app);
1696
+    }
1697
+
1698
+    /**
1699
+     * @return \OCP\Lockdown\ILockdownManager
1700
+     */
1701
+    public function getLockdownManager() {
1702
+        return $this->query('LockdownManager');
1703
+    }
1704
+
1705
+    /**
1706
+     * @return \OCP\Federation\ICloudIdManager
1707
+     */
1708
+    public function getCloudIdManager() {
1709
+        return $this->query(ICloudIdManager::class);
1710
+    }
1711 1711
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/Response.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 
227 227
 	/**
228 228
 	 * By default renders no output
229
-	 * @return null
229
+	 * @return string
230 230
 	 * @since 6.0.0
231 231
 	 */
232 232
 	public function render() {
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 
260 260
 	/**
261 261
 	 * Get the currently used Content-Security-Policy
262
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
262
+	 * @return ContentSecurityPolicy|null Used Content-Security-Policy or null if
263 263
 	 *                                    none specified.
264 264
 	 * @since 8.1.0
265 265
 	 */
Please login to merge, or discard this patch.
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -42,285 +42,285 @@
 block discarded – undo
42 42
  */
43 43
 class Response {
44 44
 
45
-	/**
46
-	 * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
-	 * @var array
48
-	 */
49
-	private $headers = array(
50
-		'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
-	);
52
-
53
-
54
-	/**
55
-	 * Cookies that will be need to be constructed as header
56
-	 * @var array
57
-	 */
58
-	private $cookies = array();
59
-
60
-
61
-	/**
62
-	 * HTTP status code - defaults to STATUS OK
63
-	 * @var int
64
-	 */
65
-	private $status = Http::STATUS_OK;
66
-
67
-
68
-	/**
69
-	 * Last modified date
70
-	 * @var \DateTime
71
-	 */
72
-	private $lastModified;
73
-
74
-
75
-	/**
76
-	 * ETag
77
-	 * @var string
78
-	 */
79
-	private $ETag;
80
-
81
-	/** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
-	private $contentSecurityPolicy = null;
83
-
84
-
85
-	/**
86
-	 * Caches the response
87
-	 * @param int $cacheSeconds the amount of seconds that should be cached
88
-	 * if 0 then caching will be disabled
89
-	 * @return $this
90
-	 * @since 6.0.0 - return value was added in 7.0.0
91
-	 */
92
-	public function cacheFor($cacheSeconds) {
93
-
94
-		if($cacheSeconds > 0) {
95
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
96
-		} else {
97
-			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
98
-		}
99
-
100
-		return $this;
101
-	}
102
-
103
-	/**
104
-	 * Adds a new cookie to the response
105
-	 * @param string $name The name of the cookie
106
-	 * @param string $value The value of the cookie
107
-	 * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
108
-	 * 									to null cookie will be considered as session
109
-	 * 									cookie.
110
-	 * @return $this
111
-	 * @since 8.0.0
112
-	 */
113
-	public function addCookie($name, $value, \DateTime $expireDate = null) {
114
-		$this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
115
-		return $this;
116
-	}
117
-
118
-
119
-	/**
120
-	 * Set the specified cookies
121
-	 * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
122
-	 * @return $this
123
-	 * @since 8.0.0
124
-	 */
125
-	public function setCookies(array $cookies) {
126
-		$this->cookies = $cookies;
127
-		return $this;
128
-	}
129
-
130
-
131
-	/**
132
-	 * Invalidates the specified cookie
133
-	 * @param string $name
134
-	 * @return $this
135
-	 * @since 8.0.0
136
-	 */
137
-	public function invalidateCookie($name) {
138
-		$this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
139
-		return $this;
140
-	}
141
-
142
-	/**
143
-	 * Invalidates the specified cookies
144
-	 * @param array $cookieNames array('foo', 'bar')
145
-	 * @return $this
146
-	 * @since 8.0.0
147
-	 */
148
-	public function invalidateCookies(array $cookieNames) {
149
-		foreach($cookieNames as $cookieName) {
150
-			$this->invalidateCookie($cookieName);
151
-		}
152
-		return $this;
153
-	}
154
-
155
-	/**
156
-	 * Returns the cookies
157
-	 * @return array
158
-	 * @since 8.0.0
159
-	 */
160
-	public function getCookies() {
161
-		return $this->cookies;
162
-	}
163
-
164
-	/**
165
-	 * Adds a new header to the response that will be called before the render
166
-	 * function
167
-	 * @param string $name The name of the HTTP header
168
-	 * @param string $value The value, null will delete it
169
-	 * @return $this
170
-	 * @since 6.0.0 - return value was added in 7.0.0
171
-	 */
172
-	public function addHeader($name, $value) {
173
-		$name = trim($name);  // always remove leading and trailing whitespace
174
-		                      // to be able to reliably check for security
175
-		                      // headers
176
-
177
-		if(is_null($value)) {
178
-			unset($this->headers[$name]);
179
-		} else {
180
-			$this->headers[$name] = $value;
181
-		}
182
-
183
-		return $this;
184
-	}
185
-
186
-
187
-	/**
188
-	 * Set the headers
189
-	 * @param array $headers value header pairs
190
-	 * @return $this
191
-	 * @since 8.0.0
192
-	 */
193
-	public function setHeaders(array $headers) {
194
-		$this->headers = $headers;
195
-
196
-		return $this;
197
-	}
198
-
199
-
200
-	/**
201
-	 * Returns the set headers
202
-	 * @return array the headers
203
-	 * @since 6.0.0
204
-	 */
205
-	public function getHeaders() {
206
-		$mergeWith = [];
207
-
208
-		if($this->lastModified) {
209
-			$mergeWith['Last-Modified'] =
210
-				$this->lastModified->format(\DateTime::RFC2822);
211
-		}
212
-
213
-		// Build Content-Security-Policy and use default if none has been specified
214
-		if(is_null($this->contentSecurityPolicy)) {
215
-			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
216
-		}
217
-		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
218
-
219
-		if($this->ETag) {
220
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
221
-		}
222
-
223
-		return array_merge($mergeWith, $this->headers);
224
-	}
225
-
226
-
227
-	/**
228
-	 * By default renders no output
229
-	 * @return null
230
-	 * @since 6.0.0
231
-	 */
232
-	public function render() {
233
-		return null;
234
-	}
235
-
236
-
237
-	/**
238
-	 * Set response status
239
-	 * @param int $status a HTTP status code, see also the STATUS constants
240
-	 * @return Response Reference to this object
241
-	 * @since 6.0.0 - return value was added in 7.0.0
242
-	 */
243
-	public function setStatus($status) {
244
-		$this->status = $status;
245
-
246
-		return $this;
247
-	}
248
-
249
-	/**
250
-	 * Set a Content-Security-Policy
251
-	 * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
252
-	 * @return $this
253
-	 * @since 8.1.0
254
-	 */
255
-	public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
256
-		$this->contentSecurityPolicy = $csp;
257
-		return $this;
258
-	}
259
-
260
-	/**
261
-	 * Get the currently used Content-Security-Policy
262
-	 * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
263
-	 *                                    none specified.
264
-	 * @since 8.1.0
265
-	 */
266
-	public function getContentSecurityPolicy() {
267
-		return $this->contentSecurityPolicy;
268
-	}
269
-
270
-
271
-	/**
272
-	 * Get response status
273
-	 * @since 6.0.0
274
-	 */
275
-	public function getStatus() {
276
-		return $this->status;
277
-	}
278
-
279
-
280
-	/**
281
-	 * Get the ETag
282
-	 * @return string the etag
283
-	 * @since 6.0.0
284
-	 */
285
-	public function getETag() {
286
-		return $this->ETag;
287
-	}
288
-
289
-
290
-	/**
291
-	 * Get "last modified" date
292
-	 * @return \DateTime RFC2822 formatted last modified date
293
-	 * @since 6.0.0
294
-	 */
295
-	public function getLastModified() {
296
-		return $this->lastModified;
297
-	}
298
-
299
-
300
-	/**
301
-	 * Set the ETag
302
-	 * @param string $ETag
303
-	 * @return Response Reference to this object
304
-	 * @since 6.0.0 - return value was added in 7.0.0
305
-	 */
306
-	public function setETag($ETag) {
307
-		$this->ETag = $ETag;
308
-
309
-		return $this;
310
-	}
311
-
312
-
313
-	/**
314
-	 * Set "last modified" date
315
-	 * @param \DateTime $lastModified
316
-	 * @return Response Reference to this object
317
-	 * @since 6.0.0 - return value was added in 7.0.0
318
-	 */
319
-	public function setLastModified($lastModified) {
320
-		$this->lastModified = $lastModified;
321
-
322
-		return $this;
323
-	}
45
+    /**
46
+     * Headers - defaults to ['Cache-Control' => 'no-cache, no-store, must-revalidate']
47
+     * @var array
48
+     */
49
+    private $headers = array(
50
+        'Cache-Control' => 'no-cache, no-store, must-revalidate'
51
+    );
52
+
53
+
54
+    /**
55
+     * Cookies that will be need to be constructed as header
56
+     * @var array
57
+     */
58
+    private $cookies = array();
59
+
60
+
61
+    /**
62
+     * HTTP status code - defaults to STATUS OK
63
+     * @var int
64
+     */
65
+    private $status = Http::STATUS_OK;
66
+
67
+
68
+    /**
69
+     * Last modified date
70
+     * @var \DateTime
71
+     */
72
+    private $lastModified;
73
+
74
+
75
+    /**
76
+     * ETag
77
+     * @var string
78
+     */
79
+    private $ETag;
80
+
81
+    /** @var ContentSecurityPolicy|null Used Content-Security-Policy */
82
+    private $contentSecurityPolicy = null;
83
+
84
+
85
+    /**
86
+     * Caches the response
87
+     * @param int $cacheSeconds the amount of seconds that should be cached
88
+     * if 0 then caching will be disabled
89
+     * @return $this
90
+     * @since 6.0.0 - return value was added in 7.0.0
91
+     */
92
+    public function cacheFor($cacheSeconds) {
93
+
94
+        if($cacheSeconds > 0) {
95
+            $this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
96
+        } else {
97
+            $this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
98
+        }
99
+
100
+        return $this;
101
+    }
102
+
103
+    /**
104
+     * Adds a new cookie to the response
105
+     * @param string $name The name of the cookie
106
+     * @param string $value The value of the cookie
107
+     * @param \DateTime|null $expireDate Date on that the cookie should expire, if set
108
+     * 									to null cookie will be considered as session
109
+     * 									cookie.
110
+     * @return $this
111
+     * @since 8.0.0
112
+     */
113
+    public function addCookie($name, $value, \DateTime $expireDate = null) {
114
+        $this->cookies[$name] = array('value' => $value, 'expireDate' => $expireDate);
115
+        return $this;
116
+    }
117
+
118
+
119
+    /**
120
+     * Set the specified cookies
121
+     * @param array $cookies array('foo' => array('value' => 'bar', 'expire' => null))
122
+     * @return $this
123
+     * @since 8.0.0
124
+     */
125
+    public function setCookies(array $cookies) {
126
+        $this->cookies = $cookies;
127
+        return $this;
128
+    }
129
+
130
+
131
+    /**
132
+     * Invalidates the specified cookie
133
+     * @param string $name
134
+     * @return $this
135
+     * @since 8.0.0
136
+     */
137
+    public function invalidateCookie($name) {
138
+        $this->addCookie($name, 'expired', new \DateTime('1971-01-01 00:00'));
139
+        return $this;
140
+    }
141
+
142
+    /**
143
+     * Invalidates the specified cookies
144
+     * @param array $cookieNames array('foo', 'bar')
145
+     * @return $this
146
+     * @since 8.0.0
147
+     */
148
+    public function invalidateCookies(array $cookieNames) {
149
+        foreach($cookieNames as $cookieName) {
150
+            $this->invalidateCookie($cookieName);
151
+        }
152
+        return $this;
153
+    }
154
+
155
+    /**
156
+     * Returns the cookies
157
+     * @return array
158
+     * @since 8.0.0
159
+     */
160
+    public function getCookies() {
161
+        return $this->cookies;
162
+    }
163
+
164
+    /**
165
+     * Adds a new header to the response that will be called before the render
166
+     * function
167
+     * @param string $name The name of the HTTP header
168
+     * @param string $value The value, null will delete it
169
+     * @return $this
170
+     * @since 6.0.0 - return value was added in 7.0.0
171
+     */
172
+    public function addHeader($name, $value) {
173
+        $name = trim($name);  // always remove leading and trailing whitespace
174
+                                // to be able to reliably check for security
175
+                                // headers
176
+
177
+        if(is_null($value)) {
178
+            unset($this->headers[$name]);
179
+        } else {
180
+            $this->headers[$name] = $value;
181
+        }
182
+
183
+        return $this;
184
+    }
185
+
186
+
187
+    /**
188
+     * Set the headers
189
+     * @param array $headers value header pairs
190
+     * @return $this
191
+     * @since 8.0.0
192
+     */
193
+    public function setHeaders(array $headers) {
194
+        $this->headers = $headers;
195
+
196
+        return $this;
197
+    }
198
+
199
+
200
+    /**
201
+     * Returns the set headers
202
+     * @return array the headers
203
+     * @since 6.0.0
204
+     */
205
+    public function getHeaders() {
206
+        $mergeWith = [];
207
+
208
+        if($this->lastModified) {
209
+            $mergeWith['Last-Modified'] =
210
+                $this->lastModified->format(\DateTime::RFC2822);
211
+        }
212
+
213
+        // Build Content-Security-Policy and use default if none has been specified
214
+        if(is_null($this->contentSecurityPolicy)) {
215
+            $this->setContentSecurityPolicy(new ContentSecurityPolicy());
216
+        }
217
+        $this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
218
+
219
+        if($this->ETag) {
220
+            $mergeWith['ETag'] = '"' . $this->ETag . '"';
221
+        }
222
+
223
+        return array_merge($mergeWith, $this->headers);
224
+    }
225
+
226
+
227
+    /**
228
+     * By default renders no output
229
+     * @return null
230
+     * @since 6.0.0
231
+     */
232
+    public function render() {
233
+        return null;
234
+    }
235
+
236
+
237
+    /**
238
+     * Set response status
239
+     * @param int $status a HTTP status code, see also the STATUS constants
240
+     * @return Response Reference to this object
241
+     * @since 6.0.0 - return value was added in 7.0.0
242
+     */
243
+    public function setStatus($status) {
244
+        $this->status = $status;
245
+
246
+        return $this;
247
+    }
248
+
249
+    /**
250
+     * Set a Content-Security-Policy
251
+     * @param EmptyContentSecurityPolicy $csp Policy to set for the response object
252
+     * @return $this
253
+     * @since 8.1.0
254
+     */
255
+    public function setContentSecurityPolicy(EmptyContentSecurityPolicy $csp) {
256
+        $this->contentSecurityPolicy = $csp;
257
+        return $this;
258
+    }
259
+
260
+    /**
261
+     * Get the currently used Content-Security-Policy
262
+     * @return EmptyContentSecurityPolicy|null Used Content-Security-Policy or null if
263
+     *                                    none specified.
264
+     * @since 8.1.0
265
+     */
266
+    public function getContentSecurityPolicy() {
267
+        return $this->contentSecurityPolicy;
268
+    }
269
+
270
+
271
+    /**
272
+     * Get response status
273
+     * @since 6.0.0
274
+     */
275
+    public function getStatus() {
276
+        return $this->status;
277
+    }
278
+
279
+
280
+    /**
281
+     * Get the ETag
282
+     * @return string the etag
283
+     * @since 6.0.0
284
+     */
285
+    public function getETag() {
286
+        return $this->ETag;
287
+    }
288
+
289
+
290
+    /**
291
+     * Get "last modified" date
292
+     * @return \DateTime RFC2822 formatted last modified date
293
+     * @since 6.0.0
294
+     */
295
+    public function getLastModified() {
296
+        return $this->lastModified;
297
+    }
298
+
299
+
300
+    /**
301
+     * Set the ETag
302
+     * @param string $ETag
303
+     * @return Response Reference to this object
304
+     * @since 6.0.0 - return value was added in 7.0.0
305
+     */
306
+    public function setETag($ETag) {
307
+        $this->ETag = $ETag;
308
+
309
+        return $this;
310
+    }
311
+
312
+
313
+    /**
314
+     * Set "last modified" date
315
+     * @param \DateTime $lastModified
316
+     * @return Response Reference to this object
317
+     * @since 6.0.0 - return value was added in 7.0.0
318
+     */
319
+    public function setLastModified($lastModified) {
320
+        $this->lastModified = $lastModified;
321
+
322
+        return $this;
323
+    }
324 324
 
325 325
 
326 326
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public function cacheFor($cacheSeconds) {
93 93
 
94
-		if($cacheSeconds > 0) {
95
-			$this->addHeader('Cache-Control', 'max-age=' . $cacheSeconds . ', must-revalidate');
94
+		if ($cacheSeconds > 0) {
95
+			$this->addHeader('Cache-Control', 'max-age='.$cacheSeconds.', must-revalidate');
96 96
 		} else {
97 97
 			$this->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate');
98 98
 		}
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 	 * @since 8.0.0
147 147
 	 */
148 148
 	public function invalidateCookies(array $cookieNames) {
149
-		foreach($cookieNames as $cookieName) {
149
+		foreach ($cookieNames as $cookieName) {
150 150
 			$this->invalidateCookie($cookieName);
151 151
 		}
152 152
 		return $this;
@@ -170,11 +170,11 @@  discard block
 block discarded – undo
170 170
 	 * @since 6.0.0 - return value was added in 7.0.0
171 171
 	 */
172 172
 	public function addHeader($name, $value) {
173
-		$name = trim($name);  // always remove leading and trailing whitespace
173
+		$name = trim($name); // always remove leading and trailing whitespace
174 174
 		                      // to be able to reliably check for security
175 175
 		                      // headers
176 176
 
177
-		if(is_null($value)) {
177
+		if (is_null($value)) {
178 178
 			unset($this->headers[$name]);
179 179
 		} else {
180 180
 			$this->headers[$name] = $value;
@@ -205,19 +205,19 @@  discard block
 block discarded – undo
205 205
 	public function getHeaders() {
206 206
 		$mergeWith = [];
207 207
 
208
-		if($this->lastModified) {
208
+		if ($this->lastModified) {
209 209
 			$mergeWith['Last-Modified'] =
210 210
 				$this->lastModified->format(\DateTime::RFC2822);
211 211
 		}
212 212
 
213 213
 		// Build Content-Security-Policy and use default if none has been specified
214
-		if(is_null($this->contentSecurityPolicy)) {
214
+		if (is_null($this->contentSecurityPolicy)) {
215 215
 			$this->setContentSecurityPolicy(new ContentSecurityPolicy());
216 216
 		}
217 217
 		$this->headers['Content-Security-Policy'] = $this->contentSecurityPolicy->buildPolicy();
218 218
 
219
-		if($this->ETag) {
220
-			$mergeWith['ETag'] = '"' . $this->ETag . '"';
219
+		if ($this->ETag) {
220
+			$mergeWith['ETag'] = '"'.$this->ETag.'"';
221 221
 		}
222 222
 
223 223
 		return array_merge($mergeWith, $this->headers);
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Publishing/PublishPlugin.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@
 block discarded – undo
134 134
 	 * @param RequestInterface $request
135 135
 	 * @param ResponseInterface $response
136 136
 	 *
137
-	 * @return void|bool
137
+	 * @return null|false
138 138
 	 */
139 139
 	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140 140
 		$path = $request->getPath();
Please login to merge, or discard this patch.
Indentation   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -34,194 +34,194 @@
 block discarded – undo
34 34
 use OCP\IConfig;
35 35
 
36 36
 class PublishPlugin extends ServerPlugin {
37
-	const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
-
39
-	/**
40
-	 * Reference to SabreDAV server object.
41
-	 *
42
-	 * @var \Sabre\DAV\Server
43
-	 */
44
-	protected $server;
45
-
46
-	/**
47
-	 * Config instance to get instance secret.
48
-	 *
49
-	 * @var IConfig
50
-	 */
51
-	protected $config;
52
-
53
-	/**
54
-	 * URL Generator for absolute URLs.
55
-	 *
56
-	 * @var IURLGenerator
57
-	 */
58
-	protected $urlGenerator;
59
-
60
-	/**
61
-	 * PublishPlugin constructor.
62
-	 *
63
-	 * @param IConfig $config
64
-	 * @param IURLGenerator $urlGenerator
65
-	 */
66
-	public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
-		$this->config = $config;
68
-		$this->urlGenerator = $urlGenerator;
69
-	}
70
-
71
-	/**
72
-	 * This method should return a list of server-features.
73
-	 *
74
-	 * This is for example 'versioning' and is added to the DAV: header
75
-	 * in an OPTIONS response.
76
-	 *
77
-	 * @return string[]
78
-	 */
79
-	public function getFeatures() {
80
-		// May have to be changed to be detected
81
-		return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
-	}
83
-
84
-	/**
85
-	 * Returns a plugin name.
86
-	 *
87
-	 * Using this name other plugins will be able to access other plugins
88
-	 * using Sabre\DAV\Server::getPlugin
89
-	 *
90
-	 * @return string
91
-	 */
92
-	public function getPluginName()	{
93
-		return 'oc-calendar-publishing';
94
-	}
95
-
96
-	/**
97
-	 * This initializes the plugin.
98
-	 *
99
-	 * This function is called by Sabre\DAV\Server, after
100
-	 * addPlugin is called.
101
-	 *
102
-	 * This method should set up the required event subscriptions.
103
-	 *
104
-	 * @param Server $server
105
-	 */
106
-	public function initialize(Server $server) {
107
-		$this->server = $server;
108
-
109
-		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
111
-	}
112
-
113
-	public function propFind(PropFind $propFind, INode $node) {
114
-		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
-				if ($node->getPublishStatus()) {
117
-					// We return the publish-url only if the calendar is published.
118
-					$token = $node->getPublishStatus();
119
-					$publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
-
121
-					return new Publisher($publishUrl, true);
122
-				}
123
-			});
124
-
125
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
-				return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
-			});
128
-		}
129
-	}
130
-
131
-	/**
132
-	 * We intercept this to handle POST requests on calendars.
133
-	 *
134
-	 * @param RequestInterface $request
135
-	 * @param ResponseInterface $response
136
-	 *
137
-	 * @return void|bool
138
-	 */
139
-	public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
-		$path = $request->getPath();
141
-
142
-		// Only handling xml
143
-		$contentType = $request->getHeader('Content-Type');
144
-		if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
-			return;
146
-		}
147
-
148
-		// Making sure the node exists
149
-		try {
150
-			$node = $this->server->tree->getNodeForPath($path);
151
-		} catch (NotFound $e) {
152
-			return;
153
-		}
154
-
155
-		$requestBody = $request->getBodyAsString();
156
-
157
-		// If this request handler could not deal with this POST request, it
158
-		// will return 'null' and other plugins get a chance to handle the
159
-		// request.
160
-		//
161
-		// However, we already requested the full body. This is a problem,
162
-		// because a body can only be read once. This is why we preemptively
163
-		// re-populated the request body with the existing data.
164
-		$request->setBody($requestBody);
165
-
166
-		$this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
-
168
-		switch ($documentType) {
169
-
170
-			case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
-
172
-			// We can only deal with IShareableCalendar objects
173
-			if (!$node instanceof Calendar) {
174
-				return;
175
-			}
176
-			$this->server->transactionType = 'post-publish-calendar';
177
-
178
-			// Getting ACL info
179
-			$acl = $this->server->getPlugin('acl');
180
-
181
-			// If there's no ACL support, we allow everything
182
-			if ($acl) {
183
-				$acl->checkPrivileges($path, '{DAV:}write');
184
-			}
185
-
186
-			$node->setPublishStatus(true);
187
-
188
-			// iCloud sends back the 202, so we will too.
189
-			$response->setStatus(202);
190
-
191
-			// Adding this because sending a response body may cause issues,
192
-			// and I wanted some type of indicator the response was handled.
193
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
194
-
195
-			// Breaking the event chain
196
-			return false;
197
-
198
-			case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
-
200
-			// We can only deal with IShareableCalendar objects
201
-			if (!$node instanceof Calendar) {
202
-				return;
203
-			}
204
-			$this->server->transactionType = 'post-unpublish-calendar';
205
-
206
-			// Getting ACL info
207
-			$acl = $this->server->getPlugin('acl');
208
-
209
-			// If there's no ACL support, we allow everything
210
-			if ($acl) {
211
-				$acl->checkPrivileges($path, '{DAV:}write');
212
-			}
213
-
214
-			$node->setPublishStatus(false);
215
-
216
-			$response->setStatus(200);
217
-
218
-			// Adding this because sending a response body may cause issues,
219
-			// and I wanted some type of indicator the response was handled.
220
-			$response->setHeader('X-Sabre-Status', 'everything-went-well');
221
-
222
-			// Breaking the event chain
223
-			return false;
37
+    const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
38
+
39
+    /**
40
+     * Reference to SabreDAV server object.
41
+     *
42
+     * @var \Sabre\DAV\Server
43
+     */
44
+    protected $server;
45
+
46
+    /**
47
+     * Config instance to get instance secret.
48
+     *
49
+     * @var IConfig
50
+     */
51
+    protected $config;
52
+
53
+    /**
54
+     * URL Generator for absolute URLs.
55
+     *
56
+     * @var IURLGenerator
57
+     */
58
+    protected $urlGenerator;
59
+
60
+    /**
61
+     * PublishPlugin constructor.
62
+     *
63
+     * @param IConfig $config
64
+     * @param IURLGenerator $urlGenerator
65
+     */
66
+    public function __construct(IConfig $config, IURLGenerator $urlGenerator) {
67
+        $this->config = $config;
68
+        $this->urlGenerator = $urlGenerator;
69
+    }
70
+
71
+    /**
72
+     * This method should return a list of server-features.
73
+     *
74
+     * This is for example 'versioning' and is added to the DAV: header
75
+     * in an OPTIONS response.
76
+     *
77
+     * @return string[]
78
+     */
79
+    public function getFeatures() {
80
+        // May have to be changed to be detected
81
+        return ['oc-calendar-publishing', 'calendarserver-sharing'];
82
+    }
83
+
84
+    /**
85
+     * Returns a plugin name.
86
+     *
87
+     * Using this name other plugins will be able to access other plugins
88
+     * using Sabre\DAV\Server::getPlugin
89
+     *
90
+     * @return string
91
+     */
92
+    public function getPluginName()	{
93
+        return 'oc-calendar-publishing';
94
+    }
95
+
96
+    /**
97
+     * This initializes the plugin.
98
+     *
99
+     * This function is called by Sabre\DAV\Server, after
100
+     * addPlugin is called.
101
+     *
102
+     * This method should set up the required event subscriptions.
103
+     *
104
+     * @param Server $server
105
+     */
106
+    public function initialize(Server $server) {
107
+        $this->server = $server;
108
+
109
+        $this->server->on('method:POST', [$this, 'httpPost']);
110
+        $this->server->on('propFind',    [$this, 'propFind']);
111
+    }
112
+
113
+    public function propFind(PropFind $propFind, INode $node) {
114
+        if ($node instanceof Calendar) {
115
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
116
+                if ($node->getPublishStatus()) {
117
+                    // We return the publish-url only if the calendar is published.
118
+                    $token = $node->getPublishStatus();
119
+                    $publishUrl = $this->urlGenerator->getAbsoluteURL($this->server->getBaseUri().'public-calendars/').$token;
120
+
121
+                    return new Publisher($publishUrl, true);
122
+                }
123
+            });
124
+
125
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}allowed-sharing-modes', function() use ($node) {
126
+                return new AllowedSharingModes(!$node->isSubscription(), !$node->isSubscription());
127
+            });
128
+        }
129
+    }
130
+
131
+    /**
132
+     * We intercept this to handle POST requests on calendars.
133
+     *
134
+     * @param RequestInterface $request
135
+     * @param ResponseInterface $response
136
+     *
137
+     * @return void|bool
138
+     */
139
+    public function httpPost(RequestInterface $request, ResponseInterface $response) {
140
+        $path = $request->getPath();
141
+
142
+        // Only handling xml
143
+        $contentType = $request->getHeader('Content-Type');
144
+        if (strpos($contentType, 'application/xml') === false && strpos($contentType, 'text/xml') === false) {
145
+            return;
146
+        }
147
+
148
+        // Making sure the node exists
149
+        try {
150
+            $node = $this->server->tree->getNodeForPath($path);
151
+        } catch (NotFound $e) {
152
+            return;
153
+        }
154
+
155
+        $requestBody = $request->getBodyAsString();
156
+
157
+        // If this request handler could not deal with this POST request, it
158
+        // will return 'null' and other plugins get a chance to handle the
159
+        // request.
160
+        //
161
+        // However, we already requested the full body. This is a problem,
162
+        // because a body can only be read once. This is why we preemptively
163
+        // re-populated the request body with the existing data.
164
+        $request->setBody($requestBody);
165
+
166
+        $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
167
+
168
+        switch ($documentType) {
169
+
170
+            case '{'.self::NS_CALENDARSERVER.'}publish-calendar' :
171
+
172
+            // We can only deal with IShareableCalendar objects
173
+            if (!$node instanceof Calendar) {
174
+                return;
175
+            }
176
+            $this->server->transactionType = 'post-publish-calendar';
177
+
178
+            // Getting ACL info
179
+            $acl = $this->server->getPlugin('acl');
180
+
181
+            // If there's no ACL support, we allow everything
182
+            if ($acl) {
183
+                $acl->checkPrivileges($path, '{DAV:}write');
184
+            }
185
+
186
+            $node->setPublishStatus(true);
187
+
188
+            // iCloud sends back the 202, so we will too.
189
+            $response->setStatus(202);
190
+
191
+            // Adding this because sending a response body may cause issues,
192
+            // and I wanted some type of indicator the response was handled.
193
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
194
+
195
+            // Breaking the event chain
196
+            return false;
197
+
198
+            case '{'.self::NS_CALENDARSERVER.'}unpublish-calendar' :
199
+
200
+            // We can only deal with IShareableCalendar objects
201
+            if (!$node instanceof Calendar) {
202
+                return;
203
+            }
204
+            $this->server->transactionType = 'post-unpublish-calendar';
205
+
206
+            // Getting ACL info
207
+            $acl = $this->server->getPlugin('acl');
208
+
209
+            // If there's no ACL support, we allow everything
210
+            if ($acl) {
211
+                $acl->checkPrivileges($path, '{DAV:}write');
212
+            }
213
+
214
+            $node->setPublishStatus(false);
215
+
216
+            $response->setStatus(200);
217
+
218
+            // Adding this because sending a response body may cause issues,
219
+            // and I wanted some type of indicator the response was handled.
220
+            $response->setHeader('X-Sabre-Status', 'everything-went-well');
221
+
222
+            // Breaking the event chain
223
+            return false;
224 224
 
225
-		}
226
-	}
225
+        }
226
+    }
227 227
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 	 *
90 90
 	 * @return string
91 91
 	 */
92
-	public function getPluginName()	{
92
+	public function getPluginName() {
93 93
 		return 'oc-calendar-publishing';
94 94
 	}
95 95
 
@@ -107,12 +107,12 @@  discard block
 block discarded – undo
107 107
 		$this->server = $server;
108 108
 
109 109
 		$this->server->on('method:POST', [$this, 'httpPost']);
110
-		$this->server->on('propFind',    [$this, 'propFind']);
110
+		$this->server->on('propFind', [$this, 'propFind']);
111 111
 	}
112 112
 
113 113
 	public function propFind(PropFind $propFind, INode $node) {
114 114
 		if ($node instanceof Calendar) {
115
-			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function () use ($node) {
115
+			$propFind->handle('{'.self::NS_CALENDARSERVER.'}publish-url', function() use ($node) {
116 116
 				if ($node->getPublishStatus()) {
117 117
 					// We return the publish-url only if the calendar is published.
118 118
 					$token = $node->getPublishStatus();
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/AddressBookRoot.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@
 block discarded – undo
30 30
 
31 31
 	/**
32 32
 	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
33
+	 * @param CardDavBackend $carddavBackend
34 34
 	 * @param string $principalPrefix
35 35
 	 */
36 36
 	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -25,46 +25,46 @@
 block discarded – undo
25 25
 
26 26
 class AddressBookRoot extends \Sabre\CardDAV\AddressBookRoot {
27 27
 
28
-	/** @var IL10N */
29
-	protected $l10n;
28
+    /** @var IL10N */
29
+    protected $l10n;
30 30
 
31
-	/**
32
-	 * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
-	 * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
-	 * @param string $principalPrefix
35
-	 */
36
-	public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
-		parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
-		$this->l10n = \OC::$server->getL10N('dav');
39
-	}
31
+    /**
32
+     * @param \Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend
33
+     * @param \Sabre\CardDAV\Backend\BackendInterface $carddavBackend
34
+     * @param string $principalPrefix
35
+     */
36
+    public function __construct(\Sabre\DAVACL\PrincipalBackend\BackendInterface $principalBackend, \Sabre\CardDAV\Backend\BackendInterface $carddavBackend, $principalPrefix = 'principals') {
37
+        parent::__construct($principalBackend, $carddavBackend, $principalPrefix);
38
+        $this->l10n = \OC::$server->getL10N('dav');
39
+    }
40 40
 
41
-	/**
42
-	 * This method returns a node for a principal.
43
-	 *
44
-	 * The passed array contains principal information, and is guaranteed to
45
-	 * at least contain a uri item. Other properties may or may not be
46
-	 * supplied by the authentication backend.
47
-	 *
48
-	 * @param array $principal
49
-	 * @return \Sabre\DAV\INode
50
-	 */
51
-	function getChildForPrincipal(array $principal) {
41
+    /**
42
+     * This method returns a node for a principal.
43
+     *
44
+     * The passed array contains principal information, and is guaranteed to
45
+     * at least contain a uri item. Other properties may or may not be
46
+     * supplied by the authentication backend.
47
+     *
48
+     * @param array $principal
49
+     * @return \Sabre\DAV\INode
50
+     */
51
+    function getChildForPrincipal(array $principal) {
52 52
 
53
-		return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
53
+        return new UserAddressBooks($this->carddavBackend, $principal['uri'], $this->l10n);
54 54
 
55
-	}
55
+    }
56 56
 
57
-	function getName() {
57
+    function getName() {
58 58
 
59
-		if ($this->principalPrefix === 'principals') {
60
-			return parent::getName();
61
-		}
62
-		// Grabbing all the components of the principal path.
63
-		$parts = explode('/', $this->principalPrefix);
59
+        if ($this->principalPrefix === 'principals') {
60
+            return parent::getName();
61
+        }
62
+        // Grabbing all the components of the principal path.
63
+        $parts = explode('/', $this->principalPrefix);
64 64
 
65
-		// We are only interested in the second part.
66
-		return $parts[1];
65
+        // We are only interested in the second part.
66
+        return $parts[1];
67 67
 
68
-	}
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.