Server   F
last analyzed

Complexity

Total Complexity 128

Size/Duplication

Total Lines 1556
Duplicated Lines 6.43 %

Coupling/Cohesion

Components 1
Dependencies 128

Importance

Changes 0
Metric Value
dl 100
loc 1556
rs 0.8
c 0
b 0
f 0
wmc 128
lcom 1
cbo 128

85 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 85 767 27
A getContactsManager() 0 3 1
A getEncryptionManager() 0 3 1
A getEncryptionFilesHelper() 0 3 1
A getEncryptionKeyStorage() 0 3 1
A getRequest() 0 3 1
A getPreviewManager() 0 3 1
A getTagManager() 0 3 1
A getSystemTagManager() 0 3 1
A getSystemTagObjectMapper() 0 3 1
A getAvatarManager() 0 3 1
A getRootFolder() 0 3 1
A getLazyRootFolder() 0 3 1
A getUserFolder() 7 11 3
A getAppFolder() 0 10 2
A getUserManager() 0 3 1
A getAccountMapper() 0 3 1
A getGroupManager() 0 3 1
A getUserSession() 0 6 2
A getSession() 0 7 2
A setSession() 0 7 2
A getTwoFactorAuthManager() 0 3 1
A getAccountModuleManager() 0 3 1
A getNavigationManager() 0 3 1
A getConfig() 0 3 1
A getSystemConfig() 0 3 1
A getAppConfig() 0 3 1
A getL10NFactory() 0 3 1
A getL10N() 0 3 1
A getURLGenerator() 0 3 1
A getHelper() 0 3 1
A getCache() 0 3 1
A getMemCacheFactory() 0 3 1
A getGetRedisFactory() 0 3 1
A getDatabaseConnection() 0 3 1
A getActivityManager() 0 3 1
A getJobList() 0 3 1
A getLogger() 0 6 2
A getSettingsManager() 0 3 1
A getRouter() 0 3 1
A getSearch() 0 3 1
A getSecureRandom() 0 3 1
A getCrypto() 0 3 1
A getHasher() 0 3 1
A getCredentialsManager() 0 3 1
A getDb() 0 3 1
A getHTTPHelper() 0 3 1
A getCertificateManager() 8 11 3
A getHTTPClientService() 0 3 1
A getWebDavClientService() 0 3 1
A createEventSource() 0 3 1
A getEventLogger() 0 3 1
A getQueryLogger() 0 3 1
A getTempManager() 0 3 1
A getAppManager() 0 3 1
A getMailer() 0 3 1
A getWebRoot() 0 3 1
A getDateTimeZone() 0 3 1
A getDateTimeFormatter() 0 3 1
A getMountProviderCollection() 0 3 1
A getIniWrapper() 0 3 1
A getCommandBus() 0 3 1
A getTrustedDomainHelper() 0 3 1
A getLockingProvider() 0 3 1
A getMountManager() 0 3 1
A getMimeTypeDetector() 0 3 1
A getMimeTypeLoader() 0 3 1
A getCapabilitiesManager() 0 3 1
A getEventDispatcher() 0 3 1
A getNotificationManager() 0 3 1
A getCommentsManager() 0 3 1
A getIntegrityCodeChecker() 0 3 1
A getSessionCryptoWrapper() 0 3 1
A getCsrfTokenManager() 0 3 1
A getContentSecurityPolicyManager() 0 3 1
A getStoragesBackendService() 0 3 1
A getGlobalStoragesService() 0 3 1
A getUserGlobalStoragesService() 0 3 1
A getUserStoragesService() 0 3 1
A getShareManager() 0 3 1
A getThemeService() 0 3 1
A getTimeFactory() 0 3 1
A getServiceLoader() 0 3 1
B load() 0 30 9
A getShutdownHandler() 0 3 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like Server often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Server, and based on these observations, apply Extract Interface, too.

1
<?php
2
/**
3
 * @author Arthur Schiwon <[email protected]>
4
 * @author Bart Visscher <[email protected]>
5
 * @author Bernhard Posselt <[email protected]>
6
 * @author Bernhard Reiter <[email protected]>
7
 * @author Björn Schießle <[email protected]>
8
 * @author Christopher Schäpers <[email protected]>
9
 * @author Christoph Wurst <[email protected]>
10
 * @author Joas Schilling <[email protected]>
11
 * @author Jörn Friedrich Dreyer <[email protected]>
12
 * @author Lukas Reschke <[email protected]>
13
 * @author Morris Jobke <[email protected]>
14
 * @author Philipp Schaffrath <[email protected]>
15
 * @author Robin Appelman <[email protected]>
16
 * @author Robin McCorkell <[email protected]>
17
 * @author Roeland Jago Douma <[email protected]>
18
 * @author Roeland Jago Douma <[email protected]>
19
 * @author Sander <[email protected]>
20
 * @author Thomas Müller <[email protected]>
21
 * @author Thomas Tanghus <[email protected]>
22
 * @author Tom Needham <[email protected]>
23
 * @author Vincent Petry <[email protected]>
24
 *
25
 * @copyright Copyright (c) 2018, ownCloud GmbH
26
 * @license AGPL-3.0
27
 *
28
 * This code is free software: you can redistribute it and/or modify
29
 * it under the terms of the GNU Affero General Public License, version 3,
30
 * as published by the Free Software Foundation.
31
 *
32
 * This program is distributed in the hope that it will be useful,
33
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
 * GNU Affero General Public License for more details.
36
 *
37
 * You should have received a copy of the GNU Affero General Public License, version 3,
38
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
39
 *
40
 */
41
namespace OC;
42
43
use bantu\IniGetWrapper\IniGetWrapper;
44
use OC\AppFramework\Http\Request;
45
use OC\AppFramework\Db\Db;
46
use OC\AppFramework\Utility\TimeFactory;
47
use OC\Authentication\AccountModule\Manager as AccountModuleManager;
48
use OC\Command\AsyncBus;
49
use OC\Diagnostics\EventLogger;
50
use OC\Diagnostics\QueryLogger;
51
use OC\Files\Config\UserMountCache;
52
use OC\Files\Config\UserMountCacheListener;
53
use OC\Files\Mount\CacheMountProvider;
54
use OC\Files\Mount\LocalHomeMountProvider;
55
use OC\Files\Mount\ObjectHomeMountProvider;
56
use OC\Files\Node\HookConnector;
57
use OC\Files\Node\LazyRoot;
58
use OC\Files\Node\Root;
59
use OC\Files\View;
60
use OC\Http\Client\ClientService;
61
use OC\IntegrityCheck\Checker;
62
use OC\IntegrityCheck\Helpers\AppLocator;
63
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
64
use OC\IntegrityCheck\Helpers\FileAccessHelper;
65
use OC\Lock\DBLockingProvider;
66
use OC\Lock\MemcacheLockingProvider;
67
use OC\Lock\NoopLockingProvider;
68
use OC\Mail\Mailer;
69
use OC\Memcache\ArrayCache;
70
use OC\Notification\Manager;
71
use OC\Security\CertificateManager;
72
use OC\Security\CSP\ContentSecurityPolicyManager;
73
use OC\Security\Crypto;
74
use OC\Security\CSRF\CsrfTokenGenerator;
75
use OC\Security\CSRF\CsrfTokenManager;
76
use OC\Security\CSRF\TokenStorage\SessionStorage;
77
use OC\Security\Hasher;
78
use OC\Security\CredentialsManager;
79
use OC\Security\SecureRandom;
80
use OC\Security\TrustedDomainHelper;
81
use OC\Session\CryptoWrapper;
82
use OC\Session\Memory;
83
use OC\Settings\Panels\Helper;
84
use OC\Settings\SettingsManager;
85
use OC\Shutdown\ShutDownManager;
86
use OC\Tagging\TagMapper;
87
use OC\Theme\ThemeService;
88
use OC\User\AccountMapper;
89
use OC\User\AccountTermMapper;
90
use OC\User\Session;
91
use OC\User\SyncService;
92
use OCP\App\IServiceLoader;
93
use OCP\AppFramework\QueryException;
94
use OCP\AppFramework\Utility\ITimeFactory;
95
use OCP\Events\EventEmitterTrait;
96
use OCP\IConfig;
97
use OCP\IDBConnection;
98
use OCP\IL10N;
99
use OCP\ILogger;
100
use OCP\IServerContainer;
101
use OCP\ISession;
102
use OCP\IUser;
103
use OCP\Security\IContentSecurityPolicyManager;
104
use OCP\Shutdown\IShutdownManager;
105
use OCP\Theme\IThemeService;
106
use OCP\Util\UserSearch;
107
use Symfony\Component\EventDispatcher\EventDispatcher;
108
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
109
use OC\Files\External\StoragesBackendService;
110
use OC\Files\External\Service\UserStoragesService;
111
use OC\Files\External\Service\UserGlobalStoragesService;
112
use OC\Files\External\Service\GlobalStoragesService;
113
use OC\Files\External\Service\DBConfigService;
114
use OC\Http\Client\WebDavClientService;
115
use Symfony\Component\EventDispatcher\GenericEvent;
116
117
/**
118
 * Class Server
119
 *
120
 * @package OC
121
 *
122
 * TODO: hookup all manager classes
123
 */
124
class Server extends ServerContainer implements IServerContainer, IServiceLoader {
125
	use EventEmitterTrait;
126
	/** @var string */
127
	private $webRoot;
128
129
	/**
130
	 * cache the logger to prevent querying it over and over again
131
	 * @var ILogger;
132
	 */
133
	private $logger;
134
135
	/**
136
	 * @param string $webRoot
137
	 * @param \OC\Config $config
138
	 */
139
	public function __construct($webRoot, \OC\Config $config) {
140
		parent::__construct();
141
		$this->webRoot = $webRoot;
142
143
		$this->registerService('SettingsManager', function (Server $c) {
144
			return new SettingsManager(
145
				$c->getL10N('lib'),
146
				$c->getAppManager(),
147
				$c->getUserSession(),
148
				$c->getLogger(),
149
				$c->getGroupManager(),
150
				$c->getConfig(),
151
				new \OCP\Defaults(),
152
				$c->getURLGenerator(),
153
				new Helper(),
154
				$c->getLockingProvider(),
155
				$c->getDatabaseConnection(),
156
				$c->getCertificateManager(),
0 ignored issues
show
Bug introduced by
It seems like $c->getCertificateManager() can be null; however, __construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
157
				$c->getL10NFactory()
158
159
			);
160
		});
161
162
		$this->registerService('ContactsManager', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
163
			return new ContactsManager();
164
		});
165
166
		$this->registerService('PreviewManager', function (Server $c) {
167
			return new PreviewManager($c->getConfig(),
168
				$c->getLazyRootFolder(),
169
				$c->getUserSession());
170
		});
171
172
		$this->registerService('EncryptionManager', function (Server $c) {
173
			$view = new View();
174
			$util = new Encryption\Util(
175
				$view,
176
				$c->getUserManager(),
177
				$c->getGroupManager(),
178
				$c->getConfig()
179
			);
180
			return new Encryption\Manager(
181
				$c->getConfig(),
182
				$c->getLogger(),
183
				$c->getL10N('core'),
184
				new View(),
185
				$util,
186
				new ArrayCache()
187
			);
188
		});
189
190
		$this->registerService('EncryptionFileHelper', function (Server $c) {
191
			$util = new Encryption\Util(
192
				new View(),
193
				$c->getUserManager(),
194
				$c->getGroupManager(),
195
				$c->getConfig()
196
			);
197
			return new Encryption\File($util);
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(
210
				$view,
211
				$util,
212
				$c->getUserSession()
213
			);
214
		});
215
		$this->registerService('TagMapper', function (Server $c) {
216
			return new TagMapper($c->getDatabaseConnection());
217
		});
218
		$this->registerService('TagManager', function (Server $c) {
219
			$tagMapper = $c->query('TagMapper');
220
			return new TagManager($tagMapper, $c->getUserSession());
221
		});
222 View Code Duplication
		$this->registerService('SystemTagManagerFactory', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
223
			$config = $c->getConfig();
224
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
225
			/** @var \OC\SystemTag\ManagerFactory $factory */
226
			$factory = new $factoryClass($this);
227
			return $factory;
228
		});
229
		$this->registerService('SystemTagManager', function (Server $c) {
230
			return $c->query('SystemTagManagerFactory')->getManager();
231
		});
232
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
233
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
234
		});
235
		$this->registerService('RootFolder', function () {
236
			$manager = \OC\Files\Filesystem::getMountManager(null);
237
			$view = new View();
238
			$root = new Root($manager, $view, null);
239
			$connector = new HookConnector($root, $view);
240
			$connector->viewToNode();
241
			return $root;
242
		});
243
		$this->registerService('LazyRootFolder', function (Server $c) {
244
			return new LazyRoot(function () use ($c) {
245
				return $c->getRootFolder();
246
			});
247
		});
248
		$this->registerService('AccountMapper', function (Server $c) {
249
			return new AccountMapper($c->getConfig(), $c->getDatabaseConnection(), new AccountTermMapper($c->getDatabaseConnection()));
250
		});
251
		$this->registerService('UserManager', function (Server $c) {
252
			return new \OC\User\Manager(
253
				$c->getConfig(),
254
				$c->getLogger(),
255
				$c->getAccountMapper(),
256
				new SyncService(
257
					$c->getConfig(),
258
					$c->getLogger(),
259
					$c->getAccountMapper()
260
				),
261
				new UserSearch(
262
					$c->getConfig()
263
				)
264
			);
265
		});
266
		$this->registerService('GroupManager', function (Server $c) {
267
			$groupManager = new \OC\Group\Manager(
268
				$this->getUserManager(),
269
				new UserSearch(
270
					$c->getConfig()
271
				),
272
				$this->getEventDispatcher()
273
			);
274
275
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
276
				\OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
277
			});
278
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
279
				\OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $gid->getGID()]);
280
			});
281
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
282
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
283
			});
284
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
285
				\OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
286
			});
287
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
289
			});
290
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
291
				\OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
292
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
293
				\OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
294
			});
295
			return $groupManager;
296
		});
297
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
298
			$dbConnection = $c->getDatabaseConnection();
299
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
300
		});
301
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
302
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
303
			$crypto = $c->getCrypto();
304
			$config = $c->getConfig();
305
			$logger = $c->getLogger();
306
			$timeFactory = new TimeFactory();
307
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
308
		});
309
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
310
		$this->registerService('TimeFactory', function () {
311
			return new TimeFactory();
312
		});
313
		$this->registerAlias('OCP\AppFramework\Utility\ITimeFactory', 'TimeFactory');
314
		$this->registerService('UserSession', function (Server $c) {
315
			$manager = $c->getUserManager();
316
			$session = new Memory();
317
			$timeFactory = new TimeFactory();
318
			// Token providers might require a working database. This code
319
			// might however be called when ownCloud is not yet setup.
320
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
321
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
322
			} else {
323
				$defaultTokenProvider = null;
324
			}
325
326
			$userSyncService = new SyncService($c->getConfig(), $c->getLogger(), $c->getAccountMapper());
327
328
			$userSession = new Session($manager, $session, $timeFactory,
329
				$defaultTokenProvider, $c->getConfig(), $c->getLogger(), $this, $userSyncService, $c->getEventDispatcher());
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
330
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
331
				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
332
			});
333
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
334
				/** @var $user \OC\User\User */
335
				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
336
			});
337
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
338
				/** @var $user \OC\User\User */
339
				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
340
			});
341
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
342
				/** @var $user \OC\User\User */
343
				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
344
				$this->emittingCall(function () {
345
					return true;
346
				}, ['before' => [], 'after' => ['uid' => $user->getUID()]], 'user', 'delete');
347
			});
348 View Code Duplication
			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
349
				/** @var $user \OC\User\User */
350
				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
351
			});
352 View Code Duplication
			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
353
				/** @var $user \OC\User\User */
354
				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
355
			});
356
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
357
				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
358
			});
359
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
360
				/** @var $user \OC\User\User */
361
				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
362
			});
363
			$userSession->listen('\OC\User', 'preLogout', function () {
364
				$event = new GenericEvent(null, []);
365
				\OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logout', $event);
366
			});
367
			$userSession->listen('\OC\User', 'logout', function () {
368
				\OC_Hook::emit('OC_User', 'logout', []);
369
			});
370
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
371
				/** @var $user \OC\User\User */
372
				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]);
373
				$this->emittingCall(function () {
374
					return true;
375
				}, [
376
					'before' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value],
377
					'after' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]
378
				], 'user', 'featurechange');
379
			});
380
			return $userSession;
381
		});
382
383
		$this->registerService('OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
384
			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig());
0 ignored issues
show
Compatibility introduced by
$c->getAppManager() of type object<OCP\App\IAppManager> is not a sub-type of object<OC\App\AppManager>. It seems like you assume a concrete implementation of the interface OCP\App\IAppManager to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
385
		});
386
387
		$this->registerService('NavigationManager', function (Server $c) {
388
			return new \OC\NavigationManager($c->getAppManager(),
389
				$c->getURLGenerator(),
390
				$c->getL10NFactory(),
391
				$c->getUserSession(),
392
				$c->getGroupManager());
393
		});
394
		$this->registerAlias(IConfig::class, 'AllConfig');
395
		$this->registerService('AllConfig', function (Server $c) {
396
			return new \OC\AllConfig(
397
				$c->getSystemConfig(),
398
				$c->getEventDispatcher()
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
399
			);
400
		});
401
		$this->registerService('SystemConfig', function ($c) use ($config) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
402
			return new \OC\SystemConfig($config);
403
		});
404
		$this->registerService('AppConfig', function (Server $c) {
405
			return new \OC\AppConfig($c->getDatabaseConnection());
406
		});
407
		$this->registerService('L10NFactory', function (Server $c) {
408
			return new \OC\L10N\Factory(
409
				$c->getConfig(),
410
				$c->getRequest(),
411
				$c->getThemeService(),
412
				$c->getUserSession(),
413
				\OC::$SERVERROOT
414
			);
415
		});
416
		$this->registerService('URLGenerator', function (Server $c) {
417
			$config = $c->getConfig();
418
			$cacheFactory = $c->getMemCacheFactory();
419
			$router = $c->getRouter();
420
			return new URLGenerator(
421
				$config,
422
				$cacheFactory,
423
				$router,
424
				new \OC\Helper\EnvironmentHelper()
425
			);
426
		});
427
		$this->registerService('AppHelper', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
428
			return new \OC\AppHelper();
429
		});
430
		$this->registerService('UserCache', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
431
			return new Cache\File();
432
		});
433
		$this->registerService('MemCacheFactory', function (Server $c) {
434
			$config = $c->getConfig();
435
436
			if ($config->getSystemValue('installed', false) && !(\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
437
				$v = \OC_App::getAppVersions();
438
				$v['core'] = \md5(\file_get_contents(\OC::$SERVERROOT . '/version.php'));
439
				$version = \implode(',', $v);
440
				$instanceId = \OC_Util::getInstanceId();
441
				$path = \OC::$SERVERROOT;
442
				$prefix = \md5($instanceId . '-' . $version . '-' . $path);
443
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
444
					$config->getSystemValue('memcache.local', null),
445
					$config->getSystemValue('memcache.distributed', null),
446
					$config->getSystemValue('memcache.locking', null)
447
				);
448
			}
449
450
			return new \OC\Memcache\Factory('', $c->getLogger(),
451
				'\\OC\\Memcache\\ArrayCache',
452
				'\\OC\\Memcache\\ArrayCache',
453
				'\\OC\\Memcache\\ArrayCache'
454
			);
455
		});
456
		$this->registerService('RedisFactory', function (Server $c) {
457
			$systemConfig = $c->getSystemConfig();
458
			return new RedisFactory($systemConfig);
459
		});
460
		$this->registerService('ActivityManager', function (Server $c) {
461
			return new \OC\Activity\Manager(
462
				$c->getRequest(),
463
				$c->getUserSession(),
464
				$c->getConfig()
465
			);
466
		});
467
		$this->registerService('AvatarManager', function (Server $c) {
468
			return new AvatarManager(
469
				$c->getUserManager(),
470
				$c->getLazyRootFolder(),  // initialize the root folder lazily
471
				$c->getL10N('lib'),
472
				$c->getLogger()
473
			);
474
		});
475
		$this->registerAlias(ILogger::class, 'Logger');
476
		$this->registerService('Logger', function (Server $c) {
477
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
478
			$logger = 'OC\\Log\\' . \ucfirst($logClass);
479
			\call_user_func([$logger, 'init']);
480
481
			return new Log($logger);
482
		});
483
		$this->registerService('JobList', function (Server $c) {
484
			$config = $c->getConfig();
485
			return new \OC\BackgroundJob\JobList(
486
				$c->getDatabaseConnection(),
487
				$config,
488
				new TimeFactory()
489
			);
490
		});
491
		$this->registerService('Router', function (Server $c) {
492
			$cacheFactory = $c->getMemCacheFactory();
493
			$logger = $c->getLogger();
494
			if ($cacheFactory->isAvailable()) {
495
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
496
			} else {
497
				$router = new \OC\Route\Router($logger);
498
			}
499
			return $router;
500
		});
501
		$this->registerService('Search', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
502
			return new Search();
503
		});
504
		$this->registerService('SecureRandom', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
505
			return new SecureRandom();
506
		});
507
		$this->registerService('Crypto', function (Server $c) {
508
			return new Crypto($c->getConfig(), $c->getSecureRandom());
509
		});
510
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
511
		$this->registerService('Hasher', function (Server $c) {
512
			return new Hasher($c->getConfig());
513
		});
514
		$this->registerService('CredentialsManager', function (Server $c) {
515
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
516
		});
517
		$this->registerService('DatabaseConnection', function (Server $c) {
518
			$systemConfig = $c->getSystemConfig();
519
			$keys = $systemConfig->getKeys();
520
			if (!isset($keys['dbname']) && !isset($keys['dbhost']) && isset($keys['dbtableprefix'])) {
521
				throw new \OC\DatabaseException('No database configured');
522
			}
523
524
			$factory = new \OC\DB\ConnectionFactory($systemConfig);
525
			$type = $systemConfig->getValue('dbtype', 'sqlite');
526
			if (!$factory->isValidType($type)) {
527
				throw new \OC\DatabaseException('Invalid database type');
528
			}
529
			$connectionParams = $factory->createConnectionParams();
530
			$connection = $factory->getConnection($type, $connectionParams);
531
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
532
			return $connection;
533
		});
534
		$this->registerAlias(IDBConnection::class, 'DatabaseConnection');
535
		$this->registerService('Db', function (Server $c) {
536
			return new Db($c->getDatabaseConnection());
537
		});
538
		$this->registerService('HTTPHelper', function (Server $c) {
539
			$config = $c->getConfig();
540
			return new HTTPHelper(
541
				$config,
542
				$c->getHTTPClientService()
543
			);
544
		});
545 View Code Duplication
		$this->registerService('HttpClientService', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
546
			$user = \OC_User::getUser();
547
			$uid = $user ? $user : null;
548
			return new ClientService(
549
				$c->getConfig(),
550
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
0 ignored issues
show
Bug introduced by
It seems like $uid defined by $user ? $user : null on line 547 can also be of type boolean or null; however, OC\Security\CertificateManager::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
551
			);
552
		});
553 View Code Duplication
		$this->registerService('WebDavClientService', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
554
			$user = \OC_User::getUser();
555
			$uid = $user ? $user : null;
556
			return new WebDavClientService(
557
				$c->getConfig(),
558
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
0 ignored issues
show
Bug introduced by
It seems like $uid defined by $user ? $user : null on line 555 can also be of type boolean or null; however, OC\Security\CertificateManager::__construct() does only seem to accept string, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
559
			);
560
		});
561 View Code Duplication
		$this->registerService('EventLogger', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
562
			$eventLogger = new EventLogger();
563
			if ($c->getSystemConfig()->getValue('debug', false)) {
564
				// In debug mode, module is being activated by default
565
				$eventLogger->activate();
566
			}
567
			return $eventLogger;
568
		});
569 View Code Duplication
		$this->registerService('QueryLogger', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
570
			$queryLogger = new QueryLogger();
571
			if ($c->getSystemConfig()->getValue('debug', false)) {
572
				// In debug mode, module is being activated by default
573
				$queryLogger->activate();
574
			}
575
			return $queryLogger;
576
		});
577
		$this->registerService('TempManager', function (Server $c) {
578
			return new TempManager(
579
				$c->getLogger(),
580
				$c->getConfig()
581
			);
582
		});
583
		$this->registerService('AppManager', function (Server $c) {
584 View Code Duplication
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
585
				$appConfig = $c->getAppConfig();
586
				$groupManager = $c->getGroupManager();
587
			} else {
588
				$appConfig = null;
589
				$groupManager = null;
590
			}
591
			return new \OC\App\AppManager(
592
				$c->getUserSession(),
593
				$appConfig,
594
				$groupManager,
595
				$c->getMemCacheFactory(),
596
				$c->getEventDispatcher(),
597
				$c->getConfig()
598
			);
599
		});
600
		$this->registerService('DateTimeZone', function (Server $c) {
601
			return new DateTimeZone(
602
				$c->getConfig(),
603
				$c->getSession()
604
			);
605
		});
606
		$this->registerService('DateTimeFormatter', function (Server $c) {
607
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
608
609
			return new DateTimeFormatter(
610
				$c->getDateTimeZone()->getTimeZone(),
611
				$c->getL10N('lib', $language)
612
			);
613
		});
614
		$this->registerService('UserMountCache', function (Server $c) {
615
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
616
			$listener = new UserMountCacheListener($mountCache);
617
			$listener->listen($c->getUserManager());
618
			return $mountCache;
619
		});
620
		$this->registerService('MountConfigManager', function (Server $c) {
621
			$loader = \OC\Files\Filesystem::getLoader();
622
			$mountCache = $c->query('UserMountCache');
623
			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
624
625
			// builtin providers
626
627
			$config = $c->getConfig();
628
			$manager->registerProvider(new CacheMountProvider($config));
629
			$manager->registerHomeProvider(new LocalHomeMountProvider());
630
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
631
632
			// external storage
633
			if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') {
634
				$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
635
					$c->query('AllConfig'),
636
					$c->query('UserStoragesService'),
637
					$c->query('UserGlobalStoragesService'),
638
					$c->getSession()
639
				));
640
			}
641
642
			return $manager;
643
		});
644
		$this->registerService('IniWrapper', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
645
			return new IniGetWrapper();
646
		});
647
		$this->registerService('AsyncCommandBus', function (Server $c) {
648
			$jobList = $c->getJobList();
649
			return new AsyncBus($jobList);
650
		});
651
		$this->registerService('TrustedDomainHelper', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
652
			return new TrustedDomainHelper($this->getConfig());
653
		});
654
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
655
			// IConfig and IAppManager requires a working database. This code
656
			// might however be called when ownCloud is not yet setup.
657 View Code Duplication
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
658
				$config = $c->getConfig();
659
				$appManager = $c->getAppManager();
660
			} else {
661
				$config = null;
662
				$appManager = null;
663
			}
664
665
			return new Checker(
666
					new EnvironmentHelper(),
667
					new FileAccessHelper(),
668
					new AppLocator(),
669
					$config,
670
					$c->getMemCacheFactory(),
671
					$appManager,
672
					$c->getTempManager()
673
			);
674
		});
675
		$this->registerService('Request', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
676
			if (isset($this['urlParams'])) {
677
				$urlParams = $this['urlParams'];
678
			} else {
679
				$urlParams = [];
680
			}
681
682
			if (\defined('PHPUNIT_RUN') && PHPUNIT_RUN
683
				&& \in_array('fakeinput', \stream_get_wrappers())
684
			) {
685
				$stream = 'fakeinput://data';
686
			} else {
687
				$stream = 'php://input';
688
			}
689
690
			return new Request(
691
				[
692
					'get' => $_GET,
693
					'post' => $_POST,
694
					'files' => $_FILES,
695
					'server' => $_SERVER,
696
					'env' => $_ENV,
697
					'cookies' => $_COOKIE,
698
					'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD']))
699
						? $_SERVER['REQUEST_METHOD']
700
						: null,
701
					'urlParams' => $urlParams,
702
				],
703
				$this->getSecureRandom(),
704
				$this->getConfig(),
705
				$this->getCsrfTokenManager(),
706
				$stream
707
			);
708
		});
709
		$this->registerService('Mailer', function (Server $c) {
710
			return new Mailer(
711
				$c->getConfig(),
712
				$c->getLogger(),
713
				new \OC_Defaults()
714
			);
715
		});
716
		$this->registerService('LockingProvider', function (Server $c) {
717
			$ini = $c->getIniWrapper();
718
			$config = $c->getConfig();
719
			$ttl = $config->getSystemValue('filelocking.ttl', \max(3600, $ini->getNumeric('max_execution_time')));
720
			if ($config->getSystemValue('filelocking.enabled', true) or (\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
721
				/** @var \OC\Memcache\Factory $memcacheFactory */
722
				$memcacheFactory = $c->getMemCacheFactory();
723
				$memcache = $memcacheFactory->createLocking('lock');
724
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
725
					return new MemcacheLockingProvider($memcache, $ttl);
726
				}
727
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
728
			}
729
			return new NoopLockingProvider();
730
		});
731
		$this->registerAlias('OCP\Lock\ILockingProvider', 'LockingProvider');
732
		$this->registerService('MountManager', function () {
733
			return new \OC\Files\Mount\Manager();
734
		});
735
		$this->registerService('MimeTypeDetector', function (Server $c) {
736
			return new \OC\Files\Type\Detection(
737
				$c->getURLGenerator(),
738
				\OC::$SERVERROOT . '/config/',
739
				\OC::$SERVERROOT . '/resources/config/'
740
			);
741
		});
742
		$this->registerService('MimeTypeLoader', function (Server $c) {
743
			return new \OC\Files\Type\Loader(
744
				$c->getDatabaseConnection()
745
			);
746
		});
747
		$this->registerAlias('OCP\Files\IMimeTypeLoader', 'MimeTypeLoader');
748
		$this->registerService('NotificationManager', function (Server $c) {
749
			return new Manager($c->getEventDispatcher());
750
		});
751
		$this->registerService('CapabilitiesManager', function (Server $c) {
752
			$manager = new \OC\CapabilitiesManager();
753
			$manager->registerCapability(function () use ($c) {
754
				return new \OC\OCS\CoreCapabilities($c->getConfig());
755
			});
756
			return $manager;
757
		});
758 View Code Duplication
		$this->registerService('CommentsManager', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
759
			$config = $c->getConfig();
760
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
761
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
762
			$factory = new $factoryClass($this);
763
			return $factory->getManager();
764
		});
765
		$this->registerService('EventDispatcher', function () {
766
			return new EventDispatcher();
767
		});
768
		$this->registerService('CryptoWrapper', function (Server $c) {
769
			// FIXME: Instantiiated here due to cyclic dependency
770
			$request = new Request(
771
				[
772
					'get' => $_GET,
773
					'post' => $_POST,
774
					'files' => $_FILES,
775
					'server' => $_SERVER,
776
					'env' => $_ENV,
777
					'cookies' => $_COOKIE,
778
					'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD']))
779
						? $_SERVER['REQUEST_METHOD']
780
						: null,
781
				],
782
				$c->getSecureRandom(),
783
				$c->getConfig()
784
			);
785
786
			return new CryptoWrapper(
787
				$c->getConfig(),
788
				$c->getCrypto(),
789
				$c->getSecureRandom(),
790
				$request
791
			);
792
		});
793
		$this->registerService('CsrfTokenManager', function (Server $c) {
794
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
795
			$sessionStorage = new SessionStorage($c->getSession());
796
797
			return new CsrfTokenManager(
798
				$tokenGenerator,
799
				$sessionStorage
800
			);
801
		});
802
		$this->registerService('ContentSecurityPolicyManager', function (Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
803
			return new ContentSecurityPolicyManager();
804
		});
805
		$this->registerService('StoragesDBConfigService', function (Server $c) {
806
			return new DBConfigService(
807
				$c->getDatabaseConnection(),
808
				$c->getCrypto()
809
			);
810
		});
811
		$this->registerService('StoragesBackendService', function (Server $c) {
812
			$service = new StoragesBackendService($c->query('AllConfig'));
813
814
			// register auth mechanisms provided by core
815
			$provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [
816
				// AuthMechanism::SCHEME_NULL mechanism
817
				'OC\Files\External\Auth\NullMechanism',
818
819
				// AuthMechanism::SCHEME_BUILTIN mechanism
820
				'OC\Files\External\Auth\Builtin',
821
822
				// AuthMechanism::SCHEME_PASSWORD mechanisms
823
				'OC\Files\External\Auth\Password\Password',
824
			]);
825
826
			$service->registerAuthMechanismProvider($provider);
827
828
			// force-load the session one as it will register hooks...
829
			// TODO: obsolete it and use the TokenProvider to get the user's password from the session
830
			$sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials(
831
				$c->getSession(),
832
				$c->getCrypto()
833
			);
834
			$service->registerAuthMechanism($sessionCreds);
835
836
			return $service;
837
		});
838
		$this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService');
839
		$this->registerService('GlobalStoragesService', function (Server $c) {
840
			return new GlobalStoragesService(
841
				$c->query('StoragesBackendService'),
842
				$c->query('StoragesDBConfigService'),
843
				$c->query('UserMountCache')
844
			);
845
		});
846
		$this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService');
847 View Code Duplication
		$this->registerService('UserGlobalStoragesService', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
848
			return new UserGlobalStoragesService(
849
				$c->query('StoragesBackendService'),
850
				$c->query('StoragesDBConfigService'),
851
				$c->query('UserSession'),
852
				$c->query('GroupManager'),
853
				$c->query('UserMountCache')
854
			);
855
		});
856
		$this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService');
857 View Code Duplication
		$this->registerService('UserStoragesService', function (Server $c) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
858
			return new UserStoragesService(
859
				$c->query('StoragesBackendService'),
860
				$c->query('StoragesDBConfigService'),
861
				$c->query('UserSession'),
862
				$c->query('UserMountCache')
863
			);
864
		});
865
		$this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService');
866
		$this->registerService('ShareManager', function (Server $c) {
867
			$config = $c->getConfig();
868
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
869
			/** @var \OCP\Share\IProviderFactory $factory */
870
			$factory = new $factoryClass($this);
871
872
			$manager = new \OC\Share20\Manager(
873
				$c->getLogger(),
874
				$c->getConfig(),
875
				$c->getSecureRandom(),
876
				$c->getHasher(),
877
				$c->getMountManager(),
878
				$c->getGroupManager(),
879
				$c->getL10N('core'),
880
				$factory,
881
				$c->getUserManager(),
882
				$c->getLazyRootFolder(),
883
				$c->getEventDispatcher(),
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
884
				new View('/'),
885
				$c->getDatabaseConnection()
886
			);
887
888
			return $manager;
889
		});
890
891
		$this->registerService('ThemeService', function ($c) {
892
			return new ThemeService(
893
				$this->getSystemConfig()->getValue('theme'),
894
				$c->getAppManager(),
895
				new \OC\Helper\EnvironmentHelper()
896
			);
897
		});
898
		$this->registerAlias('OCP\Theme\IThemeService', 'ThemeService');
899
		$this->registerAlias('OCP\IUserSession', 'UserSession');
900
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
901
902
		$this->registerService(IServiceLoader::class, function () {
903
			return $this;
904
		});
905
	}
906
907
	/**
908
	 * @return \OCP\Contacts\IManager
909
	 */
910
	public function getContactsManager() {
911
		return $this->query('ContactsManager');
912
	}
913
914
	/**
915
	 * @return \OC\Encryption\Manager
916
	 */
917
	public function getEncryptionManager() {
918
		return $this->query('EncryptionManager');
919
	}
920
921
	/**
922
	 * @return \OC\Encryption\File
923
	 */
924
	public function getEncryptionFilesHelper() {
925
		return $this->query('EncryptionFileHelper');
926
	}
927
928
	/**
929
	 * @return \OCP\Encryption\Keys\IStorage
930
	 */
931
	public function getEncryptionKeyStorage() {
932
		return $this->query('EncryptionKeyStorage');
933
	}
934
935
	/**
936
	 * The current request object holding all information about the request
937
	 * currently being processed is returned from this method.
938
	 * In case the current execution was not initiated by a web request null is returned
939
	 *
940
	 * @return \OCP\IRequest
941
	 */
942
	public function getRequest() {
943
		return $this->query('Request');
944
	}
945
946
	/**
947
	 * Returns the preview manager which can create preview images for a given file
948
	 *
949
	 * @return \OCP\IPreview
950
	 */
951
	public function getPreviewManager() {
952
		return $this->query('PreviewManager');
953
	}
954
955
	/**
956
	 * Returns the tag manager which can get and set tags for different object types
957
	 *
958
	 * @see \OCP\ITagManager::load()
959
	 * @return \OCP\ITagManager
960
	 */
961
	public function getTagManager() {
962
		return $this->query('TagManager');
963
	}
964
965
	/**
966
	 * Returns the system-tag manager
967
	 *
968
	 * @return \OCP\SystemTag\ISystemTagManager
969
	 *
970
	 * @since 9.0.0
971
	 */
972
	public function getSystemTagManager() {
973
		return $this->query('SystemTagManager');
974
	}
975
976
	/**
977
	 * Returns the system-tag object mapper
978
	 *
979
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
980
	 *
981
	 * @since 9.0.0
982
	 */
983
	public function getSystemTagObjectMapper() {
984
		return $this->query('SystemTagObjectMapper');
985
	}
986
987
	/**
988
	 * Returns the avatar manager, used for avatar functionality
989
	 *
990
	 * @return \OCP\IAvatarManager
991
	 */
992
	public function getAvatarManager() {
993
		return $this->query('AvatarManager');
994
	}
995
996
	/**
997
	 * Returns the root folder of ownCloud's data directory
998
	 *
999
	 * @return \OCP\Files\IRootFolder
1000
	 */
1001
	public function getRootFolder() {
1002
		return $this->query('RootFolder');
1003
	}
1004
1005
	/**
1006
	 * Returns the root folder of ownCloud's data directory
1007
	 * This is the lazy variant so this gets only initialized once it
1008
	 * is actually used.
1009
	 *
1010
	 * @return \OCP\Files\IRootFolder
1011
	 */
1012
	public function getLazyRootFolder() {
1013
		return $this->query('LazyRootFolder');
1014
	}
1015
1016
	/**
1017
	 * Returns a view to ownCloud's files folder
1018
	 *
1019
	 * @param string $userId user ID
1020
	 * @return \OCP\Files\Folder|null
1021
	 */
1022
	public function getUserFolder($userId = null) {
1023 View Code Duplication
		if ($userId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1024
			$user = $this->getUserSession()->getUser();
1025
			if (!$user) {
1026
				return null;
1027
			}
1028
			$userId = $user->getUID();
1029
		}
1030
		$root = $this->getRootFolder();
1031
		return $root->getUserFolder($userId);
1032
	}
1033
1034
	/**
1035
	 * Returns an app-specific view in ownClouds data directory
1036
	 *
1037
	 * @return \OCP\Files\Folder
1038
	 */
1039
	public function getAppFolder() {
1040
		$dir = '/' . \OC_App::getCurrentApp();
1041
		$root = $this->getRootFolder();
1042
		if (!$root->nodeExists($dir)) {
1043
			$folder = $root->newFolder($dir);
1044
		} else {
1045
			$folder = $root->get($dir);
1046
		}
1047
		return $folder;
1048
	}
1049
1050
	/**
1051
	 * @return \OC\User\Manager
1052
	 */
1053
	public function getUserManager() {
1054
		return $this->query('UserManager');
1055
	}
1056
1057
	/**
1058
	 * @return \OC\User\AccountMapper
1059
	 */
1060
	public function getAccountMapper() {
1061
		return $this->query('AccountMapper');
1062
	}
1063
1064
	/**
1065
	 * @return \OC\Group\Manager
1066
	 */
1067
	public function getGroupManager() {
1068
		return $this->query('GroupManager');
1069
	}
1070
1071
	/**
1072
	 * @return \OC\User\Session
1073
	 */
1074
	public function getUserSession() {
1075
		if ($this->getConfig()->getSystemValue('installed', false) === false) {
1076
			return null;
1077
		}
1078
		return $this->query('UserSession');
1079
	}
1080
1081
	/**
1082
	 * @return ISession
1083
	 */
1084
	public function getSession() {
1085
		$userSession = $this->getUserSession();
1086
		if ($userSession === null) {
1087
			return new Memory();
1088
		}
1089
		return $userSession->getSession();
1090
	}
1091
1092
	/**
1093
	 * @param ISession $session
1094
	 */
1095
	public function setSession(ISession $session) {
1096
		$userSession = $this->getUserSession();
1097
		if ($userSession === null) {
1098
			return;
1099
		}
1100
		$userSession->setSession($session);
1101
	}
1102
1103
	/**
1104
	 * @return \OC\Authentication\TwoFactorAuth\Manager
1105
	 */
1106
	public function getTwoFactorAuthManager() {
1107
		return $this->query('OC\Authentication\TwoFactorAuth\Manager');
1108
	}
1109
1110
	/**
1111
	 * @return \OC\Authentication\AccountModule\Manager
1112
	 */
1113
	public function getAccountModuleManager() {
1114
		return $this->query(AccountModuleManager::class);
1115
	}
1116
1117
	/**
1118
	 * @return \OC\NavigationManager
1119
	 */
1120
	public function getNavigationManager() {
1121
		return $this->query('NavigationManager');
1122
	}
1123
1124
	/**
1125
	 * @return \OCP\IConfig
1126
	 */
1127
	public function getConfig() {
1128
		return $this->query('AllConfig');
1129
	}
1130
1131
	/**
1132
	 * @internal For internal use only
1133
	 * @return \OC\SystemConfig
1134
	 */
1135
	public function getSystemConfig() {
1136
		return $this->query('SystemConfig');
1137
	}
1138
1139
	/**
1140
	 * Returns the app config manager
1141
	 *
1142
	 * @return \OCP\IAppConfig
1143
	 */
1144
	public function getAppConfig() {
1145
		return $this->query('AppConfig');
1146
	}
1147
1148
	/**
1149
	 * @return \OCP\L10N\IFactory
1150
	 */
1151
	public function getL10NFactory() {
1152
		return $this->query('L10NFactory');
1153
	}
1154
1155
	/**
1156
	 * get an L10N instance
1157
	 *
1158
	 * @param string $app appid
1159
	 * @param string $lang
1160
	 * @return IL10N
1161
	 */
1162
	public function getL10N($app, $lang = null) {
1163
		return $this->getL10NFactory()->get($app, $lang);
1164
	}
1165
1166
	/**
1167
	 * @return \OCP\IURLGenerator
1168
	 */
1169
	public function getURLGenerator() {
1170
		return $this->query('URLGenerator');
1171
	}
1172
1173
	/**
1174
	 * @return \OCP\IHelper
1175
	 */
1176
	public function getHelper() {
1177
		return $this->query('AppHelper');
1178
	}
1179
1180
	/**
1181
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1182
	 * getMemCacheFactory() instead.
1183
	 *
1184
	 * @return \OCP\ICache
1185
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1186
	 */
1187
	public function getCache() {
1188
		return $this->query('UserCache');
1189
	}
1190
1191
	/**
1192
	 * Returns an \OCP\CacheFactory instance
1193
	 *
1194
	 * @return \OCP\ICacheFactory
1195
	 */
1196
	public function getMemCacheFactory() {
1197
		return $this->query('MemCacheFactory');
1198
	}
1199
1200
	/**
1201
	 * Returns an \OC\RedisFactory instance
1202
	 *
1203
	 * @return \OC\RedisFactory
1204
	 */
1205
	public function getGetRedisFactory() {
1206
		return $this->query('RedisFactory');
1207
	}
1208
1209
	/**
1210
	 * Returns the current session
1211
	 *
1212
	 * @return \OCP\IDBConnection
1213
	 */
1214
	public function getDatabaseConnection() {
1215
		return $this->query('DatabaseConnection');
1216
	}
1217
1218
	/**
1219
	 * Returns the activity manager
1220
	 *
1221
	 * @return \OCP\Activity\IManager
1222
	 */
1223
	public function getActivityManager() {
1224
		return $this->query('ActivityManager');
1225
	}
1226
1227
	/**
1228
	 * Returns an job list for controlling background jobs
1229
	 *
1230
	 * @return \OCP\BackgroundJob\IJobList
1231
	 */
1232
	public function getJobList() {
1233
		return $this->query('JobList');
1234
	}
1235
1236
	/**
1237
	 * Returns a logger instance
1238
	 *
1239
	 * @return \OCP\ILogger
1240
	 */
1241
	public function getLogger() {
1242
		if ($this->logger === null) {
1243
			$this->logger = $this->query('Logger');
1244
		}
1245
		return $this->logger;
1246
	}
1247
1248
	/**
1249
	 * Returns a logger instance
1250
	 *
1251
	 * @return \OCP\Settings\ISettingsManager
1252
	 */
1253
	public function getSettingsManager() {
1254
		return $this->query('SettingsManager');
1255
	}
1256
1257
	/**
1258
	 * Returns a router for generating and matching urls
1259
	 *
1260
	 * @return \OCP\Route\IRouter
1261
	 * @since 7.0.0
1262
	 * @deprecated 9.0.0
1263
	 */
1264
	public function getRouter() {
1265
		return $this->query('Router');
1266
	}
1267
1268
	/**
1269
	 * Returns a search instance
1270
	 *
1271
	 * @return \OCP\ISearch
1272
	 */
1273
	public function getSearch() {
1274
		return $this->query('Search');
1275
	}
1276
1277
	/**
1278
	 * Returns a SecureRandom instance
1279
	 *
1280
	 * @return \OCP\Security\ISecureRandom
1281
	 */
1282
	public function getSecureRandom() {
1283
		return $this->query('SecureRandom');
1284
	}
1285
1286
	/**
1287
	 * Returns a Crypto instance
1288
	 *
1289
	 * @return \OCP\Security\ICrypto
1290
	 */
1291
	public function getCrypto() {
1292
		return $this->query('Crypto');
1293
	}
1294
1295
	/**
1296
	 * Returns a Hasher instance
1297
	 *
1298
	 * @return \OCP\Security\IHasher
1299
	 */
1300
	public function getHasher() {
1301
		return $this->query('Hasher');
1302
	}
1303
1304
	/**
1305
	 * Returns a CredentialsManager instance
1306
	 *
1307
	 * @return \OCP\Security\ICredentialsManager
1308
	 */
1309
	public function getCredentialsManager() {
1310
		return $this->query('CredentialsManager');
1311
	}
1312
1313
	/**
1314
	 * Returns an instance of the db facade
1315
	 *
1316
	 * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
1317
	 * @return \OCP\IDb
1318
	 */
1319
	public function getDb() {
1320
		return $this->query('Db');
1321
	}
1322
1323
	/**
1324
	 * Returns an instance of the HTTP helper class
1325
	 *
1326
	 * @deprecated Use getHTTPClientService()
1327
	 * @return \OC\HTTPHelper
1328
	 */
1329
	public function getHTTPHelper() {
1330
		return $this->query('HTTPHelper');
1331
	}
1332
1333
	/**
1334
	 * Get the certificate manager for the user
1335
	 *
1336
	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1337
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1338
	 */
1339
	public function getCertificateManager($userId = '') {
1340 View Code Duplication
		if ($userId === '') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1341
			$userSession = $this->getUserSession();
1342
			$user = $userSession->getUser();
1343
			if ($user === null) {
1344
				return null;
1345
			}
1346
			$userId = $user->getUID();
1347
		}
1348
		return new CertificateManager($userId, new View(), $this->getConfig());
1349
	}
1350
1351
	/**
1352
	 * Returns an instance of the HTTP client service
1353
	 *
1354
	 * @return \OCP\Http\Client\IClientService
1355
	 */
1356
	public function getHTTPClientService() {
1357
		return $this->query('HttpClientService');
1358
	}
1359
1360
	/**
1361
	 * Returns an instance of the Webdav client service
1362
	 *
1363
	 * @return \OCP\Http\Client\IWebDavClientService
1364
	 */
1365
	public function getWebDavClientService() {
1366
		return $this->query('WebDavClientService');
1367
	}
1368
1369
	/**
1370
	 * Create a new event source
1371
	 *
1372
	 * @return \OCP\IEventSource
1373
	 */
1374
	public function createEventSource() {
1375
		return new \OC_EventSource();
1376
	}
1377
1378
	/**
1379
	 * Get the active event logger
1380
	 *
1381
	 * The returned logger only logs data when debug mode is enabled
1382
	 *
1383
	 * @return \OCP\Diagnostics\IEventLogger
1384
	 */
1385
	public function getEventLogger() {
1386
		return $this->query('EventLogger');
1387
	}
1388
1389
	/**
1390
	 * Get the active query logger
1391
	 *
1392
	 * The returned logger only logs data when debug mode is enabled
1393
	 *
1394
	 * @return \OCP\Diagnostics\IQueryLogger
1395
	 */
1396
	public function getQueryLogger() {
1397
		return $this->query('QueryLogger');
1398
	}
1399
1400
	/**
1401
	 * Get the manager for temporary files and folders
1402
	 *
1403
	 * @return \OCP\ITempManager
1404
	 */
1405
	public function getTempManager() {
1406
		return $this->query('TempManager');
1407
	}
1408
1409
	/**
1410
	 * Get the app manager
1411
	 *
1412
	 * @return \OCP\App\IAppManager
1413
	 */
1414
	public function getAppManager() {
1415
		return $this->query('AppManager');
1416
	}
1417
1418
	/**
1419
	 * Creates a new mailer
1420
	 *
1421
	 * @return \OCP\Mail\IMailer
1422
	 */
1423
	public function getMailer() {
1424
		return $this->query('Mailer');
1425
	}
1426
1427
	/**
1428
	 * Get the webroot
1429
	 *
1430
	 * @return string
1431
	 */
1432
	public function getWebRoot() {
1433
		return $this->webRoot;
1434
	}
1435
1436
	/**
1437
	 * @return \OCP\IDateTimeZone
1438
	 */
1439
	public function getDateTimeZone() {
1440
		return $this->query('DateTimeZone');
1441
	}
1442
1443
	/**
1444
	 * @return \OCP\IDateTimeFormatter
1445
	 */
1446
	public function getDateTimeFormatter() {
1447
		return $this->query('DateTimeFormatter');
1448
	}
1449
1450
	/**
1451
	 * @return \OCP\Files\Config\IMountProviderCollection
1452
	 */
1453
	public function getMountProviderCollection() {
1454
		return $this->query('MountConfigManager');
1455
	}
1456
1457
	/**
1458
	 * Get the IniWrapper
1459
	 *
1460
	 * @return IniGetWrapper
1461
	 */
1462
	public function getIniWrapper() {
1463
		return $this->query('IniWrapper');
1464
	}
1465
1466
	/**
1467
	 * @return \OCP\Command\IBus
1468
	 */
1469
	public function getCommandBus() {
1470
		return $this->query('AsyncCommandBus');
1471
	}
1472
1473
	/**
1474
	 * Get the trusted domain helper
1475
	 *
1476
	 * @return TrustedDomainHelper
1477
	 */
1478
	public function getTrustedDomainHelper() {
1479
		return $this->query('TrustedDomainHelper');
1480
	}
1481
1482
	/**
1483
	 * Get the locking provider
1484
	 *
1485
	 * @return \OCP\Lock\ILockingProvider
1486
	 * @since 8.1.0
1487
	 */
1488
	public function getLockingProvider() {
1489
		return $this->query('LockingProvider');
1490
	}
1491
1492
	/**
1493
	 * @return \OCP\Files\Mount\IMountManager
1494
	 **/
1495
	public function getMountManager() {
1496
		return $this->query('MountManager');
1497
	}
1498
1499
	/**
1500
	 * Get the MimeTypeDetector
1501
	 *
1502
	 * @return \OCP\Files\IMimeTypeDetector
1503
	 */
1504
	public function getMimeTypeDetector() {
1505
		return $this->query('MimeTypeDetector');
1506
	}
1507
1508
	/**
1509
	 * Get the MimeTypeLoader
1510
	 *
1511
	 * @return \OCP\Files\IMimeTypeLoader
1512
	 */
1513
	public function getMimeTypeLoader() {
1514
		return $this->query('MimeTypeLoader');
1515
	}
1516
1517
	/**
1518
	 * Get the manager of all the capabilities
1519
	 *
1520
	 * @return \OC\CapabilitiesManager
1521
	 */
1522
	public function getCapabilitiesManager() {
1523
		return $this->query('CapabilitiesManager');
1524
	}
1525
1526
	/**
1527
	 * Get the EventDispatcher
1528
	 *
1529
	 * @return EventDispatcherInterface
1530
	 * @since 8.2.0
1531
	 */
1532
	public function getEventDispatcher() {
1533
		return $this->query('EventDispatcher');
1534
	}
1535
1536
	/**
1537
	 * Get the Notification Manager
1538
	 *
1539
	 * @return \OCP\Notification\IManager
1540
	 * @since 8.2.0
1541
	 */
1542
	public function getNotificationManager() {
1543
		return $this->query('NotificationManager');
1544
	}
1545
1546
	/**
1547
	 * @return \OCP\Comments\ICommentsManager
1548
	 */
1549
	public function getCommentsManager() {
1550
		return $this->query('CommentsManager');
1551
	}
1552
1553
	/**
1554
	 * @return \OC\IntegrityCheck\Checker
1555
	 */
1556
	public function getIntegrityCodeChecker() {
1557
		return $this->query('IntegrityCodeChecker');
1558
	}
1559
1560
	/**
1561
	 * @return \OC\Session\CryptoWrapper
1562
	 */
1563
	public function getSessionCryptoWrapper() {
1564
		return $this->query('CryptoWrapper');
1565
	}
1566
1567
	/**
1568
	 * @return CsrfTokenManager
1569
	 */
1570
	public function getCsrfTokenManager() {
1571
		return $this->query('CsrfTokenManager');
1572
	}
1573
1574
	/**
1575
	 * @return IContentSecurityPolicyManager
1576
	 */
1577
	public function getContentSecurityPolicyManager() {
1578
		return $this->query('ContentSecurityPolicyManager');
1579
	}
1580
1581
	/**
1582
	 * @return \OCP\Files\External\IStoragesBackendService
1583
	 */
1584
	public function getStoragesBackendService() {
1585
		return $this->query('StoragesBackendService');
1586
	}
1587
1588
	/**
1589
	 * @return \OCP\Files\External\Service\IGlobalStoragesService
1590
	 */
1591
	public function getGlobalStoragesService() {
1592
		return $this->query('GlobalStoragesService');
1593
	}
1594
1595
	/**
1596
	 * @return \OCP\Files\External\Service\IUserGlobalStoragesService
1597
	 */
1598
	public function getUserGlobalStoragesService() {
1599
		return $this->query('UserGlobalStoragesService');
1600
	}
1601
1602
	/**
1603
	 * @return \OCP\Files\External\Service\IUserStoragesService
1604
	 */
1605
	public function getUserStoragesService() {
1606
		return $this->query('UserStoragesService');
1607
	}
1608
1609
	/**
1610
	 * @return \OCP\Share\IManager
1611
	 */
1612
	public function getShareManager() {
1613
		return $this->query('ShareManager');
1614
	}
1615
1616
	/**
1617
	 * @return IThemeService
1618
	 */
1619
	public function getThemeService() {
1620
		return $this->query('OCP\Theme\IThemeService');
1621
	}
1622
1623
	/**
1624
	 * @return ITimeFactory
1625
	 */
1626
	public function getTimeFactory() {
1627
		return $this->query('OCP\AppFramework\Utility\ITimeFactory');
1628
	}
1629
1630
	/**
1631
	 * @return IServiceLoader
1632
	 */
1633
	public function getServiceLoader() {
1634
		return $this;
1635
	}
1636
1637
	/**
1638
	 * @inheritdoc
1639
	 */
1640
	public function load(array $xmlPath, IUser $user = null) {
1641
		$appManager = $this->getAppManager();
1642
		$allApps = $appManager->getEnabledAppsForUser($user);
1643
1644
		foreach ($allApps as $appId) {
1645
			$info = $appManager->getAppInfo($appId);
1646
			if ($info === null) {
1647
				$info = [];
1648
			}
1649
1650
			foreach ($xmlPath as $xml) {
1651
				$info = isset($info[$xml]) ? $info[$xml] : [];
1652
			}
1653
			if (!\is_array($info)) {
1654
				$info = [$info];
1655
			}
1656
1657
			foreach ($info as $class) {
1658
				try {
1659
					if (!\OC_App::isAppLoaded($appId)) {
1660
						\OC_App::loadApp($appId);
1661
					}
1662
1663
					yield $this->query($class);
1664
				} catch (QueryException $exc) {
1665
					throw new \Exception("Could not load service $class");
1666
				}
1667
			}
1668
		}
1669
	}
1670
1671
	/**
1672
	 * @return IShutdownManager
1673
	 * @throws QueryException
1674
	 * @since 10.0.10
1675
	 */
1676
	public function getShutdownHandler() {
1677
		return $this->query(ShutDownManager::class);
1678
	}
1679
}
1680