Completed
Pull Request — master (#6328)
by Blizzz
13:01
created
lib/private/Collaboration/Collaborators/GroupPlugin.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -56,17 +56,17 @@
 block discarded – undo
56 56
 		$result = ['wide' => [], 'exact' => []];
57 57
 
58 58
 		$groups = $this->groupManager->search($search, $limit, $offset);
59
-		$groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
59
+		$groupIds = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
60 60
 
61 61
 		if (!$this->shareeEnumeration || sizeof($groups) < $limit) {
62 62
 			$hasMoreResults = true;
63 63
 		}
64 64
 
65
-		$userGroups =  [];
65
+		$userGroups = [];
66 66
 		if (!empty($groups) && $this->shareWithGroupOnly) {
67 67
 			// Intersect all the groups that match with the groups this user is a member of
68 68
 			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
69
-			$userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
69
+			$userGroups = array_map(function(IGroup $group) { return $group->getGID(); }, $userGroups);
70 70
 			$groupIds = array_intersect($groupIds, $userGroups);
71 71
 		}
72 72
 
Please login to merge, or discard this patch.
Indentation   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -33,92 +33,92 @@
 block discarded – undo
33 33
 use OCP\Share;
34 34
 
35 35
 class GroupPlugin implements ISearchPlugin {
36
-	protected $shareeEnumeration;
37
-	protected $shareWithGroupOnly;
36
+    protected $shareeEnumeration;
37
+    protected $shareWithGroupOnly;
38 38
 
39
-	/** @var IGroupManager */
40
-	private $groupManager;
41
-	/** @var IConfig */
42
-	private $config;
43
-	/** @var IUserSession */
44
-	private $userSession;
39
+    /** @var IGroupManager */
40
+    private $groupManager;
41
+    /** @var IConfig */
42
+    private $config;
43
+    /** @var IUserSession */
44
+    private $userSession;
45 45
 
46
-	public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
47
-		$this->groupManager = $groupManager;
48
-		$this->config = $config;
49
-		$this->userSession = $userSession;
46
+    public function __construct(IConfig $config, IGroupManager $groupManager, IUserSession $userSession) {
47
+        $this->groupManager = $groupManager;
48
+        $this->config = $config;
49
+        $this->userSession = $userSession;
50 50
 
51
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
52
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
53
-	}
51
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
52
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
53
+    }
54 54
 
55
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
56
-		$hasMoreResults = false;
57
-		$result = ['wide' => [], 'exact' => []];
55
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
56
+        $hasMoreResults = false;
57
+        $result = ['wide' => [], 'exact' => []];
58 58
 
59
-		$groups = $this->groupManager->search($search, $limit, $offset);
60
-		$groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
59
+        $groups = $this->groupManager->search($search, $limit, $offset);
60
+        $groupIds = array_map(function (IGroup $group) { return $group->getGID(); }, $groups);
61 61
 
62
-		if (!$this->shareeEnumeration || sizeof($groups) < $limit) {
63
-			$hasMoreResults = true;
64
-		}
62
+        if (!$this->shareeEnumeration || sizeof($groups) < $limit) {
63
+            $hasMoreResults = true;
64
+        }
65 65
 
66
-		$userGroups =  [];
67
-		if (!empty($groups) && $this->shareWithGroupOnly) {
68
-			// Intersect all the groups that match with the groups this user is a member of
69
-			$userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
70
-			$userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
71
-			$groupIds = array_intersect($groupIds, $userGroups);
72
-		}
66
+        $userGroups =  [];
67
+        if (!empty($groups) && $this->shareWithGroupOnly) {
68
+            // Intersect all the groups that match with the groups this user is a member of
69
+            $userGroups = $this->groupManager->getUserGroups($this->userSession->getUser());
70
+            $userGroups = array_map(function (IGroup $group) { return $group->getGID(); }, $userGroups);
71
+            $groupIds = array_intersect($groupIds, $userGroups);
72
+        }
73 73
 
74
-		$lowerSearch = strtolower($search);
75
-		foreach ($groups as $group) {
76
-			// FIXME: use a more efficient approach
77
-			$gid = $group->getGID();
78
-			if (!in_array($gid, $groupIds)) {
79
-				continue;
80
-			}
81
-			if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
82
-				$result['exact'][] = [
83
-					'label' => $group->getDisplayName(),
84
-					'value' => [
85
-						'shareType' => Share::SHARE_TYPE_GROUP,
86
-						'shareWith' => $gid,
87
-					],
88
-				];
89
-			} else {
90
-				$result['wide'][] = [
91
-					'label' => $group->getDisplayName(),
92
-					'value' => [
93
-						'shareType' => Share::SHARE_TYPE_GROUP,
94
-						'shareWith' => $gid,
95
-					],
96
-				];
97
-			}
98
-		}
74
+        $lowerSearch = strtolower($search);
75
+        foreach ($groups as $group) {
76
+            // FIXME: use a more efficient approach
77
+            $gid = $group->getGID();
78
+            if (!in_array($gid, $groupIds)) {
79
+                continue;
80
+            }
81
+            if (strtolower($gid) === $lowerSearch || strtolower($group->getDisplayName()) === $lowerSearch) {
82
+                $result['exact'][] = [
83
+                    'label' => $group->getDisplayName(),
84
+                    'value' => [
85
+                        'shareType' => Share::SHARE_TYPE_GROUP,
86
+                        'shareWith' => $gid,
87
+                    ],
88
+                ];
89
+            } else {
90
+                $result['wide'][] = [
91
+                    'label' => $group->getDisplayName(),
92
+                    'value' => [
93
+                        'shareType' => Share::SHARE_TYPE_GROUP,
94
+                        'shareWith' => $gid,
95
+                    ],
96
+                ];
97
+            }
98
+        }
99 99
 
100
-		if ($offset === 0 && empty($result['exact'])) {
101
-			// On page one we try if the search result has a direct hit on the
102
-			// user id and if so, we add that to the exact match list
103
-			$group = $this->groupManager->get($search);
104
-			if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
105
-				array_push($result['exact'], [
106
-					'label' => $group->getDisplayName(),
107
-					'value' => [
108
-						'shareType' => Share::SHARE_TYPE_GROUP,
109
-						'shareWith' => $group->getGID(),
110
-					],
111
-				]);
112
-			}
113
-		}
100
+        if ($offset === 0 && empty($result['exact'])) {
101
+            // On page one we try if the search result has a direct hit on the
102
+            // user id and if so, we add that to the exact match list
103
+            $group = $this->groupManager->get($search);
104
+            if ($group instanceof IGroup && (!$this->shareWithGroupOnly || in_array($group->getGID(), $userGroups))) {
105
+                array_push($result['exact'], [
106
+                    'label' => $group->getDisplayName(),
107
+                    'value' => [
108
+                        'shareType' => Share::SHARE_TYPE_GROUP,
109
+                        'shareWith' => $group->getGID(),
110
+                    ],
111
+                ]);
112
+            }
113
+        }
114 114
 
115
-		if (!$this->shareeEnumeration) {
116
-			$result['wide'] = [];
117
-		}
115
+        if (!$this->shareeEnumeration) {
116
+            $result['wide'] = [];
117
+        }
118 118
 
119
-		$type = new SearchResultType('groups');
120
-		$searchResult->addResultSet($type, $result['wide'], $result['exact']);
119
+        $type = new SearchResultType('groups');
120
+        $searchResult->addResultSet($type, $result['wide'], $result['exact']);
121 121
 
122
-		return $hasMoreResults;
123
-	}
122
+        return $hasMoreResults;
123
+    }
124 124
 }
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/LookupPlugin.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@
 block discarded – undo
54 54
 		try {
55 55
 			$client = $this->clientService->newClient();
56 56
 			$response = $client->get(
57
-				$lookupServerUrl . '/users?search=' . urlencode($search),
57
+				$lookupServerUrl.'/users?search='.urlencode($search),
58 58
 				[
59 59
 					'timeout' => 10,
60 60
 					'connect_timeout' => 3,
Please login to merge, or discard this patch.
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -33,54 +33,54 @@
 block discarded – undo
33 33
 
34 34
 class LookupPlugin implements ISearchPlugin {
35 35
 
36
-	/** @var IConfig */
37
-	private $config;
38
-	/** @var IClientService */
39
-	private $clientService;
36
+    /** @var IConfig */
37
+    private $config;
38
+    /** @var IClientService */
39
+    private $clientService;
40 40
 
41
-	public function __construct(IConfig $config, IClientService $clientService) {
42
-		$this->config = $config;
43
-		$this->clientService = $clientService;
44
-	}
41
+    public function __construct(IConfig $config, IClientService $clientService) {
42
+        $this->config = $config;
43
+        $this->clientService = $clientService;
44
+    }
45 45
 
46
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
47
-		if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') {
48
-			return false;
49
-		}
46
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
47
+        if ($this->config->getAppValue('files_sharing', 'lookupServerEnabled', 'no') !== 'yes') {
48
+            return false;
49
+        }
50 50
 
51
-		$lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
52
-		$lookupServerUrl = rtrim($lookupServerUrl, '/');
53
-		$result = ['wide' => [], 'exact' => []];
51
+        $lookupServerUrl = $this->config->getSystemValue('lookup_server', 'https://lookup.nextcloud.com');
52
+        $lookupServerUrl = rtrim($lookupServerUrl, '/');
53
+        $result = ['wide' => [], 'exact' => []];
54 54
 
55
-		try {
56
-			$client = $this->clientService->newClient();
57
-			$response = $client->get(
58
-				$lookupServerUrl . '/users?search=' . urlencode($search),
59
-				[
60
-					'timeout' => 10,
61
-					'connect_timeout' => 3,
62
-				]
63
-			);
55
+        try {
56
+            $client = $this->clientService->newClient();
57
+            $response = $client->get(
58
+                $lookupServerUrl . '/users?search=' . urlencode($search),
59
+                [
60
+                    'timeout' => 10,
61
+                    'connect_timeout' => 3,
62
+                ]
63
+            );
64 64
 
65
-			$body = json_decode($response->getBody(), true);
65
+            $body = json_decode($response->getBody(), true);
66 66
 
67
-			$result = [];
68
-			foreach ($body as $lookup) {
69
-				$result[] = [
70
-					'label' => $lookup['federationId'],
71
-					'value' => [
72
-						'shareType' => Share::SHARE_TYPE_REMOTE,
73
-						'shareWith' => $lookup['federationId'],
74
-					],
75
-					'extra' => $lookup,
76
-				];
77
-			}
78
-		} catch (\Exception $e) {
79
-		}
67
+            $result = [];
68
+            foreach ($body as $lookup) {
69
+                $result[] = [
70
+                    'label' => $lookup['federationId'],
71
+                    'value' => [
72
+                        'shareType' => Share::SHARE_TYPE_REMOTE,
73
+                        'shareWith' => $lookup['federationId'],
74
+                    ],
75
+                    'extra' => $lookup,
76
+                ];
77
+            }
78
+        } catch (\Exception $e) {
79
+        }
80 80
 
81
-		$type = new SearchResultType('lookup');
82
-		$searchResult->addResultSet($type, $result, []);
81
+        $type = new SearchResultType('lookup');
82
+        $searchResult->addResultSet($type, $result, []);
83 83
 
84
-		return false;
85
-	}
84
+        return false;
85
+    }
86 86
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Controller/ShareesAPIController.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 	public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) {
140 140
 
141 141
 		// only search for string larger than a given threshold
142
-		$threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0);
142
+		$threshold = (int) $this->config->getSystemValue('sharing.minSearchStringLength', 0);
143 143
 		if (strlen($search) < $threshold) {
144 144
 			return new DataResponse($this->result);
145 145
 		}
146 146
 
147 147
 		// never return more than the max. number of results configured in the config.php
148
-		$maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0);
148
+		$maxResults = (int) $this->config->getSystemValue('sharing.maxAutocompleteResults', 0);
149 149
 		if ($maxResults > 0) {
150 150
 			$perPage = min($perPage, $maxResults);
151 151
 		}
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 	 */
238 238
 	protected function getPaginationLink($page, array $params) {
239 239
 		if ($this->isV2()) {
240
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
240
+			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees').'?';
241 241
 		} else {
242
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
242
+			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees').'?';
243 243
 		}
244 244
 		$params['page'] = $page + 1;
245
-		$link = '<' . $url . http_build_query($params) . '>; rel="next"';
245
+		$link = '<'.$url.http_build_query($params).'>; rel="next"';
246 246
 
247 247
 		return $link;
248 248
 	}
Please login to merge, or discard this patch.
Indentation   +220 added lines, -220 removed lines patch added patch discarded remove patch
@@ -36,224 +36,224 @@
 block discarded – undo
36 36
 use OCP\Share\IManager;
37 37
 
38 38
 class ShareesAPIController extends OCSController {
39
-	/** @var IConfig */
40
-	protected $config;
41
-
42
-	/** @var IURLGenerator */
43
-	protected $urlGenerator;
44
-
45
-	/** @var IManager */
46
-	protected $shareManager;
47
-
48
-	/** @var bool */
49
-	protected $shareWithGroupOnly = false;
50
-
51
-	/** @var bool */
52
-	protected $shareeEnumeration = true;
53
-
54
-	/** @var int */
55
-	protected $offset = 0;
56
-
57
-	/** @var int */
58
-	protected $limit = 10;
59
-
60
-	/** @var array */
61
-	protected $result = [
62
-		'exact' => [
63
-			'users' => [],
64
-			'groups' => [],
65
-			'remotes' => [],
66
-			'emails' => [],
67
-			'circles' => [],
68
-		],
69
-		'users' => [],
70
-		'groups' => [],
71
-		'remotes' => [],
72
-		'emails' => [],
73
-		'lookup' => [],
74
-		'circles' => [],
75
-	];
76
-
77
-	protected $reachedEndFor = [];
78
-	/** @var ISearch */
79
-	private $collaboratorSearch;
80
-
81
-	/**
82
-	 * @param string $appName
83
-	 * @param IRequest $request
84
-	 * @param IConfig $config
85
-	 * @param IURLGenerator $urlGenerator
86
-	 * @param IManager $shareManager
87
-	 * @param ISearch $collaboratorSearch
88
-	 */
89
-	public function __construct(
90
-		$appName,
91
-		IRequest $request,
92
-		IConfig $config,
93
-		IURLGenerator $urlGenerator,
94
-		IManager $shareManager,
95
-		ISearch $collaboratorSearch
96
-	) {
97
-		parent::__construct($appName, $request);
98
-
99
-		$this->config = $config;
100
-		$this->urlGenerator = $urlGenerator;
101
-		$this->shareManager = $shareManager;
102
-		$this->collaboratorSearch = $collaboratorSearch;
103
-	}
104
-
105
-	/**
106
-	 * Strips away a potential file names and trailing slashes:
107
-	 * - http://localhost
108
-	 * - http://localhost/
109
-	 * - http://localhost/index.php
110
-	 * - http://localhost/index.php/s/{shareToken}
111
-	 *
112
-	 * all return: http://localhost
113
-	 *
114
-	 * @param string $remote
115
-	 * @return string
116
-	 */
117
-	protected function fixRemoteURL($remote) {
118
-		$remote = str_replace('\\', '/', $remote);
119
-		if ($fileNamePosition = strpos($remote, '/index.php')) {
120
-			$remote = substr($remote, 0, $fileNamePosition);
121
-		}
122
-		$remote = rtrim($remote, '/');
123
-
124
-		return $remote;
125
-	}
126
-
127
-	/**
128
-	 * @NoAdminRequired
129
-	 *
130
-	 * @param string $search
131
-	 * @param string $itemType
132
-	 * @param int $page
133
-	 * @param int $perPage
134
-	 * @param int|int[] $shareType
135
-	 * @param bool $lookup
136
-	 * @return DataResponse
137
-	 * @throws OCSBadRequestException
138
-	 */
139
-	public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) {
140
-
141
-		// only search for string larger than a given threshold
142
-		$threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0);
143
-		if (strlen($search) < $threshold) {
144
-			return new DataResponse($this->result);
145
-		}
146
-
147
-		// never return more than the max. number of results configured in the config.php
148
-		$maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0);
149
-		if ($maxResults > 0) {
150
-			$perPage = min($perPage, $maxResults);
151
-		}
152
-		if ($perPage <= 0) {
153
-			throw new OCSBadRequestException('Invalid perPage argument');
154
-		}
155
-		if ($page <= 0) {
156
-			throw new OCSBadRequestException('Invalid page');
157
-		}
158
-
159
-		$shareTypes = [
160
-			Share::SHARE_TYPE_USER,
161
-		];
162
-
163
-		if ($itemType === null) {
164
-			throw new OCSBadRequestException('Missing itemType');
165
-		} elseif ($itemType === 'file' || $itemType === 'folder') {
166
-			if ($this->shareManager->allowGroupSharing()) {
167
-				$shareTypes[] = Share::SHARE_TYPE_GROUP;
168
-			}
169
-
170
-			if ($this->isRemoteSharingAllowed($itemType)) {
171
-				$shareTypes[] = Share::SHARE_TYPE_REMOTE;
172
-			}
173
-
174
-			if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
175
-				$shareTypes[] = Share::SHARE_TYPE_EMAIL;
176
-			}
177
-		} else {
178
-			$shareTypes[] = Share::SHARE_TYPE_GROUP;
179
-			$shareTypes[] = Share::SHARE_TYPE_EMAIL;
180
-		}
181
-
182
-		if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
183
-			$shareTypes[] = Share::SHARE_TYPE_CIRCLE;
184
-		}
185
-
186
-		if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
187
-			$shareTypes = array_intersect($shareTypes, $_GET['shareType']);
188
-			sort($shareTypes);
189
-		} else if (is_numeric($shareType)) {
190
-			$shareTypes = array_intersect($shareTypes, [(int) $shareType]);
191
-			sort($shareTypes);
192
-		}
193
-
194
-		$this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
195
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
196
-		$this->limit = (int) $perPage;
197
-		$this->offset = $perPage * ($page - 1);
198
-
199
-		list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
200
-
201
-		// extra treatment for 'exact' subarray, with a single merge expected keys might be lost
202
-		$result['exact'] = array_merge($this->result['exact'], $result['exact']);
203
-		$this->result = array_merge($this->result, $result);
204
-		$response = new DataResponse($this->result);
205
-
206
-		if ($hasMoreResults) {
207
-			$response->addHeader('Link', $this->getPaginationLink($page, [
208
-				'search' => $search,
209
-				'itemType' => $itemType,
210
-				'shareType' => $shareTypes,
211
-				'perPage' => $perPage,
212
-			]));
213
-		}
214
-
215
-		return $response;
216
-	}
217
-
218
-	/**
219
-	 * Method to get out the static call for better testing
220
-	 *
221
-	 * @param string $itemType
222
-	 * @return bool
223
-	 */
224
-	protected function isRemoteSharingAllowed($itemType) {
225
-		try {
226
-			$backend = \OC\Share\Share::getBackend($itemType);
227
-			return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE);
228
-		} catch (\Exception $e) {
229
-			return false;
230
-		}
231
-	}
232
-
233
-
234
-	/**
235
-	 * Generates a bunch of pagination links for the current page
236
-	 *
237
-	 * @param int $page Current page
238
-	 * @param array $params Parameters for the URL
239
-	 * @return string
240
-	 */
241
-	protected function getPaginationLink($page, array $params) {
242
-		if ($this->isV2()) {
243
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
244
-		} else {
245
-			$url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
246
-		}
247
-		$params['page'] = $page + 1;
248
-		$link = '<' . $url . http_build_query($params) . '>; rel="next"';
249
-
250
-		return $link;
251
-	}
252
-
253
-	/**
254
-	 * @return bool
255
-	 */
256
-	protected function isV2() {
257
-		return $this->request->getScriptName() === '/ocs/v2.php';
258
-	}
39
+    /** @var IConfig */
40
+    protected $config;
41
+
42
+    /** @var IURLGenerator */
43
+    protected $urlGenerator;
44
+
45
+    /** @var IManager */
46
+    protected $shareManager;
47
+
48
+    /** @var bool */
49
+    protected $shareWithGroupOnly = false;
50
+
51
+    /** @var bool */
52
+    protected $shareeEnumeration = true;
53
+
54
+    /** @var int */
55
+    protected $offset = 0;
56
+
57
+    /** @var int */
58
+    protected $limit = 10;
59
+
60
+    /** @var array */
61
+    protected $result = [
62
+        'exact' => [
63
+            'users' => [],
64
+            'groups' => [],
65
+            'remotes' => [],
66
+            'emails' => [],
67
+            'circles' => [],
68
+        ],
69
+        'users' => [],
70
+        'groups' => [],
71
+        'remotes' => [],
72
+        'emails' => [],
73
+        'lookup' => [],
74
+        'circles' => [],
75
+    ];
76
+
77
+    protected $reachedEndFor = [];
78
+    /** @var ISearch */
79
+    private $collaboratorSearch;
80
+
81
+    /**
82
+     * @param string $appName
83
+     * @param IRequest $request
84
+     * @param IConfig $config
85
+     * @param IURLGenerator $urlGenerator
86
+     * @param IManager $shareManager
87
+     * @param ISearch $collaboratorSearch
88
+     */
89
+    public function __construct(
90
+        $appName,
91
+        IRequest $request,
92
+        IConfig $config,
93
+        IURLGenerator $urlGenerator,
94
+        IManager $shareManager,
95
+        ISearch $collaboratorSearch
96
+    ) {
97
+        parent::__construct($appName, $request);
98
+
99
+        $this->config = $config;
100
+        $this->urlGenerator = $urlGenerator;
101
+        $this->shareManager = $shareManager;
102
+        $this->collaboratorSearch = $collaboratorSearch;
103
+    }
104
+
105
+    /**
106
+     * Strips away a potential file names and trailing slashes:
107
+     * - http://localhost
108
+     * - http://localhost/
109
+     * - http://localhost/index.php
110
+     * - http://localhost/index.php/s/{shareToken}
111
+     *
112
+     * all return: http://localhost
113
+     *
114
+     * @param string $remote
115
+     * @return string
116
+     */
117
+    protected function fixRemoteURL($remote) {
118
+        $remote = str_replace('\\', '/', $remote);
119
+        if ($fileNamePosition = strpos($remote, '/index.php')) {
120
+            $remote = substr($remote, 0, $fileNamePosition);
121
+        }
122
+        $remote = rtrim($remote, '/');
123
+
124
+        return $remote;
125
+    }
126
+
127
+    /**
128
+     * @NoAdminRequired
129
+     *
130
+     * @param string $search
131
+     * @param string $itemType
132
+     * @param int $page
133
+     * @param int $perPage
134
+     * @param int|int[] $shareType
135
+     * @param bool $lookup
136
+     * @return DataResponse
137
+     * @throws OCSBadRequestException
138
+     */
139
+    public function search($search = '', $itemType = null, $page = 1, $perPage = 200, $shareType = null, $lookup = true) {
140
+
141
+        // only search for string larger than a given threshold
142
+        $threshold = (int)$this->config->getSystemValue('sharing.minSearchStringLength', 0);
143
+        if (strlen($search) < $threshold) {
144
+            return new DataResponse($this->result);
145
+        }
146
+
147
+        // never return more than the max. number of results configured in the config.php
148
+        $maxResults = (int)$this->config->getSystemValue('sharing.maxAutocompleteResults', 0);
149
+        if ($maxResults > 0) {
150
+            $perPage = min($perPage, $maxResults);
151
+        }
152
+        if ($perPage <= 0) {
153
+            throw new OCSBadRequestException('Invalid perPage argument');
154
+        }
155
+        if ($page <= 0) {
156
+            throw new OCSBadRequestException('Invalid page');
157
+        }
158
+
159
+        $shareTypes = [
160
+            Share::SHARE_TYPE_USER,
161
+        ];
162
+
163
+        if ($itemType === null) {
164
+            throw new OCSBadRequestException('Missing itemType');
165
+        } elseif ($itemType === 'file' || $itemType === 'folder') {
166
+            if ($this->shareManager->allowGroupSharing()) {
167
+                $shareTypes[] = Share::SHARE_TYPE_GROUP;
168
+            }
169
+
170
+            if ($this->isRemoteSharingAllowed($itemType)) {
171
+                $shareTypes[] = Share::SHARE_TYPE_REMOTE;
172
+            }
173
+
174
+            if ($this->shareManager->shareProviderExists(Share::SHARE_TYPE_EMAIL)) {
175
+                $shareTypes[] = Share::SHARE_TYPE_EMAIL;
176
+            }
177
+        } else {
178
+            $shareTypes[] = Share::SHARE_TYPE_GROUP;
179
+            $shareTypes[] = Share::SHARE_TYPE_EMAIL;
180
+        }
181
+
182
+        if (\OC::$server->getAppManager()->isEnabledForUser('circles') && class_exists('\OCA\Circles\ShareByCircleProvider')) {
183
+            $shareTypes[] = Share::SHARE_TYPE_CIRCLE;
184
+        }
185
+
186
+        if (isset($_GET['shareType']) && is_array($_GET['shareType'])) {
187
+            $shareTypes = array_intersect($shareTypes, $_GET['shareType']);
188
+            sort($shareTypes);
189
+        } else if (is_numeric($shareType)) {
190
+            $shareTypes = array_intersect($shareTypes, [(int) $shareType]);
191
+            sort($shareTypes);
192
+        }
193
+
194
+        $this->shareWithGroupOnly = $this->config->getAppValue('core', 'shareapi_only_share_with_group_members', 'no') === 'yes';
195
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
196
+        $this->limit = (int) $perPage;
197
+        $this->offset = $perPage * ($page - 1);
198
+
199
+        list($result, $hasMoreResults) = $this->collaboratorSearch->search($search, $shareTypes, $lookup, $this->limit, $this->offset);
200
+
201
+        // extra treatment for 'exact' subarray, with a single merge expected keys might be lost
202
+        $result['exact'] = array_merge($this->result['exact'], $result['exact']);
203
+        $this->result = array_merge($this->result, $result);
204
+        $response = new DataResponse($this->result);
205
+
206
+        if ($hasMoreResults) {
207
+            $response->addHeader('Link', $this->getPaginationLink($page, [
208
+                'search' => $search,
209
+                'itemType' => $itemType,
210
+                'shareType' => $shareTypes,
211
+                'perPage' => $perPage,
212
+            ]));
213
+        }
214
+
215
+        return $response;
216
+    }
217
+
218
+    /**
219
+     * Method to get out the static call for better testing
220
+     *
221
+     * @param string $itemType
222
+     * @return bool
223
+     */
224
+    protected function isRemoteSharingAllowed($itemType) {
225
+        try {
226
+            $backend = \OC\Share\Share::getBackend($itemType);
227
+            return $backend->isShareTypeAllowed(Share::SHARE_TYPE_REMOTE);
228
+        } catch (\Exception $e) {
229
+            return false;
230
+        }
231
+    }
232
+
233
+
234
+    /**
235
+     * Generates a bunch of pagination links for the current page
236
+     *
237
+     * @param int $page Current page
238
+     * @param array $params Parameters for the URL
239
+     * @return string
240
+     */
241
+    protected function getPaginationLink($page, array $params) {
242
+        if ($this->isV2()) {
243
+            $url = $this->urlGenerator->getAbsoluteURL('/ocs/v2.php/apps/files_sharing/api/v1/sharees') . '?';
244
+        } else {
245
+            $url = $this->urlGenerator->getAbsoluteURL('/ocs/v1.php/apps/files_sharing/api/v1/sharees') . '?';
246
+        }
247
+        $params['page'] = $page + 1;
248
+        $link = '<' . $url . http_build_query($params) . '>; rel="next"';
249
+
250
+        return $link;
251
+    }
252
+
253
+    /**
254
+     * @return bool
255
+     */
256
+    protected function isV2() {
257
+        return $this->request->getScriptName() === '/ocs/v2.php';
258
+    }
259 259
 }
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		parent::__construct();
142 142
 		$this->webRoot = $webRoot;
143 143
 
144
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
144
+		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
145 145
 			return $c;
146 146
 		});
147 147
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
152 152
 
153 153
 
154
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
154
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
155 155
 			return new PreviewManager(
156 156
 				$c->getConfig(),
157 157
 				$c->getRootFolder(),
@@ -162,13 +162,13 @@  discard block
 block discarded – undo
162 162
 		});
163 163
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
164 164
 
165
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
165
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
166 166
 			return new \OC\Preview\Watcher(
167 167
 				$c->getAppDataDir('preview')
168 168
 			);
169 169
 		});
170 170
 
171
-		$this->registerService('EncryptionManager', function (Server $c) {
171
+		$this->registerService('EncryptionManager', function(Server $c) {
172 172
 			$view = new View();
173 173
 			$util = new Encryption\Util(
174 174
 				$view,
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
 			);
187 187
 		});
188 188
 
189
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
189
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
190 190
 			$util = new Encryption\Util(
191 191
 				new View(),
192 192
 				$c->getUserManager(),
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 			);
201 201
 		});
202 202
 
203
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
203
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
204 204
 			$view = new View();
205 205
 			$util = new Encryption\Util(
206 206
 				$view,
@@ -211,32 +211,32 @@  discard block
 block discarded – undo
211 211
 
212 212
 			return new Encryption\Keys\Storage($view, $util);
213 213
 		});
214
-		$this->registerService('TagMapper', function (Server $c) {
214
+		$this->registerService('TagMapper', function(Server $c) {
215 215
 			return new TagMapper($c->getDatabaseConnection());
216 216
 		});
217 217
 
218
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
218
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
219 219
 			$tagMapper = $c->query('TagMapper');
220 220
 			return new TagManager($tagMapper, $c->getUserSession());
221 221
 		});
222 222
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
223 223
 
224
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
224
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
225 225
 			$config = $c->getConfig();
226 226
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
227 227
 			/** @var \OC\SystemTag\ManagerFactory $factory */
228 228
 			$factory = new $factoryClass($this);
229 229
 			return $factory;
230 230
 		});
231
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
231
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
232 232
 			return $c->query('SystemTagManagerFactory')->getManager();
233 233
 		});
234 234
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
235 235
 
236
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
236
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
237 237
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
238 238
 		});
239
-		$this->registerService('RootFolder', function (Server $c) {
239
+		$this->registerService('RootFolder', function(Server $c) {
240 240
 			$manager = \OC\Files\Filesystem::getMountManager(null);
241 241
 			$view = new View();
242 242
 			$root = new Root(
@@ -257,37 +257,37 @@  discard block
 block discarded – undo
257 257
 		});
258 258
 		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
259 259
 
260
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
261
-			return new LazyRoot(function () use ($c) {
260
+		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
261
+			return new LazyRoot(function() use ($c) {
262 262
 				return $c->query('RootFolder');
263 263
 			});
264 264
 		});
265 265
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
266 266
 
267
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
267
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
268 268
 			$config = $c->getConfig();
269 269
 			return new \OC\User\Manager($config);
270 270
 		});
271 271
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
272 272
 
273
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
273
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
274 274
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
275
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
275
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
276 276
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
277 277
 			});
278
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
278
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
279 279
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
280 280
 			});
281
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
281
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
282 282
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
283 283
 			});
284
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
284
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
285 285
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
286 286
 			});
287
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
287
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
288 288
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
289 289
 			});
290
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
290
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
291 291
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
292 292
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
293 293
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 		});
297 297
 		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
298 298
 
299
-		$this->registerService(Store::class, function (Server $c) {
299
+		$this->registerService(Store::class, function(Server $c) {
300 300
 			$session = $c->getSession();
301 301
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
302 302
 				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
@@ -307,11 +307,11 @@  discard block
 block discarded – undo
307 307
 			return new Store($session, $logger, $tokenProvider);
308 308
 		});
309 309
 		$this->registerAlias(IStore::class, Store::class);
310
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
310
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
311 311
 			$dbConnection = $c->getDatabaseConnection();
312 312
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
313 313
 		});
314
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
314
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
315 315
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
316 316
 			$crypto = $c->getCrypto();
317 317
 			$config = $c->getConfig();
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
 		});
322 322
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
323 323
 
324
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
324
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
325 325
 			$manager = $c->getUserManager();
326 326
 			$session = new \OC\Session\Memory('');
327 327
 			$timeFactory = new TimeFactory();
@@ -334,44 +334,44 @@  discard block
 block discarded – undo
334 334
 			}
335 335
 
336 336
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
337
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
337
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
338 338
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
339 339
 			});
340
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
340
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
341 341
 				/** @var $user \OC\User\User */
342 342
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
343 343
 			});
344
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
344
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
345 345
 				/** @var $user \OC\User\User */
346 346
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
347 347
 			});
348
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
348
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
349 349
 				/** @var $user \OC\User\User */
350 350
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
351 351
 			});
352
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
352
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
353 353
 				/** @var $user \OC\User\User */
354 354
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
355 355
 			});
356
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
356
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
357 357
 				/** @var $user \OC\User\User */
358 358
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
359 359
 			});
360
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
360
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
361 361
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
362 362
 			});
363
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
363
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
364 364
 				/** @var $user \OC\User\User */
365 365
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
366 366
 			});
367
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
367
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
368 368
 				/** @var $user \OC\User\User */
369 369
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
370 370
 			});
371
-			$userSession->listen('\OC\User', 'logout', function () {
371
+			$userSession->listen('\OC\User', 'logout', function() {
372 372
 				\OC_Hook::emit('OC_User', 'logout', array());
373 373
 			});
374
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
374
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) {
375 375
 				/** @var $user \OC\User\User */
376 376
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
377 377
 			});
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 		});
380 380
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
381 381
 
382
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
382
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
383 383
 			return new \OC\Authentication\TwoFactorAuth\Manager(
384 384
 				$c->getAppManager(),
385 385
 				$c->getSession(),
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
395 395
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
396 396
 
397
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
397
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
398 398
 			return new \OC\AllConfig(
399 399
 				$c->getSystemConfig()
400 400
 			);
@@ -402,17 +402,17 @@  discard block
 block discarded – undo
402 402
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
403 403
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
404 404
 
405
-		$this->registerService('SystemConfig', function ($c) use ($config) {
405
+		$this->registerService('SystemConfig', function($c) use ($config) {
406 406
 			return new \OC\SystemConfig($config);
407 407
 		});
408 408
 
409
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
409
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
410 410
 			return new \OC\AppConfig($c->getDatabaseConnection());
411 411
 		});
412 412
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
413 413
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
414 414
 
415
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
415
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
416 416
 			return new \OC\L10N\Factory(
417 417
 				$c->getConfig(),
418 418
 				$c->getRequest(),
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 		});
423 423
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
424 424
 
425
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
425
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
426 426
 			$config = $c->getConfig();
427 427
 			$cacheFactory = $c->getMemCacheFactory();
428 428
 			$request = $c->getRequest();
@@ -434,18 +434,18 @@  discard block
 block discarded – undo
434 434
 		});
435 435
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
436 436
 
437
-		$this->registerService('AppHelper', function ($c) {
437
+		$this->registerService('AppHelper', function($c) {
438 438
 			return new \OC\AppHelper();
439 439
 		});
440 440
 		$this->registerAlias('AppFetcher', AppFetcher::class);
441 441
 		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
442 442
 
443
-		$this->registerService(\OCP\ICache::class, function ($c) {
443
+		$this->registerService(\OCP\ICache::class, function($c) {
444 444
 			return new Cache\File();
445 445
 		});
446 446
 		$this->registerAlias('UserCache', \OCP\ICache::class);
447 447
 
448
-		$this->registerService(Factory::class, function (Server $c) {
448
+		$this->registerService(Factory::class, function(Server $c) {
449 449
 
450 450
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
451 451
 				'\\OC\\Memcache\\ArrayCache',
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 				$version = implode(',', $v);
463 463
 				$instanceId = \OC_Util::getInstanceId();
464 464
 				$path = \OC::$SERVERROOT;
465
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
465
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.$urlGenerator->getBaseUrl());
466 466
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
467 467
 					$config->getSystemValue('memcache.local', null),
468 468
 					$config->getSystemValue('memcache.distributed', null),
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
 		$this->registerAlias('MemCacheFactory', Factory::class);
476 476
 		$this->registerAlias(ICacheFactory::class, Factory::class);
477 477
 
478
-		$this->registerService('RedisFactory', function (Server $c) {
478
+		$this->registerService('RedisFactory', function(Server $c) {
479 479
 			$systemConfig = $c->getSystemConfig();
480 480
 			return new RedisFactory($systemConfig);
481 481
 		});
482 482
 
483
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
483
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
484 484
 			return new \OC\Activity\Manager(
485 485
 				$c->getRequest(),
486 486
 				$c->getUserSession(),
@@ -490,14 +490,14 @@  discard block
 block discarded – undo
490 490
 		});
491 491
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
492 492
 
493
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
493
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
494 494
 			return new \OC\Activity\EventMerger(
495 495
 				$c->getL10N('lib')
496 496
 			);
497 497
 		});
498 498
 		$this->registerAlias(IValidator::class, Validator::class);
499 499
 
500
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
500
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
501 501
 			return new AvatarManager(
502 502
 				$c->getUserManager(),
503 503
 				$c->getAppDataDir('avatar'),
@@ -508,7 +508,7 @@  discard block
 block discarded – undo
508 508
 		});
509 509
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
510 510
 
511
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
511
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
512 512
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
513 513
 			$logger = Log::getLogClass($logType);
514 514
 			call_user_func(array($logger, 'init'));
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
 		});
518 518
 		$this->registerAlias('Logger', \OCP\ILogger::class);
519 519
 
520
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
520
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
521 521
 			$config = $c->getConfig();
522 522
 			return new \OC\BackgroundJob\JobList(
523 523
 				$c->getDatabaseConnection(),
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
 		});
528 528
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
529 529
 
530
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
530
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
531 531
 			$cacheFactory = $c->getMemCacheFactory();
532 532
 			$logger = $c->getLogger();
533 533
 			if ($cacheFactory->isAvailable()) {
@@ -539,12 +539,12 @@  discard block
 block discarded – undo
539 539
 		});
540 540
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
541 541
 
542
-		$this->registerService(\OCP\ISearch::class, function ($c) {
542
+		$this->registerService(\OCP\ISearch::class, function($c) {
543 543
 			return new Search();
544 544
 		});
545 545
 		$this->registerAlias('Search', \OCP\ISearch::class);
546 546
 
547
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) {
547
+		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
548 548
 			return new \OC\Security\RateLimiting\Limiter(
549 549
 				$this->getUserSession(),
550 550
 				$this->getRequest(),
@@ -552,34 +552,34 @@  discard block
 block discarded – undo
552 552
 				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
553 553
 			);
554 554
 		});
555
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
555
+		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
556 556
 			return new \OC\Security\RateLimiting\Backend\MemoryCache(
557 557
 				$this->getMemCacheFactory(),
558 558
 				new \OC\AppFramework\Utility\TimeFactory()
559 559
 			);
560 560
 		});
561 561
 
562
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
562
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
563 563
 			return new SecureRandom();
564 564
 		});
565 565
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
566 566
 
567
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
567
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
568 568
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
569 569
 		});
570 570
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
571 571
 
572
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
572
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
573 573
 			return new Hasher($c->getConfig());
574 574
 		});
575 575
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
576 576
 
577
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
577
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
578 578
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
579 579
 		});
580 580
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
581 581
 
582
-		$this->registerService(IDBConnection::class, function (Server $c) {
582
+		$this->registerService(IDBConnection::class, function(Server $c) {
583 583
 			$systemConfig = $c->getSystemConfig();
584 584
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
585 585
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 		});
594 594
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
595 595
 
596
-		$this->registerService('HTTPHelper', function (Server $c) {
596
+		$this->registerService('HTTPHelper', function(Server $c) {
597 597
 			$config = $c->getConfig();
598 598
 			return new HTTPHelper(
599 599
 				$config,
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 			);
602 602
 		});
603 603
 
604
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
604
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
605 605
 			$user = \OC_User::getUser();
606 606
 			$uid = $user ? $user : null;
607 607
 			return new ClientService(
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 			);
617 617
 		});
618 618
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
619
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
619
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
620 620
 			$eventLogger = new EventLogger();
621 621
 			if ($c->getSystemConfig()->getValue('debug', false)) {
622 622
 				// In debug mode, module is being activated by default
@@ -626,7 +626,7 @@  discard block
 block discarded – undo
626 626
 		});
627 627
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
628 628
 
629
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
629
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
630 630
 			$queryLogger = new QueryLogger();
631 631
 			if ($c->getSystemConfig()->getValue('debug', false)) {
632 632
 				// In debug mode, module is being activated by default
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 		});
637 637
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
638 638
 
639
-		$this->registerService(TempManager::class, function (Server $c) {
639
+		$this->registerService(TempManager::class, function(Server $c) {
640 640
 			return new TempManager(
641 641
 				$c->getLogger(),
642 642
 				$c->getConfig()
@@ -645,7 +645,7 @@  discard block
 block discarded – undo
645 645
 		$this->registerAlias('TempManager', TempManager::class);
646 646
 		$this->registerAlias(ITempManager::class, TempManager::class);
647 647
 
648
-		$this->registerService(AppManager::class, function (Server $c) {
648
+		$this->registerService(AppManager::class, function(Server $c) {
649 649
 			return new \OC\App\AppManager(
650 650
 				$c->getUserSession(),
651 651
 				$c->getAppConfig(),
@@ -657,7 +657,7 @@  discard block
 block discarded – undo
657 657
 		$this->registerAlias('AppManager', AppManager::class);
658 658
 		$this->registerAlias(IAppManager::class, AppManager::class);
659 659
 
660
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
660
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
661 661
 			return new DateTimeZone(
662 662
 				$c->getConfig(),
663 663
 				$c->getSession()
@@ -665,7 +665,7 @@  discard block
 block discarded – undo
665 665
 		});
666 666
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
667 667
 
668
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
668
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
669 669
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
670 670
 
671 671
 			return new DateTimeFormatter(
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 		});
676 676
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
677 677
 
678
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
678
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
679 679
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
680 680
 			$listener = new UserMountCacheListener($mountCache);
681 681
 			$listener->listen($c->getUserManager());
@@ -683,7 +683,7 @@  discard block
 block discarded – undo
683 683
 		});
684 684
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
685 685
 
686
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
686
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
687 687
 			$loader = \OC\Files\Filesystem::getLoader();
688 688
 			$mountCache = $c->query('UserMountCache');
689 689
 			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
 		});
700 700
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
701 701
 
702
-		$this->registerService('IniWrapper', function ($c) {
702
+		$this->registerService('IniWrapper', function($c) {
703 703
 			return new IniGetWrapper();
704 704
 		});
705
-		$this->registerService('AsyncCommandBus', function (Server $c) {
705
+		$this->registerService('AsyncCommandBus', function(Server $c) {
706 706
 			$busClass = $c->getConfig()->getSystemValue('commandbus');
707 707
 			if ($busClass) {
708 708
 				list($app, $class) = explode('::', $busClass, 2);
@@ -717,10 +717,10 @@  discard block
 block discarded – undo
717 717
 				return new CronBus($jobList);
718 718
 			}
719 719
 		});
720
-		$this->registerService('TrustedDomainHelper', function ($c) {
720
+		$this->registerService('TrustedDomainHelper', function($c) {
721 721
 			return new TrustedDomainHelper($this->getConfig());
722 722
 		});
723
-		$this->registerService('Throttler', function (Server $c) {
723
+		$this->registerService('Throttler', function(Server $c) {
724 724
 			return new Throttler(
725 725
 				$c->getDatabaseConnection(),
726 726
 				new TimeFactory(),
@@ -728,7 +728,7 @@  discard block
 block discarded – undo
728 728
 				$c->getConfig()
729 729
 			);
730 730
 		});
731
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
731
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
732 732
 			// IConfig and IAppManager requires a working database. This code
733 733
 			// might however be called when ownCloud is not yet setup.
734 734
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 				$c->getTempManager()
750 750
 			);
751 751
 		});
752
-		$this->registerService(\OCP\IRequest::class, function ($c) {
752
+		$this->registerService(\OCP\IRequest::class, function($c) {
753 753
 			if (isset($this['urlParams'])) {
754 754
 				$urlParams = $this['urlParams'];
755 755
 			} else {
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 		});
786 786
 		$this->registerAlias('Request', \OCP\IRequest::class);
787 787
 
788
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
788
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
789 789
 			return new Mailer(
790 790
 				$c->getConfig(),
791 791
 				$c->getLogger(),
@@ -796,7 +796,7 @@  discard block
 block discarded – undo
796 796
 		});
797 797
 		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
798 798
 
799
-		$this->registerService('LDAPProvider', function (Server $c) {
799
+		$this->registerService('LDAPProvider', function(Server $c) {
800 800
 			$config = $c->getConfig();
801 801
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
802 802
 			if (is_null($factoryClass)) {
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
 			$factory = new $factoryClass($this);
807 807
 			return $factory->getLDAPProvider();
808 808
 		});
809
-		$this->registerService(ILockingProvider::class, function (Server $c) {
809
+		$this->registerService(ILockingProvider::class, function(Server $c) {
810 810
 			$ini = $c->getIniWrapper();
811 811
 			$config = $c->getConfig();
812 812
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -823,49 +823,49 @@  discard block
 block discarded – undo
823 823
 		});
824 824
 		$this->registerAlias('LockingProvider', ILockingProvider::class);
825 825
 
826
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
826
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
827 827
 			return new \OC\Files\Mount\Manager();
828 828
 		});
829 829
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
830 830
 
831
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
831
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
832 832
 			return new \OC\Files\Type\Detection(
833 833
 				$c->getURLGenerator(),
834 834
 				\OC::$configDir,
835
-				\OC::$SERVERROOT . '/resources/config/'
835
+				\OC::$SERVERROOT.'/resources/config/'
836 836
 			);
837 837
 		});
838 838
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
839 839
 
840
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
840
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
841 841
 			return new \OC\Files\Type\Loader(
842 842
 				$c->getDatabaseConnection()
843 843
 			);
844 844
 		});
845 845
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
846
-		$this->registerService(BundleFetcher::class, function () {
846
+		$this->registerService(BundleFetcher::class, function() {
847 847
 			return new BundleFetcher($this->getL10N('lib'));
848 848
 		});
849
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
849
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
850 850
 			return new Manager(
851 851
 				$c->query(IValidator::class)
852 852
 			);
853 853
 		});
854 854
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
855 855
 
856
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
856
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
857 857
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
858
-			$manager->registerCapability(function () use ($c) {
858
+			$manager->registerCapability(function() use ($c) {
859 859
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
860 860
 			});
861
-			$manager->registerCapability(function () use ($c) {
861
+			$manager->registerCapability(function() use ($c) {
862 862
 				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
863 863
 			});
864 864
 			return $manager;
865 865
 		});
866 866
 		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
867 867
 
868
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
868
+		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
869 869
 			$config = $c->getConfig();
870 870
 			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
871 871
 			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
 		});
875 875
 		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
876 876
 
877
-		$this->registerService('ThemingDefaults', function (Server $c) {
877
+		$this->registerService('ThemingDefaults', function(Server $c) {
878 878
 			/*
879 879
 			 * Dark magic for autoloader.
880 880
 			 * If we do a class_exists it will try to load the class which will
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 			}
901 901
 			return new \OC_Defaults();
902 902
 		});
903
-		$this->registerService(SCSSCacher::class, function (Server $c) {
903
+		$this->registerService(SCSSCacher::class, function(Server $c) {
904 904
 			/** @var Factory $cacheFactory */
905 905
 			$cacheFactory = $c->query(Factory::class);
906 906
 			return new SCSSCacher(
@@ -913,13 +913,13 @@  discard block
 block discarded – undo
913 913
 				$cacheFactory->create('SCSS')
914 914
 			);
915 915
 		});
916
-		$this->registerService(EventDispatcher::class, function () {
916
+		$this->registerService(EventDispatcher::class, function() {
917 917
 			return new EventDispatcher();
918 918
 		});
919 919
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
920 920
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
921 921
 
922
-		$this->registerService('CryptoWrapper', function (Server $c) {
922
+		$this->registerService('CryptoWrapper', function(Server $c) {
923 923
 			// FIXME: Instantiiated here due to cyclic dependency
924 924
 			$request = new Request(
925 925
 				[
@@ -944,7 +944,7 @@  discard block
 block discarded – undo
944 944
 				$request
945 945
 			);
946 946
 		});
947
-		$this->registerService('CsrfTokenManager', function (Server $c) {
947
+		$this->registerService('CsrfTokenManager', function(Server $c) {
948 948
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
949 949
 
950 950
 			return new CsrfTokenManager(
@@ -952,22 +952,22 @@  discard block
 block discarded – undo
952 952
 				$c->query(SessionStorage::class)
953 953
 			);
954 954
 		});
955
-		$this->registerService(SessionStorage::class, function (Server $c) {
955
+		$this->registerService(SessionStorage::class, function(Server $c) {
956 956
 			return new SessionStorage($c->getSession());
957 957
 		});
958
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
958
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
959 959
 			return new ContentSecurityPolicyManager();
960 960
 		});
961 961
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
962 962
 
963
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
963
+		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
964 964
 			return new ContentSecurityPolicyNonceManager(
965 965
 				$c->getCsrfTokenManager(),
966 966
 				$c->getRequest()
967 967
 			);
968 968
 		});
969 969
 
970
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
970
+		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
971 971
 			$config = $c->getConfig();
972 972
 			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
973 973
 			/** @var \OCP\Share\IProviderFactory $factory */
@@ -999,7 +999,7 @@  discard block
 block discarded – undo
999 999
 		});
1000 1000
 		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1001 1001
 
1002
-		$this->registerService('SettingsManager', function (Server $c) {
1002
+		$this->registerService('SettingsManager', function(Server $c) {
1003 1003
 			$manager = new \OC\Settings\Manager(
1004 1004
 				$c->getLogger(),
1005 1005
 				$c->getDatabaseConnection(),
@@ -1019,29 +1019,29 @@  discard block
 block discarded – undo
1019 1019
 			);
1020 1020
 			return $manager;
1021 1021
 		});
1022
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1022
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
1023 1023
 			return new \OC\Files\AppData\Factory(
1024 1024
 				$c->getRootFolder(),
1025 1025
 				$c->getSystemConfig()
1026 1026
 			);
1027 1027
 		});
1028 1028
 
1029
-		$this->registerService('LockdownManager', function (Server $c) {
1030
-			return new LockdownManager(function () use ($c) {
1029
+		$this->registerService('LockdownManager', function(Server $c) {
1030
+			return new LockdownManager(function() use ($c) {
1031 1031
 				return $c->getSession();
1032 1032
 			});
1033 1033
 		});
1034 1034
 
1035
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1035
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
1036 1036
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1037 1037
 		});
1038 1038
 
1039
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1039
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
1040 1040
 			return new CloudIdManager();
1041 1041
 		});
1042 1042
 
1043 1043
 		/* To trick DI since we don't extend the DIContainer here */
1044
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1044
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
1045 1045
 			return new CleanPreviewsBackgroundJob(
1046 1046
 				$c->getRootFolder(),
1047 1047
 				$c->getLogger(),
@@ -1056,18 +1056,18 @@  discard block
 block discarded – undo
1056 1056
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1057 1057
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1058 1058
 
1059
-		$this->registerService(Defaults::class, function (Server $c) {
1059
+		$this->registerService(Defaults::class, function(Server $c) {
1060 1060
 			return new Defaults(
1061 1061
 				$c->getThemingDefaults()
1062 1062
 			);
1063 1063
 		});
1064 1064
 		$this->registerAlias('Defaults', \OCP\Defaults::class);
1065 1065
 
1066
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1066
+		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1067 1067
 			return $c->query(\OCP\IUserSession::class)->getSession();
1068 1068
 		});
1069 1069
 
1070
-		$this->registerService(IShareHelper::class, function (Server $c) {
1070
+		$this->registerService(IShareHelper::class, function(Server $c) {
1071 1071
 			return new ShareHelper(
1072 1072
 				$c->query(\OCP\Share\IManager::class)
1073 1073
 			);
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 	 * @deprecated since 9.2.0 use IAppData
1209 1209
 	 */
1210 1210
 	public function getAppFolder() {
1211
-		$dir = '/' . \OC_App::getCurrentApp();
1211
+		$dir = '/'.\OC_App::getCurrentApp();
1212 1212
 		$root = $this->getRootFolder();
1213 1213
 		if (!$root->nodeExists($dir)) {
1214 1214
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
Indentation   +1694 added lines, -1694 removed lines patch added patch discarded remove patch
@@ -127,1703 +127,1703 @@
 block discarded – undo
127 127
  * TODO: hookup all manager classes
128 128
  */
129 129
 class Server extends ServerContainer implements IServerContainer {
130
-	/** @var string */
131
-	private $webRoot;
132
-
133
-	/**
134
-	 * @param string $webRoot
135
-	 * @param \OC\Config $config
136
-	 */
137
-	public function __construct($webRoot, \OC\Config $config) {
138
-		parent::__construct();
139
-		$this->webRoot = $webRoot;
140
-
141
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
142
-			return $c;
143
-		});
144
-
145
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
146
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
147
-
148
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
149
-
150
-
151
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
152
-			return new PreviewManager(
153
-				$c->getConfig(),
154
-				$c->getRootFolder(),
155
-				$c->getAppDataDir('preview'),
156
-				$c->getEventDispatcher(),
157
-				$c->getSession()->get('user_id')
158
-			);
159
-		});
160
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
161
-
162
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
163
-			return new \OC\Preview\Watcher(
164
-				$c->getAppDataDir('preview')
165
-			);
166
-		});
167
-
168
-		$this->registerService('EncryptionManager', function (Server $c) {
169
-			$view = new View();
170
-			$util = new Encryption\Util(
171
-				$view,
172
-				$c->getUserManager(),
173
-				$c->getGroupManager(),
174
-				$c->getConfig()
175
-			);
176
-			return new Encryption\Manager(
177
-				$c->getConfig(),
178
-				$c->getLogger(),
179
-				$c->getL10N('core'),
180
-				new View(),
181
-				$util,
182
-				new ArrayCache()
183
-			);
184
-		});
185
-
186
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
187
-			$util = new Encryption\Util(
188
-				new View(),
189
-				$c->getUserManager(),
190
-				$c->getGroupManager(),
191
-				$c->getConfig()
192
-			);
193
-			return new Encryption\File(
194
-				$util,
195
-				$c->getRootFolder(),
196
-				$c->getShareManager()
197
-			);
198
-		});
199
-
200
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
201
-			$view = new View();
202
-			$util = new Encryption\Util(
203
-				$view,
204
-				$c->getUserManager(),
205
-				$c->getGroupManager(),
206
-				$c->getConfig()
207
-			);
208
-
209
-			return new Encryption\Keys\Storage($view, $util);
210
-		});
211
-		$this->registerService('TagMapper', function (Server $c) {
212
-			return new TagMapper($c->getDatabaseConnection());
213
-		});
214
-
215
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
216
-			$tagMapper = $c->query('TagMapper');
217
-			return new TagManager($tagMapper, $c->getUserSession());
218
-		});
219
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
220
-
221
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
222
-			$config = $c->getConfig();
223
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
224
-			/** @var \OC\SystemTag\ManagerFactory $factory */
225
-			$factory = new $factoryClass($this);
226
-			return $factory;
227
-		});
228
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
229
-			return $c->query('SystemTagManagerFactory')->getManager();
230
-		});
231
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
232
-
233
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
234
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
235
-		});
236
-		$this->registerService('RootFolder', function (Server $c) {
237
-			$manager = \OC\Files\Filesystem::getMountManager(null);
238
-			$view = new View();
239
-			$root = new Root(
240
-				$manager,
241
-				$view,
242
-				null,
243
-				$c->getUserMountCache(),
244
-				$this->getLogger(),
245
-				$this->getUserManager()
246
-			);
247
-			$connector = new HookConnector($root, $view);
248
-			$connector->viewToNode();
249
-
250
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
251
-			$previewConnector->connectWatcher();
252
-
253
-			return $root;
254
-		});
255
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
256
-
257
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
258
-			return new LazyRoot(function () use ($c) {
259
-				return $c->query('RootFolder');
260
-			});
261
-		});
262
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
263
-
264
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
265
-			$config = $c->getConfig();
266
-			return new \OC\User\Manager($config);
267
-		});
268
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
269
-
270
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
271
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
272
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
273
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
274
-			});
275
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
276
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
277
-			});
278
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
279
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
280
-			});
281
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
282
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
283
-			});
284
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
285
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
286
-			});
287
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
289
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
-			});
292
-			return $groupManager;
293
-		});
294
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
295
-
296
-		$this->registerService(Store::class, function (Server $c) {
297
-			$session = $c->getSession();
298
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
299
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
300
-			} else {
301
-				$tokenProvider = null;
302
-			}
303
-			$logger = $c->getLogger();
304
-			return new Store($session, $logger, $tokenProvider);
305
-		});
306
-		$this->registerAlias(IStore::class, Store::class);
307
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
308
-			$dbConnection = $c->getDatabaseConnection();
309
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
310
-		});
311
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
312
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
313
-			$crypto = $c->getCrypto();
314
-			$config = $c->getConfig();
315
-			$logger = $c->getLogger();
316
-			$timeFactory = new TimeFactory();
317
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
318
-		});
319
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
320
-
321
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
322
-			$manager = $c->getUserManager();
323
-			$session = new \OC\Session\Memory('');
324
-			$timeFactory = new TimeFactory();
325
-			// Token providers might require a working database. This code
326
-			// might however be called when ownCloud is not yet setup.
327
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
328
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
329
-			} else {
330
-				$defaultTokenProvider = null;
331
-			}
332
-
333
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
334
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
335
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
336
-			});
337
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
338
-				/** @var $user \OC\User\User */
339
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
340
-			});
341
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
342
-				/** @var $user \OC\User\User */
343
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
344
-			});
345
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
346
-				/** @var $user \OC\User\User */
347
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
348
-			});
349
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
350
-				/** @var $user \OC\User\User */
351
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
352
-			});
353
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
354
-				/** @var $user \OC\User\User */
355
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
356
-			});
357
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
358
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
359
-			});
360
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
361
-				/** @var $user \OC\User\User */
362
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
363
-			});
364
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
365
-				/** @var $user \OC\User\User */
366
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
367
-			});
368
-			$userSession->listen('\OC\User', 'logout', function () {
369
-				\OC_Hook::emit('OC_User', 'logout', array());
370
-			});
371
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
372
-				/** @var $user \OC\User\User */
373
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
374
-			});
375
-			return $userSession;
376
-		});
377
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
378
-
379
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
380
-			return new \OC\Authentication\TwoFactorAuth\Manager(
381
-				$c->getAppManager(),
382
-				$c->getSession(),
383
-				$c->getConfig(),
384
-				$c->getActivityManager(),
385
-				$c->getLogger(),
386
-				$c->query(\OC\Authentication\Token\IProvider::class),
387
-				$c->query(ITimeFactory::class)
388
-			);
389
-		});
390
-
391
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
392
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
393
-
394
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
395
-			return new \OC\AllConfig(
396
-				$c->getSystemConfig()
397
-			);
398
-		});
399
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
400
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
401
-
402
-		$this->registerService('SystemConfig', function ($c) use ($config) {
403
-			return new \OC\SystemConfig($config);
404
-		});
405
-
406
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
407
-			return new \OC\AppConfig($c->getDatabaseConnection());
408
-		});
409
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
410
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
411
-
412
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
413
-			return new \OC\L10N\Factory(
414
-				$c->getConfig(),
415
-				$c->getRequest(),
416
-				$c->getUserSession(),
417
-				\OC::$SERVERROOT
418
-			);
419
-		});
420
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
421
-
422
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
423
-			$config = $c->getConfig();
424
-			$cacheFactory = $c->getMemCacheFactory();
425
-			$request = $c->getRequest();
426
-			return new \OC\URLGenerator(
427
-				$config,
428
-				$cacheFactory,
429
-				$request
430
-			);
431
-		});
432
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
433
-
434
-		$this->registerService('AppHelper', function ($c) {
435
-			return new \OC\AppHelper();
436
-		});
437
-		$this->registerAlias('AppFetcher', AppFetcher::class);
438
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
439
-
440
-		$this->registerService(\OCP\ICache::class, function ($c) {
441
-			return new Cache\File();
442
-		});
443
-		$this->registerAlias('UserCache', \OCP\ICache::class);
444
-
445
-		$this->registerService(Factory::class, function (Server $c) {
446
-
447
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
448
-				'\\OC\\Memcache\\ArrayCache',
449
-				'\\OC\\Memcache\\ArrayCache',
450
-				'\\OC\\Memcache\\ArrayCache'
451
-			);
452
-			$config = $c->getConfig();
453
-			$request = $c->getRequest();
454
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
455
-
456
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
457
-				$v = \OC_App::getAppVersions();
458
-				$v['core'] = implode(',', \OC_Util::getVersion());
459
-				$version = implode(',', $v);
460
-				$instanceId = \OC_Util::getInstanceId();
461
-				$path = \OC::$SERVERROOT;
462
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
463
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
464
-					$config->getSystemValue('memcache.local', null),
465
-					$config->getSystemValue('memcache.distributed', null),
466
-					$config->getSystemValue('memcache.locking', null)
467
-				);
468
-			}
469
-			return $arrayCacheFactory;
470
-
471
-		});
472
-		$this->registerAlias('MemCacheFactory', Factory::class);
473
-		$this->registerAlias(ICacheFactory::class, Factory::class);
474
-
475
-		$this->registerService('RedisFactory', function (Server $c) {
476
-			$systemConfig = $c->getSystemConfig();
477
-			return new RedisFactory($systemConfig);
478
-		});
479
-
480
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
481
-			return new \OC\Activity\Manager(
482
-				$c->getRequest(),
483
-				$c->getUserSession(),
484
-				$c->getConfig(),
485
-				$c->query(IValidator::class)
486
-			);
487
-		});
488
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
489
-
490
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
491
-			return new \OC\Activity\EventMerger(
492
-				$c->getL10N('lib')
493
-			);
494
-		});
495
-		$this->registerAlias(IValidator::class, Validator::class);
496
-
497
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
498
-			return new AvatarManager(
499
-				$c->getUserManager(),
500
-				$c->getAppDataDir('avatar'),
501
-				$c->getL10N('lib'),
502
-				$c->getLogger(),
503
-				$c->getConfig()
504
-			);
505
-		});
506
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
507
-
508
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
509
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
510
-			$logger = Log::getLogClass($logType);
511
-			call_user_func(array($logger, 'init'));
512
-
513
-			return new Log($logger);
514
-		});
515
-		$this->registerAlias('Logger', \OCP\ILogger::class);
516
-
517
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
518
-			$config = $c->getConfig();
519
-			return new \OC\BackgroundJob\JobList(
520
-				$c->getDatabaseConnection(),
521
-				$config,
522
-				new TimeFactory()
523
-			);
524
-		});
525
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
526
-
527
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
528
-			$cacheFactory = $c->getMemCacheFactory();
529
-			$logger = $c->getLogger();
530
-			if ($cacheFactory->isAvailable()) {
531
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
532
-			} else {
533
-				$router = new \OC\Route\Router($logger);
534
-			}
535
-			return $router;
536
-		});
537
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
538
-
539
-		$this->registerService(\OCP\ISearch::class, function ($c) {
540
-			return new Search();
541
-		});
542
-		$this->registerAlias('Search', \OCP\ISearch::class);
543
-
544
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) {
545
-			return new \OC\Security\RateLimiting\Limiter(
546
-				$this->getUserSession(),
547
-				$this->getRequest(),
548
-				new \OC\AppFramework\Utility\TimeFactory(),
549
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
550
-			);
551
-		});
552
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
553
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
554
-				$this->getMemCacheFactory(),
555
-				new \OC\AppFramework\Utility\TimeFactory()
556
-			);
557
-		});
558
-
559
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
560
-			return new SecureRandom();
561
-		});
562
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
563
-
564
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
565
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
566
-		});
567
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
568
-
569
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
570
-			return new Hasher($c->getConfig());
571
-		});
572
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
573
-
574
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
575
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
576
-		});
577
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
578
-
579
-		$this->registerService(IDBConnection::class, function (Server $c) {
580
-			$systemConfig = $c->getSystemConfig();
581
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
582
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
583
-			if (!$factory->isValidType($type)) {
584
-				throw new \OC\DatabaseException('Invalid database type');
585
-			}
586
-			$connectionParams = $factory->createConnectionParams();
587
-			$connection = $factory->getConnection($type, $connectionParams);
588
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
589
-			return $connection;
590
-		});
591
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
592
-
593
-		$this->registerService('HTTPHelper', function (Server $c) {
594
-			$config = $c->getConfig();
595
-			return new HTTPHelper(
596
-				$config,
597
-				$c->getHTTPClientService()
598
-			);
599
-		});
600
-
601
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
602
-			$user = \OC_User::getUser();
603
-			$uid = $user ? $user : null;
604
-			return new ClientService(
605
-				$c->getConfig(),
606
-				new \OC\Security\CertificateManager(
607
-					$uid,
608
-					new View(),
609
-					$c->getConfig(),
610
-					$c->getLogger(),
611
-					$c->getSecureRandom()
612
-				)
613
-			);
614
-		});
615
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
616
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
617
-			$eventLogger = new EventLogger();
618
-			if ($c->getSystemConfig()->getValue('debug', false)) {
619
-				// In debug mode, module is being activated by default
620
-				$eventLogger->activate();
621
-			}
622
-			return $eventLogger;
623
-		});
624
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
625
-
626
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
627
-			$queryLogger = new QueryLogger();
628
-			if ($c->getSystemConfig()->getValue('debug', false)) {
629
-				// In debug mode, module is being activated by default
630
-				$queryLogger->activate();
631
-			}
632
-			return $queryLogger;
633
-		});
634
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
635
-
636
-		$this->registerService(TempManager::class, function (Server $c) {
637
-			return new TempManager(
638
-				$c->getLogger(),
639
-				$c->getConfig()
640
-			);
641
-		});
642
-		$this->registerAlias('TempManager', TempManager::class);
643
-		$this->registerAlias(ITempManager::class, TempManager::class);
644
-
645
-		$this->registerService(AppManager::class, function (Server $c) {
646
-			return new \OC\App\AppManager(
647
-				$c->getUserSession(),
648
-				$c->getAppConfig(),
649
-				$c->getGroupManager(),
650
-				$c->getMemCacheFactory(),
651
-				$c->getEventDispatcher()
652
-			);
653
-		});
654
-		$this->registerAlias('AppManager', AppManager::class);
655
-		$this->registerAlias(IAppManager::class, AppManager::class);
656
-
657
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
658
-			return new DateTimeZone(
659
-				$c->getConfig(),
660
-				$c->getSession()
661
-			);
662
-		});
663
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
664
-
665
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
666
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
667
-
668
-			return new DateTimeFormatter(
669
-				$c->getDateTimeZone()->getTimeZone(),
670
-				$c->getL10N('lib', $language)
671
-			);
672
-		});
673
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
674
-
675
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
676
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
677
-			$listener = new UserMountCacheListener($mountCache);
678
-			$listener->listen($c->getUserManager());
679
-			return $mountCache;
680
-		});
681
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
682
-
683
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
684
-			$loader = \OC\Files\Filesystem::getLoader();
685
-			$mountCache = $c->query('UserMountCache');
686
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
687
-
688
-			// builtin providers
689
-
690
-			$config = $c->getConfig();
691
-			$manager->registerProvider(new CacheMountProvider($config));
692
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
693
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
694
-
695
-			return $manager;
696
-		});
697
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
698
-
699
-		$this->registerService('IniWrapper', function ($c) {
700
-			return new IniGetWrapper();
701
-		});
702
-		$this->registerService('AsyncCommandBus', function (Server $c) {
703
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
704
-			if ($busClass) {
705
-				list($app, $class) = explode('::', $busClass, 2);
706
-				if ($c->getAppManager()->isInstalled($app)) {
707
-					\OC_App::loadApp($app);
708
-					return $c->query($class);
709
-				} else {
710
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
711
-				}
712
-			} else {
713
-				$jobList = $c->getJobList();
714
-				return new CronBus($jobList);
715
-			}
716
-		});
717
-		$this->registerService('TrustedDomainHelper', function ($c) {
718
-			return new TrustedDomainHelper($this->getConfig());
719
-		});
720
-		$this->registerService('Throttler', function (Server $c) {
721
-			return new Throttler(
722
-				$c->getDatabaseConnection(),
723
-				new TimeFactory(),
724
-				$c->getLogger(),
725
-				$c->getConfig()
726
-			);
727
-		});
728
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
729
-			// IConfig and IAppManager requires a working database. This code
730
-			// might however be called when ownCloud is not yet setup.
731
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
732
-				$config = $c->getConfig();
733
-				$appManager = $c->getAppManager();
734
-			} else {
735
-				$config = null;
736
-				$appManager = null;
737
-			}
738
-
739
-			return new Checker(
740
-				new EnvironmentHelper(),
741
-				new FileAccessHelper(),
742
-				new AppLocator(),
743
-				$config,
744
-				$c->getMemCacheFactory(),
745
-				$appManager,
746
-				$c->getTempManager()
747
-			);
748
-		});
749
-		$this->registerService(\OCP\IRequest::class, function ($c) {
750
-			if (isset($this['urlParams'])) {
751
-				$urlParams = $this['urlParams'];
752
-			} else {
753
-				$urlParams = [];
754
-			}
755
-
756
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
757
-				&& in_array('fakeinput', stream_get_wrappers())
758
-			) {
759
-				$stream = 'fakeinput://data';
760
-			} else {
761
-				$stream = 'php://input';
762
-			}
763
-
764
-			return new Request(
765
-				[
766
-					'get' => $_GET,
767
-					'post' => $_POST,
768
-					'files' => $_FILES,
769
-					'server' => $_SERVER,
770
-					'env' => $_ENV,
771
-					'cookies' => $_COOKIE,
772
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
773
-						? $_SERVER['REQUEST_METHOD']
774
-						: null,
775
-					'urlParams' => $urlParams,
776
-				],
777
-				$this->getSecureRandom(),
778
-				$this->getConfig(),
779
-				$this->getCsrfTokenManager(),
780
-				$stream
781
-			);
782
-		});
783
-		$this->registerAlias('Request', \OCP\IRequest::class);
784
-
785
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
786
-			return new Mailer(
787
-				$c->getConfig(),
788
-				$c->getLogger(),
789
-				$c->query(Defaults::class),
790
-				$c->getURLGenerator(),
791
-				$c->getL10N('lib')
792
-			);
793
-		});
794
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
795
-
796
-		$this->registerService('LDAPProvider', function (Server $c) {
797
-			$config = $c->getConfig();
798
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
799
-			if (is_null($factoryClass)) {
800
-				throw new \Exception('ldapProviderFactory not set');
801
-			}
802
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
803
-			$factory = new $factoryClass($this);
804
-			return $factory->getLDAPProvider();
805
-		});
806
-		$this->registerService(ILockingProvider::class, function (Server $c) {
807
-			$ini = $c->getIniWrapper();
808
-			$config = $c->getConfig();
809
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
810
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
811
-				/** @var \OC\Memcache\Factory $memcacheFactory */
812
-				$memcacheFactory = $c->getMemCacheFactory();
813
-				$memcache = $memcacheFactory->createLocking('lock');
814
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
815
-					return new MemcacheLockingProvider($memcache, $ttl);
816
-				}
817
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
818
-			}
819
-			return new NoopLockingProvider();
820
-		});
821
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
822
-
823
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
824
-			return new \OC\Files\Mount\Manager();
825
-		});
826
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
827
-
828
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
829
-			return new \OC\Files\Type\Detection(
830
-				$c->getURLGenerator(),
831
-				\OC::$configDir,
832
-				\OC::$SERVERROOT . '/resources/config/'
833
-			);
834
-		});
835
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
836
-
837
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
838
-			return new \OC\Files\Type\Loader(
839
-				$c->getDatabaseConnection()
840
-			);
841
-		});
842
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
843
-		$this->registerService(BundleFetcher::class, function () {
844
-			return new BundleFetcher($this->getL10N('lib'));
845
-		});
846
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
847
-			return new Manager(
848
-				$c->query(IValidator::class)
849
-			);
850
-		});
851
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
852
-
853
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
854
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
855
-			$manager->registerCapability(function () use ($c) {
856
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
857
-			});
858
-			$manager->registerCapability(function () use ($c) {
859
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
860
-			});
861
-			return $manager;
862
-		});
863
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
864
-
865
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
866
-			$config = $c->getConfig();
867
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
868
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
869
-			$factory = new $factoryClass($this);
870
-			return $factory->getManager();
871
-		});
872
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
873
-
874
-		$this->registerService('ThemingDefaults', function (Server $c) {
875
-			/*
130
+    /** @var string */
131
+    private $webRoot;
132
+
133
+    /**
134
+     * @param string $webRoot
135
+     * @param \OC\Config $config
136
+     */
137
+    public function __construct($webRoot, \OC\Config $config) {
138
+        parent::__construct();
139
+        $this->webRoot = $webRoot;
140
+
141
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
142
+            return $c;
143
+        });
144
+
145
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
146
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
147
+
148
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
149
+
150
+
151
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
152
+            return new PreviewManager(
153
+                $c->getConfig(),
154
+                $c->getRootFolder(),
155
+                $c->getAppDataDir('preview'),
156
+                $c->getEventDispatcher(),
157
+                $c->getSession()->get('user_id')
158
+            );
159
+        });
160
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
161
+
162
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
163
+            return new \OC\Preview\Watcher(
164
+                $c->getAppDataDir('preview')
165
+            );
166
+        });
167
+
168
+        $this->registerService('EncryptionManager', function (Server $c) {
169
+            $view = new View();
170
+            $util = new Encryption\Util(
171
+                $view,
172
+                $c->getUserManager(),
173
+                $c->getGroupManager(),
174
+                $c->getConfig()
175
+            );
176
+            return new Encryption\Manager(
177
+                $c->getConfig(),
178
+                $c->getLogger(),
179
+                $c->getL10N('core'),
180
+                new View(),
181
+                $util,
182
+                new ArrayCache()
183
+            );
184
+        });
185
+
186
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
187
+            $util = new Encryption\Util(
188
+                new View(),
189
+                $c->getUserManager(),
190
+                $c->getGroupManager(),
191
+                $c->getConfig()
192
+            );
193
+            return new Encryption\File(
194
+                $util,
195
+                $c->getRootFolder(),
196
+                $c->getShareManager()
197
+            );
198
+        });
199
+
200
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
201
+            $view = new View();
202
+            $util = new Encryption\Util(
203
+                $view,
204
+                $c->getUserManager(),
205
+                $c->getGroupManager(),
206
+                $c->getConfig()
207
+            );
208
+
209
+            return new Encryption\Keys\Storage($view, $util);
210
+        });
211
+        $this->registerService('TagMapper', function (Server $c) {
212
+            return new TagMapper($c->getDatabaseConnection());
213
+        });
214
+
215
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
216
+            $tagMapper = $c->query('TagMapper');
217
+            return new TagManager($tagMapper, $c->getUserSession());
218
+        });
219
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
220
+
221
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
222
+            $config = $c->getConfig();
223
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
224
+            /** @var \OC\SystemTag\ManagerFactory $factory */
225
+            $factory = new $factoryClass($this);
226
+            return $factory;
227
+        });
228
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
229
+            return $c->query('SystemTagManagerFactory')->getManager();
230
+        });
231
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
232
+
233
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
234
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
235
+        });
236
+        $this->registerService('RootFolder', function (Server $c) {
237
+            $manager = \OC\Files\Filesystem::getMountManager(null);
238
+            $view = new View();
239
+            $root = new Root(
240
+                $manager,
241
+                $view,
242
+                null,
243
+                $c->getUserMountCache(),
244
+                $this->getLogger(),
245
+                $this->getUserManager()
246
+            );
247
+            $connector = new HookConnector($root, $view);
248
+            $connector->viewToNode();
249
+
250
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
251
+            $previewConnector->connectWatcher();
252
+
253
+            return $root;
254
+        });
255
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
256
+
257
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
258
+            return new LazyRoot(function () use ($c) {
259
+                return $c->query('RootFolder');
260
+            });
261
+        });
262
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
263
+
264
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
265
+            $config = $c->getConfig();
266
+            return new \OC\User\Manager($config);
267
+        });
268
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
269
+
270
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
271
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
272
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
273
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
274
+            });
275
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
276
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
277
+            });
278
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
279
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
280
+            });
281
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
282
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
283
+            });
284
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
285
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
286
+            });
287
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
289
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
291
+            });
292
+            return $groupManager;
293
+        });
294
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
295
+
296
+        $this->registerService(Store::class, function (Server $c) {
297
+            $session = $c->getSession();
298
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
299
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
300
+            } else {
301
+                $tokenProvider = null;
302
+            }
303
+            $logger = $c->getLogger();
304
+            return new Store($session, $logger, $tokenProvider);
305
+        });
306
+        $this->registerAlias(IStore::class, Store::class);
307
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
308
+            $dbConnection = $c->getDatabaseConnection();
309
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
310
+        });
311
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
312
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
313
+            $crypto = $c->getCrypto();
314
+            $config = $c->getConfig();
315
+            $logger = $c->getLogger();
316
+            $timeFactory = new TimeFactory();
317
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
318
+        });
319
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
320
+
321
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
322
+            $manager = $c->getUserManager();
323
+            $session = new \OC\Session\Memory('');
324
+            $timeFactory = new TimeFactory();
325
+            // Token providers might require a working database. This code
326
+            // might however be called when ownCloud is not yet setup.
327
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
328
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
329
+            } else {
330
+                $defaultTokenProvider = null;
331
+            }
332
+
333
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
334
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
335
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
336
+            });
337
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
338
+                /** @var $user \OC\User\User */
339
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
340
+            });
341
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
342
+                /** @var $user \OC\User\User */
343
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
344
+            });
345
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
346
+                /** @var $user \OC\User\User */
347
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
348
+            });
349
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
350
+                /** @var $user \OC\User\User */
351
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
352
+            });
353
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
354
+                /** @var $user \OC\User\User */
355
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
356
+            });
357
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
358
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
359
+            });
360
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
361
+                /** @var $user \OC\User\User */
362
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
363
+            });
364
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
365
+                /** @var $user \OC\User\User */
366
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
367
+            });
368
+            $userSession->listen('\OC\User', 'logout', function () {
369
+                \OC_Hook::emit('OC_User', 'logout', array());
370
+            });
371
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) {
372
+                /** @var $user \OC\User\User */
373
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
374
+            });
375
+            return $userSession;
376
+        });
377
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
378
+
379
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
380
+            return new \OC\Authentication\TwoFactorAuth\Manager(
381
+                $c->getAppManager(),
382
+                $c->getSession(),
383
+                $c->getConfig(),
384
+                $c->getActivityManager(),
385
+                $c->getLogger(),
386
+                $c->query(\OC\Authentication\Token\IProvider::class),
387
+                $c->query(ITimeFactory::class)
388
+            );
389
+        });
390
+
391
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
392
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
393
+
394
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
395
+            return new \OC\AllConfig(
396
+                $c->getSystemConfig()
397
+            );
398
+        });
399
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
400
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
401
+
402
+        $this->registerService('SystemConfig', function ($c) use ($config) {
403
+            return new \OC\SystemConfig($config);
404
+        });
405
+
406
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
407
+            return new \OC\AppConfig($c->getDatabaseConnection());
408
+        });
409
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
410
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
411
+
412
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
413
+            return new \OC\L10N\Factory(
414
+                $c->getConfig(),
415
+                $c->getRequest(),
416
+                $c->getUserSession(),
417
+                \OC::$SERVERROOT
418
+            );
419
+        });
420
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
421
+
422
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
423
+            $config = $c->getConfig();
424
+            $cacheFactory = $c->getMemCacheFactory();
425
+            $request = $c->getRequest();
426
+            return new \OC\URLGenerator(
427
+                $config,
428
+                $cacheFactory,
429
+                $request
430
+            );
431
+        });
432
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
433
+
434
+        $this->registerService('AppHelper', function ($c) {
435
+            return new \OC\AppHelper();
436
+        });
437
+        $this->registerAlias('AppFetcher', AppFetcher::class);
438
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
439
+
440
+        $this->registerService(\OCP\ICache::class, function ($c) {
441
+            return new Cache\File();
442
+        });
443
+        $this->registerAlias('UserCache', \OCP\ICache::class);
444
+
445
+        $this->registerService(Factory::class, function (Server $c) {
446
+
447
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
448
+                '\\OC\\Memcache\\ArrayCache',
449
+                '\\OC\\Memcache\\ArrayCache',
450
+                '\\OC\\Memcache\\ArrayCache'
451
+            );
452
+            $config = $c->getConfig();
453
+            $request = $c->getRequest();
454
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
455
+
456
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
457
+                $v = \OC_App::getAppVersions();
458
+                $v['core'] = implode(',', \OC_Util::getVersion());
459
+                $version = implode(',', $v);
460
+                $instanceId = \OC_Util::getInstanceId();
461
+                $path = \OC::$SERVERROOT;
462
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
463
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
464
+                    $config->getSystemValue('memcache.local', null),
465
+                    $config->getSystemValue('memcache.distributed', null),
466
+                    $config->getSystemValue('memcache.locking', null)
467
+                );
468
+            }
469
+            return $arrayCacheFactory;
470
+
471
+        });
472
+        $this->registerAlias('MemCacheFactory', Factory::class);
473
+        $this->registerAlias(ICacheFactory::class, Factory::class);
474
+
475
+        $this->registerService('RedisFactory', function (Server $c) {
476
+            $systemConfig = $c->getSystemConfig();
477
+            return new RedisFactory($systemConfig);
478
+        });
479
+
480
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
481
+            return new \OC\Activity\Manager(
482
+                $c->getRequest(),
483
+                $c->getUserSession(),
484
+                $c->getConfig(),
485
+                $c->query(IValidator::class)
486
+            );
487
+        });
488
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
489
+
490
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
491
+            return new \OC\Activity\EventMerger(
492
+                $c->getL10N('lib')
493
+            );
494
+        });
495
+        $this->registerAlias(IValidator::class, Validator::class);
496
+
497
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
498
+            return new AvatarManager(
499
+                $c->getUserManager(),
500
+                $c->getAppDataDir('avatar'),
501
+                $c->getL10N('lib'),
502
+                $c->getLogger(),
503
+                $c->getConfig()
504
+            );
505
+        });
506
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
507
+
508
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
509
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
510
+            $logger = Log::getLogClass($logType);
511
+            call_user_func(array($logger, 'init'));
512
+
513
+            return new Log($logger);
514
+        });
515
+        $this->registerAlias('Logger', \OCP\ILogger::class);
516
+
517
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
518
+            $config = $c->getConfig();
519
+            return new \OC\BackgroundJob\JobList(
520
+                $c->getDatabaseConnection(),
521
+                $config,
522
+                new TimeFactory()
523
+            );
524
+        });
525
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
526
+
527
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
528
+            $cacheFactory = $c->getMemCacheFactory();
529
+            $logger = $c->getLogger();
530
+            if ($cacheFactory->isAvailable()) {
531
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
532
+            } else {
533
+                $router = new \OC\Route\Router($logger);
534
+            }
535
+            return $router;
536
+        });
537
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
538
+
539
+        $this->registerService(\OCP\ISearch::class, function ($c) {
540
+            return new Search();
541
+        });
542
+        $this->registerAlias('Search', \OCP\ISearch::class);
543
+
544
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) {
545
+            return new \OC\Security\RateLimiting\Limiter(
546
+                $this->getUserSession(),
547
+                $this->getRequest(),
548
+                new \OC\AppFramework\Utility\TimeFactory(),
549
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
550
+            );
551
+        });
552
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
553
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
554
+                $this->getMemCacheFactory(),
555
+                new \OC\AppFramework\Utility\TimeFactory()
556
+            );
557
+        });
558
+
559
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
560
+            return new SecureRandom();
561
+        });
562
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
563
+
564
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
565
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
566
+        });
567
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
568
+
569
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
570
+            return new Hasher($c->getConfig());
571
+        });
572
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
573
+
574
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
575
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
576
+        });
577
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
578
+
579
+        $this->registerService(IDBConnection::class, function (Server $c) {
580
+            $systemConfig = $c->getSystemConfig();
581
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
582
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
583
+            if (!$factory->isValidType($type)) {
584
+                throw new \OC\DatabaseException('Invalid database type');
585
+            }
586
+            $connectionParams = $factory->createConnectionParams();
587
+            $connection = $factory->getConnection($type, $connectionParams);
588
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
589
+            return $connection;
590
+        });
591
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
592
+
593
+        $this->registerService('HTTPHelper', function (Server $c) {
594
+            $config = $c->getConfig();
595
+            return new HTTPHelper(
596
+                $config,
597
+                $c->getHTTPClientService()
598
+            );
599
+        });
600
+
601
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
602
+            $user = \OC_User::getUser();
603
+            $uid = $user ? $user : null;
604
+            return new ClientService(
605
+                $c->getConfig(),
606
+                new \OC\Security\CertificateManager(
607
+                    $uid,
608
+                    new View(),
609
+                    $c->getConfig(),
610
+                    $c->getLogger(),
611
+                    $c->getSecureRandom()
612
+                )
613
+            );
614
+        });
615
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
616
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
617
+            $eventLogger = new EventLogger();
618
+            if ($c->getSystemConfig()->getValue('debug', false)) {
619
+                // In debug mode, module is being activated by default
620
+                $eventLogger->activate();
621
+            }
622
+            return $eventLogger;
623
+        });
624
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
625
+
626
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
627
+            $queryLogger = new QueryLogger();
628
+            if ($c->getSystemConfig()->getValue('debug', false)) {
629
+                // In debug mode, module is being activated by default
630
+                $queryLogger->activate();
631
+            }
632
+            return $queryLogger;
633
+        });
634
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
635
+
636
+        $this->registerService(TempManager::class, function (Server $c) {
637
+            return new TempManager(
638
+                $c->getLogger(),
639
+                $c->getConfig()
640
+            );
641
+        });
642
+        $this->registerAlias('TempManager', TempManager::class);
643
+        $this->registerAlias(ITempManager::class, TempManager::class);
644
+
645
+        $this->registerService(AppManager::class, function (Server $c) {
646
+            return new \OC\App\AppManager(
647
+                $c->getUserSession(),
648
+                $c->getAppConfig(),
649
+                $c->getGroupManager(),
650
+                $c->getMemCacheFactory(),
651
+                $c->getEventDispatcher()
652
+            );
653
+        });
654
+        $this->registerAlias('AppManager', AppManager::class);
655
+        $this->registerAlias(IAppManager::class, AppManager::class);
656
+
657
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
658
+            return new DateTimeZone(
659
+                $c->getConfig(),
660
+                $c->getSession()
661
+            );
662
+        });
663
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
664
+
665
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
666
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
667
+
668
+            return new DateTimeFormatter(
669
+                $c->getDateTimeZone()->getTimeZone(),
670
+                $c->getL10N('lib', $language)
671
+            );
672
+        });
673
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
674
+
675
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
676
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
677
+            $listener = new UserMountCacheListener($mountCache);
678
+            $listener->listen($c->getUserManager());
679
+            return $mountCache;
680
+        });
681
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
682
+
683
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
684
+            $loader = \OC\Files\Filesystem::getLoader();
685
+            $mountCache = $c->query('UserMountCache');
686
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
687
+
688
+            // builtin providers
689
+
690
+            $config = $c->getConfig();
691
+            $manager->registerProvider(new CacheMountProvider($config));
692
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
693
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
694
+
695
+            return $manager;
696
+        });
697
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
698
+
699
+        $this->registerService('IniWrapper', function ($c) {
700
+            return new IniGetWrapper();
701
+        });
702
+        $this->registerService('AsyncCommandBus', function (Server $c) {
703
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
704
+            if ($busClass) {
705
+                list($app, $class) = explode('::', $busClass, 2);
706
+                if ($c->getAppManager()->isInstalled($app)) {
707
+                    \OC_App::loadApp($app);
708
+                    return $c->query($class);
709
+                } else {
710
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
711
+                }
712
+            } else {
713
+                $jobList = $c->getJobList();
714
+                return new CronBus($jobList);
715
+            }
716
+        });
717
+        $this->registerService('TrustedDomainHelper', function ($c) {
718
+            return new TrustedDomainHelper($this->getConfig());
719
+        });
720
+        $this->registerService('Throttler', function (Server $c) {
721
+            return new Throttler(
722
+                $c->getDatabaseConnection(),
723
+                new TimeFactory(),
724
+                $c->getLogger(),
725
+                $c->getConfig()
726
+            );
727
+        });
728
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
729
+            // IConfig and IAppManager requires a working database. This code
730
+            // might however be called when ownCloud is not yet setup.
731
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
732
+                $config = $c->getConfig();
733
+                $appManager = $c->getAppManager();
734
+            } else {
735
+                $config = null;
736
+                $appManager = null;
737
+            }
738
+
739
+            return new Checker(
740
+                new EnvironmentHelper(),
741
+                new FileAccessHelper(),
742
+                new AppLocator(),
743
+                $config,
744
+                $c->getMemCacheFactory(),
745
+                $appManager,
746
+                $c->getTempManager()
747
+            );
748
+        });
749
+        $this->registerService(\OCP\IRequest::class, function ($c) {
750
+            if (isset($this['urlParams'])) {
751
+                $urlParams = $this['urlParams'];
752
+            } else {
753
+                $urlParams = [];
754
+            }
755
+
756
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
757
+                && in_array('fakeinput', stream_get_wrappers())
758
+            ) {
759
+                $stream = 'fakeinput://data';
760
+            } else {
761
+                $stream = 'php://input';
762
+            }
763
+
764
+            return new Request(
765
+                [
766
+                    'get' => $_GET,
767
+                    'post' => $_POST,
768
+                    'files' => $_FILES,
769
+                    'server' => $_SERVER,
770
+                    'env' => $_ENV,
771
+                    'cookies' => $_COOKIE,
772
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
773
+                        ? $_SERVER['REQUEST_METHOD']
774
+                        : null,
775
+                    'urlParams' => $urlParams,
776
+                ],
777
+                $this->getSecureRandom(),
778
+                $this->getConfig(),
779
+                $this->getCsrfTokenManager(),
780
+                $stream
781
+            );
782
+        });
783
+        $this->registerAlias('Request', \OCP\IRequest::class);
784
+
785
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
786
+            return new Mailer(
787
+                $c->getConfig(),
788
+                $c->getLogger(),
789
+                $c->query(Defaults::class),
790
+                $c->getURLGenerator(),
791
+                $c->getL10N('lib')
792
+            );
793
+        });
794
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
795
+
796
+        $this->registerService('LDAPProvider', function (Server $c) {
797
+            $config = $c->getConfig();
798
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
799
+            if (is_null($factoryClass)) {
800
+                throw new \Exception('ldapProviderFactory not set');
801
+            }
802
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
803
+            $factory = new $factoryClass($this);
804
+            return $factory->getLDAPProvider();
805
+        });
806
+        $this->registerService(ILockingProvider::class, function (Server $c) {
807
+            $ini = $c->getIniWrapper();
808
+            $config = $c->getConfig();
809
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
810
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
811
+                /** @var \OC\Memcache\Factory $memcacheFactory */
812
+                $memcacheFactory = $c->getMemCacheFactory();
813
+                $memcache = $memcacheFactory->createLocking('lock');
814
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
815
+                    return new MemcacheLockingProvider($memcache, $ttl);
816
+                }
817
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
818
+            }
819
+            return new NoopLockingProvider();
820
+        });
821
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
822
+
823
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
824
+            return new \OC\Files\Mount\Manager();
825
+        });
826
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
827
+
828
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
829
+            return new \OC\Files\Type\Detection(
830
+                $c->getURLGenerator(),
831
+                \OC::$configDir,
832
+                \OC::$SERVERROOT . '/resources/config/'
833
+            );
834
+        });
835
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
836
+
837
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
838
+            return new \OC\Files\Type\Loader(
839
+                $c->getDatabaseConnection()
840
+            );
841
+        });
842
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
843
+        $this->registerService(BundleFetcher::class, function () {
844
+            return new BundleFetcher($this->getL10N('lib'));
845
+        });
846
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
847
+            return new Manager(
848
+                $c->query(IValidator::class)
849
+            );
850
+        });
851
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
852
+
853
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
854
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
855
+            $manager->registerCapability(function () use ($c) {
856
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
857
+            });
858
+            $manager->registerCapability(function () use ($c) {
859
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
860
+            });
861
+            return $manager;
862
+        });
863
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
864
+
865
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
866
+            $config = $c->getConfig();
867
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
868
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
869
+            $factory = new $factoryClass($this);
870
+            return $factory->getManager();
871
+        });
872
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
873
+
874
+        $this->registerService('ThemingDefaults', function (Server $c) {
875
+            /*
876 876
 			 * Dark magic for autoloader.
877 877
 			 * If we do a class_exists it will try to load the class which will
878 878
 			 * make composer cache the result. Resulting in errors when enabling
879 879
 			 * the theming app.
880 880
 			 */
881
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
882
-			if (isset($prefixes['OCA\\Theming\\'])) {
883
-				$classExists = true;
884
-			} else {
885
-				$classExists = false;
886
-			}
887
-
888
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
889
-				return new ThemingDefaults(
890
-					$c->getConfig(),
891
-					$c->getL10N('theming'),
892
-					$c->getURLGenerator(),
893
-					$c->getAppDataDir('theming'),
894
-					$c->getMemCacheFactory(),
895
-					new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')),
896
-					$this->getAppManager()
897
-				);
898
-			}
899
-			return new \OC_Defaults();
900
-		});
901
-		$this->registerService(SCSSCacher::class, function (Server $c) {
902
-			/** @var Factory $cacheFactory */
903
-			$cacheFactory = $c->query(Factory::class);
904
-			return new SCSSCacher(
905
-				$c->getLogger(),
906
-				$c->query(\OC\Files\AppData\Factory::class),
907
-				$c->getURLGenerator(),
908
-				$c->getConfig(),
909
-				$c->getThemingDefaults(),
910
-				\OC::$SERVERROOT,
911
-				$cacheFactory->create('SCSS')
912
-			);
913
-		});
914
-		$this->registerService(EventDispatcher::class, function () {
915
-			return new EventDispatcher();
916
-		});
917
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
918
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
919
-
920
-		$this->registerService('CryptoWrapper', function (Server $c) {
921
-			// FIXME: Instantiiated here due to cyclic dependency
922
-			$request = new Request(
923
-				[
924
-					'get' => $_GET,
925
-					'post' => $_POST,
926
-					'files' => $_FILES,
927
-					'server' => $_SERVER,
928
-					'env' => $_ENV,
929
-					'cookies' => $_COOKIE,
930
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
931
-						? $_SERVER['REQUEST_METHOD']
932
-						: null,
933
-				],
934
-				$c->getSecureRandom(),
935
-				$c->getConfig()
936
-			);
937
-
938
-			return new CryptoWrapper(
939
-				$c->getConfig(),
940
-				$c->getCrypto(),
941
-				$c->getSecureRandom(),
942
-				$request
943
-			);
944
-		});
945
-		$this->registerService('CsrfTokenManager', function (Server $c) {
946
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
947
-
948
-			return new CsrfTokenManager(
949
-				$tokenGenerator,
950
-				$c->query(SessionStorage::class)
951
-			);
952
-		});
953
-		$this->registerService(SessionStorage::class, function (Server $c) {
954
-			return new SessionStorage($c->getSession());
955
-		});
956
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
957
-			return new ContentSecurityPolicyManager();
958
-		});
959
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
960
-
961
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
962
-			return new ContentSecurityPolicyNonceManager(
963
-				$c->getCsrfTokenManager(),
964
-				$c->getRequest()
965
-			);
966
-		});
967
-
968
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
969
-			$config = $c->getConfig();
970
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
971
-			/** @var \OCP\Share\IProviderFactory $factory */
972
-			$factory = new $factoryClass($this);
973
-
974
-			$manager = new \OC\Share20\Manager(
975
-				$c->getLogger(),
976
-				$c->getConfig(),
977
-				$c->getSecureRandom(),
978
-				$c->getHasher(),
979
-				$c->getMountManager(),
980
-				$c->getGroupManager(),
981
-				$c->getL10N('lib'),
982
-				$c->getL10NFactory(),
983
-				$factory,
984
-				$c->getUserManager(),
985
-				$c->getLazyRootFolder(),
986
-				$c->getEventDispatcher(),
987
-				$c->getMailer(),
988
-				$c->getURLGenerator(),
989
-				$c->getThemingDefaults()
990
-			);
991
-
992
-			return $manager;
993
-		});
994
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
995
-
996
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
997
-			return new Collaboration\Collaborators\Search($c);
998
-		});
999
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1000
-
1001
-		$this->registerService('SettingsManager', function (Server $c) {
1002
-			$manager = new \OC\Settings\Manager(
1003
-				$c->getLogger(),
1004
-				$c->getDatabaseConnection(),
1005
-				$c->getL10N('lib'),
1006
-				$c->getConfig(),
1007
-				$c->getEncryptionManager(),
1008
-				$c->getUserManager(),
1009
-				$c->getLockingProvider(),
1010
-				$c->getRequest(),
1011
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
1012
-				$c->getURLGenerator(),
1013
-				$c->query(AccountManager::class),
1014
-				$c->getGroupManager(),
1015
-				$c->getL10NFactory(),
1016
-				$c->getThemingDefaults(),
1017
-				$c->getAppManager()
1018
-			);
1019
-			return $manager;
1020
-		});
1021
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1022
-			return new \OC\Files\AppData\Factory(
1023
-				$c->getRootFolder(),
1024
-				$c->getSystemConfig()
1025
-			);
1026
-		});
1027
-
1028
-		$this->registerService('LockdownManager', function (Server $c) {
1029
-			return new LockdownManager(function () use ($c) {
1030
-				return $c->getSession();
1031
-			});
1032
-		});
1033
-
1034
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1035
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1036
-		});
1037
-
1038
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1039
-			return new CloudIdManager();
1040
-		});
1041
-
1042
-		/* To trick DI since we don't extend the DIContainer here */
1043
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1044
-			return new CleanPreviewsBackgroundJob(
1045
-				$c->getRootFolder(),
1046
-				$c->getLogger(),
1047
-				$c->getJobList(),
1048
-				new TimeFactory()
1049
-			);
1050
-		});
1051
-
1052
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1053
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1054
-
1055
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1056
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1057
-
1058
-		$this->registerService(Defaults::class, function (Server $c) {
1059
-			return new Defaults(
1060
-				$c->getThemingDefaults()
1061
-			);
1062
-		});
1063
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1064
-
1065
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1066
-			return $c->query(\OCP\IUserSession::class)->getSession();
1067
-		});
1068
-
1069
-		$this->registerService(IShareHelper::class, function (Server $c) {
1070
-			return new ShareHelper(
1071
-				$c->query(\OCP\Share\IManager::class)
1072
-			);
1073
-		});
1074
-	}
1075
-
1076
-	/**
1077
-	 * @return \OCP\Contacts\IManager
1078
-	 */
1079
-	public function getContactsManager() {
1080
-		return $this->query('ContactsManager');
1081
-	}
1082
-
1083
-	/**
1084
-	 * @return \OC\Encryption\Manager
1085
-	 */
1086
-	public function getEncryptionManager() {
1087
-		return $this->query('EncryptionManager');
1088
-	}
1089
-
1090
-	/**
1091
-	 * @return \OC\Encryption\File
1092
-	 */
1093
-	public function getEncryptionFilesHelper() {
1094
-		return $this->query('EncryptionFileHelper');
1095
-	}
1096
-
1097
-	/**
1098
-	 * @return \OCP\Encryption\Keys\IStorage
1099
-	 */
1100
-	public function getEncryptionKeyStorage() {
1101
-		return $this->query('EncryptionKeyStorage');
1102
-	}
1103
-
1104
-	/**
1105
-	 * The current request object holding all information about the request
1106
-	 * currently being processed is returned from this method.
1107
-	 * In case the current execution was not initiated by a web request null is returned
1108
-	 *
1109
-	 * @return \OCP\IRequest
1110
-	 */
1111
-	public function getRequest() {
1112
-		return $this->query('Request');
1113
-	}
1114
-
1115
-	/**
1116
-	 * Returns the preview manager which can create preview images for a given file
1117
-	 *
1118
-	 * @return \OCP\IPreview
1119
-	 */
1120
-	public function getPreviewManager() {
1121
-		return $this->query('PreviewManager');
1122
-	}
1123
-
1124
-	/**
1125
-	 * Returns the tag manager which can get and set tags for different object types
1126
-	 *
1127
-	 * @see \OCP\ITagManager::load()
1128
-	 * @return \OCP\ITagManager
1129
-	 */
1130
-	public function getTagManager() {
1131
-		return $this->query('TagManager');
1132
-	}
1133
-
1134
-	/**
1135
-	 * Returns the system-tag manager
1136
-	 *
1137
-	 * @return \OCP\SystemTag\ISystemTagManager
1138
-	 *
1139
-	 * @since 9.0.0
1140
-	 */
1141
-	public function getSystemTagManager() {
1142
-		return $this->query('SystemTagManager');
1143
-	}
1144
-
1145
-	/**
1146
-	 * Returns the system-tag object mapper
1147
-	 *
1148
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1149
-	 *
1150
-	 * @since 9.0.0
1151
-	 */
1152
-	public function getSystemTagObjectMapper() {
1153
-		return $this->query('SystemTagObjectMapper');
1154
-	}
1155
-
1156
-	/**
1157
-	 * Returns the avatar manager, used for avatar functionality
1158
-	 *
1159
-	 * @return \OCP\IAvatarManager
1160
-	 */
1161
-	public function getAvatarManager() {
1162
-		return $this->query('AvatarManager');
1163
-	}
1164
-
1165
-	/**
1166
-	 * Returns the root folder of ownCloud's data directory
1167
-	 *
1168
-	 * @return \OCP\Files\IRootFolder
1169
-	 */
1170
-	public function getRootFolder() {
1171
-		return $this->query('LazyRootFolder');
1172
-	}
1173
-
1174
-	/**
1175
-	 * Returns the root folder of ownCloud's data directory
1176
-	 * This is the lazy variant so this gets only initialized once it
1177
-	 * is actually used.
1178
-	 *
1179
-	 * @return \OCP\Files\IRootFolder
1180
-	 */
1181
-	public function getLazyRootFolder() {
1182
-		return $this->query('LazyRootFolder');
1183
-	}
1184
-
1185
-	/**
1186
-	 * Returns a view to ownCloud's files folder
1187
-	 *
1188
-	 * @param string $userId user ID
1189
-	 * @return \OCP\Files\Folder|null
1190
-	 */
1191
-	public function getUserFolder($userId = null) {
1192
-		if ($userId === null) {
1193
-			$user = $this->getUserSession()->getUser();
1194
-			if (!$user) {
1195
-				return null;
1196
-			}
1197
-			$userId = $user->getUID();
1198
-		}
1199
-		$root = $this->getRootFolder();
1200
-		return $root->getUserFolder($userId);
1201
-	}
1202
-
1203
-	/**
1204
-	 * Returns an app-specific view in ownClouds data directory
1205
-	 *
1206
-	 * @return \OCP\Files\Folder
1207
-	 * @deprecated since 9.2.0 use IAppData
1208
-	 */
1209
-	public function getAppFolder() {
1210
-		$dir = '/' . \OC_App::getCurrentApp();
1211
-		$root = $this->getRootFolder();
1212
-		if (!$root->nodeExists($dir)) {
1213
-			$folder = $root->newFolder($dir);
1214
-		} else {
1215
-			$folder = $root->get($dir);
1216
-		}
1217
-		return $folder;
1218
-	}
1219
-
1220
-	/**
1221
-	 * @return \OC\User\Manager
1222
-	 */
1223
-	public function getUserManager() {
1224
-		return $this->query('UserManager');
1225
-	}
1226
-
1227
-	/**
1228
-	 * @return \OC\Group\Manager
1229
-	 */
1230
-	public function getGroupManager() {
1231
-		return $this->query('GroupManager');
1232
-	}
1233
-
1234
-	/**
1235
-	 * @return \OC\User\Session
1236
-	 */
1237
-	public function getUserSession() {
1238
-		return $this->query('UserSession');
1239
-	}
1240
-
1241
-	/**
1242
-	 * @return \OCP\ISession
1243
-	 */
1244
-	public function getSession() {
1245
-		return $this->query('UserSession')->getSession();
1246
-	}
1247
-
1248
-	/**
1249
-	 * @param \OCP\ISession $session
1250
-	 */
1251
-	public function setSession(\OCP\ISession $session) {
1252
-		$this->query(SessionStorage::class)->setSession($session);
1253
-		$this->query('UserSession')->setSession($session);
1254
-		$this->query(Store::class)->setSession($session);
1255
-	}
1256
-
1257
-	/**
1258
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1259
-	 */
1260
-	public function getTwoFactorAuthManager() {
1261
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1262
-	}
1263
-
1264
-	/**
1265
-	 * @return \OC\NavigationManager
1266
-	 */
1267
-	public function getNavigationManager() {
1268
-		return $this->query('NavigationManager');
1269
-	}
1270
-
1271
-	/**
1272
-	 * @return \OCP\IConfig
1273
-	 */
1274
-	public function getConfig() {
1275
-		return $this->query('AllConfig');
1276
-	}
1277
-
1278
-	/**
1279
-	 * @return \OC\SystemConfig
1280
-	 */
1281
-	public function getSystemConfig() {
1282
-		return $this->query('SystemConfig');
1283
-	}
1284
-
1285
-	/**
1286
-	 * Returns the app config manager
1287
-	 *
1288
-	 * @return \OCP\IAppConfig
1289
-	 */
1290
-	public function getAppConfig() {
1291
-		return $this->query('AppConfig');
1292
-	}
1293
-
1294
-	/**
1295
-	 * @return \OCP\L10N\IFactory
1296
-	 */
1297
-	public function getL10NFactory() {
1298
-		return $this->query('L10NFactory');
1299
-	}
1300
-
1301
-	/**
1302
-	 * get an L10N instance
1303
-	 *
1304
-	 * @param string $app appid
1305
-	 * @param string $lang
1306
-	 * @return IL10N
1307
-	 */
1308
-	public function getL10N($app, $lang = null) {
1309
-		return $this->getL10NFactory()->get($app, $lang);
1310
-	}
1311
-
1312
-	/**
1313
-	 * @return \OCP\IURLGenerator
1314
-	 */
1315
-	public function getURLGenerator() {
1316
-		return $this->query('URLGenerator');
1317
-	}
1318
-
1319
-	/**
1320
-	 * @return \OCP\IHelper
1321
-	 */
1322
-	public function getHelper() {
1323
-		return $this->query('AppHelper');
1324
-	}
1325
-
1326
-	/**
1327
-	 * @return AppFetcher
1328
-	 */
1329
-	public function getAppFetcher() {
1330
-		return $this->query(AppFetcher::class);
1331
-	}
1332
-
1333
-	/**
1334
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1335
-	 * getMemCacheFactory() instead.
1336
-	 *
1337
-	 * @return \OCP\ICache
1338
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1339
-	 */
1340
-	public function getCache() {
1341
-		return $this->query('UserCache');
1342
-	}
1343
-
1344
-	/**
1345
-	 * Returns an \OCP\CacheFactory instance
1346
-	 *
1347
-	 * @return \OCP\ICacheFactory
1348
-	 */
1349
-	public function getMemCacheFactory() {
1350
-		return $this->query('MemCacheFactory');
1351
-	}
1352
-
1353
-	/**
1354
-	 * Returns an \OC\RedisFactory instance
1355
-	 *
1356
-	 * @return \OC\RedisFactory
1357
-	 */
1358
-	public function getGetRedisFactory() {
1359
-		return $this->query('RedisFactory');
1360
-	}
1361
-
1362
-
1363
-	/**
1364
-	 * Returns the current session
1365
-	 *
1366
-	 * @return \OCP\IDBConnection
1367
-	 */
1368
-	public function getDatabaseConnection() {
1369
-		return $this->query('DatabaseConnection');
1370
-	}
1371
-
1372
-	/**
1373
-	 * Returns the activity manager
1374
-	 *
1375
-	 * @return \OCP\Activity\IManager
1376
-	 */
1377
-	public function getActivityManager() {
1378
-		return $this->query('ActivityManager');
1379
-	}
1380
-
1381
-	/**
1382
-	 * Returns an job list for controlling background jobs
1383
-	 *
1384
-	 * @return \OCP\BackgroundJob\IJobList
1385
-	 */
1386
-	public function getJobList() {
1387
-		return $this->query('JobList');
1388
-	}
1389
-
1390
-	/**
1391
-	 * Returns a logger instance
1392
-	 *
1393
-	 * @return \OCP\ILogger
1394
-	 */
1395
-	public function getLogger() {
1396
-		return $this->query('Logger');
1397
-	}
1398
-
1399
-	/**
1400
-	 * Returns a router for generating and matching urls
1401
-	 *
1402
-	 * @return \OCP\Route\IRouter
1403
-	 */
1404
-	public function getRouter() {
1405
-		return $this->query('Router');
1406
-	}
1407
-
1408
-	/**
1409
-	 * Returns a search instance
1410
-	 *
1411
-	 * @return \OCP\ISearch
1412
-	 */
1413
-	public function getSearch() {
1414
-		return $this->query('Search');
1415
-	}
1416
-
1417
-	/**
1418
-	 * Returns a SecureRandom instance
1419
-	 *
1420
-	 * @return \OCP\Security\ISecureRandom
1421
-	 */
1422
-	public function getSecureRandom() {
1423
-		return $this->query('SecureRandom');
1424
-	}
1425
-
1426
-	/**
1427
-	 * Returns a Crypto instance
1428
-	 *
1429
-	 * @return \OCP\Security\ICrypto
1430
-	 */
1431
-	public function getCrypto() {
1432
-		return $this->query('Crypto');
1433
-	}
1434
-
1435
-	/**
1436
-	 * Returns a Hasher instance
1437
-	 *
1438
-	 * @return \OCP\Security\IHasher
1439
-	 */
1440
-	public function getHasher() {
1441
-		return $this->query('Hasher');
1442
-	}
1443
-
1444
-	/**
1445
-	 * Returns a CredentialsManager instance
1446
-	 *
1447
-	 * @return \OCP\Security\ICredentialsManager
1448
-	 */
1449
-	public function getCredentialsManager() {
1450
-		return $this->query('CredentialsManager');
1451
-	}
1452
-
1453
-	/**
1454
-	 * Returns an instance of the HTTP helper class
1455
-	 *
1456
-	 * @deprecated Use getHTTPClientService()
1457
-	 * @return \OC\HTTPHelper
1458
-	 */
1459
-	public function getHTTPHelper() {
1460
-		return $this->query('HTTPHelper');
1461
-	}
1462
-
1463
-	/**
1464
-	 * Get the certificate manager for the user
1465
-	 *
1466
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1467
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1468
-	 */
1469
-	public function getCertificateManager($userId = '') {
1470
-		if ($userId === '') {
1471
-			$userSession = $this->getUserSession();
1472
-			$user = $userSession->getUser();
1473
-			if (is_null($user)) {
1474
-				return null;
1475
-			}
1476
-			$userId = $user->getUID();
1477
-		}
1478
-		return new CertificateManager(
1479
-			$userId,
1480
-			new View(),
1481
-			$this->getConfig(),
1482
-			$this->getLogger(),
1483
-			$this->getSecureRandom()
1484
-		);
1485
-	}
1486
-
1487
-	/**
1488
-	 * Returns an instance of the HTTP client service
1489
-	 *
1490
-	 * @return \OCP\Http\Client\IClientService
1491
-	 */
1492
-	public function getHTTPClientService() {
1493
-		return $this->query('HttpClientService');
1494
-	}
1495
-
1496
-	/**
1497
-	 * Create a new event source
1498
-	 *
1499
-	 * @return \OCP\IEventSource
1500
-	 */
1501
-	public function createEventSource() {
1502
-		return new \OC_EventSource();
1503
-	}
1504
-
1505
-	/**
1506
-	 * Get the active event logger
1507
-	 *
1508
-	 * The returned logger only logs data when debug mode is enabled
1509
-	 *
1510
-	 * @return \OCP\Diagnostics\IEventLogger
1511
-	 */
1512
-	public function getEventLogger() {
1513
-		return $this->query('EventLogger');
1514
-	}
1515
-
1516
-	/**
1517
-	 * Get the active query logger
1518
-	 *
1519
-	 * The returned logger only logs data when debug mode is enabled
1520
-	 *
1521
-	 * @return \OCP\Diagnostics\IQueryLogger
1522
-	 */
1523
-	public function getQueryLogger() {
1524
-		return $this->query('QueryLogger');
1525
-	}
1526
-
1527
-	/**
1528
-	 * Get the manager for temporary files and folders
1529
-	 *
1530
-	 * @return \OCP\ITempManager
1531
-	 */
1532
-	public function getTempManager() {
1533
-		return $this->query('TempManager');
1534
-	}
1535
-
1536
-	/**
1537
-	 * Get the app manager
1538
-	 *
1539
-	 * @return \OCP\App\IAppManager
1540
-	 */
1541
-	public function getAppManager() {
1542
-		return $this->query('AppManager');
1543
-	}
1544
-
1545
-	/**
1546
-	 * Creates a new mailer
1547
-	 *
1548
-	 * @return \OCP\Mail\IMailer
1549
-	 */
1550
-	public function getMailer() {
1551
-		return $this->query('Mailer');
1552
-	}
1553
-
1554
-	/**
1555
-	 * Get the webroot
1556
-	 *
1557
-	 * @return string
1558
-	 */
1559
-	public function getWebRoot() {
1560
-		return $this->webRoot;
1561
-	}
1562
-
1563
-	/**
1564
-	 * @return \OC\OCSClient
1565
-	 */
1566
-	public function getOcsClient() {
1567
-		return $this->query('OcsClient');
1568
-	}
1569
-
1570
-	/**
1571
-	 * @return \OCP\IDateTimeZone
1572
-	 */
1573
-	public function getDateTimeZone() {
1574
-		return $this->query('DateTimeZone');
1575
-	}
1576
-
1577
-	/**
1578
-	 * @return \OCP\IDateTimeFormatter
1579
-	 */
1580
-	public function getDateTimeFormatter() {
1581
-		return $this->query('DateTimeFormatter');
1582
-	}
1583
-
1584
-	/**
1585
-	 * @return \OCP\Files\Config\IMountProviderCollection
1586
-	 */
1587
-	public function getMountProviderCollection() {
1588
-		return $this->query('MountConfigManager');
1589
-	}
1590
-
1591
-	/**
1592
-	 * Get the IniWrapper
1593
-	 *
1594
-	 * @return IniGetWrapper
1595
-	 */
1596
-	public function getIniWrapper() {
1597
-		return $this->query('IniWrapper');
1598
-	}
1599
-
1600
-	/**
1601
-	 * @return \OCP\Command\IBus
1602
-	 */
1603
-	public function getCommandBus() {
1604
-		return $this->query('AsyncCommandBus');
1605
-	}
1606
-
1607
-	/**
1608
-	 * Get the trusted domain helper
1609
-	 *
1610
-	 * @return TrustedDomainHelper
1611
-	 */
1612
-	public function getTrustedDomainHelper() {
1613
-		return $this->query('TrustedDomainHelper');
1614
-	}
1615
-
1616
-	/**
1617
-	 * Get the locking provider
1618
-	 *
1619
-	 * @return \OCP\Lock\ILockingProvider
1620
-	 * @since 8.1.0
1621
-	 */
1622
-	public function getLockingProvider() {
1623
-		return $this->query('LockingProvider');
1624
-	}
1625
-
1626
-	/**
1627
-	 * @return \OCP\Files\Mount\IMountManager
1628
-	 **/
1629
-	function getMountManager() {
1630
-		return $this->query('MountManager');
1631
-	}
1632
-
1633
-	/** @return \OCP\Files\Config\IUserMountCache */
1634
-	function getUserMountCache() {
1635
-		return $this->query('UserMountCache');
1636
-	}
1637
-
1638
-	/**
1639
-	 * Get the MimeTypeDetector
1640
-	 *
1641
-	 * @return \OCP\Files\IMimeTypeDetector
1642
-	 */
1643
-	public function getMimeTypeDetector() {
1644
-		return $this->query('MimeTypeDetector');
1645
-	}
1646
-
1647
-	/**
1648
-	 * Get the MimeTypeLoader
1649
-	 *
1650
-	 * @return \OCP\Files\IMimeTypeLoader
1651
-	 */
1652
-	public function getMimeTypeLoader() {
1653
-		return $this->query('MimeTypeLoader');
1654
-	}
1655
-
1656
-	/**
1657
-	 * Get the manager of all the capabilities
1658
-	 *
1659
-	 * @return \OC\CapabilitiesManager
1660
-	 */
1661
-	public function getCapabilitiesManager() {
1662
-		return $this->query('CapabilitiesManager');
1663
-	}
1664
-
1665
-	/**
1666
-	 * Get the EventDispatcher
1667
-	 *
1668
-	 * @return EventDispatcherInterface
1669
-	 * @since 8.2.0
1670
-	 */
1671
-	public function getEventDispatcher() {
1672
-		return $this->query('EventDispatcher');
1673
-	}
1674
-
1675
-	/**
1676
-	 * Get the Notification Manager
1677
-	 *
1678
-	 * @return \OCP\Notification\IManager
1679
-	 * @since 8.2.0
1680
-	 */
1681
-	public function getNotificationManager() {
1682
-		return $this->query('NotificationManager');
1683
-	}
1684
-
1685
-	/**
1686
-	 * @return \OCP\Comments\ICommentsManager
1687
-	 */
1688
-	public function getCommentsManager() {
1689
-		return $this->query('CommentsManager');
1690
-	}
1691
-
1692
-	/**
1693
-	 * @return \OCA\Theming\ThemingDefaults
1694
-	 */
1695
-	public function getThemingDefaults() {
1696
-		return $this->query('ThemingDefaults');
1697
-	}
1698
-
1699
-	/**
1700
-	 * @return \OC\IntegrityCheck\Checker
1701
-	 */
1702
-	public function getIntegrityCodeChecker() {
1703
-		return $this->query('IntegrityCodeChecker');
1704
-	}
1705
-
1706
-	/**
1707
-	 * @return \OC\Session\CryptoWrapper
1708
-	 */
1709
-	public function getSessionCryptoWrapper() {
1710
-		return $this->query('CryptoWrapper');
1711
-	}
1712
-
1713
-	/**
1714
-	 * @return CsrfTokenManager
1715
-	 */
1716
-	public function getCsrfTokenManager() {
1717
-		return $this->query('CsrfTokenManager');
1718
-	}
1719
-
1720
-	/**
1721
-	 * @return Throttler
1722
-	 */
1723
-	public function getBruteForceThrottler() {
1724
-		return $this->query('Throttler');
1725
-	}
1726
-
1727
-	/**
1728
-	 * @return IContentSecurityPolicyManager
1729
-	 */
1730
-	public function getContentSecurityPolicyManager() {
1731
-		return $this->query('ContentSecurityPolicyManager');
1732
-	}
1733
-
1734
-	/**
1735
-	 * @return ContentSecurityPolicyNonceManager
1736
-	 */
1737
-	public function getContentSecurityPolicyNonceManager() {
1738
-		return $this->query('ContentSecurityPolicyNonceManager');
1739
-	}
1740
-
1741
-	/**
1742
-	 * Not a public API as of 8.2, wait for 9.0
1743
-	 *
1744
-	 * @return \OCA\Files_External\Service\BackendService
1745
-	 */
1746
-	public function getStoragesBackendService() {
1747
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1748
-	}
1749
-
1750
-	/**
1751
-	 * Not a public API as of 8.2, wait for 9.0
1752
-	 *
1753
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1754
-	 */
1755
-	public function getGlobalStoragesService() {
1756
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1757
-	}
1758
-
1759
-	/**
1760
-	 * Not a public API as of 8.2, wait for 9.0
1761
-	 *
1762
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1763
-	 */
1764
-	public function getUserGlobalStoragesService() {
1765
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1766
-	}
1767
-
1768
-	/**
1769
-	 * Not a public API as of 8.2, wait for 9.0
1770
-	 *
1771
-	 * @return \OCA\Files_External\Service\UserStoragesService
1772
-	 */
1773
-	public function getUserStoragesService() {
1774
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1775
-	}
1776
-
1777
-	/**
1778
-	 * @return \OCP\Share\IManager
1779
-	 */
1780
-	public function getShareManager() {
1781
-		return $this->query('ShareManager');
1782
-	}
1783
-
1784
-	/**
1785
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1786
-	 */
1787
-	public function getCollaboratorSearch() {
1788
-		return $this->query('CollaboratorSearch');
1789
-	}
1790
-
1791
-	/**
1792
-	 * Returns the LDAP Provider
1793
-	 *
1794
-	 * @return \OCP\LDAP\ILDAPProvider
1795
-	 */
1796
-	public function getLDAPProvider() {
1797
-		return $this->query('LDAPProvider');
1798
-	}
1799
-
1800
-	/**
1801
-	 * @return \OCP\Settings\IManager
1802
-	 */
1803
-	public function getSettingsManager() {
1804
-		return $this->query('SettingsManager');
1805
-	}
1806
-
1807
-	/**
1808
-	 * @return \OCP\Files\IAppData
1809
-	 */
1810
-	public function getAppDataDir($app) {
1811
-		/** @var \OC\Files\AppData\Factory $factory */
1812
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1813
-		return $factory->get($app);
1814
-	}
1815
-
1816
-	/**
1817
-	 * @return \OCP\Lockdown\ILockdownManager
1818
-	 */
1819
-	public function getLockdownManager() {
1820
-		return $this->query('LockdownManager');
1821
-	}
1822
-
1823
-	/**
1824
-	 * @return \OCP\Federation\ICloudIdManager
1825
-	 */
1826
-	public function getCloudIdManager() {
1827
-		return $this->query(ICloudIdManager::class);
1828
-	}
881
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
882
+            if (isset($prefixes['OCA\\Theming\\'])) {
883
+                $classExists = true;
884
+            } else {
885
+                $classExists = false;
886
+            }
887
+
888
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
889
+                return new ThemingDefaults(
890
+                    $c->getConfig(),
891
+                    $c->getL10N('theming'),
892
+                    $c->getURLGenerator(),
893
+                    $c->getAppDataDir('theming'),
894
+                    $c->getMemCacheFactory(),
895
+                    new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')),
896
+                    $this->getAppManager()
897
+                );
898
+            }
899
+            return new \OC_Defaults();
900
+        });
901
+        $this->registerService(SCSSCacher::class, function (Server $c) {
902
+            /** @var Factory $cacheFactory */
903
+            $cacheFactory = $c->query(Factory::class);
904
+            return new SCSSCacher(
905
+                $c->getLogger(),
906
+                $c->query(\OC\Files\AppData\Factory::class),
907
+                $c->getURLGenerator(),
908
+                $c->getConfig(),
909
+                $c->getThemingDefaults(),
910
+                \OC::$SERVERROOT,
911
+                $cacheFactory->create('SCSS')
912
+            );
913
+        });
914
+        $this->registerService(EventDispatcher::class, function () {
915
+            return new EventDispatcher();
916
+        });
917
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
918
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
919
+
920
+        $this->registerService('CryptoWrapper', function (Server $c) {
921
+            // FIXME: Instantiiated here due to cyclic dependency
922
+            $request = new Request(
923
+                [
924
+                    'get' => $_GET,
925
+                    'post' => $_POST,
926
+                    'files' => $_FILES,
927
+                    'server' => $_SERVER,
928
+                    'env' => $_ENV,
929
+                    'cookies' => $_COOKIE,
930
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
931
+                        ? $_SERVER['REQUEST_METHOD']
932
+                        : null,
933
+                ],
934
+                $c->getSecureRandom(),
935
+                $c->getConfig()
936
+            );
937
+
938
+            return new CryptoWrapper(
939
+                $c->getConfig(),
940
+                $c->getCrypto(),
941
+                $c->getSecureRandom(),
942
+                $request
943
+            );
944
+        });
945
+        $this->registerService('CsrfTokenManager', function (Server $c) {
946
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
947
+
948
+            return new CsrfTokenManager(
949
+                $tokenGenerator,
950
+                $c->query(SessionStorage::class)
951
+            );
952
+        });
953
+        $this->registerService(SessionStorage::class, function (Server $c) {
954
+            return new SessionStorage($c->getSession());
955
+        });
956
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
957
+            return new ContentSecurityPolicyManager();
958
+        });
959
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
960
+
961
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
962
+            return new ContentSecurityPolicyNonceManager(
963
+                $c->getCsrfTokenManager(),
964
+                $c->getRequest()
965
+            );
966
+        });
967
+
968
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
969
+            $config = $c->getConfig();
970
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
971
+            /** @var \OCP\Share\IProviderFactory $factory */
972
+            $factory = new $factoryClass($this);
973
+
974
+            $manager = new \OC\Share20\Manager(
975
+                $c->getLogger(),
976
+                $c->getConfig(),
977
+                $c->getSecureRandom(),
978
+                $c->getHasher(),
979
+                $c->getMountManager(),
980
+                $c->getGroupManager(),
981
+                $c->getL10N('lib'),
982
+                $c->getL10NFactory(),
983
+                $factory,
984
+                $c->getUserManager(),
985
+                $c->getLazyRootFolder(),
986
+                $c->getEventDispatcher(),
987
+                $c->getMailer(),
988
+                $c->getURLGenerator(),
989
+                $c->getThemingDefaults()
990
+            );
991
+
992
+            return $manager;
993
+        });
994
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
995
+
996
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
997
+            return new Collaboration\Collaborators\Search($c);
998
+        });
999
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1000
+
1001
+        $this->registerService('SettingsManager', function (Server $c) {
1002
+            $manager = new \OC\Settings\Manager(
1003
+                $c->getLogger(),
1004
+                $c->getDatabaseConnection(),
1005
+                $c->getL10N('lib'),
1006
+                $c->getConfig(),
1007
+                $c->getEncryptionManager(),
1008
+                $c->getUserManager(),
1009
+                $c->getLockingProvider(),
1010
+                $c->getRequest(),
1011
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
1012
+                $c->getURLGenerator(),
1013
+                $c->query(AccountManager::class),
1014
+                $c->getGroupManager(),
1015
+                $c->getL10NFactory(),
1016
+                $c->getThemingDefaults(),
1017
+                $c->getAppManager()
1018
+            );
1019
+            return $manager;
1020
+        });
1021
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1022
+            return new \OC\Files\AppData\Factory(
1023
+                $c->getRootFolder(),
1024
+                $c->getSystemConfig()
1025
+            );
1026
+        });
1027
+
1028
+        $this->registerService('LockdownManager', function (Server $c) {
1029
+            return new LockdownManager(function () use ($c) {
1030
+                return $c->getSession();
1031
+            });
1032
+        });
1033
+
1034
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1035
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1036
+        });
1037
+
1038
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1039
+            return new CloudIdManager();
1040
+        });
1041
+
1042
+        /* To trick DI since we don't extend the DIContainer here */
1043
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
1044
+            return new CleanPreviewsBackgroundJob(
1045
+                $c->getRootFolder(),
1046
+                $c->getLogger(),
1047
+                $c->getJobList(),
1048
+                new TimeFactory()
1049
+            );
1050
+        });
1051
+
1052
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1053
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1054
+
1055
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1056
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1057
+
1058
+        $this->registerService(Defaults::class, function (Server $c) {
1059
+            return new Defaults(
1060
+                $c->getThemingDefaults()
1061
+            );
1062
+        });
1063
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1064
+
1065
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1066
+            return $c->query(\OCP\IUserSession::class)->getSession();
1067
+        });
1068
+
1069
+        $this->registerService(IShareHelper::class, function (Server $c) {
1070
+            return new ShareHelper(
1071
+                $c->query(\OCP\Share\IManager::class)
1072
+            );
1073
+        });
1074
+    }
1075
+
1076
+    /**
1077
+     * @return \OCP\Contacts\IManager
1078
+     */
1079
+    public function getContactsManager() {
1080
+        return $this->query('ContactsManager');
1081
+    }
1082
+
1083
+    /**
1084
+     * @return \OC\Encryption\Manager
1085
+     */
1086
+    public function getEncryptionManager() {
1087
+        return $this->query('EncryptionManager');
1088
+    }
1089
+
1090
+    /**
1091
+     * @return \OC\Encryption\File
1092
+     */
1093
+    public function getEncryptionFilesHelper() {
1094
+        return $this->query('EncryptionFileHelper');
1095
+    }
1096
+
1097
+    /**
1098
+     * @return \OCP\Encryption\Keys\IStorage
1099
+     */
1100
+    public function getEncryptionKeyStorage() {
1101
+        return $this->query('EncryptionKeyStorage');
1102
+    }
1103
+
1104
+    /**
1105
+     * The current request object holding all information about the request
1106
+     * currently being processed is returned from this method.
1107
+     * In case the current execution was not initiated by a web request null is returned
1108
+     *
1109
+     * @return \OCP\IRequest
1110
+     */
1111
+    public function getRequest() {
1112
+        return $this->query('Request');
1113
+    }
1114
+
1115
+    /**
1116
+     * Returns the preview manager which can create preview images for a given file
1117
+     *
1118
+     * @return \OCP\IPreview
1119
+     */
1120
+    public function getPreviewManager() {
1121
+        return $this->query('PreviewManager');
1122
+    }
1123
+
1124
+    /**
1125
+     * Returns the tag manager which can get and set tags for different object types
1126
+     *
1127
+     * @see \OCP\ITagManager::load()
1128
+     * @return \OCP\ITagManager
1129
+     */
1130
+    public function getTagManager() {
1131
+        return $this->query('TagManager');
1132
+    }
1133
+
1134
+    /**
1135
+     * Returns the system-tag manager
1136
+     *
1137
+     * @return \OCP\SystemTag\ISystemTagManager
1138
+     *
1139
+     * @since 9.0.0
1140
+     */
1141
+    public function getSystemTagManager() {
1142
+        return $this->query('SystemTagManager');
1143
+    }
1144
+
1145
+    /**
1146
+     * Returns the system-tag object mapper
1147
+     *
1148
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1149
+     *
1150
+     * @since 9.0.0
1151
+     */
1152
+    public function getSystemTagObjectMapper() {
1153
+        return $this->query('SystemTagObjectMapper');
1154
+    }
1155
+
1156
+    /**
1157
+     * Returns the avatar manager, used for avatar functionality
1158
+     *
1159
+     * @return \OCP\IAvatarManager
1160
+     */
1161
+    public function getAvatarManager() {
1162
+        return $this->query('AvatarManager');
1163
+    }
1164
+
1165
+    /**
1166
+     * Returns the root folder of ownCloud's data directory
1167
+     *
1168
+     * @return \OCP\Files\IRootFolder
1169
+     */
1170
+    public function getRootFolder() {
1171
+        return $this->query('LazyRootFolder');
1172
+    }
1173
+
1174
+    /**
1175
+     * Returns the root folder of ownCloud's data directory
1176
+     * This is the lazy variant so this gets only initialized once it
1177
+     * is actually used.
1178
+     *
1179
+     * @return \OCP\Files\IRootFolder
1180
+     */
1181
+    public function getLazyRootFolder() {
1182
+        return $this->query('LazyRootFolder');
1183
+    }
1184
+
1185
+    /**
1186
+     * Returns a view to ownCloud's files folder
1187
+     *
1188
+     * @param string $userId user ID
1189
+     * @return \OCP\Files\Folder|null
1190
+     */
1191
+    public function getUserFolder($userId = null) {
1192
+        if ($userId === null) {
1193
+            $user = $this->getUserSession()->getUser();
1194
+            if (!$user) {
1195
+                return null;
1196
+            }
1197
+            $userId = $user->getUID();
1198
+        }
1199
+        $root = $this->getRootFolder();
1200
+        return $root->getUserFolder($userId);
1201
+    }
1202
+
1203
+    /**
1204
+     * Returns an app-specific view in ownClouds data directory
1205
+     *
1206
+     * @return \OCP\Files\Folder
1207
+     * @deprecated since 9.2.0 use IAppData
1208
+     */
1209
+    public function getAppFolder() {
1210
+        $dir = '/' . \OC_App::getCurrentApp();
1211
+        $root = $this->getRootFolder();
1212
+        if (!$root->nodeExists($dir)) {
1213
+            $folder = $root->newFolder($dir);
1214
+        } else {
1215
+            $folder = $root->get($dir);
1216
+        }
1217
+        return $folder;
1218
+    }
1219
+
1220
+    /**
1221
+     * @return \OC\User\Manager
1222
+     */
1223
+    public function getUserManager() {
1224
+        return $this->query('UserManager');
1225
+    }
1226
+
1227
+    /**
1228
+     * @return \OC\Group\Manager
1229
+     */
1230
+    public function getGroupManager() {
1231
+        return $this->query('GroupManager');
1232
+    }
1233
+
1234
+    /**
1235
+     * @return \OC\User\Session
1236
+     */
1237
+    public function getUserSession() {
1238
+        return $this->query('UserSession');
1239
+    }
1240
+
1241
+    /**
1242
+     * @return \OCP\ISession
1243
+     */
1244
+    public function getSession() {
1245
+        return $this->query('UserSession')->getSession();
1246
+    }
1247
+
1248
+    /**
1249
+     * @param \OCP\ISession $session
1250
+     */
1251
+    public function setSession(\OCP\ISession $session) {
1252
+        $this->query(SessionStorage::class)->setSession($session);
1253
+        $this->query('UserSession')->setSession($session);
1254
+        $this->query(Store::class)->setSession($session);
1255
+    }
1256
+
1257
+    /**
1258
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1259
+     */
1260
+    public function getTwoFactorAuthManager() {
1261
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1262
+    }
1263
+
1264
+    /**
1265
+     * @return \OC\NavigationManager
1266
+     */
1267
+    public function getNavigationManager() {
1268
+        return $this->query('NavigationManager');
1269
+    }
1270
+
1271
+    /**
1272
+     * @return \OCP\IConfig
1273
+     */
1274
+    public function getConfig() {
1275
+        return $this->query('AllConfig');
1276
+    }
1277
+
1278
+    /**
1279
+     * @return \OC\SystemConfig
1280
+     */
1281
+    public function getSystemConfig() {
1282
+        return $this->query('SystemConfig');
1283
+    }
1284
+
1285
+    /**
1286
+     * Returns the app config manager
1287
+     *
1288
+     * @return \OCP\IAppConfig
1289
+     */
1290
+    public function getAppConfig() {
1291
+        return $this->query('AppConfig');
1292
+    }
1293
+
1294
+    /**
1295
+     * @return \OCP\L10N\IFactory
1296
+     */
1297
+    public function getL10NFactory() {
1298
+        return $this->query('L10NFactory');
1299
+    }
1300
+
1301
+    /**
1302
+     * get an L10N instance
1303
+     *
1304
+     * @param string $app appid
1305
+     * @param string $lang
1306
+     * @return IL10N
1307
+     */
1308
+    public function getL10N($app, $lang = null) {
1309
+        return $this->getL10NFactory()->get($app, $lang);
1310
+    }
1311
+
1312
+    /**
1313
+     * @return \OCP\IURLGenerator
1314
+     */
1315
+    public function getURLGenerator() {
1316
+        return $this->query('URLGenerator');
1317
+    }
1318
+
1319
+    /**
1320
+     * @return \OCP\IHelper
1321
+     */
1322
+    public function getHelper() {
1323
+        return $this->query('AppHelper');
1324
+    }
1325
+
1326
+    /**
1327
+     * @return AppFetcher
1328
+     */
1329
+    public function getAppFetcher() {
1330
+        return $this->query(AppFetcher::class);
1331
+    }
1332
+
1333
+    /**
1334
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1335
+     * getMemCacheFactory() instead.
1336
+     *
1337
+     * @return \OCP\ICache
1338
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1339
+     */
1340
+    public function getCache() {
1341
+        return $this->query('UserCache');
1342
+    }
1343
+
1344
+    /**
1345
+     * Returns an \OCP\CacheFactory instance
1346
+     *
1347
+     * @return \OCP\ICacheFactory
1348
+     */
1349
+    public function getMemCacheFactory() {
1350
+        return $this->query('MemCacheFactory');
1351
+    }
1352
+
1353
+    /**
1354
+     * Returns an \OC\RedisFactory instance
1355
+     *
1356
+     * @return \OC\RedisFactory
1357
+     */
1358
+    public function getGetRedisFactory() {
1359
+        return $this->query('RedisFactory');
1360
+    }
1361
+
1362
+
1363
+    /**
1364
+     * Returns the current session
1365
+     *
1366
+     * @return \OCP\IDBConnection
1367
+     */
1368
+    public function getDatabaseConnection() {
1369
+        return $this->query('DatabaseConnection');
1370
+    }
1371
+
1372
+    /**
1373
+     * Returns the activity manager
1374
+     *
1375
+     * @return \OCP\Activity\IManager
1376
+     */
1377
+    public function getActivityManager() {
1378
+        return $this->query('ActivityManager');
1379
+    }
1380
+
1381
+    /**
1382
+     * Returns an job list for controlling background jobs
1383
+     *
1384
+     * @return \OCP\BackgroundJob\IJobList
1385
+     */
1386
+    public function getJobList() {
1387
+        return $this->query('JobList');
1388
+    }
1389
+
1390
+    /**
1391
+     * Returns a logger instance
1392
+     *
1393
+     * @return \OCP\ILogger
1394
+     */
1395
+    public function getLogger() {
1396
+        return $this->query('Logger');
1397
+    }
1398
+
1399
+    /**
1400
+     * Returns a router for generating and matching urls
1401
+     *
1402
+     * @return \OCP\Route\IRouter
1403
+     */
1404
+    public function getRouter() {
1405
+        return $this->query('Router');
1406
+    }
1407
+
1408
+    /**
1409
+     * Returns a search instance
1410
+     *
1411
+     * @return \OCP\ISearch
1412
+     */
1413
+    public function getSearch() {
1414
+        return $this->query('Search');
1415
+    }
1416
+
1417
+    /**
1418
+     * Returns a SecureRandom instance
1419
+     *
1420
+     * @return \OCP\Security\ISecureRandom
1421
+     */
1422
+    public function getSecureRandom() {
1423
+        return $this->query('SecureRandom');
1424
+    }
1425
+
1426
+    /**
1427
+     * Returns a Crypto instance
1428
+     *
1429
+     * @return \OCP\Security\ICrypto
1430
+     */
1431
+    public function getCrypto() {
1432
+        return $this->query('Crypto');
1433
+    }
1434
+
1435
+    /**
1436
+     * Returns a Hasher instance
1437
+     *
1438
+     * @return \OCP\Security\IHasher
1439
+     */
1440
+    public function getHasher() {
1441
+        return $this->query('Hasher');
1442
+    }
1443
+
1444
+    /**
1445
+     * Returns a CredentialsManager instance
1446
+     *
1447
+     * @return \OCP\Security\ICredentialsManager
1448
+     */
1449
+    public function getCredentialsManager() {
1450
+        return $this->query('CredentialsManager');
1451
+    }
1452
+
1453
+    /**
1454
+     * Returns an instance of the HTTP helper class
1455
+     *
1456
+     * @deprecated Use getHTTPClientService()
1457
+     * @return \OC\HTTPHelper
1458
+     */
1459
+    public function getHTTPHelper() {
1460
+        return $this->query('HTTPHelper');
1461
+    }
1462
+
1463
+    /**
1464
+     * Get the certificate manager for the user
1465
+     *
1466
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1467
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1468
+     */
1469
+    public function getCertificateManager($userId = '') {
1470
+        if ($userId === '') {
1471
+            $userSession = $this->getUserSession();
1472
+            $user = $userSession->getUser();
1473
+            if (is_null($user)) {
1474
+                return null;
1475
+            }
1476
+            $userId = $user->getUID();
1477
+        }
1478
+        return new CertificateManager(
1479
+            $userId,
1480
+            new View(),
1481
+            $this->getConfig(),
1482
+            $this->getLogger(),
1483
+            $this->getSecureRandom()
1484
+        );
1485
+    }
1486
+
1487
+    /**
1488
+     * Returns an instance of the HTTP client service
1489
+     *
1490
+     * @return \OCP\Http\Client\IClientService
1491
+     */
1492
+    public function getHTTPClientService() {
1493
+        return $this->query('HttpClientService');
1494
+    }
1495
+
1496
+    /**
1497
+     * Create a new event source
1498
+     *
1499
+     * @return \OCP\IEventSource
1500
+     */
1501
+    public function createEventSource() {
1502
+        return new \OC_EventSource();
1503
+    }
1504
+
1505
+    /**
1506
+     * Get the active event logger
1507
+     *
1508
+     * The returned logger only logs data when debug mode is enabled
1509
+     *
1510
+     * @return \OCP\Diagnostics\IEventLogger
1511
+     */
1512
+    public function getEventLogger() {
1513
+        return $this->query('EventLogger');
1514
+    }
1515
+
1516
+    /**
1517
+     * Get the active query logger
1518
+     *
1519
+     * The returned logger only logs data when debug mode is enabled
1520
+     *
1521
+     * @return \OCP\Diagnostics\IQueryLogger
1522
+     */
1523
+    public function getQueryLogger() {
1524
+        return $this->query('QueryLogger');
1525
+    }
1526
+
1527
+    /**
1528
+     * Get the manager for temporary files and folders
1529
+     *
1530
+     * @return \OCP\ITempManager
1531
+     */
1532
+    public function getTempManager() {
1533
+        return $this->query('TempManager');
1534
+    }
1535
+
1536
+    /**
1537
+     * Get the app manager
1538
+     *
1539
+     * @return \OCP\App\IAppManager
1540
+     */
1541
+    public function getAppManager() {
1542
+        return $this->query('AppManager');
1543
+    }
1544
+
1545
+    /**
1546
+     * Creates a new mailer
1547
+     *
1548
+     * @return \OCP\Mail\IMailer
1549
+     */
1550
+    public function getMailer() {
1551
+        return $this->query('Mailer');
1552
+    }
1553
+
1554
+    /**
1555
+     * Get the webroot
1556
+     *
1557
+     * @return string
1558
+     */
1559
+    public function getWebRoot() {
1560
+        return $this->webRoot;
1561
+    }
1562
+
1563
+    /**
1564
+     * @return \OC\OCSClient
1565
+     */
1566
+    public function getOcsClient() {
1567
+        return $this->query('OcsClient');
1568
+    }
1569
+
1570
+    /**
1571
+     * @return \OCP\IDateTimeZone
1572
+     */
1573
+    public function getDateTimeZone() {
1574
+        return $this->query('DateTimeZone');
1575
+    }
1576
+
1577
+    /**
1578
+     * @return \OCP\IDateTimeFormatter
1579
+     */
1580
+    public function getDateTimeFormatter() {
1581
+        return $this->query('DateTimeFormatter');
1582
+    }
1583
+
1584
+    /**
1585
+     * @return \OCP\Files\Config\IMountProviderCollection
1586
+     */
1587
+    public function getMountProviderCollection() {
1588
+        return $this->query('MountConfigManager');
1589
+    }
1590
+
1591
+    /**
1592
+     * Get the IniWrapper
1593
+     *
1594
+     * @return IniGetWrapper
1595
+     */
1596
+    public function getIniWrapper() {
1597
+        return $this->query('IniWrapper');
1598
+    }
1599
+
1600
+    /**
1601
+     * @return \OCP\Command\IBus
1602
+     */
1603
+    public function getCommandBus() {
1604
+        return $this->query('AsyncCommandBus');
1605
+    }
1606
+
1607
+    /**
1608
+     * Get the trusted domain helper
1609
+     *
1610
+     * @return TrustedDomainHelper
1611
+     */
1612
+    public function getTrustedDomainHelper() {
1613
+        return $this->query('TrustedDomainHelper');
1614
+    }
1615
+
1616
+    /**
1617
+     * Get the locking provider
1618
+     *
1619
+     * @return \OCP\Lock\ILockingProvider
1620
+     * @since 8.1.0
1621
+     */
1622
+    public function getLockingProvider() {
1623
+        return $this->query('LockingProvider');
1624
+    }
1625
+
1626
+    /**
1627
+     * @return \OCP\Files\Mount\IMountManager
1628
+     **/
1629
+    function getMountManager() {
1630
+        return $this->query('MountManager');
1631
+    }
1632
+
1633
+    /** @return \OCP\Files\Config\IUserMountCache */
1634
+    function getUserMountCache() {
1635
+        return $this->query('UserMountCache');
1636
+    }
1637
+
1638
+    /**
1639
+     * Get the MimeTypeDetector
1640
+     *
1641
+     * @return \OCP\Files\IMimeTypeDetector
1642
+     */
1643
+    public function getMimeTypeDetector() {
1644
+        return $this->query('MimeTypeDetector');
1645
+    }
1646
+
1647
+    /**
1648
+     * Get the MimeTypeLoader
1649
+     *
1650
+     * @return \OCP\Files\IMimeTypeLoader
1651
+     */
1652
+    public function getMimeTypeLoader() {
1653
+        return $this->query('MimeTypeLoader');
1654
+    }
1655
+
1656
+    /**
1657
+     * Get the manager of all the capabilities
1658
+     *
1659
+     * @return \OC\CapabilitiesManager
1660
+     */
1661
+    public function getCapabilitiesManager() {
1662
+        return $this->query('CapabilitiesManager');
1663
+    }
1664
+
1665
+    /**
1666
+     * Get the EventDispatcher
1667
+     *
1668
+     * @return EventDispatcherInterface
1669
+     * @since 8.2.0
1670
+     */
1671
+    public function getEventDispatcher() {
1672
+        return $this->query('EventDispatcher');
1673
+    }
1674
+
1675
+    /**
1676
+     * Get the Notification Manager
1677
+     *
1678
+     * @return \OCP\Notification\IManager
1679
+     * @since 8.2.0
1680
+     */
1681
+    public function getNotificationManager() {
1682
+        return $this->query('NotificationManager');
1683
+    }
1684
+
1685
+    /**
1686
+     * @return \OCP\Comments\ICommentsManager
1687
+     */
1688
+    public function getCommentsManager() {
1689
+        return $this->query('CommentsManager');
1690
+    }
1691
+
1692
+    /**
1693
+     * @return \OCA\Theming\ThemingDefaults
1694
+     */
1695
+    public function getThemingDefaults() {
1696
+        return $this->query('ThemingDefaults');
1697
+    }
1698
+
1699
+    /**
1700
+     * @return \OC\IntegrityCheck\Checker
1701
+     */
1702
+    public function getIntegrityCodeChecker() {
1703
+        return $this->query('IntegrityCodeChecker');
1704
+    }
1705
+
1706
+    /**
1707
+     * @return \OC\Session\CryptoWrapper
1708
+     */
1709
+    public function getSessionCryptoWrapper() {
1710
+        return $this->query('CryptoWrapper');
1711
+    }
1712
+
1713
+    /**
1714
+     * @return CsrfTokenManager
1715
+     */
1716
+    public function getCsrfTokenManager() {
1717
+        return $this->query('CsrfTokenManager');
1718
+    }
1719
+
1720
+    /**
1721
+     * @return Throttler
1722
+     */
1723
+    public function getBruteForceThrottler() {
1724
+        return $this->query('Throttler');
1725
+    }
1726
+
1727
+    /**
1728
+     * @return IContentSecurityPolicyManager
1729
+     */
1730
+    public function getContentSecurityPolicyManager() {
1731
+        return $this->query('ContentSecurityPolicyManager');
1732
+    }
1733
+
1734
+    /**
1735
+     * @return ContentSecurityPolicyNonceManager
1736
+     */
1737
+    public function getContentSecurityPolicyNonceManager() {
1738
+        return $this->query('ContentSecurityPolicyNonceManager');
1739
+    }
1740
+
1741
+    /**
1742
+     * Not a public API as of 8.2, wait for 9.0
1743
+     *
1744
+     * @return \OCA\Files_External\Service\BackendService
1745
+     */
1746
+    public function getStoragesBackendService() {
1747
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1748
+    }
1749
+
1750
+    /**
1751
+     * Not a public API as of 8.2, wait for 9.0
1752
+     *
1753
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1754
+     */
1755
+    public function getGlobalStoragesService() {
1756
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1757
+    }
1758
+
1759
+    /**
1760
+     * Not a public API as of 8.2, wait for 9.0
1761
+     *
1762
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1763
+     */
1764
+    public function getUserGlobalStoragesService() {
1765
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1766
+    }
1767
+
1768
+    /**
1769
+     * Not a public API as of 8.2, wait for 9.0
1770
+     *
1771
+     * @return \OCA\Files_External\Service\UserStoragesService
1772
+     */
1773
+    public function getUserStoragesService() {
1774
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1775
+    }
1776
+
1777
+    /**
1778
+     * @return \OCP\Share\IManager
1779
+     */
1780
+    public function getShareManager() {
1781
+        return $this->query('ShareManager');
1782
+    }
1783
+
1784
+    /**
1785
+     * @return \OCP\Collaboration\Collaborators\ISearch
1786
+     */
1787
+    public function getCollaboratorSearch() {
1788
+        return $this->query('CollaboratorSearch');
1789
+    }
1790
+
1791
+    /**
1792
+     * Returns the LDAP Provider
1793
+     *
1794
+     * @return \OCP\LDAP\ILDAPProvider
1795
+     */
1796
+    public function getLDAPProvider() {
1797
+        return $this->query('LDAPProvider');
1798
+    }
1799
+
1800
+    /**
1801
+     * @return \OCP\Settings\IManager
1802
+     */
1803
+    public function getSettingsManager() {
1804
+        return $this->query('SettingsManager');
1805
+    }
1806
+
1807
+    /**
1808
+     * @return \OCP\Files\IAppData
1809
+     */
1810
+    public function getAppDataDir($app) {
1811
+        /** @var \OC\Files\AppData\Factory $factory */
1812
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1813
+        return $factory->get($app);
1814
+    }
1815
+
1816
+    /**
1817
+     * @return \OCP\Lockdown\ILockdownManager
1818
+     */
1819
+    public function getLockdownManager() {
1820
+        return $this->query('LockdownManager');
1821
+    }
1822
+
1823
+    /**
1824
+     * @return \OCP\Federation\ICloudIdManager
1825
+     */
1826
+    public function getCloudIdManager() {
1827
+        return $this->query(ICloudIdManager::class);
1828
+    }
1829 1829
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Collaborators/ISearchPlugin.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -30,13 +30,13 @@
 block discarded – undo
30 30
  * @since 13.0.0
31 31
  */
32 32
 interface ISearchPlugin {
33
-	/**
34
-	 * @param string $search
35
-	 * @param int $limit
36
-	 * @param int $offset
37
-	 * @param ISearchResult $searchResult
38
-	 * @return bool whether the plugin has more results
39
-	 * @since 13.0.0
40
-	 */
41
-	public function search($search, $limit, $offset, ISearchResult $searchResult);
33
+    /**
34
+     * @param string $search
35
+     * @param int $limit
36
+     * @param int $offset
37
+     * @param ISearchResult $searchResult
38
+     * @return bool whether the plugin has more results
39
+     * @since 13.0.0
40
+     */
41
+    public function search($search, $limit, $offset, ISearchResult $searchResult);
42 42
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Collaborators/ISearch.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -30,21 +30,21 @@
 block discarded – undo
30 30
  * @since 13.0.0
31 31
  */
32 32
 interface ISearch {
33
-	/**
34
-	 * @param string $search
35
-	 * @param array $shareTypes
36
-	 * @param bool $lookup
37
-	 * @param int $limit
38
-	 * @param int $offset
39
-	 * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available
40
-	 * @since 13.0.0
41
-	 */
42
-	public function search($search, array $shareTypes, $lookup, $limit, $offset);
33
+    /**
34
+     * @param string $search
35
+     * @param array $shareTypes
36
+     * @param bool $lookup
37
+     * @param int $limit
38
+     * @param int $offset
39
+     * @return array with two elements, 1st ISearchResult as array, 2nd a bool indicating whether more result are available
40
+     * @since 13.0.0
41
+     */
42
+    public function search($search, array $shareTypes, $lookup, $limit, $offset);
43 43
 
44
-	/**
45
-	 * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and
46
-	 * 	'class' with the class name of the plugin
47
-	 * @since 13.0.0
48
-	 */
49
-	public function registerPlugin(array $pluginInfo);
44
+    /**
45
+     * @param array $pluginInfo with keys 'shareType' containing the name of a corresponding constant in \OCP\Share and
46
+     * 	'class' with the class name of the plugin
47
+     * @since 13.0.0
48
+     */
49
+    public function registerPlugin(array $pluginInfo);
50 50
 }
Please login to merge, or discard this patch.
lib/public/Collaboration/Collaborators/ISearchResult.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -30,44 +30,44 @@
 block discarded – undo
30 30
  * @since 13.0.0
31 31
  */
32 32
 interface ISearchResult {
33
-	/**
34
-	 * @param SearchResultType $type
35
-	 * @param array $matches
36
-	 * @param array|null $exactMatches
37
-	 * @since 13.0.0
38
-	 */
39
-	public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null);
33
+    /**
34
+     * @param SearchResultType $type
35
+     * @param array $matches
36
+     * @param array|null $exactMatches
37
+     * @since 13.0.0
38
+     */
39
+    public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null);
40 40
 
41
-	/**
42
-	 * @param SearchResultType $type
43
-	 * @param string $collaboratorId
44
-	 * @return bool
45
-	 * @since 13.0.0
46
-	 */
47
-	public function hasResult(SearchResultType $type, $collaboratorId);
41
+    /**
42
+     * @param SearchResultType $type
43
+     * @param string $collaboratorId
44
+     * @return bool
45
+     * @since 13.0.0
46
+     */
47
+    public function hasResult(SearchResultType $type, $collaboratorId);
48 48
 
49
-	/**
50
-	 * @param SearchResultType $type
51
-	 * @since 13.0.0
52
-	 */
53
-	public function unsetResult(SearchResultType $type);
49
+    /**
50
+     * @param SearchResultType $type
51
+     * @since 13.0.0
52
+     */
53
+    public function unsetResult(SearchResultType $type);
54 54
 
55
-	/**
56
-	 * @param SearchResultType $type
57
-	 * @since 13.0.0
58
-	 */
59
-	public function markExactIdMatch(SearchResultType $type);
55
+    /**
56
+     * @param SearchResultType $type
57
+     * @since 13.0.0
58
+     */
59
+    public function markExactIdMatch(SearchResultType $type);
60 60
 
61
-	/**
62
-	 * @param SearchResultType $type
63
-	 * @return bool
64
-	 * @since 13.0.0
65
-	 */
66
-	public function hasExactIdMatch(SearchResultType $type);
61
+    /**
62
+     * @param SearchResultType $type
63
+     * @return bool
64
+     * @since 13.0.0
65
+     */
66
+    public function hasExactIdMatch(SearchResultType $type);
67 67
 
68
-	/**
69
-	 * @return array
70
-	 * @since 13.0.0
71
-	 */
72
-	public function asArray();
68
+    /**
69
+     * @return array
70
+     * @since 13.0.0
71
+     */
72
+    public function asArray();
73 73
 }
Please login to merge, or discard this patch.
lib/private/App/InfoParser.php 2 patches
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -30,203 +30,203 @@
 block discarded – undo
30 30
 use OCP\ICache;
31 31
 
32 32
 class InfoParser {
33
-	/** @var \OCP\ICache|null */
34
-	private $cache;
35
-
36
-	/**
37
-	 * @param ICache|null $cache
38
-	 */
39
-	public function __construct(ICache $cache = null) {
40
-		$this->cache = $cache;
41
-	}
42
-
43
-	/**
44
-	 * @param string $file the xml file to be loaded
45
-	 * @return null|array where null is an indicator for an error
46
-	 */
47
-	public function parse($file) {
48
-		if (!file_exists($file)) {
49
-			return null;
50
-		}
51
-
52
-		if(!is_null($this->cache)) {
53
-			$fileCacheKey = $file . filemtime($file);
54
-			if ($cachedValue = $this->cache->get($fileCacheKey)) {
55
-				return json_decode($cachedValue, true);
56
-			}
57
-		}
58
-
59
-		libxml_use_internal_errors(true);
60
-		$loadEntities = libxml_disable_entity_loader(false);
61
-		$xml = simplexml_load_file($file);
62
-
63
-		libxml_disable_entity_loader($loadEntities);
64
-		if ($xml === false) {
65
-			libxml_clear_errors();
66
-			return null;
67
-		}
68
-		$array = $this->xmlToArray($xml);
69
-
70
-		if (is_null($array)) {
71
-			return null;
72
-		}
73
-
74
-		if (!array_key_exists('info', $array)) {
75
-			$array['info'] = [];
76
-		}
77
-		if (!array_key_exists('remote', $array)) {
78
-			$array['remote'] = [];
79
-		}
80
-		if (!array_key_exists('public', $array)) {
81
-			$array['public'] = [];
82
-		}
83
-		if (!array_key_exists('types', $array)) {
84
-			$array['types'] = [];
85
-		}
86
-		if (!array_key_exists('repair-steps', $array)) {
87
-			$array['repair-steps'] = [];
88
-		}
89
-		if (!array_key_exists('install', $array['repair-steps'])) {
90
-			$array['repair-steps']['install'] = [];
91
-		}
92
-		if (!array_key_exists('pre-migration', $array['repair-steps'])) {
93
-			$array['repair-steps']['pre-migration'] = [];
94
-		}
95
-		if (!array_key_exists('post-migration', $array['repair-steps'])) {
96
-			$array['repair-steps']['post-migration'] = [];
97
-		}
98
-		if (!array_key_exists('live-migration', $array['repair-steps'])) {
99
-			$array['repair-steps']['live-migration'] = [];
100
-		}
101
-		if (!array_key_exists('uninstall', $array['repair-steps'])) {
102
-			$array['repair-steps']['uninstall'] = [];
103
-		}
104
-		if (!array_key_exists('background-jobs', $array)) {
105
-			$array['background-jobs'] = [];
106
-		}
107
-		if (!array_key_exists('two-factor-providers', $array)) {
108
-			$array['two-factor-providers'] = [];
109
-		}
110
-		if (!array_key_exists('commands', $array)) {
111
-			$array['commands'] = [];
112
-		}
113
-		if (!array_key_exists('activity', $array)) {
114
-			$array['activity'] = [];
115
-		}
116
-		if (!array_key_exists('filters', $array['activity'])) {
117
-			$array['activity']['filters'] = [];
118
-		}
119
-		if (!array_key_exists('settings', $array['activity'])) {
120
-			$array['activity']['settings'] = [];
121
-		}
122
-		if (!array_key_exists('providers', $array['activity'])) {
123
-			$array['activity']['providers'] = [];
124
-		}
125
-
126
-		if (array_key_exists('types', $array)) {
127
-			if (is_array($array['types'])) {
128
-				foreach ($array['types'] as $type => $v) {
129
-					unset($array['types'][$type]);
130
-					if (is_string($type)) {
131
-						$array['types'][] = $type;
132
-					}
133
-				}
134
-			} else {
135
-				$array['types'] = [];
136
-			}
137
-		}
138
-		if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
139
-			$array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
140
-		}
141
-		if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
142
-			$array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
143
-		}
144
-		if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
145
-			$array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
146
-		}
147
-		if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
148
-			$array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
149
-		}
150
-		if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
151
-			$array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
152
-		}
153
-		if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
154
-			$array['background-jobs'] = $array['background-jobs']['job'];
155
-		}
156
-		if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
157
-			$array['commands'] = $array['commands']['command'];
158
-		}
159
-		if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
160
-			$array['activity']['filters'] = $array['activity']['filters']['filter'];
161
-		}
162
-		if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
163
-			$array['activity']['settings'] = $array['activity']['settings']['setting'];
164
-		}
165
-		if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
166
-			$array['activity']['providers'] = $array['activity']['providers']['provider'];
167
-		}
168
-		if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
169
-			&& is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
170
-			&& !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
171
-		) {
172
-			$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
173
-		}
174
-
175
-		if(!is_null($this->cache)) {
176
-			$this->cache->set($fileCacheKey, json_encode($array));
177
-		}
178
-		return $array;
179
-	}
180
-
181
-	/**
182
-	 * @param \SimpleXMLElement $xml
183
-	 * @return array
184
-	 */
185
-	public function xmlToArray($xml) {
186
-		if (!$xml->children()) {
187
-			return (string)$xml;
188
-		}
189
-
190
-		$array = [];
191
-		foreach ($xml->children() as $element => $node) {
192
-			$totalElement = count($xml->{$element});
193
-
194
-			if (!isset($array[$element])) {
195
-				$array[$element] = $totalElement > 1 ? [] : "";
196
-			}
197
-			/** @var \SimpleXMLElement $node */
198
-			// Has attributes
199
-			if ($attributes = $node->attributes()) {
200
-				$data = [
201
-					'@attributes' => [],
202
-				];
203
-				if (!count($node->children())){
204
-					$value = (string)$node;
205
-					if (!empty($value)) {
206
-						$data['@value'] = (string)$node;
207
-					}
208
-				} else {
209
-					$data = array_merge($data, $this->xmlToArray($node));
210
-				}
211
-				foreach ($attributes as $attr => $value) {
212
-					$data['@attributes'][$attr] = (string)$value;
213
-				}
214
-
215
-				if ($totalElement > 1) {
216
-					$array[$element][] = $data;
217
-				} else {
218
-					$array[$element] = $data;
219
-				}
220
-				// Just a value
221
-			} else {
222
-				if ($totalElement > 1) {
223
-					$array[$element][] = $this->xmlToArray($node);
224
-				} else {
225
-					$array[$element] = $this->xmlToArray($node);
226
-				}
227
-			}
228
-		}
229
-
230
-		return $array;
231
-	}
33
+    /** @var \OCP\ICache|null */
34
+    private $cache;
35
+
36
+    /**
37
+     * @param ICache|null $cache
38
+     */
39
+    public function __construct(ICache $cache = null) {
40
+        $this->cache = $cache;
41
+    }
42
+
43
+    /**
44
+     * @param string $file the xml file to be loaded
45
+     * @return null|array where null is an indicator for an error
46
+     */
47
+    public function parse($file) {
48
+        if (!file_exists($file)) {
49
+            return null;
50
+        }
51
+
52
+        if(!is_null($this->cache)) {
53
+            $fileCacheKey = $file . filemtime($file);
54
+            if ($cachedValue = $this->cache->get($fileCacheKey)) {
55
+                return json_decode($cachedValue, true);
56
+            }
57
+        }
58
+
59
+        libxml_use_internal_errors(true);
60
+        $loadEntities = libxml_disable_entity_loader(false);
61
+        $xml = simplexml_load_file($file);
62
+
63
+        libxml_disable_entity_loader($loadEntities);
64
+        if ($xml === false) {
65
+            libxml_clear_errors();
66
+            return null;
67
+        }
68
+        $array = $this->xmlToArray($xml);
69
+
70
+        if (is_null($array)) {
71
+            return null;
72
+        }
73
+
74
+        if (!array_key_exists('info', $array)) {
75
+            $array['info'] = [];
76
+        }
77
+        if (!array_key_exists('remote', $array)) {
78
+            $array['remote'] = [];
79
+        }
80
+        if (!array_key_exists('public', $array)) {
81
+            $array['public'] = [];
82
+        }
83
+        if (!array_key_exists('types', $array)) {
84
+            $array['types'] = [];
85
+        }
86
+        if (!array_key_exists('repair-steps', $array)) {
87
+            $array['repair-steps'] = [];
88
+        }
89
+        if (!array_key_exists('install', $array['repair-steps'])) {
90
+            $array['repair-steps']['install'] = [];
91
+        }
92
+        if (!array_key_exists('pre-migration', $array['repair-steps'])) {
93
+            $array['repair-steps']['pre-migration'] = [];
94
+        }
95
+        if (!array_key_exists('post-migration', $array['repair-steps'])) {
96
+            $array['repair-steps']['post-migration'] = [];
97
+        }
98
+        if (!array_key_exists('live-migration', $array['repair-steps'])) {
99
+            $array['repair-steps']['live-migration'] = [];
100
+        }
101
+        if (!array_key_exists('uninstall', $array['repair-steps'])) {
102
+            $array['repair-steps']['uninstall'] = [];
103
+        }
104
+        if (!array_key_exists('background-jobs', $array)) {
105
+            $array['background-jobs'] = [];
106
+        }
107
+        if (!array_key_exists('two-factor-providers', $array)) {
108
+            $array['two-factor-providers'] = [];
109
+        }
110
+        if (!array_key_exists('commands', $array)) {
111
+            $array['commands'] = [];
112
+        }
113
+        if (!array_key_exists('activity', $array)) {
114
+            $array['activity'] = [];
115
+        }
116
+        if (!array_key_exists('filters', $array['activity'])) {
117
+            $array['activity']['filters'] = [];
118
+        }
119
+        if (!array_key_exists('settings', $array['activity'])) {
120
+            $array['activity']['settings'] = [];
121
+        }
122
+        if (!array_key_exists('providers', $array['activity'])) {
123
+            $array['activity']['providers'] = [];
124
+        }
125
+
126
+        if (array_key_exists('types', $array)) {
127
+            if (is_array($array['types'])) {
128
+                foreach ($array['types'] as $type => $v) {
129
+                    unset($array['types'][$type]);
130
+                    if (is_string($type)) {
131
+                        $array['types'][] = $type;
132
+                    }
133
+                }
134
+            } else {
135
+                $array['types'] = [];
136
+            }
137
+        }
138
+        if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) {
139
+            $array['repair-steps']['install'] = $array['repair-steps']['install']['step'];
140
+        }
141
+        if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) {
142
+            $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step'];
143
+        }
144
+        if (isset($array['repair-steps']['post-migration']['step']) && is_array($array['repair-steps']['post-migration']['step'])) {
145
+            $array['repair-steps']['post-migration'] = $array['repair-steps']['post-migration']['step'];
146
+        }
147
+        if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) {
148
+            $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step'];
149
+        }
150
+        if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) {
151
+            $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step'];
152
+        }
153
+        if (isset($array['background-jobs']['job']) && is_array($array['background-jobs']['job'])) {
154
+            $array['background-jobs'] = $array['background-jobs']['job'];
155
+        }
156
+        if (isset($array['commands']['command']) && is_array($array['commands']['command'])) {
157
+            $array['commands'] = $array['commands']['command'];
158
+        }
159
+        if (isset($array['activity']['filters']['filter']) && is_array($array['activity']['filters']['filter'])) {
160
+            $array['activity']['filters'] = $array['activity']['filters']['filter'];
161
+        }
162
+        if (isset($array['activity']['settings']['setting']) && is_array($array['activity']['settings']['setting'])) {
163
+            $array['activity']['settings'] = $array['activity']['settings']['setting'];
164
+        }
165
+        if (isset($array['activity']['providers']['provider']) && is_array($array['activity']['providers']['provider'])) {
166
+            $array['activity']['providers'] = $array['activity']['providers']['provider'];
167
+        }
168
+        if (isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
169
+            && is_array($array['collaboration']['collaborators']['searchPlugins']['searchPlugin'])
170
+            && !isset($array['collaboration']['collaborators']['searchPlugins']['searchPlugin']['class'])
171
+        ) {
172
+            $array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
173
+        }
174
+
175
+        if(!is_null($this->cache)) {
176
+            $this->cache->set($fileCacheKey, json_encode($array));
177
+        }
178
+        return $array;
179
+    }
180
+
181
+    /**
182
+     * @param \SimpleXMLElement $xml
183
+     * @return array
184
+     */
185
+    public function xmlToArray($xml) {
186
+        if (!$xml->children()) {
187
+            return (string)$xml;
188
+        }
189
+
190
+        $array = [];
191
+        foreach ($xml->children() as $element => $node) {
192
+            $totalElement = count($xml->{$element});
193
+
194
+            if (!isset($array[$element])) {
195
+                $array[$element] = $totalElement > 1 ? [] : "";
196
+            }
197
+            /** @var \SimpleXMLElement $node */
198
+            // Has attributes
199
+            if ($attributes = $node->attributes()) {
200
+                $data = [
201
+                    '@attributes' => [],
202
+                ];
203
+                if (!count($node->children())){
204
+                    $value = (string)$node;
205
+                    if (!empty($value)) {
206
+                        $data['@value'] = (string)$node;
207
+                    }
208
+                } else {
209
+                    $data = array_merge($data, $this->xmlToArray($node));
210
+                }
211
+                foreach ($attributes as $attr => $value) {
212
+                    $data['@attributes'][$attr] = (string)$value;
213
+                }
214
+
215
+                if ($totalElement > 1) {
216
+                    $array[$element][] = $data;
217
+                } else {
218
+                    $array[$element] = $data;
219
+                }
220
+                // Just a value
221
+            } else {
222
+                if ($totalElement > 1) {
223
+                    $array[$element][] = $this->xmlToArray($node);
224
+                } else {
225
+                    $array[$element] = $this->xmlToArray($node);
226
+                }
227
+            }
228
+        }
229
+
230
+        return $array;
231
+    }
232 232
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
 			return null;
50 50
 		}
51 51
 
52
-		if(!is_null($this->cache)) {
53
-			$fileCacheKey = $file . filemtime($file);
52
+		if (!is_null($this->cache)) {
53
+			$fileCacheKey = $file.filemtime($file);
54 54
 			if ($cachedValue = $this->cache->get($fileCacheKey)) {
55 55
 				return json_decode($cachedValue, true);
56 56
 			}
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 			$array['collaboration']['collaborators']['searchPlugins'] = $array['collaboration']['collaborators']['searchPlugins']['searchPlugin'];
173 173
 		}
174 174
 
175
-		if(!is_null($this->cache)) {
175
+		if (!is_null($this->cache)) {
176 176
 			$this->cache->set($fileCacheKey, json_encode($array));
177 177
 		}
178 178
 		return $array;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 	 */
185 185
 	public function xmlToArray($xml) {
186 186
 		if (!$xml->children()) {
187
-			return (string)$xml;
187
+			return (string) $xml;
188 188
 		}
189 189
 
190 190
 		$array = [];
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
 				$data = [
201 201
 					'@attributes' => [],
202 202
 				];
203
-				if (!count($node->children())){
204
-					$value = (string)$node;
203
+				if (!count($node->children())) {
204
+					$value = (string) $node;
205 205
 					if (!empty($value)) {
206
-						$data['@value'] = (string)$node;
206
+						$data['@value'] = (string) $node;
207 207
 					}
208 208
 				} else {
209 209
 					$data = array_merge($data, $this->xmlToArray($node));
210 210
 				}
211 211
 				foreach ($attributes as $attr => $value) {
212
-					$data['@attributes'][$attr] = (string)$value;
212
+					$data['@attributes'][$attr] = (string) $value;
213 213
 				}
214 214
 
215 215
 				if ($totalElement > 1) {
Please login to merge, or discard this patch.
lib/private/Collaboration/Collaborators/MailPlugin.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 
87 87
 							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
88 88
 								$singleResult = [[
89
-									'label' => $contact['FN'] . " ($emailAddress)",
89
+									'label' => $contact['FN']." ($emailAddress)",
90 90
 									'value' => [
91 91
 										'shareType' => Share::SHARE_TYPE_USER,
92 92
 										'shareWith' => $cloud->getUser(),
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 
108 108
 							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
109 109
 								$singleResult = [[
110
-									'label' => $contact['FN'] . " ($emailAddress)",
110
+									'label' => $contact['FN']." ($emailAddress)",
111 111
 									'value' => [
112 112
 										'shareType' => Share::SHARE_TYPE_USER,
113 113
 										'shareWith' => $cloud->getUser(),
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 							$searchResult->markExactIdMatch($emailType);
125 125
 						}
126 126
 						$result['exact'][] = [
127
-							'label' => $contact['FN'] . " ($emailAddress)",
127
+							'label' => $contact['FN']." ($emailAddress)",
128 128
 							'value' => [
129 129
 								'shareType' => Share::SHARE_TYPE_EMAIL,
130 130
 								'shareWith' => $emailAddress,
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 						];
133 133
 					} else {
134 134
 						$result['wide'][] = [
135
-							'label' => $contact['FN'] . " ($emailAddress)",
135
+							'label' => $contact['FN']." ($emailAddress)",
136 136
 							'value' => [
137 137
 								'shareType' => Share::SHARE_TYPE_EMAIL,
138 138
 								'shareWith' => $emailAddress,
Please login to merge, or discard this patch.
Indentation   +128 added lines, -128 removed lines patch added patch discarded remove patch
@@ -33,132 +33,132 @@
 block discarded – undo
33 33
 use OCP\Share;
34 34
 
35 35
 class MailPlugin implements ISearchPlugin {
36
-	protected $shareeEnumeration;
37
-
38
-	/** @var IManager */
39
-	private $contactsManager;
40
-	/** @var ICloudIdManager */
41
-	private $cloudIdManager;
42
-	/** @var IConfig */
43
-	private $config;
44
-
45
-	public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
46
-		$this->contactsManager = $contactsManager;
47
-		$this->cloudIdManager = $cloudIdManager;
48
-		$this->config = $config;
49
-
50
-		$this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
-	}
52
-
53
-	/**
54
-	 * @param $search
55
-	 * @param $limit
56
-	 * @param $offset
57
-	 * @param ISearchResult $searchResult
58
-	 * @return bool
59
-	 * @since 13.0.0
60
-	 */
61
-	public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
-		$result = ['wide' => [], 'exact' => []];
63
-		$userType = new SearchResultType('users');
64
-		$emailType = new SearchResultType('emails');
65
-
66
-		// Search in contacts
67
-		//@todo Pagination missing
68
-		$addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
69
-		$lowerSearch = strtolower($search);
70
-		foreach ($addressBookContacts as $contact) {
71
-			if (isset($contact['EMAIL'])) {
72
-				$emailAddresses = $contact['EMAIL'];
73
-				if (!is_array($emailAddresses)) {
74
-					$emailAddresses = [$emailAddresses];
75
-				}
76
-				foreach ($emailAddresses as $emailAddress) {
77
-					$exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
78
-
79
-					if (isset($contact['isLocalSystemBook'])) {
80
-						if ($exactEmailMatch) {
81
-							try {
82
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
83
-							} catch (\InvalidArgumentException $e) {
84
-								continue;
85
-							}
86
-
87
-							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
88
-								$singleResult = [[
89
-									'label' => $contact['FN'] . " ($emailAddress)",
90
-									'value' => [
91
-										'shareType' => Share::SHARE_TYPE_USER,
92
-										'shareWith' => $cloud->getUser(),
93
-									],
94
-								]];
95
-								$searchResult->addResultSet($userType, [], $singleResult);
96
-								$searchResult->markExactIdMatch($emailType);
97
-							}
98
-							return false;
99
-						}
100
-
101
-						if ($this->shareeEnumeration) {
102
-							try {
103
-								$cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
104
-							} catch (\InvalidArgumentException $e) {
105
-								continue;
106
-							}
107
-
108
-							if (!$searchResult->hasResult($userType, $cloud->getUser())) {
109
-								$singleResult = [[
110
-									'label' => $contact['FN'] . " ($emailAddress)",
111
-									'value' => [
112
-										'shareType' => Share::SHARE_TYPE_USER,
113
-										'shareWith' => $cloud->getUser(),
114
-									]],
115
-								];
116
-								$searchResult->addResultSet($userType, $singleResult, []);
117
-							}
118
-						}
119
-						continue;
120
-					}
121
-
122
-					if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
123
-						if ($exactEmailMatch) {
124
-							$searchResult->markExactIdMatch($emailType);
125
-						}
126
-						$result['exact'][] = [
127
-							'label' => $contact['FN'] . " ($emailAddress)",
128
-							'value' => [
129
-								'shareType' => Share::SHARE_TYPE_EMAIL,
130
-								'shareWith' => $emailAddress,
131
-							],
132
-						];
133
-					} else {
134
-						$result['wide'][] = [
135
-							'label' => $contact['FN'] . " ($emailAddress)",
136
-							'value' => [
137
-								'shareType' => Share::SHARE_TYPE_EMAIL,
138
-								'shareWith' => $emailAddress,
139
-							],
140
-						];
141
-					}
142
-				}
143
-			}
144
-		}
145
-
146
-		if (!$this->shareeEnumeration) {
147
-			$result['wide'] = [];
148
-		}
149
-
150
-		if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
151
-			$result['exact'][] = [
152
-				'label' => $search,
153
-				'value' => [
154
-					'shareType' => Share::SHARE_TYPE_EMAIL,
155
-					'shareWith' => $search,
156
-				],
157
-			];
158
-		}
159
-
160
-		$searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
161
-
162
-		return true;
163
-	}
36
+    protected $shareeEnumeration;
37
+
38
+    /** @var IManager */
39
+    private $contactsManager;
40
+    /** @var ICloudIdManager */
41
+    private $cloudIdManager;
42
+    /** @var IConfig */
43
+    private $config;
44
+
45
+    public function __construct(IManager $contactsManager, ICloudIdManager $cloudIdManager, IConfig $config) {
46
+        $this->contactsManager = $contactsManager;
47
+        $this->cloudIdManager = $cloudIdManager;
48
+        $this->config = $config;
49
+
50
+        $this->shareeEnumeration = $this->config->getAppValue('core', 'shareapi_allow_share_dialog_user_enumeration', 'yes') === 'yes';
51
+    }
52
+
53
+    /**
54
+     * @param $search
55
+     * @param $limit
56
+     * @param $offset
57
+     * @param ISearchResult $searchResult
58
+     * @return bool
59
+     * @since 13.0.0
60
+     */
61
+    public function search($search, $limit, $offset, ISearchResult $searchResult) {
62
+        $result = ['wide' => [], 'exact' => []];
63
+        $userType = new SearchResultType('users');
64
+        $emailType = new SearchResultType('emails');
65
+
66
+        // Search in contacts
67
+        //@todo Pagination missing
68
+        $addressBookContacts = $this->contactsManager->search($search, ['EMAIL', 'FN']);
69
+        $lowerSearch = strtolower($search);
70
+        foreach ($addressBookContacts as $contact) {
71
+            if (isset($contact['EMAIL'])) {
72
+                $emailAddresses = $contact['EMAIL'];
73
+                if (!is_array($emailAddresses)) {
74
+                    $emailAddresses = [$emailAddresses];
75
+                }
76
+                foreach ($emailAddresses as $emailAddress) {
77
+                    $exactEmailMatch = strtolower($emailAddress) === $lowerSearch;
78
+
79
+                    if (isset($contact['isLocalSystemBook'])) {
80
+                        if ($exactEmailMatch) {
81
+                            try {
82
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
83
+                            } catch (\InvalidArgumentException $e) {
84
+                                continue;
85
+                            }
86
+
87
+                            if (!$searchResult->hasResult($userType, $cloud->getUser())) {
88
+                                $singleResult = [[
89
+                                    'label' => $contact['FN'] . " ($emailAddress)",
90
+                                    'value' => [
91
+                                        'shareType' => Share::SHARE_TYPE_USER,
92
+                                        'shareWith' => $cloud->getUser(),
93
+                                    ],
94
+                                ]];
95
+                                $searchResult->addResultSet($userType, [], $singleResult);
96
+                                $searchResult->markExactIdMatch($emailType);
97
+                            }
98
+                            return false;
99
+                        }
100
+
101
+                        if ($this->shareeEnumeration) {
102
+                            try {
103
+                                $cloud = $this->cloudIdManager->resolveCloudId($contact['CLOUD'][0]);
104
+                            } catch (\InvalidArgumentException $e) {
105
+                                continue;
106
+                            }
107
+
108
+                            if (!$searchResult->hasResult($userType, $cloud->getUser())) {
109
+                                $singleResult = [[
110
+                                    'label' => $contact['FN'] . " ($emailAddress)",
111
+                                    'value' => [
112
+                                        'shareType' => Share::SHARE_TYPE_USER,
113
+                                        'shareWith' => $cloud->getUser(),
114
+                                    ]],
115
+                                ];
116
+                                $searchResult->addResultSet($userType, $singleResult, []);
117
+                            }
118
+                        }
119
+                        continue;
120
+                    }
121
+
122
+                    if ($exactEmailMatch || strtolower($contact['FN']) === $lowerSearch) {
123
+                        if ($exactEmailMatch) {
124
+                            $searchResult->markExactIdMatch($emailType);
125
+                        }
126
+                        $result['exact'][] = [
127
+                            'label' => $contact['FN'] . " ($emailAddress)",
128
+                            'value' => [
129
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
130
+                                'shareWith' => $emailAddress,
131
+                            ],
132
+                        ];
133
+                    } else {
134
+                        $result['wide'][] = [
135
+                            'label' => $contact['FN'] . " ($emailAddress)",
136
+                            'value' => [
137
+                                'shareType' => Share::SHARE_TYPE_EMAIL,
138
+                                'shareWith' => $emailAddress,
139
+                            ],
140
+                        ];
141
+                    }
142
+                }
143
+            }
144
+        }
145
+
146
+        if (!$this->shareeEnumeration) {
147
+            $result['wide'] = [];
148
+        }
149
+
150
+        if (!$searchResult->hasExactIdMatch($emailType) && filter_var($search, FILTER_VALIDATE_EMAIL)) {
151
+            $result['exact'][] = [
152
+                'label' => $search,
153
+                'value' => [
154
+                    'shareType' => Share::SHARE_TYPE_EMAIL,
155
+                    'shareWith' => $search,
156
+                ],
157
+            ];
158
+        }
159
+
160
+        $searchResult->addResultSet($emailType, $result['wide'], $result['exact']);
161
+
162
+        return true;
163
+    }
164 164
 }
Please login to merge, or discard this patch.