Completed
Push — master ( a82218...06e071 )
by Thomas
11:03
created

Server::getServiceLoader()   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\App\IServiceLoader;
91
use OCP\AppFramework\QueryException;
92
use OCP\AppFramework\Utility\ITimeFactory;
93
use OCP\IL10N;
94
use OCP\ILogger;
95
use OCP\IServerContainer;
96
use OCP\ISession;
97
use OCP\IUser;
98
use OCP\Security\IContentSecurityPolicyManager;
99
use OCP\Theme\IThemeService;
100
use Symfony\Component\EventDispatcher\EventDispatcher;
101
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
102
use OC\Files\External\StoragesBackendService;
103
use OC\Files\External\Service\UserStoragesService;
104
use OC\Files\External\Service\UserGlobalStoragesService;
105
use OC\Files\External\Service\GlobalStoragesService;
106
use OC\Files\External\Service\DBConfigService;
107
use OC\Http\Client\WebDavClientService;
108
use Symfony\Component\EventDispatcher\GenericEvent;
109
110
/**
111
 * Class Server
112
 *
113
 * @package OC
114
 *
115
 * TODO: hookup all manager classes
116
 */
117
class Server extends ServerContainer implements IServerContainer, IServiceLoader {
118
	/** @var string */
119
	private $webRoot;
120
121
	/**
122
	 * cache the logger to prevent querying it over and over again
123
	 * @var ILogger;
124
	 */
125
	private $logger;
126
127
	/**
128
	 * @param string $webRoot
129
	 * @param \OC\Config $config
130
	 */
131
	public function __construct($webRoot, \OC\Config $config) {
132
		parent::__construct();
133
		$this->webRoot = $webRoot;
134
135
		$this->registerService('SettingsManager', function(Server $c) {
136
			return new SettingsManager(
137
				$c->getL10N('lib'),
138
				$c->getAppManager(),
139
				$c->getUserSession(),
140
				$c->getLogger(),
141
				$c->getGroupManager(),
142
				$c->getConfig(),
143
				new \OCP\Defaults(),
144
				$c->getURLGenerator(),
145
				new Helper(),
146
				$c->getLockingProvider(),
147
				$c->getDatabaseConnection(),
148
				$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...
149
				$c->getL10NFactory()
150
151
			);
152
		});
153
154
		$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...
155
			return new ContactsManager();
156
		});
157
158
		$this->registerService('PreviewManager', function (Server $c) {
159
			return new PreviewManager($c->getConfig());
160
		});
161
162
		$this->registerService('EncryptionManager', function (Server $c) {
163
			$view = new View();
164
			$util = new Encryption\Util(
165
				$view,
166
				$c->getUserManager(),
167
				$c->getGroupManager(),
168
				$c->getConfig()
169
			);
170
			return new Encryption\Manager(
171
				$c->getConfig(),
172
				$c->getLogger(),
173
				$c->getL10N('core'),
174
				new View(),
175
				$util,
176
				new ArrayCache()
177
			);
178
		});
179
180
		$this->registerService('EncryptionFileHelper', function (Server $c) {
181
			$util = new Encryption\Util(
182
				new View(),
183
				$c->getUserManager(),
184
				$c->getGroupManager(),
185
				$c->getConfig()
186
			);
187
			return new Encryption\File($util);
188
		});
189
190
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
191
			$view = new View();
192
			$util = new Encryption\Util(
193
				$view,
194
				$c->getUserManager(),
195
				$c->getGroupManager(),
196
				$c->getConfig()
197
			);
198
199
			return new Encryption\Keys\Storage(
200
				$view,
201
				$util,
202
				$c->getUserSession()
203
			);
204
		});
205
		$this->registerService('TagMapper', function (Server $c) {
206
			return new TagMapper($c->getDatabaseConnection());
207
		});
208
		$this->registerService('TagManager', function (Server $c) {
209
			$tagMapper = $c->query('TagMapper');
210
			return new TagManager($tagMapper, $c->getUserSession());
211
		});
212 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...
213
			$config = $c->getConfig();
214
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
215
			/** @var \OC\SystemTag\ManagerFactory $factory */
216
			$factory = new $factoryClass($this);
217
			return $factory;
218
		});
219
		$this->registerService('SystemTagManager', function (Server $c) {
220
			return $c->query('SystemTagManagerFactory')->getManager();
221
		});
222
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
223
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
224
		});
225
		$this->registerService('RootFolder', function () {
226
			$manager = \OC\Files\Filesystem::getMountManager(null);
227
			$view = new View();
228
			$root = new Root($manager, $view, null);
229
			$connector = new HookConnector($root, $view);
230
			$connector->viewToNode();
231
			return $root;
232
		});
233
		$this->registerService('LazyRootFolder', function(Server $c) {
234
			return new LazyRoot(function() use ($c) {
235
				return $c->getRootFolder();
236
			});
237
		});
238
		$this->registerService('AccountMapper', function(Server $c) {
239
			return new AccountMapper($c->getConfig(), $c->getDatabaseConnection(), new AccountTermMapper($c->getDatabaseConnection()));
240
		});
241
		$this->registerService('UserManager', function (Server $c) {
242
			$config = $c->getConfig();
243
			$logger = $c->getLogger();
244
			return new \OC\User\Manager($config, $logger, $c->getAccountMapper());
245
		});
246
		$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...
247
			$groupManager = new \OC\Group\Manager($this->getUserManager());
248
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
249
				\OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
250
			});
251
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
252
				\OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $gid->getGID()]);
253
			});
254
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
255
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
256
			});
257
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
258
				\OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
259
			});
260
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
261
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
262
			});
263
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
				\OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
265
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
266
				\OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
267
			});
268
			return $groupManager;
269
		});
270
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
271
			$dbConnection = $c->getDatabaseConnection();
272
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
273
		});
274
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
275
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
276
			$crypto = $c->getCrypto();
277
			$config = $c->getConfig();
278
			$logger = $c->getLogger();
279
			$timeFactory = new TimeFactory();
280
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
281
		});
282
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
283
		$this->registerService('TimeFactory', function() {
284
			return new TimeFactory();
285
		});
286
		$this->registerAlias('OCP\AppFramework\Utility\ITimeFactory', 'TimeFactory');
287
		$this->registerService('UserSession', function (Server $c) {
288
			$manager = $c->getUserManager();
289
			$session = new \OC\Session\Memory('');
290
			$timeFactory = new TimeFactory();
291
			// Token providers might require a working database. This code
292
			// might however be called when ownCloud is not yet setup.
293
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
294
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
295
			} else {
296
				$defaultTokenProvider = null;
297
			}
298
299
			$userSession = new \OC\User\Session($manager, $session, $timeFactory,
300
				$defaultTokenProvider, $c->getConfig(), $this);
301
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
302
				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
303
			});
304
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
305
				/** @var $user \OC\User\User */
306
				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
307
			});
308
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
309
				/** @var $user \OC\User\User */
310
				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
311
			});
312
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
313
				/** @var $user \OC\User\User */
314
				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
315
			});
316 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...
317
				/** @var $user \OC\User\User */
318
				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
319
			});
320 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...
321
				/** @var $user \OC\User\User */
322
				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
323
			});
324
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
325
				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
326
			});
327
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
328
				/** @var $user \OC\User\User */
329
				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
330
			});
331
			$userSession->listen('\OC\User', 'preLogout', function () {
332
				$event = new GenericEvent(null, []);
333
				\OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logout', $event);
334
			});
335
			$userSession->listen('\OC\User', 'logout', function () {
336
				\OC_Hook::emit('OC_User', 'logout', []);
337
			});
338
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
339
				/** @var $user \OC\User\User */
340
				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]);
341
			});
342
			return $userSession;
343
		});
344
345
		$this->registerService('\OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
346
			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...
347
		});
348
349
		$this->registerService('NavigationManager', function (Server $c) {
350
			return new \OC\NavigationManager($c->getAppManager(),
351
				$c->getURLGenerator(),
352
				$c->getL10NFactory(),
353
				$c->getUserSession(),
354
				$c->getGroupManager());
355
		});
356
		$this->registerService('AllConfig', function (Server $c) {
357
			return new \OC\AllConfig(
358
				$c->getSystemConfig()
359
			);
360
		});
361
		$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...
362
			return new \OC\SystemConfig($config);
363
		});
364
		$this->registerService('AppConfig', function (Server $c) {
365
			return new \OC\AppConfig($c->getDatabaseConnection());
366
		});
367
		$this->registerService('L10NFactory', function (Server $c) {
368
			return new \OC\L10N\Factory(
369
				$c->getConfig(),
370
				$c->getRequest(),
371
				$c->getUserSession(),
372
				\OC::$SERVERROOT
373
			);
374
		});
375
		$this->registerService('URLGenerator', function (Server $c) {
376
			$config = $c->getConfig();
377
			$cacheFactory = $c->getMemCacheFactory();
378
			$router = $c->getRouter();
379
			return new URLGenerator(
380
				$config,
381
				$cacheFactory,
382
				$router
383
			);
384
		});
385
		$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...
386
			return new \OC\AppHelper();
387
		});
388
		$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...
389
			return new Cache\File();
390
		});
391
		$this->registerService('MemCacheFactory', function (Server $c) {
392
			$config = $c->getConfig();
393
394
			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
395
				$v = \OC_App::getAppVersions();
396
				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
397
				$version = implode(',', $v);
398
				$instanceId = \OC_Util::getInstanceId();
399
				$path = \OC::$SERVERROOT;
400
				$prefix = md5($instanceId . '-' . $version . '-' . $path);
401
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
402
					$config->getSystemValue('memcache.local', null),
403
					$config->getSystemValue('memcache.distributed', null),
404
					$config->getSystemValue('memcache.locking', null)
405
				);
406
			}
407
408
			return new \OC\Memcache\Factory('', $c->getLogger(),
409
				'\\OC\\Memcache\\ArrayCache',
410
				'\\OC\\Memcache\\ArrayCache',
411
				'\\OC\\Memcache\\ArrayCache'
412
			);
413
		});
414
		$this->registerService('RedisFactory', function (Server $c) {
415
			$systemConfig = $c->getSystemConfig();
416
			return new RedisFactory($systemConfig);
417
		});
418
		$this->registerService('ActivityManager', function (Server $c) {
419
			return new \OC\Activity\Manager(
420
				$c->getRequest(),
421
				$c->getUserSession(),
422
				$c->getConfig()
423
			);
424
		});
425
		$this->registerService('AvatarManager', function (Server $c) {
426
			return new AvatarManager(
427
				$c->getUserManager(),
428
				$c->getRootFolder(),
429
				$c->getL10N('lib'),
430
				$c->getLogger()
431
			);
432
		});
433
		$this->registerService('Logger', function (Server $c) {
434
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
435
			$logger = 'OC\\Log\\' . ucfirst($logClass);
436
			call_user_func([$logger, 'init']);
437
438
			return new Log($logger);
439
		});
440
		$this->registerService('JobList', function (Server $c) {
441
			$config = $c->getConfig();
442
			return new \OC\BackgroundJob\JobList(
443
				$c->getDatabaseConnection(),
444
				$config,
445
				new TimeFactory()
446
			);
447
		});
448
		$this->registerService('Router', function (Server $c) {
449
			$cacheFactory = $c->getMemCacheFactory();
450
			$logger = $c->getLogger();
451
			if ($cacheFactory->isAvailable()) {
452
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
453
			} else {
454
				$router = new \OC\Route\Router($logger);
455
			}
456
			return $router;
457
		});
458
		$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...
459
			return new Search();
460
		});
461
		$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...
462
			return new SecureRandom();
463
		});
464
		$this->registerService('Crypto', function (Server $c) {
465
			return new Crypto($c->getConfig(), $c->getSecureRandom());
466
		});
467
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
468
		$this->registerService('Hasher', function (Server $c) {
469
			return new Hasher($c->getConfig());
470
		});
471
		$this->registerService('CredentialsManager', function (Server $c) {
472
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
473
		});
474
		$this->registerService('DatabaseConnection', function (Server $c) {
475
			$systemConfig = $c->getSystemConfig();
476
			$keys = $systemConfig->getKeys();
477
			if (!isset($keys['dbname']) && !isset($keys['dbhost']) && isset($keys['dbtableprefix'])) {
478
				throw new \OC\DatabaseException('No database configured');
479
			}
480
481
			$factory = new \OC\DB\ConnectionFactory($systemConfig);
482
			$type = $systemConfig->getValue('dbtype', 'sqlite');
483
			if (!$factory->isValidType($type)) {
484
				throw new \OC\DatabaseException('Invalid database type');
485
			}
486
			$connectionParams = $factory->createConnectionParams();
487
			$connection = $factory->getConnection($type, $connectionParams);
488
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
489
			return $connection;
490
		});
491
		$this->registerService('Db', function (Server $c) {
492
			return new Db($c->getDatabaseConnection());
493
		});
494
		$this->registerService('HTTPHelper', function (Server $c) {
495
			$config = $c->getConfig();
496
			return new HTTPHelper(
497
				$config,
498
				$c->getHTTPClientService()
499
			);
500
		});
501 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...
502
			$user = \OC_User::getUser();
503
			$uid = $user ? $user : null;
504
			return new ClientService(
505
				$c->getConfig(),
506
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
507
			);
508
		});
509 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...
510
			$user = \OC_User::getUser();
511
			$uid = $user ? $user : null;
512
			return new WebDavClientService(
513
				$c->getConfig(),
514
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
515
			);
516
		});
517 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...
518
			$eventLogger = new EventLogger();
519
			if ($c->getSystemConfig()->getValue('debug', false)) {
520
				// In debug mode, module is being activated by default
521
				$eventLogger->activate();
522
			}
523
			return $eventLogger;
524
		});
525 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...
526
			$queryLogger = new QueryLogger();
527
			if ($c->getSystemConfig()->getValue('debug', false)) {
528
				// In debug mode, module is being activated by default
529
				$queryLogger->activate();
530
			}
531
			return $queryLogger;
532
		});
533
		$this->registerService('TempManager', function (Server $c) {
534
			return new TempManager(
535
				$c->getLogger(),
536
				$c->getConfig()
537
			);
538
		});
539
		$this->registerService('AppManager', function (Server $c) {
540
			return new \OC\App\AppManager(
541
				$c->getUserSession(),
542
				$c->getAppConfig(),
543
				$c->getGroupManager(),
544
				$c->getMemCacheFactory(),
545
				$c->getEventDispatcher(),
546
				$c->getConfig()
547
			);
548
		});
549
		$this->registerService('DateTimeZone', function (Server $c) {
550
			return new DateTimeZone(
551
				$c->getConfig(),
552
				$c->getSession()
553
			);
554
		});
555
		$this->registerService('DateTimeFormatter', function (Server $c) {
556
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
557
558
			return new DateTimeFormatter(
559
				$c->getDateTimeZone()->getTimeZone(),
560
				$c->getL10N('lib', $language)
561
			);
562
		});
563
		$this->registerService('UserMountCache', function (Server $c) {
564
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
565
			$listener = new UserMountCacheListener($mountCache);
566
			$listener->listen($c->getUserManager());
567
			return $mountCache;
568
		});
569
		$this->registerService('MountConfigManager', function (Server $c) {
570
			$loader = \OC\Files\Filesystem::getLoader();
571
			$mountCache = $c->query('UserMountCache');
572
			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
573
574
			// builtin providers
575
576
			$config = $c->getConfig();
577
			$manager->registerProvider(new CacheMountProvider($config));
578
			$manager->registerHomeProvider(new LocalHomeMountProvider());
579
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
580
581
			// external storage
582
			if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') {
583
				$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
584
					$c->query('AllConfig'),
585
					$c->query('UserStoragesService'),
586
					$c->query('UserGlobalStoragesService')
587
				));
588
			}
589
590
			return $manager;
591
		});
592
		$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...
593
			return new IniGetWrapper();
594
		});
595
		$this->registerService('AsyncCommandBus', function (Server $c) {
596
			$jobList = $c->getJobList();
597
			return new AsyncBus($jobList);
598
		});
599
		$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...
600
			return new TrustedDomainHelper($this->getConfig());
601
		});
602
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
603
			// IConfig and IAppManager requires a working database. This code
604
			// might however be called when ownCloud is not yet setup.
605
			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
606
				$config = $c->getConfig();
607
				$appManager = $c->getAppManager();
608
			} else {
609
				$config = null;
610
				$appManager = null;
611
			}
612
613
			return new Checker(
614
					new EnvironmentHelper(),
615
					new FileAccessHelper(),
616
					new AppLocator(),
617
					$config,
618
					$c->getMemCacheFactory(),
619
					$appManager,
620
					$c->getTempManager()
621
			);
622
		});
623
		$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...
624
			if (isset($this['urlParams'])) {
625
				$urlParams = $this['urlParams'];
626
			} else {
627
				$urlParams = [];
628
			}
629
630
			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
631
				&& in_array('fakeinput', stream_get_wrappers())
632
			) {
633
				$stream = 'fakeinput://data';
634
			} else {
635
				$stream = 'php://input';
636
			}
637
638
			return new Request(
639
				[
640
					'get' => $_GET,
641
					'post' => $_POST,
642
					'files' => $_FILES,
643
					'server' => $_SERVER,
644
					'env' => $_ENV,
645
					'cookies' => $_COOKIE,
646
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
647
						? $_SERVER['REQUEST_METHOD']
648
						: null,
649
					'urlParams' => $urlParams,
650
				],
651
				$this->getSecureRandom(),
652
				$this->getConfig(),
653
				$this->getCsrfTokenManager(),
654
				$stream
655
			);
656
		});
657
		$this->registerService('Mailer', function (Server $c) {
658
			return new Mailer(
659
				$c->getConfig(),
660
				$c->getLogger(),
661
				new \OC_Defaults()
662
			);
663
		});
664
		$this->registerService('LockingProvider', function (Server $c) {
665
			$ini = $c->getIniWrapper();
666
			$config = $c->getConfig();
667
			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
668
			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
669
				/** @var \OC\Memcache\Factory $memcacheFactory */
670
				$memcacheFactory = $c->getMemCacheFactory();
671
				$memcache = $memcacheFactory->createLocking('lock');
672
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
673
					return new MemcacheLockingProvider($memcache, $ttl);
674
				}
675
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
676
			}
677
			return new NoopLockingProvider();
678
		});
679
		$this->registerAlias('OCP\Lock\ILockingProvider', 'LockingProvider');
680
		$this->registerService('MountManager', function () {
681
			return new \OC\Files\Mount\Manager();
682
		});
683
		$this->registerService('MimeTypeDetector', function (Server $c) {
684
			return new \OC\Files\Type\Detection(
685
				$c->getURLGenerator(),
686
				\OC::$SERVERROOT . '/config/',
687
				\OC::$SERVERROOT . '/resources/config/'
688
			);
689
		});
690
		$this->registerService('MimeTypeLoader', function (Server $c) {
691
			return new \OC\Files\Type\Loader(
692
				$c->getDatabaseConnection()
693
			);
694
		});
695
		$this->registerAlias('OCP\Files\IMimeTypeLoader', 'MimeTypeLoader');
696
		$this->registerService('NotificationManager', function () {
697
			return new Manager();
698
		});
699
		$this->registerService('CapabilitiesManager', function (Server $c) {
700
			$manager = new \OC\CapabilitiesManager();
701
			$manager->registerCapability(function () use ($c) {
702
				return new \OC\OCS\CoreCapabilities($c->getConfig());
703
			});
704
			return $manager;
705
		});
706 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...
707
			$config = $c->getConfig();
708
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
709
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
710
			$factory = new $factoryClass($this);
711
			return $factory->getManager();
712
		});
713
		$this->registerService('EventDispatcher', function () {
714
			return new EventDispatcher();
715
		});
716
		$this->registerService('CryptoWrapper', function (Server $c) {
717
			// FIXME: Instantiiated here due to cyclic dependency
718
			$request = new Request(
719
				[
720
					'get' => $_GET,
721
					'post' => $_POST,
722
					'files' => $_FILES,
723
					'server' => $_SERVER,
724
					'env' => $_ENV,
725
					'cookies' => $_COOKIE,
726
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
727
						? $_SERVER['REQUEST_METHOD']
728
						: null,
729
				],
730
				$c->getSecureRandom(),
731
				$c->getConfig()
732
			);
733
734
			return new CryptoWrapper(
735
				$c->getConfig(),
736
				$c->getCrypto(),
737
				$c->getSecureRandom(),
738
				$request
739
			);
740
		});
741
		$this->registerService('CsrfTokenManager', function (Server $c) {
742
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
743
			$sessionStorage = new SessionStorage($c->getSession());
744
745
			return new CsrfTokenManager(
746
				$tokenGenerator,
747
				$sessionStorage
748
			);
749
		});
750
		$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...
751
			return new ContentSecurityPolicyManager();
752
		});
753
		$this->registerService('StoragesDBConfigService', function (Server $c) {
754
			return new DBConfigService(
755
				$c->getDatabaseConnection(),
756
				$c->getCrypto()
757
			);
758
		});
759
		$this->registerService('StoragesBackendService', function (Server $c) {
760
			$service = new StoragesBackendService($c->query('AllConfig'));
761
762
			// register auth mechanisms provided by core
763
			$provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [
764
				// AuthMechanism::SCHEME_NULL mechanism
765
				'OC\Files\External\Auth\NullMechanism',
766
767
				// AuthMechanism::SCHEME_BUILTIN mechanism
768
				'OC\Files\External\Auth\Builtin',
769
770
				// AuthMechanism::SCHEME_PASSWORD mechanisms
771
				'OC\Files\External\Auth\Password\Password',
772
			]);
773
774
			$service->registerAuthMechanismProvider($provider);
775
776
			// force-load the session one as it will register hooks...
777
			// TODO: obsolete it and use the TokenProvider to get the user's password from the session
778
			$sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials(
779
				$c->getSession(),
780
				$c->getCrypto()
781
			);
782
			$service->registerAuthMechanism($sessionCreds);
783
784
			return $service;
785
		});
786
		$this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService');
787
		$this->registerService('GlobalStoragesService', function (Server $c) {
788
			return new GlobalStoragesService(
789
				$c->query('StoragesBackendService'),
790
				$c->query('StoragesDBConfigService'),
791
				$c->query('UserMountCache')
792
			);
793
		});
794
		$this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService');
795 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...
796
			return new UserGlobalStoragesService(
797
				$c->query('StoragesBackendService'),
798
				$c->query('StoragesDBConfigService'),
799
				$c->query('UserSession'),
800
				$c->query('GroupManager'),
801
				$c->query('UserMountCache')
802
			);
803
		});
804
		$this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService');
805 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...
806
			return new UserStoragesService(
807
				$c->query('StoragesBackendService'),
808
				$c->query('StoragesDBConfigService'),
809
				$c->query('UserSession'),
810
				$c->query('UserMountCache')
811
			);
812
		});
813
		$this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService');
814
		$this->registerService('ShareManager', function(Server $c) {
815
			$config = $c->getConfig();
816
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
817
			/** @var \OCP\Share\IProviderFactory $factory */
818
			$factory = new $factoryClass($this);
819
820
			$manager = new \OC\Share20\Manager(
821
				$c->getLogger(),
822
				$c->getConfig(),
823
				$c->getSecureRandom(),
824
				$c->getHasher(),
825
				$c->getMountManager(),
826
				$c->getGroupManager(),
827
				$c->getL10N('core'),
828
				$factory,
829
				$c->getUserManager(),
830
				$c->getLazyRootFolder()
831
			);
832
833
			return $manager;
834
		});
835
836
		$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...
837
			return new ThemeService($this->getSystemConfig()->getValue('theme'));
838
		});
839
		$this->registerAlias('OCP\Theme\IThemeService', 'ThemeService');
840
		$this->registerAlias('OCP\IUserSession', 'UserSession');
841
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
842
	}
843
844
	/**
845
	 * @return \OCP\Contacts\IManager
846
	 */
847
	public function getContactsManager() {
848
		return $this->query('ContactsManager');
849
	}
850
851
	/**
852
	 * @return \OC\Encryption\Manager
853
	 */
854
	public function getEncryptionManager() {
855
		return $this->query('EncryptionManager');
856
	}
857
858
	/**
859
	 * @return \OC\Encryption\File
860
	 */
861
	public function getEncryptionFilesHelper() {
862
		return $this->query('EncryptionFileHelper');
863
	}
864
865
	/**
866
	 * @return \OCP\Encryption\Keys\IStorage
867
	 */
868
	public function getEncryptionKeyStorage() {
869
		return $this->query('EncryptionKeyStorage');
870
	}
871
872
	/**
873
	 * The current request object holding all information about the request
874
	 * currently being processed is returned from this method.
875
	 * In case the current execution was not initiated by a web request null is returned
876
	 *
877
	 * @return \OCP\IRequest
878
	 */
879
	public function getRequest() {
880
		return $this->query('Request');
881
	}
882
883
	/**
884
	 * Returns the preview manager which can create preview images for a given file
885
	 *
886
	 * @return \OCP\IPreview
887
	 */
888
	public function getPreviewManager() {
889
		return $this->query('PreviewManager');
890
	}
891
892
	/**
893
	 * Returns the tag manager which can get and set tags for different object types
894
	 *
895
	 * @see \OCP\ITagManager::load()
896
	 * @return \OCP\ITagManager
897
	 */
898
	public function getTagManager() {
899
		return $this->query('TagManager');
900
	}
901
902
	/**
903
	 * Returns the system-tag manager
904
	 *
905
	 * @return \OCP\SystemTag\ISystemTagManager
906
	 *
907
	 * @since 9.0.0
908
	 */
909
	public function getSystemTagManager() {
910
		return $this->query('SystemTagManager');
911
	}
912
913
	/**
914
	 * Returns the system-tag object mapper
915
	 *
916
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
917
	 *
918
	 * @since 9.0.0
919
	 */
920
	public function getSystemTagObjectMapper() {
921
		return $this->query('SystemTagObjectMapper');
922
	}
923
924
925
	/**
926
	 * Returns the avatar manager, used for avatar functionality
927
	 *
928
	 * @return \OCP\IAvatarManager
929
	 */
930
	public function getAvatarManager() {
931
		return $this->query('AvatarManager');
932
	}
933
934
	/**
935
	 * Returns the root folder of ownCloud's data directory
936
	 *
937
	 * @return \OCP\Files\IRootFolder
938
	 */
939
	public function getRootFolder() {
940
		return $this->query('RootFolder');
941
	}
942
943
	/**
944
	 * Returns the root folder of ownCloud's data directory
945
	 * This is the lazy variant so this gets only initialized once it
946
	 * is actually used.
947
	 *
948
	 * @return \OCP\Files\IRootFolder
949
	 */
950
	public function getLazyRootFolder() {
951
		return $this->query('LazyRootFolder');
952
	}
953
954
	/**
955
	 * Returns a view to ownCloud's files folder
956
	 *
957
	 * @param string $userId user ID
958
	 * @return \OCP\Files\Folder|null
959
	 */
960
	public function getUserFolder($userId = null) {
961 View Code Duplication
		if ($userId === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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

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

Loading history...
962
			$user = $this->getUserSession()->getUser();
963
			if (!$user) {
964
				return null;
965
			}
966
			$userId = $user->getUID();
967
		}
968
		$root = $this->getRootFolder();
969
		return $root->getUserFolder($userId);
970
	}
971
972
	/**
973
	 * Returns an app-specific view in ownClouds data directory
974
	 *
975
	 * @return \OCP\Files\Folder
976
	 */
977
	public function getAppFolder() {
978
		$dir = '/' . \OC_App::getCurrentApp();
979
		$root = $this->getRootFolder();
980
		if (!$root->nodeExists($dir)) {
981
			$folder = $root->newFolder($dir);
982
		} else {
983
			$folder = $root->get($dir);
984
		}
985
		return $folder;
986
	}
987
988
	/**
989
	 * @return \OC\User\Manager
990
	 */
991
	public function getUserManager() {
992
		return $this->query('UserManager');
993
	}
994
995
	/**
996
	 * @return \OC\User\AccountMapper
997
	 */
998
	public function getAccountMapper() {
999
		return $this->query('AccountMapper');
1000
	}
1001
1002
	/**
1003
	 * @return \OC\Group\Manager
1004
	 */
1005
	public function getGroupManager() {
1006
		return $this->query('GroupManager');
1007
	}
1008
1009
	/**
1010
	 * @return \OC\User\Session
1011
	 */
1012
	public function getUserSession() {
1013
		if($this->getConfig()->getSystemValue('installed', false) === false) {
1014
			return null;
1015
		}
1016
		return $this->query('UserSession');
1017
	}
1018
1019
	/**
1020
	 * @return ISession
1021
	 */
1022
	public function getSession() {
1023
		$userSession = $this->getUserSession();
1024
		if (is_null($userSession)) {
1025
			return new Memory('');
1026
		}
1027
		return $userSession->getSession();
1028
	}
1029
1030
	/**
1031
	 * @param ISession $session
1032
	 */
1033
	public function setSession(ISession $session) {
1034
		$userSession = $this->getUserSession();
1035
		if (is_null($userSession)) {
1036
			return;
1037
		}
1038
		$userSession->setSession($session);
1039
	}
1040
1041
	/**
1042
	 * @return \OC\Authentication\TwoFactorAuth\Manager
1043
	 */
1044
	public function getTwoFactorAuthManager() {
1045
		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1046
	}
1047
1048
	/**
1049
	 * @return \OC\NavigationManager
1050
	 */
1051
	public function getNavigationManager() {
1052
		return $this->query('NavigationManager');
1053
	}
1054
1055
	/**
1056
	 * @return \OCP\IConfig
1057
	 */
1058
	public function getConfig() {
1059
		return $this->query('AllConfig');
1060
	}
1061
1062
	/**
1063
	 * @internal For internal use only
1064
	 * @return \OC\SystemConfig
1065
	 */
1066
	public function getSystemConfig() {
1067
		return $this->query('SystemConfig');
1068
	}
1069
1070
	/**
1071
	 * Returns the app config manager
1072
	 *
1073
	 * @return \OCP\IAppConfig
1074
	 */
1075
	public function getAppConfig() {
1076
		return $this->query('AppConfig');
1077
	}
1078
1079
	/**
1080
	 * @return \OCP\L10N\IFactory
1081
	 */
1082
	public function getL10NFactory() {
1083
		return $this->query('L10NFactory');
1084
	}
1085
1086
	/**
1087
	 * get an L10N instance
1088
	 *
1089
	 * @param string $app appid
1090
	 * @param string $lang
1091
	 * @return IL10N
1092
	 */
1093
	public function getL10N($app, $lang = null) {
1094
		return $this->getL10NFactory()->get($app, $lang);
1095
	}
1096
1097
	/**
1098
	 * @return \OCP\IURLGenerator
1099
	 */
1100
	public function getURLGenerator() {
1101
		return $this->query('URLGenerator');
1102
	}
1103
1104
	/**
1105
	 * @return \OCP\IHelper
1106
	 */
1107
	public function getHelper() {
1108
		return $this->query('AppHelper');
1109
	}
1110
1111
	/**
1112
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1113
	 * getMemCacheFactory() instead.
1114
	 *
1115
	 * @return \OCP\ICache
1116
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1117
	 */
1118
	public function getCache() {
1119
		return $this->query('UserCache');
1120
	}
1121
1122
	/**
1123
	 * Returns an \OCP\CacheFactory instance
1124
	 *
1125
	 * @return \OCP\ICacheFactory
1126
	 */
1127
	public function getMemCacheFactory() {
1128
		return $this->query('MemCacheFactory');
1129
	}
1130
1131
	/**
1132
	 * Returns an \OC\RedisFactory instance
1133
	 *
1134
	 * @return \OC\RedisFactory
1135
	 */
1136
	public function getGetRedisFactory() {
1137
		return $this->query('RedisFactory');
1138
	}
1139
1140
1141
	/**
1142
	 * Returns the current session
1143
	 *
1144
	 * @return \OCP\IDBConnection
1145
	 */
1146
	public function getDatabaseConnection() {
1147
		return $this->query('DatabaseConnection');
1148
	}
1149
1150
	/**
1151
	 * Returns the activity manager
1152
	 *
1153
	 * @return \OCP\Activity\IManager
1154
	 */
1155
	public function getActivityManager() {
1156
		return $this->query('ActivityManager');
1157
	}
1158
1159
	/**
1160
	 * Returns an job list for controlling background jobs
1161
	 *
1162
	 * @return \OCP\BackgroundJob\IJobList
1163
	 */
1164
	public function getJobList() {
1165
		return $this->query('JobList');
1166
	}
1167
1168
	/**
1169
	 * Returns a logger instance
1170
	 *
1171
	 * @return \OCP\ILogger
1172
	 */
1173
	public function getLogger() {
1174
		if ($this->logger === null) {
1175
			$this->logger = $this->query('Logger');
1176
		}
1177
		return $this->logger;
1178
	}
1179
1180
	/**
1181
	 * Returns a logger instance
1182
	 *
1183
	 * @return \OCP\Settings\ISettingsManager
1184
	 */
1185
	public function getSettingsManager() {
1186
		return $this->query('SettingsManager');
1187
	}
1188
1189
1190
	/**
1191
	 * Returns a router for generating and matching urls
1192
	 *
1193
	 * @return \OCP\Route\IRouter
1194
	 */
1195
	public function getRouter() {
1196
		return $this->query('Router');
1197
	}
1198
1199
	/**
1200
	 * Returns a search instance
1201
	 *
1202
	 * @return \OCP\ISearch
1203
	 */
1204
	public function getSearch() {
1205
		return $this->query('Search');
1206
	}
1207
1208
	/**
1209
	 * Returns a SecureRandom instance
1210
	 *
1211
	 * @return \OCP\Security\ISecureRandom
1212
	 */
1213
	public function getSecureRandom() {
1214
		return $this->query('SecureRandom');
1215
	}
1216
1217
	/**
1218
	 * Returns a Crypto instance
1219
	 *
1220
	 * @return \OCP\Security\ICrypto
1221
	 */
1222
	public function getCrypto() {
1223
		return $this->query('Crypto');
1224
	}
1225
1226
	/**
1227
	 * Returns a Hasher instance
1228
	 *
1229
	 * @return \OCP\Security\IHasher
1230
	 */
1231
	public function getHasher() {
1232
		return $this->query('Hasher');
1233
	}
1234
1235
	/**
1236
	 * Returns a CredentialsManager instance
1237
	 *
1238
	 * @return \OCP\Security\ICredentialsManager
1239
	 */
1240
	public function getCredentialsManager() {
1241
		return $this->query('CredentialsManager');
1242
	}
1243
1244
	/**
1245
	 * Returns an instance of the db facade
1246
	 *
1247
	 * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
1248
	 * @return \OCP\IDb
1249
	 */
1250
	public function getDb() {
1251
		return $this->query('Db');
1252
	}
1253
1254
	/**
1255
	 * Returns an instance of the HTTP helper class
1256
	 *
1257
	 * @deprecated Use getHTTPClientService()
1258
	 * @return \OC\HTTPHelper
1259
	 */
1260
	public function getHTTPHelper() {
1261
		return $this->query('HTTPHelper');
1262
	}
1263
1264
	/**
1265
	 * Get the certificate manager for the user
1266
	 *
1267
	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1268
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1269
	 */
1270
	public function getCertificateManager($userId = '') {
1271 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...
1272
			$userSession = $this->getUserSession();
1273
			$user = $userSession->getUser();
1274
			if (is_null($user)) {
1275
				return null;
1276
			}
1277
			$userId = $user->getUID();
1278
		}
1279
		return new CertificateManager($userId, new View(), $this->getConfig());
1280
	}
1281
1282
	/**
1283
	 * Returns an instance of the HTTP client service
1284
	 *
1285
	 * @return \OCP\Http\Client\IClientService
1286
	 */
1287
	public function getHTTPClientService() {
1288
		return $this->query('HttpClientService');
1289
	}
1290
1291
	/**
1292
	 * Returns an instance of the Webdav client service
1293
	 *
1294
	 * @return \OCP\Http\Client\IWebDavClientService
1295
	 */
1296
	public function getWebDavClientService() {
1297
		return $this->query('WebDavClientService');
1298
	}
1299
1300
	/**
1301
	 * Create a new event source
1302
	 *
1303
	 * @return \OCP\IEventSource
1304
	 */
1305
	public function createEventSource() {
1306
		return new \OC_EventSource();
1307
	}
1308
1309
	/**
1310
	 * Get the active event logger
1311
	 *
1312
	 * The returned logger only logs data when debug mode is enabled
1313
	 *
1314
	 * @return \OCP\Diagnostics\IEventLogger
1315
	 */
1316
	public function getEventLogger() {
1317
		return $this->query('EventLogger');
1318
	}
1319
1320
	/**
1321
	 * Get the active query logger
1322
	 *
1323
	 * The returned logger only logs data when debug mode is enabled
1324
	 *
1325
	 * @return \OCP\Diagnostics\IQueryLogger
1326
	 */
1327
	public function getQueryLogger() {
1328
		return $this->query('QueryLogger');
1329
	}
1330
1331
	/**
1332
	 * Get the manager for temporary files and folders
1333
	 *
1334
	 * @return \OCP\ITempManager
1335
	 */
1336
	public function getTempManager() {
1337
		return $this->query('TempManager');
1338
	}
1339
1340
	/**
1341
	 * Get the app manager
1342
	 *
1343
	 * @return \OCP\App\IAppManager
1344
	 */
1345
	public function getAppManager() {
1346
		return $this->query('AppManager');
1347
	}
1348
1349
	/**
1350
	 * Creates a new mailer
1351
	 *
1352
	 * @return \OCP\Mail\IMailer
1353
	 */
1354
	public function getMailer() {
1355
		return $this->query('Mailer');
1356
	}
1357
1358
	/**
1359
	 * Get the webroot
1360
	 *
1361
	 * @return string
1362
	 */
1363
	public function getWebRoot() {
1364
		return $this->webRoot;
1365
	}
1366
1367
	/**
1368
	 * @return \OCP\IDateTimeZone
1369
	 */
1370
	public function getDateTimeZone() {
1371
		return $this->query('DateTimeZone');
1372
	}
1373
1374
	/**
1375
	 * @return \OCP\IDateTimeFormatter
1376
	 */
1377
	public function getDateTimeFormatter() {
1378
		return $this->query('DateTimeFormatter');
1379
	}
1380
1381
	/**
1382
	 * @return \OCP\Files\Config\IMountProviderCollection
1383
	 */
1384
	public function getMountProviderCollection() {
1385
		return $this->query('MountConfigManager');
1386
	}
1387
1388
	/**
1389
	 * Get the IniWrapper
1390
	 *
1391
	 * @return IniGetWrapper
1392
	 */
1393
	public function getIniWrapper() {
1394
		return $this->query('IniWrapper');
1395
	}
1396
1397
	/**
1398
	 * @return \OCP\Command\IBus
1399
	 */
1400
	public function getCommandBus() {
1401
		return $this->query('AsyncCommandBus');
1402
	}
1403
1404
	/**
1405
	 * Get the trusted domain helper
1406
	 *
1407
	 * @return TrustedDomainHelper
1408
	 */
1409
	public function getTrustedDomainHelper() {
1410
		return $this->query('TrustedDomainHelper');
1411
	}
1412
1413
	/**
1414
	 * Get the locking provider
1415
	 *
1416
	 * @return \OCP\Lock\ILockingProvider
1417
	 * @since 8.1.0
1418
	 */
1419
	public function getLockingProvider() {
1420
		return $this->query('LockingProvider');
1421
	}
1422
1423
	/**
1424
	 * @return \OCP\Files\Mount\IMountManager
1425
	 **/
1426
	function getMountManager() {
1427
		return $this->query('MountManager');
1428
	}
1429
1430
	/**
1431
	 * Get the MimeTypeDetector
1432
	 *
1433
	 * @return \OCP\Files\IMimeTypeDetector
1434
	 */
1435
	public function getMimeTypeDetector() {
1436
		return $this->query('MimeTypeDetector');
1437
	}
1438
1439
	/**
1440
	 * Get the MimeTypeLoader
1441
	 *
1442
	 * @return \OCP\Files\IMimeTypeLoader
1443
	 */
1444
	public function getMimeTypeLoader() {
1445
		return $this->query('MimeTypeLoader');
1446
	}
1447
1448
	/**
1449
	 * Get the manager of all the capabilities
1450
	 *
1451
	 * @return \OC\CapabilitiesManager
1452
	 */
1453
	public function getCapabilitiesManager() {
1454
		return $this->query('CapabilitiesManager');
1455
	}
1456
1457
	/**
1458
	 * Get the EventDispatcher
1459
	 *
1460
	 * @return EventDispatcherInterface
1461
	 * @since 8.2.0
1462
	 */
1463
	public function getEventDispatcher() {
1464
		return $this->query('EventDispatcher');
1465
	}
1466
1467
	/**
1468
	 * Get the Notification Manager
1469
	 *
1470
	 * @return \OCP\Notification\IManager
1471
	 * @since 8.2.0
1472
	 */
1473
	public function getNotificationManager() {
1474
		return $this->query('NotificationManager');
1475
	}
1476
1477
	/**
1478
	 * @return \OCP\Comments\ICommentsManager
1479
	 */
1480
	public function getCommentsManager() {
1481
		return $this->query('CommentsManager');
1482
	}
1483
1484
	/**
1485
	 * @return \OC\IntegrityCheck\Checker
1486
	 */
1487
	public function getIntegrityCodeChecker() {
1488
		return $this->query('IntegrityCodeChecker');
1489
	}
1490
1491
	/**
1492
	 * @return \OC\Session\CryptoWrapper
1493
	 */
1494
	public function getSessionCryptoWrapper() {
1495
		return $this->query('CryptoWrapper');
1496
	}
1497
1498
	/**
1499
	 * @return CsrfTokenManager
1500
	 */
1501
	public function getCsrfTokenManager() {
1502
		return $this->query('CsrfTokenManager');
1503
	}
1504
1505
	/**
1506
	 * @return IContentSecurityPolicyManager
1507
	 */
1508
	public function getContentSecurityPolicyManager() {
1509
		return $this->query('ContentSecurityPolicyManager');
1510
	}
1511
1512
	/**
1513
	 * @return \OCP\Files\External\IStoragesBackendService
1514
	 */
1515
	public function getStoragesBackendService() {
1516
		return $this->query('StoragesBackendService');
1517
	}
1518
1519
	/**
1520
	 * @return \OCP\Files\External\Service\IGlobalStoragesService
1521
	 */
1522
	public function getGlobalStoragesService() {
1523
		return $this->query('GlobalStoragesService');
1524
	}
1525
1526
	/**
1527
	 * @return \OCP\Files\External\Service\IUserGlobalStoragesService
1528
	 */
1529
	public function getUserGlobalStoragesService() {
1530
		return $this->query('UserGlobalStoragesService');
1531
	}
1532
1533
	/**
1534
	 * @return \OCP\Files\External\Service\IUserStoragesService
1535
	 */
1536
	public function getUserStoragesService() {
1537
		return $this->query('UserStoragesService');
1538
	}
1539
1540
	/**
1541
	 * @return \OCP\Share\IManager
1542
	 */
1543
	public function getShareManager() {
1544
		return $this->query('ShareManager');
1545
	}
1546
1547
	/**
1548
	 * @return IThemeService
1549
	 */
1550
	public function getThemeService() {
1551
		return $this->query('\OCP\Theme\IThemeService');
1552
	}
1553
1554
	/**
1555
	 * @return ITimeFactory
1556
	 */
1557
	public function getTimeFactory() {
1558
		return $this->query('\OCP\AppFramework\Utility\ITimeFactory');
1559
	}
1560
1561
	/**
1562
	 * @return IServiceLoader
1563
	 */
1564
	public function getServiceLoader() {
1565
		return $this;
1566
	}
1567
1568
	/**
1569
	 * @inheritdoc
1570
	 */
1571
	public function load(array $xmlPath, IUser $user = null) {
1572
		$appManager = $this->getAppManager();
1573
		$allApps = $appManager->getEnabledAppsForUser($user);
1574
1575
		foreach ($allApps as $appId) {
1576
			$info = $appManager->getAppInfo($appId);
1577
			if ($info === null) {
1578
				$info = [];
1579
			}
1580
1581
			foreach($xmlPath as $xml) {
1582
				$info = isset($info[$xml]) ? $info[$xml] : [];
1583
			}
1584
			if (!is_array($info)) {
1585
				$info = [$info];
1586
			}
1587
1588
			foreach ($info as $class) {
1589
				try {
1590
					if (!\OC_App::isAppLoaded($appId)) {
1591
						\OC_App::loadApp($appId);
1592
					}
1593
1594
					yield $this->query($class);
1595
1596
				} catch (QueryException $exc) {
1597
					throw new \Exception("Could not load service $class");
1598
				}
1599
			}
1600
		}
1601
	}
1602
}
1603