Completed
Push — master ( f4b338...f199c6 )
by Thomas
08:27
created

Server::getCrypto()   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
 * @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) 2017, 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\Command\AsyncBus;
48
use OC\Diagnostics\EventLogger;
49
use OC\Diagnostics\NullEventLogger;
50
use OC\Diagnostics\NullQueryLogger;
51
use OC\Diagnostics\QueryLogger;
52
use OC\Files\Config\UserMountCache;
53
use OC\Files\Config\UserMountCacheListener;
54
use OC\Files\Mount\CacheMountProvider;
55
use OC\Files\Mount\LocalHomeMountProvider;
56
use OC\Files\Mount\ObjectHomeMountProvider;
57
use OC\Files\Node\HookConnector;
58
use OC\Files\Node\LazyRoot;
59
use OC\Files\Node\Root;
60
use OC\Files\View;
61
use OC\Http\Client\ClientService;
62
use OC\IntegrityCheck\Checker;
63
use OC\IntegrityCheck\Helpers\AppLocator;
64
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
65
use OC\IntegrityCheck\Helpers\FileAccessHelper;
66
use OC\Lock\DBLockingProvider;
67
use OC\Lock\MemcacheLockingProvider;
68
use OC\Lock\NoopLockingProvider;
69
use OC\Mail\Mailer;
70
use OC\Memcache\ArrayCache;
71
use OC\Notification\Manager;
72
use OC\Security\CertificateManager;
73
use OC\Security\CSP\ContentSecurityPolicyManager;
74
use OC\Security\Crypto;
75
use OC\Security\CSRF\CsrfTokenGenerator;
76
use OC\Security\CSRF\CsrfTokenManager;
77
use OC\Security\CSRF\TokenStorage\SessionStorage;
78
use OC\Security\Hasher;
79
use OC\Security\CredentialsManager;
80
use OC\Security\SecureRandom;
81
use OC\Security\TrustedDomainHelper;
82
use OC\Session\CryptoWrapper;
83
use OC\Session\Memory;
84
use OC\Settings\Panels\Helper;
85
use OC\Settings\SettingsManager;
86
use OC\Tagging\TagMapper;
87
use OC\Theme\ThemeService;
88
use OC\User\AccountMapper;
89
use OC\User\AccountTermMapper;
90
use OCP\IL10N;
91
use OCP\ILogger;
92
use OCP\IServerContainer;
93
use OCP\ISession;
94
use OCP\Security\IContentSecurityPolicyManager;
95
use OCP\Theme\IThemeService;
96
use Symfony\Component\EventDispatcher\EventDispatcher;
97
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
98
use OC\Files\External\StoragesBackendService;
99
use OC\Files\External\Service\UserStoragesService;
100
use OC\Files\External\Service\UserGlobalStoragesService;
101
use OC\Files\External\Service\GlobalStoragesService;
102
use OC\Files\External\Service\DBConfigService;
103
use OC\Http\Client\WebDavClientService;
104
use Symfony\Component\EventDispatcher\GenericEvent;
105
106
/**
107
 * Class Server
108
 *
109
 * @package OC
110
 *
111
 * TODO: hookup all manager classes
112
 */
113
class Server extends ServerContainer implements IServerContainer {
114
	/** @var string */
115
	private $webRoot;
116
117
	/**
118
	 * cache the logger to prevent querying it over and over again
119
	 * @var ILogger;
120
	 */
121
	private $logger;
122
123
	/**
124
	 * @param string $webRoot
125
	 * @param \OC\Config $config
126
	 */
127
	public function __construct($webRoot, \OC\Config $config) {
128
		parent::__construct();
129
		$this->webRoot = $webRoot;
130
131
		$this->registerService('SettingsManager', function(Server $c) {
132
			return new SettingsManager(
133
				$c->getL10N('lib'),
134
				$c->getAppManager(),
135
				$c->getUserSession(),
136
				$c->getLogger(),
137
				$c->getGroupManager(),
138
				$c->getConfig(),
139
				new \OCP\Defaults(),
140
				$c->getURLGenerator(),
141
				new Helper(),
142
				$c->getLockingProvider(),
143
				$c->getDatabaseConnection(),
144
				$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...
145
				$c->getL10NFactory()
146
147
			);
148
		});
149
150
		$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...
151
			return new ContactsManager();
152
		});
153
154
		$this->registerService('PreviewManager', function (Server $c) {
155
			return new PreviewManager($c->getConfig());
156
		});
157
158
		$this->registerService('EncryptionManager', function (Server $c) {
159
			$view = new View();
160
			$util = new Encryption\Util(
161
				$view,
162
				$c->getUserManager(),
163
				$c->getGroupManager(),
164
				$c->getConfig()
165
			);
166
			return new Encryption\Manager(
167
				$c->getConfig(),
168
				$c->getLogger(),
169
				$c->getL10N('core'),
170
				new View(),
171
				$util,
172
				new ArrayCache()
173
			);
174
		});
175
176
		$this->registerService('EncryptionFileHelper', function (Server $c) {
177
			$util = new Encryption\Util(
178
				new View(),
179
				$c->getUserManager(),
180
				$c->getGroupManager(),
181
				$c->getConfig()
182
			);
183
			return new Encryption\File($util);
184
		});
185
186
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
187
			$view = new View();
188
			$util = new Encryption\Util(
189
				$view,
190
				$c->getUserManager(),
191
				$c->getGroupManager(),
192
				$c->getConfig()
193
			);
194
195
			return new Encryption\Keys\Storage(
196
				$view,
197
				$util,
198
				$c->getUserSession()
199
			);
200
		});
201
		$this->registerService('TagMapper', function (Server $c) {
202
			return new TagMapper($c->getDatabaseConnection());
203
		});
204
		$this->registerService('TagManager', function (Server $c) {
205
			$tagMapper = $c->query('TagMapper');
206
			return new TagManager($tagMapper, $c->getUserSession());
207
		});
208 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...
209
			$config = $c->getConfig();
210
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
211
			/** @var \OC\SystemTag\ManagerFactory $factory */
212
			$factory = new $factoryClass($this);
213
			return $factory;
214
		});
215
		$this->registerService('SystemTagManager', function (Server $c) {
216
			return $c->query('SystemTagManagerFactory')->getManager();
217
		});
218
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
219
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
220
		});
221
		$this->registerService('RootFolder', function () {
222
			$manager = \OC\Files\Filesystem::getMountManager(null);
223
			$view = new View();
224
			$root = new Root($manager, $view, null);
225
			$connector = new HookConnector($root, $view);
226
			$connector->viewToNode();
227
			return $root;
228
		});
229
		$this->registerService('LazyRootFolder', function(Server $c) {
230
			return new LazyRoot(function() use ($c) {
231
				return $c->getRootFolder();
232
			});
233
		});
234
		$this->registerService('AccountMapper', function(Server $c) {
235
			return new AccountMapper($c->getConfig(), $c->getDatabaseConnection(), new AccountTermMapper($c->getDatabaseConnection()));
236
		});
237
		$this->registerService('UserManager', function (Server $c) {
238
			$config = $c->getConfig();
239
			$logger = $c->getLogger();
240
			return new \OC\User\Manager($config, $logger, $c->getAccountMapper());
241
		});
242
		$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...
243
			$groupManager = new \OC\Group\Manager($this->getUserManager());
244
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
245
				\OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
246
			});
247
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
248
				\OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $gid->getGID()]);
249
			});
250
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
251
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
252
			});
253
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
254
				\OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
255
			});
256
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
257
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
258
			});
259
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
260
				\OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
261
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
262
				\OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
263
			});
264
			return $groupManager;
265
		});
266
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
267
			$dbConnection = $c->getDatabaseConnection();
268
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
269
		});
270
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
271
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
272
			$crypto = $c->getCrypto();
273
			$config = $c->getConfig();
274
			$logger = $c->getLogger();
275
			$timeFactory = new TimeFactory();
276
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
277
		});
278
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
279
		$this->registerService('TimeFactory', function() {
280
			return new TimeFactory();
281
		});
282
		$this->registerAlias('OCP\AppFramework\Utility\ITimeFactory', 'TimeFactory');
283
		$this->registerService('UserSession', function (Server $c) {
284
			$manager = $c->getUserManager();
285
			$session = new \OC\Session\Memory('');
286
			$timeFactory = new TimeFactory();
287
			// Token providers might require a working database. This code
288
			// might however be called when ownCloud is not yet setup.
289
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
290
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
291
			} else {
292
				$defaultTokenProvider = null;
293
			}
294
295
			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig());
296
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
297
				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
298
			});
299
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
300
				/** @var $user \OC\User\User */
301
				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
302
			});
303
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
304
				/** @var $user \OC\User\User */
305
				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
306
			});
307
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
308
				/** @var $user \OC\User\User */
309
				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
310
			});
311 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...
312
				/** @var $user \OC\User\User */
313
				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
314
			});
315 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...
316
				/** @var $user \OC\User\User */
317
				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
318
			});
319
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
320
				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
321
			});
322
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
323
				/** @var $user \OC\User\User */
324
				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
325
			});
326
			$userSession->listen('\OC\User', 'preLogout', function () {
327
				$event = new GenericEvent(null, []);
328
				\OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logout', $event);
329
			});
330
			$userSession->listen('\OC\User', 'logout', function () {
331
				\OC_Hook::emit('OC_User', 'logout', []);
332
			});
333
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
334
				/** @var $user \OC\User\User */
335
				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]);
336
			});
337
			return $userSession;
338
		});
339
340
		$this->registerService('\OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
341
			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...
342
		});
343
344
		$this->registerService('NavigationManager', function (Server $c) {
345
			return new \OC\NavigationManager($c->getAppManager(),
346
				$c->getURLGenerator(),
347
				$c->getL10NFactory(),
348
				$c->getUserSession(),
349
				$c->getGroupManager());
350
		});
351
		$this->registerService('AllConfig', function (Server $c) {
352
			return new \OC\AllConfig(
353
				$c->getSystemConfig()
354
			);
355
		});
356
		$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...
357
			return new \OC\SystemConfig($config);
358
		});
359
		$this->registerService('AppConfig', function (Server $c) {
360
			return new \OC\AppConfig($c->getDatabaseConnection());
361
		});
362
		$this->registerService('L10NFactory', function (Server $c) {
363
			return new \OC\L10N\Factory(
364
				$c->getConfig(),
365
				$c->getRequest(),
366
				$c->getUserSession(),
367
				\OC::$SERVERROOT
368
			);
369
		});
370
		$this->registerService('URLGenerator', function (Server $c) {
371
			$config = $c->getConfig();
372
			$cacheFactory = $c->getMemCacheFactory();
373
			$router = $c->getRouter();
374
			return new URLGenerator(
375
				$config,
376
				$cacheFactory,
377
				$router
378
			);
379
		});
380
		$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...
381
			return new \OC\AppHelper();
382
		});
383
		$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...
384
			return new Cache\File();
385
		});
386
		$this->registerService('MemCacheFactory', function (Server $c) {
387
			$config = $c->getConfig();
388
389
			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
390
				$v = \OC_App::getAppVersions();
391
				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
392
				$version = implode(',', $v);
393
				$instanceId = \OC_Util::getInstanceId();
394
				$path = \OC::$SERVERROOT;
395
				$prefix = md5($instanceId . '-' . $version . '-' . $path);
396
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
397
					$config->getSystemValue('memcache.local', null),
398
					$config->getSystemValue('memcache.distributed', null),
399
					$config->getSystemValue('memcache.locking', null)
400
				);
401
			}
402
403
			return new \OC\Memcache\Factory('', $c->getLogger(),
404
				'\\OC\\Memcache\\ArrayCache',
405
				'\\OC\\Memcache\\ArrayCache',
406
				'\\OC\\Memcache\\ArrayCache'
407
			);
408
		});
409
		$this->registerService('RedisFactory', function (Server $c) {
410
			$systemConfig = $c->getSystemConfig();
411
			return new RedisFactory($systemConfig);
412
		});
413
		$this->registerService('ActivityManager', function (Server $c) {
414
			return new \OC\Activity\Manager(
415
				$c->getRequest(),
416
				$c->getUserSession(),
417
				$c->getConfig()
418
			);
419
		});
420
		$this->registerService('AvatarManager', function (Server $c) {
421
			return new AvatarManager(
422
				$c->getUserManager(),
423
				$c->getRootFolder(),
424
				$c->getL10N('lib'),
425
				$c->getLogger()
426
			);
427
		});
428
		$this->registerService('Logger', function (Server $c) {
429
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
430
			$logger = 'OC\\Log\\' . ucfirst($logClass);
431
			call_user_func([$logger, 'init']);
432
433
			return new Log($logger);
434
		});
435
		$this->registerService('JobList', function (Server $c) {
436
			$config = $c->getConfig();
437
			return new \OC\BackgroundJob\JobList(
438
				$c->getDatabaseConnection(),
439
				$config,
440
				new TimeFactory()
441
			);
442
		});
443
		$this->registerService('Router', function (Server $c) {
444
			$cacheFactory = $c->getMemCacheFactory();
445
			$logger = $c->getLogger();
446
			if ($cacheFactory->isAvailable()) {
447
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
448
			} else {
449
				$router = new \OC\Route\Router($logger);
450
			}
451
			return $router;
452
		});
453
		$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...
454
			return new Search();
455
		});
456
		$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...
457
			return new SecureRandom();
458
		});
459
		$this->registerService('Crypto', function (Server $c) {
460
			return new Crypto($c->getConfig(), $c->getSecureRandom());
461
		});
462
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
463
		$this->registerService('Hasher', function (Server $c) {
464
			return new Hasher($c->getConfig());
465
		});
466
		$this->registerService('CredentialsManager', function (Server $c) {
467
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
468
		});
469
		$this->registerService('DatabaseConnection', function (Server $c) {
470
			$systemConfig = $c->getSystemConfig();
471
			$keys = $systemConfig->getKeys();
472
			if (!isset($keys['dbname']) && !isset($keys['dbhost']) && isset($keys['dbtableprefix'])) {
473
				throw new \OC\DatabaseException('No database configured');
474
			}
475
476
			$factory = new \OC\DB\ConnectionFactory($systemConfig);
477
			$type = $systemConfig->getValue('dbtype', 'sqlite');
478
			if (!$factory->isValidType($type)) {
479
				throw new \OC\DatabaseException('Invalid database type');
480
			}
481
			$connectionParams = $factory->createConnectionParams();
482
			$connection = $factory->getConnection($type, $connectionParams);
483
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
484
			return $connection;
485
		});
486
		$this->registerService('Db', function (Server $c) {
487
			return new Db($c->getDatabaseConnection());
488
		});
489
		$this->registerService('HTTPHelper', function (Server $c) {
490
			$config = $c->getConfig();
491
			return new HTTPHelper(
492
				$config,
493
				$c->getHTTPClientService()
494
			);
495
		});
496 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...
497
			$user = \OC_User::getUser();
498
			$uid = $user ? $user : null;
499
			return new ClientService(
500
				$c->getConfig(),
501
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
502
			);
503
		});
504 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...
505
			$user = \OC_User::getUser();
506
			$uid = $user ? $user : null;
507
			return new WebDavClientService(
508
				$c->getConfig(),
509
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
510
			);
511
		});
512 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...
513
			$eventLogger = new EventLogger();
514
			if ($c->getSystemConfig()->getValue('debug', false)) {
515
				// In debug mode, module is being activated by default
516
				$eventLogger->activate();
517
			}
518
			return $eventLogger;
519
		});
520 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...
521
			$queryLogger = new QueryLogger();
522
			if ($c->getSystemConfig()->getValue('debug', false)) {
523
				// In debug mode, module is being activated by default
524
				$queryLogger->activate();
525
			}
526
			return $queryLogger;
527
		});
528
		$this->registerService('TempManager', function (Server $c) {
529
			return new TempManager(
530
				$c->getLogger(),
531
				$c->getConfig()
532
			);
533
		});
534
		$this->registerService('AppManager', function (Server $c) {
535
			return new \OC\App\AppManager(
536
				$c->getUserSession(),
537
				$c->getAppConfig(),
538
				$c->getGroupManager(),
539
				$c->getMemCacheFactory(),
540
				$c->getEventDispatcher()
541
			);
542
		});
543
		$this->registerService('DateTimeZone', function (Server $c) {
544
			return new DateTimeZone(
545
				$c->getConfig(),
546
				$c->getSession()
547
			);
548
		});
549
		$this->registerService('DateTimeFormatter', function (Server $c) {
550
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
551
552
			return new DateTimeFormatter(
553
				$c->getDateTimeZone()->getTimeZone(),
554
				$c->getL10N('lib', $language)
555
			);
556
		});
557
		$this->registerService('UserMountCache', function (Server $c) {
558
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
559
			$listener = new UserMountCacheListener($mountCache);
560
			$listener->listen($c->getUserManager());
561
			return $mountCache;
562
		});
563
		$this->registerService('MountConfigManager', function (Server $c) {
564
			$loader = \OC\Files\Filesystem::getLoader();
565
			$mountCache = $c->query('UserMountCache');
566
			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
567
568
			// builtin providers
569
570
			$config = $c->getConfig();
571
			$manager->registerProvider(new CacheMountProvider($config));
572
			$manager->registerHomeProvider(new LocalHomeMountProvider());
573
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
574
575
			// external storage
576
			if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') {
577
				$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
578
					$c->query('AllConfig'),
579
					$c->query('UserStoragesService'),
580
					$c->query('UserGlobalStoragesService')
581
				));
582
			}
583
584
			return $manager;
585
		});
586
		$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...
587
			return new IniGetWrapper();
588
		});
589
		$this->registerService('AsyncCommandBus', function (Server $c) {
590
			$jobList = $c->getJobList();
591
			return new AsyncBus($jobList);
592
		});
593
		$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...
594
			return new TrustedDomainHelper($this->getConfig());
595
		});
596
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
597
			// IConfig and IAppManager requires a working database. This code
598
			// might however be called when ownCloud is not yet setup.
599
			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
600
				$config = $c->getConfig();
601
				$appManager = $c->getAppManager();
602
			} else {
603
				$config = null;
604
				$appManager = null;
605
			}
606
607
			return new Checker(
608
					new EnvironmentHelper(),
609
					new FileAccessHelper(),
610
					new AppLocator(),
611
					$config,
612
					$c->getMemCacheFactory(),
613
					$appManager,
614
					$c->getTempManager()
615
			);
616
		});
617
		$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...
618
			if (isset($this['urlParams'])) {
619
				$urlParams = $this['urlParams'];
620
			} else {
621
				$urlParams = [];
622
			}
623
624
			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
625
				&& in_array('fakeinput', stream_get_wrappers())
626
			) {
627
				$stream = 'fakeinput://data';
628
			} else {
629
				$stream = 'php://input';
630
			}
631
632
			return new Request(
633
				[
634
					'get' => $_GET,
635
					'post' => $_POST,
636
					'files' => $_FILES,
637
					'server' => $_SERVER,
638
					'env' => $_ENV,
639
					'cookies' => $_COOKIE,
640
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
641
						? $_SERVER['REQUEST_METHOD']
642
						: null,
643
					'urlParams' => $urlParams,
644
				],
645
				$this->getSecureRandom(),
646
				$this->getConfig(),
647
				$this->getCsrfTokenManager(),
648
				$stream
649
			);
650
		});
651
		$this->registerService('Mailer', function (Server $c) {
652
			return new Mailer(
653
				$c->getConfig(),
654
				$c->getLogger(),
655
				new \OC_Defaults()
656
			);
657
		});
658
		$this->registerService('LockingProvider', function (Server $c) {
659
			$ini = $c->getIniWrapper();
660
			$config = $c->getConfig();
661
			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
662
			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
663
				/** @var \OC\Memcache\Factory $memcacheFactory */
664
				$memcacheFactory = $c->getMemCacheFactory();
665
				$memcache = $memcacheFactory->createLocking('lock');
666
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
667
					return new MemcacheLockingProvider($memcache, $ttl);
668
				}
669
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
670
			}
671
			return new NoopLockingProvider();
672
		});
673
		$this->registerAlias('OCP\Lock\ILockingProvider', 'LockingProvider');
674
		$this->registerService('MountManager', function () {
675
			return new \OC\Files\Mount\Manager();
676
		});
677
		$this->registerService('MimeTypeDetector', function (Server $c) {
678
			return new \OC\Files\Type\Detection(
679
				$c->getURLGenerator(),
680
				\OC::$SERVERROOT . '/config/',
681
				\OC::$SERVERROOT . '/resources/config/'
682
			);
683
		});
684
		$this->registerService('MimeTypeLoader', function (Server $c) {
685
			return new \OC\Files\Type\Loader(
686
				$c->getDatabaseConnection()
687
			);
688
		});
689
		$this->registerAlias('OCP\Files\IMimeTypeLoader', 'MimeTypeLoader');
690
		$this->registerService('NotificationManager', function () {
691
			return new Manager();
692
		});
693
		$this->registerService('CapabilitiesManager', function (Server $c) {
694
			$manager = new \OC\CapabilitiesManager();
695
			$manager->registerCapability(function () use ($c) {
696
				return new \OC\OCS\CoreCapabilities($c->getConfig());
697
			});
698
			return $manager;
699
		});
700 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...
701
			$config = $c->getConfig();
702
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
703
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
704
			$factory = new $factoryClass($this);
705
			return $factory->getManager();
706
		});
707
		$this->registerService('EventDispatcher', function () {
708
			return new EventDispatcher();
709
		});
710
		$this->registerService('CryptoWrapper', function (Server $c) {
711
			// FIXME: Instantiiated here due to cyclic dependency
712
			$request = new Request(
713
				[
714
					'get' => $_GET,
715
					'post' => $_POST,
716
					'files' => $_FILES,
717
					'server' => $_SERVER,
718
					'env' => $_ENV,
719
					'cookies' => $_COOKIE,
720
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
721
						? $_SERVER['REQUEST_METHOD']
722
						: null,
723
				],
724
				$c->getSecureRandom(),
725
				$c->getConfig()
726
			);
727
728
			return new CryptoWrapper(
729
				$c->getConfig(),
730
				$c->getCrypto(),
731
				$c->getSecureRandom(),
732
				$request
733
			);
734
		});
735
		$this->registerService('CsrfTokenManager', function (Server $c) {
736
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
737
			$sessionStorage = new SessionStorage($c->getSession());
738
739
			return new CsrfTokenManager(
740
				$tokenGenerator,
741
				$sessionStorage
742
			);
743
		});
744
		$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...
745
			return new ContentSecurityPolicyManager();
746
		});
747
		$this->registerService('StoragesDBConfigService', function (Server $c) {
748
			return new DBConfigService(
749
				$c->getDatabaseConnection(),
750
				$c->getCrypto()
751
			);
752
		});
753
		$this->registerService('StoragesBackendService', function (Server $c) {
754
			$service = new StoragesBackendService($c->query('AllConfig'));
755
756
			// register auth mechanisms provided by core
757
			$provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [
758
				// AuthMechanism::SCHEME_NULL mechanism
759
				'OC\Files\External\Auth\NullMechanism',
760
761
				// AuthMechanism::SCHEME_BUILTIN mechanism
762
				'OC\Files\External\Auth\Builtin',
763
764
				// AuthMechanism::SCHEME_PASSWORD mechanisms
765
				'OC\Files\External\Auth\Password\Password',
766
			]);
767
768
			$service->registerAuthMechanismProvider($provider);
769
770
			// force-load the session one as it will register hooks...
771
			// TODO: obsolete it and use the TokenProvider to get the user's password from the session
772
			$sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials(
773
				$c->getSession(),
774
				$c->getCrypto()
775
			);
776
			$service->registerAuthMechanism($sessionCreds);
777
778
			return $service;
779
		});
780
		$this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService');
781
		$this->registerService('GlobalStoragesService', function (Server $c) {
782
			return new GlobalStoragesService(
783
				$c->query('StoragesBackendService'),
784
				$c->query('StoragesDBConfigService'),
785
				$c->query('UserMountCache')
786
			);
787
		});
788
		$this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService');
789 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...
790
			return new UserGlobalStoragesService(
791
				$c->query('StoragesBackendService'),
792
				$c->query('StoragesDBConfigService'),
793
				$c->query('UserSession'),
794
				$c->query('GroupManager'),
795
				$c->query('UserMountCache')
796
			);
797
		});
798
		$this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService');
799 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...
800
			return new UserStoragesService(
801
				$c->query('StoragesBackendService'),
802
				$c->query('StoragesDBConfigService'),
803
				$c->query('UserSession'),
804
				$c->query('UserMountCache')
805
			);
806
		});
807
		$this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService');
808
		$this->registerService('ShareManager', function(Server $c) {
809
			$config = $c->getConfig();
810
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
811
			/** @var \OCP\Share\IProviderFactory $factory */
812
			$factory = new $factoryClass($this);
813
814
			$manager = new \OC\Share20\Manager(
815
				$c->getLogger(),
816
				$c->getConfig(),
817
				$c->getSecureRandom(),
818
				$c->getHasher(),
819
				$c->getMountManager(),
820
				$c->getGroupManager(),
821
				$c->getL10N('core'),
822
				$factory,
823
				$c->getUserManager(),
824
				$c->getLazyRootFolder()
825
			);
826
827
			return $manager;
828
		});
829
830
		$this->registerService('ThemeService', 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...
831
			return new ThemeService($this->getSystemConfig()->getValue('theme'));
832
		});
833
		$this->registerAlias('OCP\Theme\IThemeService', 'ThemeService');
834
		$this->registerAlias('OCP\IUserSession', 'UserSession');
835
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
836
	}
837
838
	/**
839
	 * @return \OCP\Contacts\IManager
840
	 */
841
	public function getContactsManager() {
842
		return $this->query('ContactsManager');
843
	}
844
845
	/**
846
	 * @return \OC\Encryption\Manager
847
	 */
848
	public function getEncryptionManager() {
849
		return $this->query('EncryptionManager');
850
	}
851
852
	/**
853
	 * @return \OC\Encryption\File
854
	 */
855
	public function getEncryptionFilesHelper() {
856
		return $this->query('EncryptionFileHelper');
857
	}
858
859
	/**
860
	 * @return \OCP\Encryption\Keys\IStorage
861
	 */
862
	public function getEncryptionKeyStorage() {
863
		return $this->query('EncryptionKeyStorage');
864
	}
865
866
	/**
867
	 * The current request object holding all information about the request
868
	 * currently being processed is returned from this method.
869
	 * In case the current execution was not initiated by a web request null is returned
870
	 *
871
	 * @return \OCP\IRequest
872
	 */
873
	public function getRequest() {
874
		return $this->query('Request');
875
	}
876
877
	/**
878
	 * Returns the preview manager which can create preview images for a given file
879
	 *
880
	 * @return \OCP\IPreview
881
	 */
882
	public function getPreviewManager() {
883
		return $this->query('PreviewManager');
884
	}
885
886
	/**
887
	 * Returns the tag manager which can get and set tags for different object types
888
	 *
889
	 * @see \OCP\ITagManager::load()
890
	 * @return \OCP\ITagManager
891
	 */
892
	public function getTagManager() {
893
		return $this->query('TagManager');
894
	}
895
896
	/**
897
	 * Returns the system-tag manager
898
	 *
899
	 * @return \OCP\SystemTag\ISystemTagManager
900
	 *
901
	 * @since 9.0.0
902
	 */
903
	public function getSystemTagManager() {
904
		return $this->query('SystemTagManager');
905
	}
906
907
	/**
908
	 * Returns the system-tag object mapper
909
	 *
910
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
911
	 *
912
	 * @since 9.0.0
913
	 */
914
	public function getSystemTagObjectMapper() {
915
		return $this->query('SystemTagObjectMapper');
916
	}
917
918
919
	/**
920
	 * Returns the avatar manager, used for avatar functionality
921
	 *
922
	 * @return \OCP\IAvatarManager
923
	 */
924
	public function getAvatarManager() {
925
		return $this->query('AvatarManager');
926
	}
927
928
	/**
929
	 * Returns the root folder of ownCloud's data directory
930
	 *
931
	 * @return \OCP\Files\IRootFolder
932
	 */
933
	public function getRootFolder() {
934
		return $this->query('RootFolder');
935
	}
936
937
	/**
938
	 * Returns the root folder of ownCloud's data directory
939
	 * This is the lazy variant so this gets only initialized once it
940
	 * is actually used.
941
	 *
942
	 * @return \OCP\Files\IRootFolder
943
	 */
944
	public function getLazyRootFolder() {
945
		return $this->query('LazyRootFolder');
946
	}
947
948
	/**
949
	 * Returns a view to ownCloud's files folder
950
	 *
951
	 * @param string $userId user ID
952
	 * @return \OCP\Files\Folder|null
953
	 */
954
	public function getUserFolder($userId = null) {
955 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...
956
			$user = $this->getUserSession()->getUser();
957
			if (!$user) {
958
				return null;
959
			}
960
			$userId = $user->getUID();
961
		}
962
		$root = $this->getRootFolder();
963
		return $root->getUserFolder($userId);
964
	}
965
966
	/**
967
	 * Returns an app-specific view in ownClouds data directory
968
	 *
969
	 * @return \OCP\Files\Folder
970
	 */
971
	public function getAppFolder() {
972
		$dir = '/' . \OC_App::getCurrentApp();
973
		$root = $this->getRootFolder();
974
		if (!$root->nodeExists($dir)) {
975
			$folder = $root->newFolder($dir);
976
		} else {
977
			$folder = $root->get($dir);
978
		}
979
		return $folder;
980
	}
981
982
	/**
983
	 * @return \OC\User\Manager
984
	 */
985
	public function getUserManager() {
986
		return $this->query('UserManager');
987
	}
988
989
	/**
990
	 * @return \OC\User\AccountMapper
991
	 */
992
	public function getAccountMapper() {
993
		return $this->query('AccountMapper');
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
		if($this->getConfig()->getSystemValue('installed', false) === false) {
1008
			return null;
1009
		}
1010
		return $this->query('UserSession');
1011
	}
1012
1013
	/**
1014
	 * @return ISession
1015
	 */
1016
	public function getSession() {
1017
		$userSession = $this->getUserSession();
1018
		if (is_null($userSession)) {
1019
			return new Memory('');
1020
		}
1021
		return $userSession->getSession();
1022
	}
1023
1024
	/**
1025
	 * @param ISession $session
1026
	 */
1027
	public function setSession(ISession $session) {
1028
		$userSession = $this->getUserSession();
1029
		if (is_null($userSession)) {
1030
			return;
1031
		}
1032
		$userSession->setSession($session);
1033
	}
1034
1035
	/**
1036
	 * @return \OC\Authentication\TwoFactorAuth\Manager
1037
	 */
1038
	public function getTwoFactorAuthManager() {
1039
		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1040
	}
1041
1042
	/**
1043
	 * @return \OC\NavigationManager
1044
	 */
1045
	public function getNavigationManager() {
1046
		return $this->query('NavigationManager');
1047
	}
1048
1049
	/**
1050
	 * @return \OCP\IConfig
1051
	 */
1052
	public function getConfig() {
1053
		return $this->query('AllConfig');
1054
	}
1055
1056
	/**
1057
	 * @internal For internal use only
1058
	 * @return \OC\SystemConfig
1059
	 */
1060
	public function getSystemConfig() {
1061
		return $this->query('SystemConfig');
1062
	}
1063
1064
	/**
1065
	 * Returns the app config manager
1066
	 *
1067
	 * @return \OCP\IAppConfig
1068
	 */
1069
	public function getAppConfig() {
1070
		return $this->query('AppConfig');
1071
	}
1072
1073
	/**
1074
	 * @return \OCP\L10N\IFactory
1075
	 */
1076
	public function getL10NFactory() {
1077
		return $this->query('L10NFactory');
1078
	}
1079
1080
	/**
1081
	 * get an L10N instance
1082
	 *
1083
	 * @param string $app appid
1084
	 * @param string $lang
1085
	 * @return IL10N
1086
	 */
1087
	public function getL10N($app, $lang = null) {
1088
		return $this->getL10NFactory()->get($app, $lang);
1089
	}
1090
1091
	/**
1092
	 * @return \OCP\IURLGenerator
1093
	 */
1094
	public function getURLGenerator() {
1095
		return $this->query('URLGenerator');
1096
	}
1097
1098
	/**
1099
	 * @return \OCP\IHelper
1100
	 */
1101
	public function getHelper() {
1102
		return $this->query('AppHelper');
1103
	}
1104
1105
	/**
1106
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1107
	 * getMemCacheFactory() instead.
1108
	 *
1109
	 * @return \OCP\ICache
1110
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1111
	 */
1112
	public function getCache() {
1113
		return $this->query('UserCache');
1114
	}
1115
1116
	/**
1117
	 * Returns an \OCP\CacheFactory instance
1118
	 *
1119
	 * @return \OCP\ICacheFactory
1120
	 */
1121
	public function getMemCacheFactory() {
1122
		return $this->query('MemCacheFactory');
1123
	}
1124
1125
	/**
1126
	 * Returns an \OC\RedisFactory instance
1127
	 *
1128
	 * @return \OC\RedisFactory
1129
	 */
1130
	public function getGetRedisFactory() {
1131
		return $this->query('RedisFactory');
1132
	}
1133
1134
1135
	/**
1136
	 * Returns the current session
1137
	 *
1138
	 * @return \OCP\IDBConnection
1139
	 */
1140
	public function getDatabaseConnection() {
1141
		return $this->query('DatabaseConnection');
1142
	}
1143
1144
	/**
1145
	 * Returns the activity manager
1146
	 *
1147
	 * @return \OCP\Activity\IManager
1148
	 */
1149
	public function getActivityManager() {
1150
		return $this->query('ActivityManager');
1151
	}
1152
1153
	/**
1154
	 * Returns an job list for controlling background jobs
1155
	 *
1156
	 * @return \OCP\BackgroundJob\IJobList
1157
	 */
1158
	public function getJobList() {
1159
		return $this->query('JobList');
1160
	}
1161
1162
	/**
1163
	 * Returns a logger instance
1164
	 *
1165
	 * @return \OCP\ILogger
1166
	 */
1167
	public function getLogger() {
1168
		if ($this->logger === null) {
1169
			$this->logger = $this->query('Logger');
1170
		}
1171
		return $this->logger;
1172
	}
1173
1174
	/**
1175
	 * Returns a logger instance
1176
	 *
1177
	 * @return \OCP\Settings\ISettingsManager
1178
	 */
1179
	public function getSettingsManager() {
1180
		return $this->query('SettingsManager');
1181
	}
1182
1183
1184
	/**
1185
	 * Returns a router for generating and matching urls
1186
	 *
1187
	 * @return \OCP\Route\IRouter
1188
	 */
1189
	public function getRouter() {
1190
		return $this->query('Router');
1191
	}
1192
1193
	/**
1194
	 * Returns a search instance
1195
	 *
1196
	 * @return \OCP\ISearch
1197
	 */
1198
	public function getSearch() {
1199
		return $this->query('Search');
1200
	}
1201
1202
	/**
1203
	 * Returns a SecureRandom instance
1204
	 *
1205
	 * @return \OCP\Security\ISecureRandom
1206
	 */
1207
	public function getSecureRandom() {
1208
		return $this->query('SecureRandom');
1209
	}
1210
1211
	/**
1212
	 * Returns a Crypto instance
1213
	 *
1214
	 * @return \OCP\Security\ICrypto
1215
	 */
1216
	public function getCrypto() {
1217
		return $this->query('Crypto');
1218
	}
1219
1220
	/**
1221
	 * Returns a Hasher instance
1222
	 *
1223
	 * @return \OCP\Security\IHasher
1224
	 */
1225
	public function getHasher() {
1226
		return $this->query('Hasher');
1227
	}
1228
1229
	/**
1230
	 * Returns a CredentialsManager instance
1231
	 *
1232
	 * @return \OCP\Security\ICredentialsManager
1233
	 */
1234
	public function getCredentialsManager() {
1235
		return $this->query('CredentialsManager');
1236
	}
1237
1238
	/**
1239
	 * Returns an instance of the db facade
1240
	 *
1241
	 * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
1242
	 * @return \OCP\IDb
1243
	 */
1244
	public function getDb() {
1245
		return $this->query('Db');
1246
	}
1247
1248
	/**
1249
	 * Returns an instance of the HTTP helper class
1250
	 *
1251
	 * @deprecated Use getHTTPClientService()
1252
	 * @return \OC\HTTPHelper
1253
	 */
1254
	public function getHTTPHelper() {
1255
		return $this->query('HTTPHelper');
1256
	}
1257
1258
	/**
1259
	 * Get the certificate manager for the user
1260
	 *
1261
	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1262
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1263
	 */
1264
	public function getCertificateManager($userId = '') {
1265 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...
1266
			$userSession = $this->getUserSession();
1267
			$user = $userSession->getUser();
1268
			if (is_null($user)) {
1269
				return null;
1270
			}
1271
			$userId = $user->getUID();
1272
		}
1273
		return new CertificateManager($userId, new View(), $this->getConfig());
1274
	}
1275
1276
	/**
1277
	 * Returns an instance of the HTTP client service
1278
	 *
1279
	 * @return \OCP\Http\Client\IClientService
1280
	 */
1281
	public function getHTTPClientService() {
1282
		return $this->query('HttpClientService');
1283
	}
1284
1285
	/**
1286
	 * Returns an instance of the Webdav client service
1287
	 *
1288
	 * @return \OCP\Http\Client\IWebDavClientService
1289
	 */
1290
	public function getWebDavClientService() {
1291
		return $this->query('WebDavClientService');
1292
	}
1293
1294
	/**
1295
	 * Create a new event source
1296
	 *
1297
	 * @return \OCP\IEventSource
1298
	 */
1299
	public function createEventSource() {
1300
		return new \OC_EventSource();
1301
	}
1302
1303
	/**
1304
	 * Get the active event logger
1305
	 *
1306
	 * The returned logger only logs data when debug mode is enabled
1307
	 *
1308
	 * @return \OCP\Diagnostics\IEventLogger
1309
	 */
1310
	public function getEventLogger() {
1311
		return $this->query('EventLogger');
1312
	}
1313
1314
	/**
1315
	 * Get the active query logger
1316
	 *
1317
	 * The returned logger only logs data when debug mode is enabled
1318
	 *
1319
	 * @return \OCP\Diagnostics\IQueryLogger
1320
	 */
1321
	public function getQueryLogger() {
1322
		return $this->query('QueryLogger');
1323
	}
1324
1325
	/**
1326
	 * Get the manager for temporary files and folders
1327
	 *
1328
	 * @return \OCP\ITempManager
1329
	 */
1330
	public function getTempManager() {
1331
		return $this->query('TempManager');
1332
	}
1333
1334
	/**
1335
	 * Get the app manager
1336
	 *
1337
	 * @return \OCP\App\IAppManager
1338
	 */
1339
	public function getAppManager() {
1340
		return $this->query('AppManager');
1341
	}
1342
1343
	/**
1344
	 * Creates a new mailer
1345
	 *
1346
	 * @return \OCP\Mail\IMailer
1347
	 */
1348
	public function getMailer() {
1349
		return $this->query('Mailer');
1350
	}
1351
1352
	/**
1353
	 * Get the webroot
1354
	 *
1355
	 * @return string
1356
	 */
1357
	public function getWebRoot() {
1358
		return $this->webRoot;
1359
	}
1360
1361
	/**
1362
	 * @return \OCP\IDateTimeZone
1363
	 */
1364
	public function getDateTimeZone() {
1365
		return $this->query('DateTimeZone');
1366
	}
1367
1368
	/**
1369
	 * @return \OCP\IDateTimeFormatter
1370
	 */
1371
	public function getDateTimeFormatter() {
1372
		return $this->query('DateTimeFormatter');
1373
	}
1374
1375
	/**
1376
	 * @return \OCP\Files\Config\IMountProviderCollection
1377
	 */
1378
	public function getMountProviderCollection() {
1379
		return $this->query('MountConfigManager');
1380
	}
1381
1382
	/**
1383
	 * Get the IniWrapper
1384
	 *
1385
	 * @return IniGetWrapper
1386
	 */
1387
	public function getIniWrapper() {
1388
		return $this->query('IniWrapper');
1389
	}
1390
1391
	/**
1392
	 * @return \OCP\Command\IBus
1393
	 */
1394
	public function getCommandBus() {
1395
		return $this->query('AsyncCommandBus');
1396
	}
1397
1398
	/**
1399
	 * Get the trusted domain helper
1400
	 *
1401
	 * @return TrustedDomainHelper
1402
	 */
1403
	public function getTrustedDomainHelper() {
1404
		return $this->query('TrustedDomainHelper');
1405
	}
1406
1407
	/**
1408
	 * Get the locking provider
1409
	 *
1410
	 * @return \OCP\Lock\ILockingProvider
1411
	 * @since 8.1.0
1412
	 */
1413
	public function getLockingProvider() {
1414
		return $this->query('LockingProvider');
1415
	}
1416
1417
	/**
1418
	 * @return \OCP\Files\Mount\IMountManager
1419
	 **/
1420
	function getMountManager() {
1421
		return $this->query('MountManager');
1422
	}
1423
1424
	/**
1425
	 * Get the MimeTypeDetector
1426
	 *
1427
	 * @return \OCP\Files\IMimeTypeDetector
1428
	 */
1429
	public function getMimeTypeDetector() {
1430
		return $this->query('MimeTypeDetector');
1431
	}
1432
1433
	/**
1434
	 * Get the MimeTypeLoader
1435
	 *
1436
	 * @return \OCP\Files\IMimeTypeLoader
1437
	 */
1438
	public function getMimeTypeLoader() {
1439
		return $this->query('MimeTypeLoader');
1440
	}
1441
1442
	/**
1443
	 * Get the manager of all the capabilities
1444
	 *
1445
	 * @return \OC\CapabilitiesManager
1446
	 */
1447
	public function getCapabilitiesManager() {
1448
		return $this->query('CapabilitiesManager');
1449
	}
1450
1451
	/**
1452
	 * Get the EventDispatcher
1453
	 *
1454
	 * @return EventDispatcherInterface
1455
	 * @since 8.2.0
1456
	 */
1457
	public function getEventDispatcher() {
1458
		return $this->query('EventDispatcher');
1459
	}
1460
1461
	/**
1462
	 * Get the Notification Manager
1463
	 *
1464
	 * @return \OCP\Notification\IManager
1465
	 * @since 8.2.0
1466
	 */
1467
	public function getNotificationManager() {
1468
		return $this->query('NotificationManager');
1469
	}
1470
1471
	/**
1472
	 * @return \OCP\Comments\ICommentsManager
1473
	 */
1474
	public function getCommentsManager() {
1475
		return $this->query('CommentsManager');
1476
	}
1477
1478
	/**
1479
	 * @return \OC\IntegrityCheck\Checker
1480
	 */
1481
	public function getIntegrityCodeChecker() {
1482
		return $this->query('IntegrityCodeChecker');
1483
	}
1484
1485
	/**
1486
	 * @return \OC\Session\CryptoWrapper
1487
	 */
1488
	public function getSessionCryptoWrapper() {
1489
		return $this->query('CryptoWrapper');
1490
	}
1491
1492
	/**
1493
	 * @return CsrfTokenManager
1494
	 */
1495
	public function getCsrfTokenManager() {
1496
		return $this->query('CsrfTokenManager');
1497
	}
1498
1499
	/**
1500
	 * @return IContentSecurityPolicyManager
1501
	 */
1502
	public function getContentSecurityPolicyManager() {
1503
		return $this->query('ContentSecurityPolicyManager');
1504
	}
1505
1506
	/**
1507
	 * @return \OCP\Files\External\IStoragesBackendService
1508
	 */
1509
	public function getStoragesBackendService() {
1510
		return $this->query('StoragesBackendService');
1511
	}
1512
1513
	/**
1514
	 * @return \OCP\Files\External\Service\IGlobalStoragesService
1515
	 */
1516
	public function getGlobalStoragesService() {
1517
		return $this->query('GlobalStoragesService');
1518
	}
1519
1520
	/**
1521
	 * @return \OCP\Files\External\Service\IUserGlobalStoragesService
1522
	 */
1523
	public function getUserGlobalStoragesService() {
1524
		return $this->query('UserGlobalStoragesService');
1525
	}
1526
1527
	/**
1528
	 * @return \OCP\Files\External\Service\IUserStoragesService
1529
	 */
1530
	public function getUserStoragesService() {
1531
		return $this->query('UserStoragesService');
1532
	}
1533
1534
	/**
1535
	 * @return \OCP\Share\IManager
1536
	 */
1537
	public function getShareManager() {
1538
		return $this->query('ShareManager');
1539
	}
1540
1541
	/**
1542
	 * @return IThemeService
1543
	 */
1544
	public function getThemeService() {
1545
		return $this->query('\OCP\Theme\IThemeService');
1546
	}
1547
1548
	/**
1549
	 * @return ITimeFactory
1550
	 */
1551
	public function getTimeFactory() {
1552
		return $this->query('\OCP\AppFramework\Utility\ITimeFactory');
1553
	}
1554
}
1555