Completed
Push — master ( ff3e8c...ea9b1c )
by Lukas
13:22 queued 02:44
created

Server::getTrustedDomainHelper()   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
 *
5
 * @author Arthur Schiwon <[email protected]>
6
 * @author Bart Visscher <[email protected]>
7
 * @author Bernhard Posselt <[email protected]>
8
 * @author Bernhard Reiter <[email protected]>
9
 * @author Bjoern Schiessle <[email protected]>
10
 * @author Björn Schießle <[email protected]>
11
 * @author Christopher Schäpers <[email protected]>
12
 * @author Christoph Wurst <[email protected]>
13
 * @author Joas Schilling <[email protected]>
14
 * @author Jörn Friedrich Dreyer <[email protected]>
15
 * @author Lukas Reschke <[email protected]>
16
 * @author Morris Jobke <[email protected]>
17
 * @author Robin Appelman <[email protected]>
18
 * @author Robin McCorkell <[email protected]>
19
 * @author Roeland Jago Douma <[email protected]>
20
 * @author Sander <[email protected]>
21
 * @author Thomas Müller <[email protected]>
22
 * @author Thomas Tanghus <[email protected]>
23
 * @author Vincent Petry <[email protected]>
24
 * @author Roger Szabo <[email protected]>
25
 *
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\Bruteforce\Throttler;
73
use OC\Security\CertificateManager;
74
use OC\Security\CSP\ContentSecurityPolicyManager;
75
use OC\Security\Crypto;
76
use OC\Security\CSRF\CsrfTokenGenerator;
77
use OC\Security\CSRF\CsrfTokenManager;
78
use OC\Security\CSRF\TokenStorage\SessionStorage;
79
use OC\Security\Hasher;
80
use OC\Security\CredentialsManager;
81
use OC\Security\SecureRandom;
82
use OC\Security\TrustedDomainHelper;
83
use OC\Session\CryptoWrapper;
84
use OC\Tagging\TagMapper;
85
use OCA\Theming\ThemingDefaults;
86
use OCP\IL10N;
87
use OCP\IServerContainer;
88
use OCP\Security\IContentSecurityPolicyManager;
89
use Symfony\Component\EventDispatcher\EventDispatcher;
90
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
91
92
/**
93
 * Class Server
94
 *
95
 * @package OC
96
 *
97
 * TODO: hookup all manager classes
98
 */
99
class Server extends ServerContainer implements IServerContainer {
100
	/** @var string */
101
	private $webRoot;
102
103
	/**
104
	 * @param string $webRoot
105
	 * @param \OC\Config $config
106
	 */
107
	public function __construct($webRoot, \OC\Config $config) {
108
		parent::__construct();
109
		$this->webRoot = $webRoot;
110
111
		$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...
112
			return new ContactsManager();
113
		});
114
115
		$this->registerService('PreviewManager', function (Server $c) {
116
			return new PreviewManager($c->getConfig());
117
		});
118
119
		$this->registerService('EncryptionManager', function (Server $c) {
120
			$view = new View();
121
			$util = new Encryption\Util(
122
				$view,
123
				$c->getUserManager(),
124
				$c->getGroupManager(),
125
				$c->getConfig()
126
			);
127
			return new Encryption\Manager(
128
				$c->getConfig(),
129
				$c->getLogger(),
130
				$c->getL10N('core'),
131
				new View(),
132
				$util,
133
				new ArrayCache()
134
			);
135
		});
136
137
		$this->registerService('EncryptionFileHelper', function (Server $c) {
138
			$util = new Encryption\Util(
139
				new View(),
140
				$c->getUserManager(),
141
				$c->getGroupManager(),
142
				$c->getConfig()
143
			);
144
			return new Encryption\File($util);
145
		});
146
147
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
148
			$view = new View();
149
			$util = new Encryption\Util(
150
				$view,
151
				$c->getUserManager(),
152
				$c->getGroupManager(),
153
				$c->getConfig()
154
			);
155
156
			return new Encryption\Keys\Storage($view, $util);
157
		});
158
		$this->registerService('TagMapper', function (Server $c) {
159
			return new TagMapper($c->getDatabaseConnection());
160
		});
161
		$this->registerService('TagManager', function (Server $c) {
162
			$tagMapper = $c->query('TagMapper');
163
			return new TagManager($tagMapper, $c->getUserSession());
164
		});
165 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...
166
			$config = $c->getConfig();
167
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
168
			/** @var \OC\SystemTag\ManagerFactory $factory */
169
			$factory = new $factoryClass($this);
170
			return $factory;
171
		});
172
		$this->registerService('SystemTagManager', function (Server $c) {
173
			return $c->query('SystemTagManagerFactory')->getManager();
174
		});
175
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
176
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
177
		});
178
		$this->registerService('RootFolder', function () {
179
			$manager = \OC\Files\Filesystem::getMountManager(null);
180
			$view = new View();
181
			$root = new Root($manager, $view, null);
182
			$connector = new HookConnector($root, $view);
183
			$connector->viewToNode();
184
			return $root;
185
		});
186
		$this->registerService('LazyRootFolder', function(Server $c) {
187
			return new LazyRoot(function() use ($c) {
188
				return $c->query('RootFolder');
189
			});
190
		});
191
		$this->registerService('UserManager', function (Server $c) {
192
			$config = $c->getConfig();
193
			return new \OC\User\Manager($config);
194
		});
195
		$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...
196
			$groupManager = new \OC\Group\Manager($this->getUserManager());
197
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
198
				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
199
			});
200
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
201
				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
202
			});
203
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
204
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
205
			});
206
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
207
				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
208
			});
209
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
210
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
211
			});
212
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
213
				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
214
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
215
				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
216
			});
217
			return $groupManager;
218
		});
219
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
220
			$dbConnection = $c->getDatabaseConnection();
221
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
222
		});
223
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
224
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
225
			$crypto = $c->getCrypto();
226
			$config = $c->getConfig();
227
			$logger = $c->getLogger();
228
			$timeFactory = new TimeFactory();
229
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
230
		});
231
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
232
		$this->registerService('UserSession', function (Server $c) {
233
			$manager = $c->getUserManager();
234
			$session = new \OC\Session\Memory('');
235
			$timeFactory = new TimeFactory();
236
			// Token providers might require a working database. This code
237
			// might however be called when ownCloud is not yet setup.
238 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...
239
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
240
			} else {
241
				$defaultTokenProvider = null;
242
			}
243
244
			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig());
245
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
246
				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
247
			});
248
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
249
				/** @var $user \OC\User\User */
250
				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
251
			});
252
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
253
				/** @var $user \OC\User\User */
254
				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
255
			});
256
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
257
				/** @var $user \OC\User\User */
258
				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
259
			});
260 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...
261
				/** @var $user \OC\User\User */
262
				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
263
			});
264 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...
265
				/** @var $user \OC\User\User */
266
				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
267
			});
268
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
269
				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
270
			});
271
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
272
				/** @var $user \OC\User\User */
273
				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
274
			});
275
			$userSession->listen('\OC\User', 'logout', function () {
276
				\OC_Hook::emit('OC_User', 'logout', array());
277
			});
278
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
279
				/** @var $user \OC\User\User */
280
				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
281
			});
282
			return $userSession;
283
		});
284
285
		$this->registerService('\OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
286
			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...
287
		});
288
289
		$this->registerService('NavigationManager', 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...
290
			return new \OC\NavigationManager();
291
		});
292
		$this->registerService('AllConfig', function (Server $c) {
293
			return new \OC\AllConfig(
294
				$c->getSystemConfig()
295
			);
296
		});
297
		$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...
298
			return new \OC\SystemConfig($config);
299
		});
300
		$this->registerService('AppConfig', function (Server $c) {
301
			return new \OC\AppConfig($c->getDatabaseConnection());
302
		});
303
		$this->registerService('L10NFactory', function (Server $c) {
304
			return new \OC\L10N\Factory(
305
				$c->getConfig(),
306
				$c->getRequest(),
307
				$c->getUserSession(),
308
				\OC::$SERVERROOT
309
			);
310
		});
311
		$this->registerService('URLGenerator', function (Server $c) {
312
			$config = $c->getConfig();
313
			$cacheFactory = $c->getMemCacheFactory();
314
			return new \OC\URLGenerator(
315
				$config,
316
				$cacheFactory
317
			);
318
		});
319
		$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...
320
			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...
321
		});
322
		$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...
323
			return new Cache\File();
324
		});
325
		$this->registerService('MemCacheFactory', function (Server $c) {
326
			$config = $c->getConfig();
327
328
			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
329
				$v = \OC_App::getAppVersions();
330
				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
331
				$version = implode(',', $v);
332
				$instanceId = \OC_Util::getInstanceId();
333
				$path = \OC::$SERVERROOT;
334
				$prefix = md5($instanceId . '-' . $version . '-' . $path);
335
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
336
					$config->getSystemValue('memcache.local', null),
337
					$config->getSystemValue('memcache.distributed', null),
338
					$config->getSystemValue('memcache.locking', null)
339
				);
340
			}
341
342
			return new \OC\Memcache\Factory('', $c->getLogger(),
343
				'\\OC\\Memcache\\ArrayCache',
344
				'\\OC\\Memcache\\ArrayCache',
345
				'\\OC\\Memcache\\ArrayCache'
346
			);
347
		});
348
		$this->registerService('RedisFactory', function (Server $c) {
349
			$systemConfig = $c->getSystemConfig();
350
			return new RedisFactory($systemConfig);
351
		});
352
		$this->registerService('ActivityManager', function (Server $c) {
353
			return new \OC\Activity\Manager(
354
				$c->getRequest(),
355
				$c->getUserSession(),
356
				$c->getConfig()
357
			);
358
		});
359
		$this->registerService('AvatarManager', function (Server $c) {
360
			return new AvatarManager(
361
				$c->getUserManager(),
362
				$c->getAppDataDir('avatar'),
363
				$c->getL10N('lib'),
364
				$c->getLogger(),
365
				$c->getConfig()
366
			);
367
		});
368
		$this->registerService('Logger', function (Server $c) {
369
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'file');
370
			// TODO: Drop backwards compatibility for config in the future
371
			$logger = 'OC\\Log\\' . ucfirst($logClass=='owncloud' ? 'file' : $logClass);
372
			call_user_func(array($logger, 'init'));
373
374
			return new Log($logger);
375
		});
376
		$this->registerService('JobList', function (Server $c) {
377
			$config = $c->getConfig();
378
			return new \OC\BackgroundJob\JobList(
379
				$c->getDatabaseConnection(),
380
				$config,
381
				new TimeFactory()
382
			);
383
		});
384
		$this->registerService('Router', function (Server $c) {
385
			$cacheFactory = $c->getMemCacheFactory();
386
			$logger = $c->getLogger();
387
			if ($cacheFactory->isAvailable()) {
388
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
389
			} else {
390
				$router = new \OC\Route\Router($logger);
391
			}
392
			return $router;
393
		});
394
		$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...
395
			return new Search();
396
		});
397
		$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...
398
			return new SecureRandom();
399
		});
400
		$this->registerService('Crypto', function (Server $c) {
401
			return new Crypto($c->getConfig(), $c->getSecureRandom());
402
		});
403
		$this->registerService('Hasher', function (Server $c) {
404
			return new Hasher($c->getConfig());
405
		});
406
		$this->registerService('CredentialsManager', function (Server $c) {
407
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
408
		});
409
		$this->registerService('DatabaseConnection', function (Server $c) {
410
			$factory = new \OC\DB\ConnectionFactory();
411
			$systemConfig = $c->getSystemConfig();
412
			$type = $systemConfig->getValue('dbtype', 'sqlite');
413
			if (!$factory->isValidType($type)) {
414
				throw new \OC\DatabaseException('Invalid database type');
415
			}
416
			$connectionParams = $factory->createConnectionParams($systemConfig);
417
			$connection = $factory->getConnection($type, $connectionParams);
418
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
419
			return $connection;
420
		});
421
		$this->registerService('Db', function (Server $c) {
422
			return new Db($c->getDatabaseConnection());
0 ignored issues
show
Deprecated Code introduced by
The class OC\AppFramework\Db\Db has been deprecated with message: use IDBConnection directly, will be removed in ownCloud 10
Small Facade for being able to inject the database connection for tests

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