Completed
Push — master ( 4a5a36...bf8806 )
by Robin
27s
created

Server::getCloudIdManager()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016, Lukas Reschke <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 * @author Bart Visscher <[email protected]>
8
 * @author Bernhard Posselt <[email protected]>
9
 * @author Bernhard Reiter <[email protected]>
10
 * @author Bjoern Schiessle <[email protected]>
11
 * @author Björn Schießle <[email protected]>
12
 * @author Christopher Schäpers <[email protected]>
13
 * @author Christoph Wurst <[email protected]>
14
 * @author Joas Schilling <[email protected]>
15
 * @author Jörn Friedrich Dreyer <[email protected]>
16
 * @author Lukas Reschke <[email protected]>
17
 * @author Morris Jobke <[email protected]>
18
 * @author Robin Appelman <[email protected]>
19
 * @author Robin McCorkell <[email protected]>
20
 * @author Roeland Jago Douma <[email protected]>
21
 * @author Sander <[email protected]>
22
 * @author Thomas Müller <[email protected]>
23
 * @author Thomas Tanghus <[email protected]>
24
 * @author Vincent Petry <[email protected]>
25
 * @author Roger Szabo <[email protected]>
26
 *
27
 * @license AGPL-3.0
28
 *
29
 * This code is free software: you can redistribute it and/or modify
30
 * it under the terms of the GNU Affero General Public License, version 3,
31
 * as published by the Free Software Foundation.
32
 *
33
 * This program is distributed in the hope that it will be useful,
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36
 * GNU Affero General Public License for more details.
37
 *
38
 * You should have received a copy of the GNU Affero General Public License, version 3,
39
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
40
 *
41
 */
42
namespace OC;
43
44
use bantu\IniGetWrapper\IniGetWrapper;
45
use OC\App\AppStore\Fetcher\AppFetcher;
46
use OC\App\AppStore\Fetcher\CategoryFetcher;
47
use OC\AppFramework\Http\Request;
48
use OC\AppFramework\Utility\TimeFactory;
49
use OC\Authentication\LoginCredentials\Store;
50
use OC\Command\AsyncBus;
51
use OC\Diagnostics\EventLogger;
52
use OC\Diagnostics\NullEventLogger;
53
use OC\Diagnostics\NullQueryLogger;
54
use OC\Diagnostics\QueryLogger;
55
use OC\Federation\CloudIdManager;
56
use OC\Files\Config\UserMountCache;
57
use OC\Files\Config\UserMountCacheListener;
58
use OC\Files\Mount\CacheMountProvider;
59
use OC\Files\Mount\LocalHomeMountProvider;
60
use OC\Files\Mount\ObjectHomeMountProvider;
61
use OC\Files\Node\HookConnector;
62
use OC\Files\Node\LazyRoot;
63
use OC\Files\Node\Root;
64
use OC\Files\View;
65
use OC\Http\Client\ClientService;
66
use OC\IntegrityCheck\Checker;
67
use OC\IntegrityCheck\Helpers\AppLocator;
68
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
69
use OC\IntegrityCheck\Helpers\FileAccessHelper;
70
use OC\Lock\DBLockingProvider;
71
use OC\Lock\MemcacheLockingProvider;
72
use OC\Lock\NoopLockingProvider;
73
use OC\Lockdown\LockdownManager;
74
use OC\Mail\Mailer;
75
use OC\Memcache\ArrayCache;
76
use OC\Notification\Manager;
77
use OC\Repair\NC11\CleanPreviewsBackgroundJob;
78
use OC\RichObjectStrings\Validator;
79
use OC\Security\Bruteforce\Throttler;
80
use OC\Security\CertificateManager;
81
use OC\Security\CSP\ContentSecurityPolicyManager;
82
use OC\Security\Crypto;
83
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
84
use OC\Security\CSRF\CsrfTokenGenerator;
85
use OC\Security\CSRF\CsrfTokenManager;
86
use OC\Security\CSRF\TokenStorage\SessionStorage;
87
use OC\Security\Hasher;
88
use OC\Security\CredentialsManager;
89
use OC\Security\SecureRandom;
90
use OC\Security\TrustedDomainHelper;
91
use OC\Session\CryptoWrapper;
92
use OC\Tagging\TagMapper;
93
use OCA\Theming\ThemingDefaults;
94
use OCP\Federation\ICloudIdManager;
95
use OCP\Authentication\LoginCredentials\IStore;
96
use OCP\IL10N;
97
use OCP\IServerContainer;
98
use OCP\RichObjectStrings\IValidator;
99
use OCP\Security\IContentSecurityPolicyManager;
100
use Symfony\Component\EventDispatcher\EventDispatcher;
101
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
102
103
/**
104
 * Class Server
105
 *
106
 * @package OC
107
 *
108
 * TODO: hookup all manager classes
109
 */
110
class Server extends ServerContainer implements IServerContainer {
111
	/** @var string */
112
	private $webRoot;
113
114
	/**
115
	 * @param string $webRoot
116
	 * @param \OC\Config $config
117
	 */
118
	public function __construct($webRoot, \OC\Config $config) {
119
		parent::__construct();
120
		$this->webRoot = $webRoot;
121
122
		$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...
123
			return new ContactsManager();
124
		});
125
126
		$this->registerService('PreviewManager', function (Server $c) {
127
			return new PreviewManager(
128
				$c->getConfig(),
129
				$c->getRootFolder(),
130
				$c->getAppDataDir('preview'),
131
				$c->getEventDispatcher(),
132
				$c->getSession()->get('user_id')
133
			);
134
		});
135
136
		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
137
			return new \OC\Preview\Watcher(
138
				$c->getAppDataDir('preview')
139
			);
140
		});
141
142
		$this->registerService('EncryptionManager', function (Server $c) {
143
			$view = new View();
144
			$util = new Encryption\Util(
145
				$view,
146
				$c->getUserManager(),
147
				$c->getGroupManager(),
148
				$c->getConfig()
149
			);
150
			return new Encryption\Manager(
151
				$c->getConfig(),
152
				$c->getLogger(),
153
				$c->getL10N('core'),
154
				new View(),
155
				$util,
156
				new ArrayCache()
157
			);
158
		});
159
160
		$this->registerService('EncryptionFileHelper', function (Server $c) {
161
			$util = new Encryption\Util(
162
				new View(),
163
				$c->getUserManager(),
164
				$c->getGroupManager(),
165
				$c->getConfig()
166
			);
167
			return new Encryption\File($util);
168
		});
169
170
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
171
			$view = new View();
172
			$util = new Encryption\Util(
173
				$view,
174
				$c->getUserManager(),
175
				$c->getGroupManager(),
176
				$c->getConfig()
177
			);
178
179
			return new Encryption\Keys\Storage($view, $util);
180
		});
181
		$this->registerService('TagMapper', function (Server $c) {
182
			return new TagMapper($c->getDatabaseConnection());
183
		});
184
		$this->registerService('TagManager', function (Server $c) {
185
			$tagMapper = $c->query('TagMapper');
186
			return new TagManager($tagMapper, $c->getUserSession());
187
		});
188 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...
189
			$config = $c->getConfig();
190
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
191
			/** @var \OC\SystemTag\ManagerFactory $factory */
192
			$factory = new $factoryClass($this);
193
			return $factory;
194
		});
195
		$this->registerService('SystemTagManager', function (Server $c) {
196
			return $c->query('SystemTagManagerFactory')->getManager();
197
		});
198
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
199
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
200
		});
201
		$this->registerService('RootFolder', function (Server $c) {
202
			$manager = \OC\Files\Filesystem::getMountManager(null);
203
			$view = new View();
204
			$root = new Root(
205
				$manager,
206
				$view,
207
				null,
208
				$c->getUserMountCache(),
209
				$this->getLogger(),
210
				$this->getUserManager()
211
			);
212
			$connector = new HookConnector($root, $view);
213
			$connector->viewToNode();
214
215
			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
216
			$previewConnector->connectWatcher();
217
218
			return $root;
219
		});
220
		$this->registerService('LazyRootFolder', function(Server $c) {
221
			return new LazyRoot(function() use ($c) {
222
				return $c->query('RootFolder');
223
			});
224
		});
225
		$this->registerService('UserManager', function (Server $c) {
226
			$config = $c->getConfig();
227
			return new \OC\User\Manager($config);
228
		});
229
		$this->registerService('GroupManager', 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...
230
			$groupManager = new \OC\Group\Manager($this->getUserManager());
231
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
232
				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
233
			});
234
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
235
				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
236
			});
237
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
238
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
239
			});
240
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
241
				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
242
			});
243
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
244
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
245
			});
246
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
247
				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
248
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
249
				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
250
			});
251
			return $groupManager;
252
		});
253
		$this->registerService(Store::class, function(Server $c) {
254
			$session = $c->getSession();
255 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...
256
				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
257
			} else {
258
				$tokenProvider = null;
259
			}
260
			$logger = $c->getLogger();
261
			return new Store($session, $logger, $tokenProvider);
262
		});
263
		$this->registerAlias(IStore::class, Store::class);
264
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
265
			$dbConnection = $c->getDatabaseConnection();
266
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
267
		});
268
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
269
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
270
			$crypto = $c->getCrypto();
271
			$config = $c->getConfig();
272
			$logger = $c->getLogger();
273
			$timeFactory = new TimeFactory();
274
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
275
		});
276
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
277
		$this->registerService('UserSession', function (Server $c) {
278
			$manager = $c->getUserManager();
279
			$session = new \OC\Session\Memory('');
280
			$timeFactory = new TimeFactory();
281
			// Token providers might require a working database. This code
282
			// might however be called when ownCloud is not yet setup.
283 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...
284
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
285
			} else {
286
				$defaultTokenProvider = null;
287
			}
288
289
			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom());
290
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
291
				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
292
			});
293
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
294
				/** @var $user \OC\User\User */
295
				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
296
			});
297
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
298
				/** @var $user \OC\User\User */
299
				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
300
			});
301
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
302
				/** @var $user \OC\User\User */
303
				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
304
			});
305 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...
306
				/** @var $user \OC\User\User */
307
				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
308
			});
309 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...
310
				/** @var $user \OC\User\User */
311
				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
312
			});
313
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
314
				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
315
			});
316
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
317
				/** @var $user \OC\User\User */
318
				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
319
			});
320
			$userSession->listen('\OC\User', 'logout', function () {
321
				\OC_Hook::emit('OC_User', 'logout', array());
322
			});
323
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
324
				/** @var $user \OC\User\User */
325
				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
326
			});
327
			return $userSession;
328
		});
329
330
		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
331
			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
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...
332
		});
333
334
		$this->registerService('NavigationManager', function (Server $c) {
335
			return new \OC\NavigationManager($c->getAppManager(),
336
				$c->getURLGenerator(),
337
				$c->getL10NFactory(),
338
				$c->getUserSession(),
339
				$c->getGroupManager());
340
		});
341
		$this->registerService('AllConfig', function (Server $c) {
342
			return new \OC\AllConfig(
343
				$c->getSystemConfig()
344
			);
345
		});
346
		$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...
347
			return new \OC\SystemConfig($config);
348
		});
349
		$this->registerService('AppConfig', function (Server $c) {
350
			return new \OC\AppConfig($c->getDatabaseConnection());
351
		});
352
		$this->registerService('L10NFactory', function (Server $c) {
353
			return new \OC\L10N\Factory(
354
				$c->getConfig(),
355
				$c->getRequest(),
356
				$c->getUserSession(),
357
				\OC::$SERVERROOT
358
			);
359
		});
360
		$this->registerService('URLGenerator', function (Server $c) {
361
			$config = $c->getConfig();
362
			$cacheFactory = $c->getMemCacheFactory();
363
			return new \OC\URLGenerator(
364
				$config,
365
				$cacheFactory
366
			);
367
		});
368
		$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...
369
			return new \OC\AppHelper();
0 ignored issues
show
Deprecated Code introduced by
The class OC\AppHelper has been deprecated with message: 8.1.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
370
		});
371
		$this->registerService('AppFetcher', 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...
372
			return new AppFetcher(
373
				$this->getAppDataDir('appstore'),
374
				$this->getHTTPClientService(),
375
				$this->query(TimeFactory::class),
376
				$this->getConfig()
377
			);
378
		});
379
		$this->registerService('CategoryFetcher', 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...
380
			return new CategoryFetcher(
381
				$this->getAppDataDir('appstore'),
382
				$this->getHTTPClientService(),
383
				$this->query(TimeFactory::class),
384
				$this->getConfig()
385
			);
386
		});
387
		$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...
388
			return new Cache\File();
389
		});
390
		$this->registerService('MemCacheFactory', function (Server $c) {
391
			$config = $c->getConfig();
392
393
			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
394
				$v = \OC_App::getAppVersions();
395
				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
396
				$version = implode(',', $v);
397
				$instanceId = \OC_Util::getInstanceId();
398
				$path = \OC::$SERVERROOT;
399
				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
400
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
401
					$config->getSystemValue('memcache.local', null),
402
					$config->getSystemValue('memcache.distributed', null),
403
					$config->getSystemValue('memcache.locking', null)
404
				);
405
			}
406
407
			return new \OC\Memcache\Factory('', $c->getLogger(),
408
				'\\OC\\Memcache\\ArrayCache',
409
				'\\OC\\Memcache\\ArrayCache',
410
				'\\OC\\Memcache\\ArrayCache'
411
			);
412
		});
413
		$this->registerService('RedisFactory', function (Server $c) {
414
			$systemConfig = $c->getSystemConfig();
415
			return new RedisFactory($systemConfig);
416
		});
417
		$this->registerService('ActivityManager', function (Server $c) {
418
			return new \OC\Activity\Manager(
419
				$c->getRequest(),
420
				$c->getUserSession(),
421
				$c->getConfig(),
422
				$c->query(IValidator::class)
423
			);
424
		});
425
		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
426
			return new \OC\Activity\EventMerger(
427
				$c->getL10N('lib')
428
			);
429
		});
430
		$this->registerAlias(IValidator::class, Validator::class);
431
		$this->registerService('AvatarManager', function (Server $c) {
432
			return new AvatarManager(
433
				$c->getUserManager(),
434
				$c->getAppDataDir('avatar'),
435
				$c->getL10N('lib'),
436
				$c->getLogger(),
437
				$c->getConfig()
438
			);
439
		});
440
		$this->registerService('Logger', function (Server $c) {
441
			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
442
			$logger = Log::getLogClass($logType);
443
			call_user_func(array($logger, 'init'));
444
445
			return new Log($logger);
446
		});
447
		$this->registerService('JobList', function (Server $c) {
448
			$config = $c->getConfig();
449
			return new \OC\BackgroundJob\JobList(
450
				$c->getDatabaseConnection(),
451
				$config,
452
				new TimeFactory()
453
			);
454
		});
455
		$this->registerService('Router', function (Server $c) {
456
			$cacheFactory = $c->getMemCacheFactory();
457
			$logger = $c->getLogger();
458
			if ($cacheFactory->isAvailable()) {
459
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
460
			} else {
461
				$router = new \OC\Route\Router($logger);
462
			}
463
			return $router;
464
		});
465
		$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...
466
			return new Search();
467
		});
468
		$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...
469
			return new SecureRandom();
470
		});
471
		$this->registerService('Crypto', function (Server $c) {
472
			return new Crypto($c->getConfig(), $c->getSecureRandom());
473
		});
474
		$this->registerService('Hasher', function (Server $c) {
475
			return new Hasher($c->getConfig());
476
		});
477
		$this->registerService('CredentialsManager', function (Server $c) {
478
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
479
		});
480
		$this->registerService('DatabaseConnection', function (Server $c) {
481
			$systemConfig = $c->getSystemConfig();
482
			$factory = new \OC\DB\ConnectionFactory($c->getConfig());
483
			$type = $systemConfig->getValue('dbtype', 'sqlite');
484
			if (!$factory->isValidType($type)) {
485
				throw new \OC\DatabaseException('Invalid database type');
486
			}
487
			$connectionParams = $factory->createConnectionParams($systemConfig);
488
			$connection = $factory->getConnection($type, $connectionParams);
489
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
490
			return $connection;
491
		});
492
		$this->registerService('HTTPHelper', function (Server $c) {
493
			$config = $c->getConfig();
494
			return new HTTPHelper(
0 ignored issues
show
Deprecated Code introduced by
The class OC\HTTPHelper has been deprecated with message: Use \OCP\Http\Client\IClientService

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
495
				$config,
496
				$c->getHTTPClientService()
497
			);
498
		});
499
		$this->registerService('HttpClientService', function (Server $c) {
500
			$user = \OC_User::getUser();
501
			$uid = $user ? $user : null;
502
			return new ClientService(
503
				$c->getConfig(),
504
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
505
			);
506
		});
507
		$this->registerService('EventLogger', function (Server $c) {
508
			if ($c->getSystemConfig()->getValue('debug', false)) {
509
				return new EventLogger();
510
			} else {
511
				return new NullEventLogger();
512
			}
513
		});
514
		$this->registerService('QueryLogger', function (Server $c) {
515
			if ($c->getSystemConfig()->getValue('debug', false)) {
516
				return new QueryLogger();
517
			} else {
518
				return new NullQueryLogger();
519
			}
520
		});
521
		$this->registerService('TempManager', function (Server $c) {
522
			return new TempManager(
523
				$c->getLogger(),
524
				$c->getConfig()
525
			);
526
		});
527
		$this->registerService('AppManager', function (Server $c) {
528
			return new \OC\App\AppManager(
529
				$c->getUserSession(),
530
				$c->getAppConfig(),
531
				$c->getGroupManager(),
532
				$c->getMemCacheFactory(),
533
				$c->getEventDispatcher()
534
			);
535
		});
536
		$this->registerService('DateTimeZone', function (Server $c) {
537
			return new DateTimeZone(
538
				$c->getConfig(),
539
				$c->getSession()
540
			);
541
		});
542
		$this->registerService('DateTimeFormatter', function (Server $c) {
543
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
544
545
			return new DateTimeFormatter(
546
				$c->getDateTimeZone()->getTimeZone(),
547
				$c->getL10N('lib', $language)
548
			);
549
		});
550
		$this->registerService('UserMountCache', function (Server $c) {
551
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
552
			$listener = new UserMountCacheListener($mountCache);
553
			$listener->listen($c->getUserManager());
554
			return $mountCache;
555
		});
556
		$this->registerService('MountConfigManager', function (Server $c) {
557
			$loader = \OC\Files\Filesystem::getLoader();
558
			$mountCache = $c->query('UserMountCache');
559
			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
560
561
			// builtin providers
562
563
			$config = $c->getConfig();
564
			$manager->registerProvider(new CacheMountProvider($config));
565
			$manager->registerHomeProvider(new LocalHomeMountProvider());
566
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
567
568
			return $manager;
569
		});
570
		$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...
571
			return new IniGetWrapper();
572
		});
573
		$this->registerService('AsyncCommandBus', function (Server $c) {
574
			$jobList = $c->getJobList();
575
			return new AsyncBus($jobList);
576
		});
577
		$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...
578
			return new TrustedDomainHelper($this->getConfig());
579
		});
580
		$this->registerService('Throttler', function(Server $c) {
581
			return new Throttler(
582
				$c->getDatabaseConnection(),
583
				new TimeFactory(),
584
				$c->getLogger(),
585
				$c->getConfig()
586
			);
587
		});
588
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
589
			// IConfig and IAppManager requires a working database. This code
590
			// might however be called when ownCloud is not yet setup.
591
			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
592
				$config = $c->getConfig();
593
				$appManager = $c->getAppManager();
594
			} else {
595
				$config = null;
596
				$appManager = null;
597
			}
598
599
			return new Checker(
600
					new EnvironmentHelper(),
601
					new FileAccessHelper(),
602
					new AppLocator(),
603
					$config,
604
					$c->getMemCacheFactory(),
605
					$appManager,
606
					$c->getTempManager()
607
			);
608
		});
609
		$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...
610
			if (isset($this['urlParams'])) {
611
				$urlParams = $this['urlParams'];
612
			} else {
613
				$urlParams = [];
614
			}
615
616
			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
617
				&& in_array('fakeinput', stream_get_wrappers())
618
			) {
619
				$stream = 'fakeinput://data';
620
			} else {
621
				$stream = 'php://input';
622
			}
623
624
			return new Request(
625
				[
626
					'get' => $_GET,
627
					'post' => $_POST,
628
					'files' => $_FILES,
629
					'server' => $_SERVER,
630
					'env' => $_ENV,
631
					'cookies' => $_COOKIE,
632
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
633
						? $_SERVER['REQUEST_METHOD']
634
						: null,
635
					'urlParams' => $urlParams,
636
				],
637
				$this->getSecureRandom(),
638
				$this->getConfig(),
639
				$this->getCsrfTokenManager(),
640
				$stream
641
			);
642
		});
643
		$this->registerService('Mailer', function (Server $c) {
644
			return new Mailer(
645
				$c->getConfig(),
646
				$c->getLogger(),
647
				$c->getThemingDefaults()
648
			);
649
		});
650
		$this->registerService('LDAPProvider', function(Server $c) {
651
			$config = $c->getConfig();
652
			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
653
			if(is_null($factoryClass)) {
654
				throw new \Exception('ldapProviderFactory not set');
655
			}
656
			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
657
			$factory = new $factoryClass($this);
658
			return $factory->getLDAPProvider();
659
		});
660
		$this->registerService('LockingProvider', function (Server $c) {
661
			$ini = $c->getIniWrapper();
662
			$config = $c->getConfig();
663
			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
664
			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
665
				/** @var \OC\Memcache\Factory $memcacheFactory */
666
				$memcacheFactory = $c->getMemCacheFactory();
667
				$memcache = $memcacheFactory->createLocking('lock');
668
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
669
					return new MemcacheLockingProvider($memcache, $ttl);
670
				}
671
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
672
			}
673
			return new NoopLockingProvider();
674
		});
675
		$this->registerService('MountManager', function () {
676
			return new \OC\Files\Mount\Manager();
677
		});
678
		$this->registerService('MimeTypeDetector', function (Server $c) {
679
			return new \OC\Files\Type\Detection(
680
				$c->getURLGenerator(),
681
				\OC::$configDir,
682
				\OC::$SERVERROOT . '/resources/config/'
683
			);
684
		});
685
		$this->registerService('MimeTypeLoader', function (Server $c) {
686
			return new \OC\Files\Type\Loader(
687
				$c->getDatabaseConnection()
688
			);
689
		});
690
		$this->registerService('NotificationManager', function (Server $c) {
691
			return new Manager(
692
				$c->query(IValidator::class)
693
			);
694
		});
695
		$this->registerService('CapabilitiesManager', function (Server $c) {
696
			$manager = new \OC\CapabilitiesManager($c->getLogger());
697
			$manager->registerCapability(function () use ($c) {
698
				return new \OC\OCS\CoreCapabilities($c->getConfig());
699
			});
700
			return $manager;
701
		});
702 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...
703
			$config = $c->getConfig();
704
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
705
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
706
			$factory = new $factoryClass($this);
707
			return $factory->getManager();
708
		});
709
		$this->registerService('ThemingDefaults', function(Server $c) {
710
			/*
711
			 * Dark magic for autoloader.
712
			 * If we do a class_exists it will try to load the class which will
713
			 * make composer cache the result. Resulting in errors when enabling
714
			 * the theming app.
715
			 */
716
			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
717
			if (isset($prefixes['OCA\\Theming\\'])) {
718
				$classExists = true;
719
			} else {
720
				$classExists = false;
721
			}
722
723
			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
724
				return new ThemingDefaults(
725
					$c->getConfig(),
726
					$c->getL10N('theming'),
727
					$c->getURLGenerator(),
728
					new \OC_Defaults(),
729
					$c->getLazyRootFolder(),
730
					$c->getMemCacheFactory()
731
				);
732
			}
733
			return new \OC_Defaults();
734
		});
735
		$this->registerService('EventDispatcher', function () {
736
			return new EventDispatcher();
737
		});
738
		$this->registerService('CryptoWrapper', function (Server $c) {
739
			// FIXME: Instantiiated here due to cyclic dependency
740
			$request = new Request(
741
				[
742
					'get' => $_GET,
743
					'post' => $_POST,
744
					'files' => $_FILES,
745
					'server' => $_SERVER,
746
					'env' => $_ENV,
747
					'cookies' => $_COOKIE,
748
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
749
						? $_SERVER['REQUEST_METHOD']
750
						: null,
751
				],
752
				$c->getSecureRandom(),
753
				$c->getConfig()
754
			);
755
756
			return new CryptoWrapper(
757
				$c->getConfig(),
758
				$c->getCrypto(),
759
				$c->getSecureRandom(),
760
				$request
761
			);
762
		});
763
		$this->registerService('CsrfTokenManager', function (Server $c) {
764
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
765
766
			return new CsrfTokenManager(
767
				$tokenGenerator,
768
				$c->query(SessionStorage::class)
769
			);
770
		});
771
		$this->registerService(SessionStorage::class, function (Server $c) {
772
			return new SessionStorage($c->getSession());
773
		});
774
		$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...
775
			return new ContentSecurityPolicyManager();
776
		});
777
		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
778
			return new ContentSecurityPolicyNonceManager(
779
				$c->getCsrfTokenManager(),
780
				$c->getRequest()
781
			);
782
		});
783
		$this->registerService('ShareManager', function(Server $c) {
784
			$config = $c->getConfig();
785
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
786
			/** @var \OCP\Share\IProviderFactory $factory */
787
			$factory = new $factoryClass($this);
788
789
			$manager = new \OC\Share20\Manager(
790
				$c->getLogger(),
791
				$c->getConfig(),
792
				$c->getSecureRandom(),
793
				$c->getHasher(),
794
				$c->getMountManager(),
795
				$c->getGroupManager(),
796
				$c->getL10N('core'),
797
				$factory,
798
				$c->getUserManager(),
799
				$c->getLazyRootFolder(),
800
				$c->getEventDispatcher()
801
			);
802
803
			return $manager;
804
		});
805
		$this->registerService('SettingsManager', function(Server $c) {
806
			$manager = new \OC\Settings\Manager(
807
				$c->getLogger(),
808
				$c->getDatabaseConnection(),
809
				$c->getL10N('lib'),
810
				$c->getConfig(),
811
				$c->getEncryptionManager(),
812
				$c->getUserManager(),
813
				$c->getLockingProvider(),
814
				new \OC\Settings\Mapper($c->getDatabaseConnection()),
815
				$c->getURLGenerator()
816
			);
817
			return $manager;
818
		});
819
		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
820
			return new \OC\Files\AppData\Factory(
821
				$c->getRootFolder(),
822
				$c->getSystemConfig()
823
			);
824
		});
825
826
		$this->registerService('LockdownManager', 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...
827
			return new LockdownManager();
828
		});
829
830
		$this->registerService(ICloudIdManager::class, 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...
831
			return new CloudIdManager();
832
		});
833
834
		/* To trick DI since we don't extend the DIContainer here */
835
		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
836
			return new CleanPreviewsBackgroundJob(
837
				$c->getRootFolder(),
838
				$c->getLogger(),
839
				$c->getJobList(),
840
				new TimeFactory()
841
			);
842
		});
843
	}
844
845
	/**
846
	 * @return \OCP\Contacts\IManager
847
	 */
848
	public function getContactsManager() {
849
		return $this->query('ContactsManager');
850
	}
851
852
	/**
853
	 * @return \OC\Encryption\Manager
854
	 */
855
	public function getEncryptionManager() {
856
		return $this->query('EncryptionManager');
857
	}
858
859
	/**
860
	 * @return \OC\Encryption\File
861
	 */
862
	public function getEncryptionFilesHelper() {
863
		return $this->query('EncryptionFileHelper');
864
	}
865
866
	/**
867
	 * @return \OCP\Encryption\Keys\IStorage
868
	 */
869
	public function getEncryptionKeyStorage() {
870
		return $this->query('EncryptionKeyStorage');
871
	}
872
873
	/**
874
	 * The current request object holding all information about the request
875
	 * currently being processed is returned from this method.
876
	 * In case the current execution was not initiated by a web request null is returned
877
	 *
878
	 * @return \OCP\IRequest
879
	 */
880
	public function getRequest() {
881
		return $this->query('Request');
882
	}
883
884
	/**
885
	 * Returns the preview manager which can create preview images for a given file
886
	 *
887
	 * @return \OCP\IPreview
888
	 */
889
	public function getPreviewManager() {
890
		return $this->query('PreviewManager');
891
	}
892
893
	/**
894
	 * Returns the tag manager which can get and set tags for different object types
895
	 *
896
	 * @see \OCP\ITagManager::load()
897
	 * @return \OCP\ITagManager
898
	 */
899
	public function getTagManager() {
900
		return $this->query('TagManager');
901
	}
902
903
	/**
904
	 * Returns the system-tag manager
905
	 *
906
	 * @return \OCP\SystemTag\ISystemTagManager
907
	 *
908
	 * @since 9.0.0
909
	 */
910
	public function getSystemTagManager() {
911
		return $this->query('SystemTagManager');
912
	}
913
914
	/**
915
	 * Returns the system-tag object mapper
916
	 *
917
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
918
	 *
919
	 * @since 9.0.0
920
	 */
921
	public function getSystemTagObjectMapper() {
922
		return $this->query('SystemTagObjectMapper');
923
	}
924
925
	/**
926
	 * Returns the avatar manager, used for avatar functionality
927
	 *
928
	 * @return \OCP\IAvatarManager
929
	 */
930
	public function getAvatarManager() {
931
		return $this->query('AvatarManager');
932
	}
933
934
	/**
935
	 * Returns the root folder of ownCloud's data directory
936
	 *
937
	 * @return \OCP\Files\IRootFolder
938
	 */
939
	public function getRootFolder() {
940
		return $this->query('LazyRootFolder');
941
	}
942
943
	/**
944
	 * Returns the root folder of ownCloud's data directory
945
	 * This is the lazy variant so this gets only initialized once it
946
	 * is actually used.
947
	 *
948
	 * @return \OCP\Files\IRootFolder
949
	 */
950
	public function getLazyRootFolder() {
951
		return $this->query('LazyRootFolder');
952
	}
953
954
	/**
955
	 * Returns a view to ownCloud's files folder
956
	 *
957
	 * @param string $userId user ID
958
	 * @return \OCP\Files\Folder|null
959
	 */
960
	public function getUserFolder($userId = null) {
961 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...
962
			$user = $this->getUserSession()->getUser();
963
			if (!$user) {
964
				return null;
965
			}
966
			$userId = $user->getUID();
967
		}
968
		$root = $this->getRootFolder();
969
		return $root->getUserFolder($userId);
970
	}
971
972
	/**
973
	 * Returns an app-specific view in ownClouds data directory
974
	 *
975
	 * @return \OCP\Files\Folder
976
	 * @deprecated since 9.2.0 use IAppData
977
	 */
978
	public function getAppFolder() {
979
		$dir = '/' . \OC_App::getCurrentApp();
980
		$root = $this->getRootFolder();
981
		if (!$root->nodeExists($dir)) {
982
			$folder = $root->newFolder($dir);
983
		} else {
984
			$folder = $root->get($dir);
985
		}
986
		return $folder;
987
	}
988
989
	/**
990
	 * @return \OC\User\Manager
991
	 */
992
	public function getUserManager() {
993
		return $this->query('UserManager');
994
	}
995
996
	/**
997
	 * @return \OC\Group\Manager
998
	 */
999
	public function getGroupManager() {
1000
		return $this->query('GroupManager');
1001
	}
1002
1003
	/**
1004
	 * @return \OC\User\Session
1005
	 */
1006
	public function getUserSession() {
1007
		return $this->query('UserSession');
1008
	}
1009
1010
	/**
1011
	 * @return \OCP\ISession
1012
	 */
1013
	public function getSession() {
1014
		return $this->query('UserSession')->getSession();
1015
	}
1016
1017
	/**
1018
	 * @param \OCP\ISession $session
1019
	 */
1020
	public function setSession(\OCP\ISession $session) {
1021
		$this->query(SessionStorage::class)->setSession($session);
1022
		$this->query('UserSession')->setSession($session);
1023
		$this->query(Store::class)->setSession($session);
1024
	}
1025
1026
	/**
1027
	 * @return \OC\Authentication\TwoFactorAuth\Manager
1028
	 */
1029
	public function getTwoFactorAuthManager() {
1030
		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1031
	}
1032
1033
	/**
1034
	 * @return \OC\NavigationManager
1035
	 */
1036
	public function getNavigationManager() {
1037
		return $this->query('NavigationManager');
1038
	}
1039
1040
	/**
1041
	 * @return \OCP\IConfig
1042
	 */
1043
	public function getConfig() {
1044
		return $this->query('AllConfig');
1045
	}
1046
1047
	/**
1048
	 * @internal For internal use only
1049
	 * @return \OC\SystemConfig
1050
	 */
1051
	public function getSystemConfig() {
1052
		return $this->query('SystemConfig');
1053
	}
1054
1055
	/**
1056
	 * Returns the app config manager
1057
	 *
1058
	 * @return \OCP\IAppConfig
1059
	 */
1060
	public function getAppConfig() {
1061
		return $this->query('AppConfig');
1062
	}
1063
1064
	/**
1065
	 * @return \OCP\L10N\IFactory
1066
	 */
1067
	public function getL10NFactory() {
1068
		return $this->query('L10NFactory');
1069
	}
1070
1071
	/**
1072
	 * get an L10N instance
1073
	 *
1074
	 * @param string $app appid
1075
	 * @param string $lang
1076
	 * @return IL10N
1077
	 */
1078
	public function getL10N($app, $lang = null) {
1079
		return $this->getL10NFactory()->get($app, $lang);
1080
	}
1081
1082
	/**
1083
	 * @return \OCP\IURLGenerator
1084
	 */
1085
	public function getURLGenerator() {
1086
		return $this->query('URLGenerator');
1087
	}
1088
1089
	/**
1090
	 * @return \OCP\IHelper
1091
	 */
1092
	public function getHelper() {
1093
		return $this->query('AppHelper');
1094
	}
1095
1096
	/**
1097
	 * @return AppFetcher
1098
	 */
1099
	public function getAppFetcher() {
1100
		return $this->query('AppFetcher');
1101
	}
1102
1103
	/**
1104
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1105
	 * getMemCacheFactory() instead.
1106
	 *
1107
	 * @return \OCP\ICache
1108
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1109
	 */
1110
	public function getCache() {
1111
		return $this->query('UserCache');
1112
	}
1113
1114
	/**
1115
	 * Returns an \OCP\CacheFactory instance
1116
	 *
1117
	 * @return \OCP\ICacheFactory
1118
	 */
1119
	public function getMemCacheFactory() {
1120
		return $this->query('MemCacheFactory');
1121
	}
1122
1123
	/**
1124
	 * Returns an \OC\RedisFactory instance
1125
	 *
1126
	 * @return \OC\RedisFactory
1127
	 */
1128
	public function getGetRedisFactory() {
1129
		return $this->query('RedisFactory');
1130
	}
1131
1132
1133
	/**
1134
	 * Returns the current session
1135
	 *
1136
	 * @return \OCP\IDBConnection
1137
	 */
1138
	public function getDatabaseConnection() {
1139
		return $this->query('DatabaseConnection');
1140
	}
1141
1142
	/**
1143
	 * Returns the activity manager
1144
	 *
1145
	 * @return \OCP\Activity\IManager
1146
	 */
1147
	public function getActivityManager() {
1148
		return $this->query('ActivityManager');
1149
	}
1150
1151
	/**
1152
	 * Returns an job list for controlling background jobs
1153
	 *
1154
	 * @return \OCP\BackgroundJob\IJobList
1155
	 */
1156
	public function getJobList() {
1157
		return $this->query('JobList');
1158
	}
1159
1160
	/**
1161
	 * Returns a logger instance
1162
	 *
1163
	 * @return \OCP\ILogger
1164
	 */
1165
	public function getLogger() {
1166
		return $this->query('Logger');
1167
	}
1168
1169
	/**
1170
	 * Returns a router for generating and matching urls
1171
	 *
1172
	 * @return \OCP\Route\IRouter
1173
	 */
1174
	public function getRouter() {
1175
		return $this->query('Router');
1176
	}
1177
1178
	/**
1179
	 * Returns a search instance
1180
	 *
1181
	 * @return \OCP\ISearch
1182
	 */
1183
	public function getSearch() {
1184
		return $this->query('Search');
1185
	}
1186
1187
	/**
1188
	 * Returns a SecureRandom instance
1189
	 *
1190
	 * @return \OCP\Security\ISecureRandom
1191
	 */
1192
	public function getSecureRandom() {
1193
		return $this->query('SecureRandom');
1194
	}
1195
1196
	/**
1197
	 * Returns a Crypto instance
1198
	 *
1199
	 * @return \OCP\Security\ICrypto
1200
	 */
1201
	public function getCrypto() {
1202
		return $this->query('Crypto');
1203
	}
1204
1205
	/**
1206
	 * Returns a Hasher instance
1207
	 *
1208
	 * @return \OCP\Security\IHasher
1209
	 */
1210
	public function getHasher() {
1211
		return $this->query('Hasher');
1212
	}
1213
1214
	/**
1215
	 * Returns a CredentialsManager instance
1216
	 *
1217
	 * @return \OCP\Security\ICredentialsManager
1218
	 */
1219
	public function getCredentialsManager() {
1220
		return $this->query('CredentialsManager');
1221
	}
1222
1223
	/**
1224
	 * Returns an instance of the HTTP helper class
1225
	 *
1226
	 * @deprecated Use getHTTPClientService()
1227
	 * @return \OC\HTTPHelper
1228
	 */
1229
	public function getHTTPHelper() {
1230
		return $this->query('HTTPHelper');
1231
	}
1232
1233
	/**
1234
	 * Get the certificate manager for the user
1235
	 *
1236
	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1237
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1238
	 */
1239
	public function getCertificateManager($userId = '') {
1240 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...
1241
			$userSession = $this->getUserSession();
1242
			$user = $userSession->getUser();
1243
			if (is_null($user)) {
1244
				return null;
1245
			}
1246
			$userId = $user->getUID();
1247
		}
1248
		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1249
	}
1250
1251
	/**
1252
	 * Returns an instance of the HTTP client service
1253
	 *
1254
	 * @return \OCP\Http\Client\IClientService
1255
	 */
1256
	public function getHTTPClientService() {
1257
		return $this->query('HttpClientService');
1258
	}
1259
1260
	/**
1261
	 * Create a new event source
1262
	 *
1263
	 * @return \OCP\IEventSource
1264
	 */
1265
	public function createEventSource() {
1266
		return new \OC_EventSource();
1267
	}
1268
1269
	/**
1270
	 * Get the active event logger
1271
	 *
1272
	 * The returned logger only logs data when debug mode is enabled
1273
	 *
1274
	 * @return \OCP\Diagnostics\IEventLogger
1275
	 */
1276
	public function getEventLogger() {
1277
		return $this->query('EventLogger');
1278
	}
1279
1280
	/**
1281
	 * Get the active query logger
1282
	 *
1283
	 * The returned logger only logs data when debug mode is enabled
1284
	 *
1285
	 * @return \OCP\Diagnostics\IQueryLogger
1286
	 */
1287
	public function getQueryLogger() {
1288
		return $this->query('QueryLogger');
1289
	}
1290
1291
	/**
1292
	 * Get the manager for temporary files and folders
1293
	 *
1294
	 * @return \OCP\ITempManager
1295
	 */
1296
	public function getTempManager() {
1297
		return $this->query('TempManager');
1298
	}
1299
1300
	/**
1301
	 * Get the app manager
1302
	 *
1303
	 * @return \OCP\App\IAppManager
1304
	 */
1305
	public function getAppManager() {
1306
		return $this->query('AppManager');
1307
	}
1308
1309
	/**
1310
	 * Creates a new mailer
1311
	 *
1312
	 * @return \OCP\Mail\IMailer
1313
	 */
1314
	public function getMailer() {
1315
		return $this->query('Mailer');
1316
	}
1317
1318
	/**
1319
	 * Get the webroot
1320
	 *
1321
	 * @return string
1322
	 */
1323
	public function getWebRoot() {
1324
		return $this->webRoot;
1325
	}
1326
1327
	/**
1328
	 * @return \OC\OCSClient
1329
	 */
1330
	public function getOcsClient() {
1331
		return $this->query('OcsClient');
1332
	}
1333
1334
	/**
1335
	 * @return \OCP\IDateTimeZone
1336
	 */
1337
	public function getDateTimeZone() {
1338
		return $this->query('DateTimeZone');
1339
	}
1340
1341
	/**
1342
	 * @return \OCP\IDateTimeFormatter
1343
	 */
1344
	public function getDateTimeFormatter() {
1345
		return $this->query('DateTimeFormatter');
1346
	}
1347
1348
	/**
1349
	 * @return \OCP\Files\Config\IMountProviderCollection
1350
	 */
1351
	public function getMountProviderCollection() {
1352
		return $this->query('MountConfigManager');
1353
	}
1354
1355
	/**
1356
	 * Get the IniWrapper
1357
	 *
1358
	 * @return IniGetWrapper
1359
	 */
1360
	public function getIniWrapper() {
1361
		return $this->query('IniWrapper');
1362
	}
1363
1364
	/**
1365
	 * @return \OCP\Command\IBus
1366
	 */
1367
	public function getCommandBus() {
1368
		return $this->query('AsyncCommandBus');
1369
	}
1370
1371
	/**
1372
	 * Get the trusted domain helper
1373
	 *
1374
	 * @return TrustedDomainHelper
1375
	 */
1376
	public function getTrustedDomainHelper() {
1377
		return $this->query('TrustedDomainHelper');
1378
	}
1379
1380
	/**
1381
	 * Get the locking provider
1382
	 *
1383
	 * @return \OCP\Lock\ILockingProvider
1384
	 * @since 8.1.0
1385
	 */
1386
	public function getLockingProvider() {
1387
		return $this->query('LockingProvider');
1388
	}
1389
1390
	/**
1391
	 * @return \OCP\Files\Mount\IMountManager
1392
	 **/
1393
	function getMountManager() {
1394
		return $this->query('MountManager');
1395
	}
1396
1397
	/** @return \OCP\Files\Config\IUserMountCache */
1398
	function getUserMountCache() {
1399
		return $this->query('UserMountCache');
1400
	}
1401
1402
	/**
1403
	 * Get the MimeTypeDetector
1404
	 *
1405
	 * @return \OCP\Files\IMimeTypeDetector
1406
	 */
1407
	public function getMimeTypeDetector() {
1408
		return $this->query('MimeTypeDetector');
1409
	}
1410
1411
	/**
1412
	 * Get the MimeTypeLoader
1413
	 *
1414
	 * @return \OCP\Files\IMimeTypeLoader
1415
	 */
1416
	public function getMimeTypeLoader() {
1417
		return $this->query('MimeTypeLoader');
1418
	}
1419
1420
	/**
1421
	 * Get the manager of all the capabilities
1422
	 *
1423
	 * @return \OC\CapabilitiesManager
1424
	 */
1425
	public function getCapabilitiesManager() {
1426
		return $this->query('CapabilitiesManager');
1427
	}
1428
1429
	/**
1430
	 * Get the EventDispatcher
1431
	 *
1432
	 * @return EventDispatcherInterface
1433
	 * @since 8.2.0
1434
	 */
1435
	public function getEventDispatcher() {
1436
		return $this->query('EventDispatcher');
1437
	}
1438
1439
	/**
1440
	 * Get the Notification Manager
1441
	 *
1442
	 * @return \OCP\Notification\IManager
1443
	 * @since 8.2.0
1444
	 */
1445
	public function getNotificationManager() {
1446
		return $this->query('NotificationManager');
1447
	}
1448
1449
	/**
1450
	 * @return \OCP\Comments\ICommentsManager
1451
	 */
1452
	public function getCommentsManager() {
1453
		return $this->query('CommentsManager');
1454
	}
1455
1456
	/**
1457
	 * @return \OC_Defaults
1458
	 */
1459
	public function getThemingDefaults() {
1460
		return $this->query('ThemingDefaults');
1461
	}
1462
1463
	/**
1464
	 * @return \OC\IntegrityCheck\Checker
1465
	 */
1466
	public function getIntegrityCodeChecker() {
1467
		return $this->query('IntegrityCodeChecker');
1468
	}
1469
1470
	/**
1471
	 * @return \OC\Session\CryptoWrapper
1472
	 */
1473
	public function getSessionCryptoWrapper() {
1474
		return $this->query('CryptoWrapper');
1475
	}
1476
1477
	/**
1478
	 * @return CsrfTokenManager
1479
	 */
1480
	public function getCsrfTokenManager() {
1481
		return $this->query('CsrfTokenManager');
1482
	}
1483
1484
	/**
1485
	 * @return Throttler
1486
	 */
1487
	public function getBruteForceThrottler() {
1488
		return $this->query('Throttler');
1489
	}
1490
1491
	/**
1492
	 * @return IContentSecurityPolicyManager
1493
	 */
1494
	public function getContentSecurityPolicyManager() {
1495
		return $this->query('ContentSecurityPolicyManager');
1496
	}
1497
1498
	/**
1499
	 * @return ContentSecurityPolicyNonceManager
1500
	 */
1501
	public function getContentSecurityPolicyNonceManager() {
1502
		return $this->query('ContentSecurityPolicyNonceManager');
1503
	}
1504
1505
	/**
1506
	 * Not a public API as of 8.2, wait for 9.0
1507
	 *
1508
	 * @return \OCA\Files_External\Service\BackendService
1509
	 */
1510
	public function getStoragesBackendService() {
1511
		return $this->query('OCA\\Files_External\\Service\\BackendService');
1512
	}
1513
1514
	/**
1515
	 * Not a public API as of 8.2, wait for 9.0
1516
	 *
1517
	 * @return \OCA\Files_External\Service\GlobalStoragesService
1518
	 */
1519
	public function getGlobalStoragesService() {
1520
		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1521
	}
1522
1523
	/**
1524
	 * Not a public API as of 8.2, wait for 9.0
1525
	 *
1526
	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1527
	 */
1528
	public function getUserGlobalStoragesService() {
1529
		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1530
	}
1531
1532
	/**
1533
	 * Not a public API as of 8.2, wait for 9.0
1534
	 *
1535
	 * @return \OCA\Files_External\Service\UserStoragesService
1536
	 */
1537
	public function getUserStoragesService() {
1538
		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1539
	}
1540
1541
	/**
1542
	 * @return \OCP\Share\IManager
1543
	 */
1544
	public function getShareManager() {
1545
		return $this->query('ShareManager');
1546
	}
1547
1548
	/**
1549
	 * Returns the LDAP Provider
1550
	 *
1551
	 * @return \OCP\LDAP\ILDAPProvider
1552
	 */
1553
	public function getLDAPProvider() {
1554
		return $this->query('LDAPProvider');
1555
	}
1556
1557
	/**
1558
	 * @return \OCP\Settings\IManager
1559
	 */
1560
	public function getSettingsManager() {
1561
		return $this->query('SettingsManager');
1562
	}
1563
1564
	/**
1565
	 * @return \OCP\Files\IAppData
1566
	 */
1567
	public function getAppDataDir($app) {
1568
		/** @var \OC\Files\AppData\Factory $factory */
1569
		$factory = $this->query(\OC\Files\AppData\Factory::class);
1570
		return $factory->get($app);
1571
	}
1572
1573
	/**
1574
	 * @return \OCP\Lockdown\ILockdownManager
1575
	 */
1576
	public function getLockdownManager() {
1577
		return $this->query('LockdownManager');
1578
	}
1579
1580
	/**
1581
	 * @return \OCP\Federation\ICloudIdManager
1582
	 */
1583
	public function getCloudIdManager() {
1584
		return $this->query(ICloudIdManager::class);
1585
	}
1586
}
1587