Completed
Push — master ( f6aa8b...0d64f5 )
by Thomas
19:48 queued 05:52
created

Server::getQueryLogger()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
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) 2018, ownCloud GmbH
26
 * @license AGPL-3.0
27
 *
28
 * This code is free software: you can redistribute it and/or modify
29
 * it under the terms of the GNU Affero General Public License, version 3,
30
 * as published by the Free Software Foundation.
31
 *
32
 * This program is distributed in the hope that it will be useful,
33
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35
 * GNU Affero General Public License for more details.
36
 *
37
 * You should have received a copy of the GNU Affero General Public License, version 3,
38
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
39
 *
40
 */
41
namespace OC;
42
43
use bantu\IniGetWrapper\IniGetWrapper;
44
use OC\AppFramework\Http\Request;
45
use OC\AppFramework\Db\Db;
46
use OC\AppFramework\Utility\TimeFactory;
47
use OC\Command\AsyncBus;
48
use OC\Diagnostics\EventLogger;
49
use OC\Diagnostics\QueryLogger;
50
use OC\Files\Config\UserMountCache;
51
use OC\Files\Config\UserMountCacheListener;
52
use OC\Files\Mount\CacheMountProvider;
53
use OC\Files\Mount\LocalHomeMountProvider;
54
use OC\Files\Mount\ObjectHomeMountProvider;
55
use OC\Files\Node\HookConnector;
56
use OC\Files\Node\LazyRoot;
57
use OC\Files\Node\Root;
58
use OC\Files\View;
59
use OC\Http\Client\ClientService;
60
use OC\IntegrityCheck\Checker;
61
use OC\IntegrityCheck\Helpers\AppLocator;
62
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
63
use OC\IntegrityCheck\Helpers\FileAccessHelper;
64
use OC\Lock\DBLockingProvider;
65
use OC\Lock\MemcacheLockingProvider;
66
use OC\Lock\NoopLockingProvider;
67
use OC\Mail\Mailer;
68
use OC\Memcache\ArrayCache;
69
use OC\Notification\Manager;
70
use OC\Security\CertificateManager;
71
use OC\Security\CSP\ContentSecurityPolicyManager;
72
use OC\Security\Crypto;
73
use OC\Security\CSRF\CsrfTokenGenerator;
74
use OC\Security\CSRF\CsrfTokenManager;
75
use OC\Security\CSRF\TokenStorage\SessionStorage;
76
use OC\Security\Hasher;
77
use OC\Security\CredentialsManager;
78
use OC\Security\SecureRandom;
79
use OC\Security\TrustedDomainHelper;
80
use OC\Session\CryptoWrapper;
81
use OC\Session\Memory;
82
use OC\Settings\Panels\Helper;
83
use OC\Settings\SettingsManager;
84
use OC\Shutdown\ShutDownManager;
85
use OC\Tagging\TagMapper;
86
use OC\Theme\ThemeService;
87
use OC\User\AccountMapper;
88
use OC\User\AccountTermMapper;
89
use OC\User\Session;
90
use OC\User\SyncService;
91
use OCP\App\IServiceLoader;
92
use OCP\AppFramework\QueryException;
93
use OCP\AppFramework\Utility\ITimeFactory;
94
use OCP\Events\EventEmitterTrait;
95
use OCP\IL10N;
96
use OCP\ILogger;
97
use OCP\IServerContainer;
98
use OCP\ISession;
99
use OCP\IUser;
100
use OCP\Security\IContentSecurityPolicyManager;
101
use OCP\Shutdown\IShutdownManager;
102
use OCP\Theme\IThemeService;
103
use OCP\Util\UserSearch;
104
use Symfony\Component\EventDispatcher\EventDispatcher;
105
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
106
use OC\Files\External\StoragesBackendService;
107
use OC\Files\External\Service\UserStoragesService;
108
use OC\Files\External\Service\UserGlobalStoragesService;
109
use OC\Files\External\Service\GlobalStoragesService;
110
use OC\Files\External\Service\DBConfigService;
111
use OC\Http\Client\WebDavClientService;
112
use Symfony\Component\EventDispatcher\GenericEvent;
113
114
/**
115
 * Class Server
116
 *
117
 * @package OC
118
 *
119
 * TODO: hookup all manager classes
120
 */
121
class Server extends ServerContainer implements IServerContainer, IServiceLoader {
122
	use EventEmitterTrait;
123
	/** @var string */
124
	private $webRoot;
125
126
	/**
127
	 * cache the logger to prevent querying it over and over again
128
	 * @var ILogger;
129
	 */
130
	private $logger;
131
132
	/**
133
	 * @param string $webRoot
134
	 * @param \OC\Config $config
135
	 */
136
	public function __construct($webRoot, \OC\Config $config) {
137
		parent::__construct();
138
		$this->webRoot = $webRoot;
139
140
		$this->registerService('SettingsManager', function (Server $c) {
141
			return new SettingsManager(
142
				$c->getL10N('lib'),
143
				$c->getAppManager(),
144
				$c->getUserSession(),
145
				$c->getLogger(),
146
				$c->getGroupManager(),
147
				$c->getConfig(),
148
				new \OCP\Defaults(),
149
				$c->getURLGenerator(),
150
				new Helper(),
151
				$c->getLockingProvider(),
152
				$c->getDatabaseConnection(),
153
				$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...
154
				$c->getL10NFactory()
155
156
			);
157
		});
158
159
		$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...
160
			return new ContactsManager();
161
		});
162
163
		$this->registerService('PreviewManager', function (Server $c) {
164
			return new PreviewManager($c->getConfig(),
165
				$c->getLazyRootFolder(),
166
				$c->getUserSession());
167
		});
168
169
		$this->registerService('EncryptionManager', function (Server $c) {
170
			$view = new View();
171
			$util = new Encryption\Util(
172
				$view,
173
				$c->getUserManager(),
174
				$c->getGroupManager(),
175
				$c->getConfig()
176
			);
177
			return new Encryption\Manager(
178
				$c->getConfig(),
179
				$c->getLogger(),
180
				$c->getL10N('core'),
181
				new View(),
182
				$util,
183
				new ArrayCache()
184
			);
185
		});
186
187
		$this->registerService('EncryptionFileHelper', function (Server $c) {
188
			$util = new Encryption\Util(
189
				new View(),
190
				$c->getUserManager(),
191
				$c->getGroupManager(),
192
				$c->getConfig()
193
			);
194
			return new Encryption\File($util);
195
		});
196
197
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
198
			$view = new View();
199
			$util = new Encryption\Util(
200
				$view,
201
				$c->getUserManager(),
202
				$c->getGroupManager(),
203
				$c->getConfig()
204
			);
205
206
			return new Encryption\Keys\Storage(
207
				$view,
208
				$util,
209
				$c->getUserSession()
210
			);
211
		});
212
		$this->registerService('TagMapper', function (Server $c) {
213
			return new TagMapper($c->getDatabaseConnection());
214
		});
215
		$this->registerService('TagManager', function (Server $c) {
216
			$tagMapper = $c->query('TagMapper');
217
			return new TagManager($tagMapper, $c->getUserSession());
218
		});
219 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...
220
			$config = $c->getConfig();
221
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
222
			/** @var \OC\SystemTag\ManagerFactory $factory */
223
			$factory = new $factoryClass($this);
224
			return $factory;
225
		});
226
		$this->registerService('SystemTagManager', function (Server $c) {
227
			return $c->query('SystemTagManagerFactory')->getManager();
228
		});
229
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
230
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
231
		});
232
		$this->registerService('RootFolder', function () {
233
			$manager = \OC\Files\Filesystem::getMountManager(null);
234
			$view = new View();
235
			$root = new Root($manager, $view, null);
236
			$connector = new HookConnector($root, $view);
237
			$connector->viewToNode();
238
			return $root;
239
		});
240
		$this->registerService('LazyRootFolder', function (Server $c) {
241
			return new LazyRoot(function () use ($c) {
242
				return $c->getRootFolder();
243
			});
244
		});
245
		$this->registerService('AccountMapper', function (Server $c) {
246
			return new AccountMapper($c->getConfig(), $c->getDatabaseConnection(), new AccountTermMapper($c->getDatabaseConnection()));
247
		});
248
		$this->registerService('UserManager', function (Server $c) {
249
			return new \OC\User\Manager(
250
				$c->getConfig(),
251
				$c->getLogger(),
252
				$c->getAccountMapper(),
253
				new SyncService(
254
					$c->getConfig(),
255
					$c->getLogger(),
256
					$c->getAccountMapper()
257
				),
258
				new UserSearch(
259
					$c->getConfig()
260
				)
261
			);
262
		});
263
		$this->registerService('GroupManager', function (Server $c) {
264
			$groupManager = new \OC\Group\Manager(
265
				$this->getUserManager(),
266
				new UserSearch(
267
					$c->getConfig()
268
				),
269
				$this->getEventDispatcher()
270
			);
271
272
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
273
				\OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]);
274
			});
275
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
276
				\OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $gid->getGID()]);
277
			});
278
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
279
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]);
280
			});
281
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
282
				\OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]);
283
			});
284
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
285
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]);
286
			});
287
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
288
				\OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
289
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
290
				\OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]);
291
			});
292
			return $groupManager;
293
		});
294
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
295
			$dbConnection = $c->getDatabaseConnection();
296
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
297
		});
298
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
299
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
300
			$crypto = $c->getCrypto();
301
			$config = $c->getConfig();
302
			$logger = $c->getLogger();
303
			$timeFactory = new TimeFactory();
304
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
305
		});
306
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
307
		$this->registerService('TimeFactory', function () {
308
			return new TimeFactory();
309
		});
310
		$this->registerAlias('OCP\AppFramework\Utility\ITimeFactory', 'TimeFactory');
311
		$this->registerService('UserSession', function (Server $c) {
312
			$manager = $c->getUserManager();
313
			$session = new \OC\Session\Memory('');
314
			$timeFactory = new TimeFactory();
315
			// Token providers might require a working database. This code
316
			// might however be called when ownCloud is not yet setup.
317
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
318
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
319
			} else {
320
				$defaultTokenProvider = null;
321
			}
322
323
			$userSyncService = new SyncService($c->getConfig(), $c->getLogger(), $c->getAccountMapper());
324
325
			$userSession = new Session($manager, $session, $timeFactory,
326
				$defaultTokenProvider, $c->getConfig(), $c->getLogger(), $this, $userSyncService, $c->getEventDispatcher());
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

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

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

Loading history...
327
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
328
				\OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]);
329
			});
330
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
331
				/** @var $user \OC\User\User */
332
				\OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]);
333
			});
334
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
335
				/** @var $user \OC\User\User */
336
				\OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]);
337
			});
338
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
339
				/** @var $user \OC\User\User */
340
				\OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]);
341
				$this->emittingCall(function () use (&$user) {
342
					return true;
343
				}, ['before' => [], 'after' => ['uid' => $user->getUID()]], 'user', 'delete');
344
			});
345 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...
346
				/** @var $user \OC\User\User */
347
				\OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
348
			});
349 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...
350
				/** @var $user \OC\User\User */
351
				\OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]);
352
			});
353
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
354
				\OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]);
355
			});
356
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
357
				/** @var $user \OC\User\User */
358
				\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]);
359
			});
360
			$userSession->listen('\OC\User', 'preLogout', function () {
361
				$event = new GenericEvent(null, []);
362
				\OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logout', $event);
363
			});
364
			$userSession->listen('\OC\User', 'logout', function () {
365
				\OC_Hook::emit('OC_User', 'logout', []);
366
			});
367
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
368
				/** @var $user \OC\User\User */
369
				\OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]);
370
				$this->emittingCall(function () use (&$user, &$feature, &$value) {
371
					return true;
372
				}, [
373
					'before' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value],
374
					'after' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]
375
				], 'user', 'featurechange');
376
			});
377
			return $userSession;
378
		});
379
380
		$this->registerService('OC\Authentication\TwoFactorAuth\Manager', function (Server $c) {
381
			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...
382
		});
383
384
		$this->registerService('NavigationManager', function (Server $c) {
385
			return new \OC\NavigationManager($c->getAppManager(),
386
				$c->getURLGenerator(),
387
				$c->getL10NFactory(),
388
				$c->getUserSession(),
389
				$c->getGroupManager());
390
		});
391
		$this->registerService('AllConfig', function (Server $c) {
392
			return new \OC\AllConfig(
393
				$c->getSystemConfig(),
394
				$c->getEventDispatcher()
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

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

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

Loading history...
395
			);
396
		});
397
		$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...
398
			return new \OC\SystemConfig($config);
399
		});
400
		$this->registerService('AppConfig', function (Server $c) {
401
			return new \OC\AppConfig($c->getDatabaseConnection());
402
		});
403
		$this->registerService('L10NFactory', function (Server $c) {
404
			return new \OC\L10N\Factory(
405
				$c->getConfig(),
406
				$c->getRequest(),
407
				$c->getThemeService(),
408
				$c->getUserSession(),
409
				\OC::$SERVERROOT
410
			);
411
		});
412
		$this->registerService('URLGenerator', function (Server $c) {
413
			$config = $c->getConfig();
414
			$cacheFactory = $c->getMemCacheFactory();
415
			$router = $c->getRouter();
416
			return new URLGenerator(
417
				$config,
418
				$cacheFactory,
419
				$router
420
			);
421
		});
422
		$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...
423
			return new \OC\AppHelper();
424
		});
425
		$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...
426
			return new Cache\File();
427
		});
428
		$this->registerService('MemCacheFactory', function (Server $c) {
429
			$config = $c->getConfig();
430
431
			if ($config->getSystemValue('installed', false) && !(\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
432
				$v = \OC_App::getAppVersions();
433
				$v['core'] = \md5(\file_get_contents(\OC::$SERVERROOT . '/version.php'));
434
				$version = \implode(',', $v);
435
				$instanceId = \OC_Util::getInstanceId();
436
				$path = \OC::$SERVERROOT;
437
				$prefix = \md5($instanceId . '-' . $version . '-' . $path);
438
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
439
					$config->getSystemValue('memcache.local', null),
440
					$config->getSystemValue('memcache.distributed', null),
441
					$config->getSystemValue('memcache.locking', null)
442
				);
443
			}
444
445
			return new \OC\Memcache\Factory('', $c->getLogger(),
446
				'\\OC\\Memcache\\ArrayCache',
447
				'\\OC\\Memcache\\ArrayCache',
448
				'\\OC\\Memcache\\ArrayCache'
449
			);
450
		});
451
		$this->registerService('RedisFactory', function (Server $c) {
452
			$systemConfig = $c->getSystemConfig();
453
			return new RedisFactory($systemConfig);
454
		});
455
		$this->registerService('ActivityManager', function (Server $c) {
456
			return new \OC\Activity\Manager(
457
				$c->getRequest(),
458
				$c->getUserSession(),
459
				$c->getConfig()
460
			);
461
		});
462
		$this->registerService('AvatarManager', function (Server $c) {
463
			return new AvatarManager(
464
				$c->getUserManager(),
465
				$c->getLazyRootFolder(),  // initialize the root folder lazily
466
				$c->getL10N('lib'),
467
				$c->getLogger()
468
			);
469
		});
470
		$this->registerService('Logger', function (Server $c) {
471
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
472
			$logger = 'OC\\Log\\' . \ucfirst($logClass);
473
			\call_user_func([$logger, 'init']);
474
475
			return new Log($logger);
476
		});
477
		$this->registerService('JobList', function (Server $c) {
478
			$config = $c->getConfig();
479
			return new \OC\BackgroundJob\JobList(
480
				$c->getDatabaseConnection(),
481
				$config,
482
				new TimeFactory()
483
			);
484
		});
485
		$this->registerService('Router', function (Server $c) {
486
			$cacheFactory = $c->getMemCacheFactory();
487
			$logger = $c->getLogger();
488
			if ($cacheFactory->isAvailable()) {
489
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
490
			} else {
491
				$router = new \OC\Route\Router($logger);
492
			}
493
			return $router;
494
		});
495
		$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...
496
			return new Search();
497
		});
498
		$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...
499
			return new SecureRandom();
500
		});
501
		$this->registerService('Crypto', function (Server $c) {
502
			return new Crypto($c->getConfig(), $c->getSecureRandom());
503
		});
504
		$this->registerAlias('OCP\Security\ICrypto', 'Crypto');
505
		$this->registerService('Hasher', function (Server $c) {
506
			return new Hasher($c->getConfig());
507
		});
508
		$this->registerService('CredentialsManager', function (Server $c) {
509
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
510
		});
511
		$this->registerService('DatabaseConnection', function (Server $c) {
512
			$systemConfig = $c->getSystemConfig();
513
			$keys = $systemConfig->getKeys();
514
			if (!isset($keys['dbname']) && !isset($keys['dbhost']) && isset($keys['dbtableprefix'])) {
515
				throw new \OC\DatabaseException('No database configured');
516
			}
517
518
			$factory = new \OC\DB\ConnectionFactory($systemConfig);
519
			$type = $systemConfig->getValue('dbtype', 'sqlite');
520
			if (!$factory->isValidType($type)) {
521
				throw new \OC\DatabaseException('Invalid database type');
522
			}
523
			$connectionParams = $factory->createConnectionParams();
524
			$connection = $factory->getConnection($type, $connectionParams);
525
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
526
			return $connection;
527
		});
528
		$this->registerService('Db', function (Server $c) {
529
			return new Db($c->getDatabaseConnection());
530
		});
531
		$this->registerService('HTTPHelper', function (Server $c) {
532
			$config = $c->getConfig();
533
			return new HTTPHelper(
534
				$config,
535
				$c->getHTTPClientService()
536
			);
537
		});
538 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...
539
			$user = \OC_User::getUser();
540
			$uid = $user ? $user : null;
541
			return new ClientService(
542
				$c->getConfig(),
543
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
0 ignored issues
show
Bug introduced by
It seems like $uid defined by $user ? $user : null on line 540 can also be of type boolean or null; however, OC\Security\CertificateManager::__construct() does only seem to accept string, maybe add an additional type check?

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

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

    return array();
}

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

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

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

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

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

    return array();
}

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

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

Loading history...
552
			);
553
		});
554 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...
555
			$eventLogger = new EventLogger();
556
			if ($c->getSystemConfig()->getValue('debug', false)) {
557
				// In debug mode, module is being activated by default
558
				$eventLogger->activate();
559
			}
560
			return $eventLogger;
561
		});
562 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...
563
			$queryLogger = new QueryLogger();
564
			if ($c->getSystemConfig()->getValue('debug', false)) {
565
				// In debug mode, module is being activated by default
566
				$queryLogger->activate();
567
			}
568
			return $queryLogger;
569
		});
570
		$this->registerService('TempManager', function (Server $c) {
571
			return new TempManager(
572
				$c->getLogger(),
573
				$c->getConfig()
574
			);
575
		});
576
		$this->registerService('AppManager', function (Server $c) {
577 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...
578
				$appConfig = $c->getAppConfig();
579
				$groupManager = $c->getGroupManager();
580
			} else {
581
				$appConfig = null;
582
				$groupManager = null;
583
			}
584
			return new \OC\App\AppManager(
585
				$c->getUserSession(),
586
				$appConfig,
587
				$groupManager,
588
				$c->getMemCacheFactory(),
589
				$c->getEventDispatcher(),
590
				$c->getConfig()
591
			);
592
		});
593
		$this->registerService('DateTimeZone', function (Server $c) {
594
			return new DateTimeZone(
595
				$c->getConfig(),
596
				$c->getSession()
597
			);
598
		});
599
		$this->registerService('DateTimeFormatter', function (Server $c) {
600
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
601
602
			return new DateTimeFormatter(
603
				$c->getDateTimeZone()->getTimeZone(),
604
				$c->getL10N('lib', $language)
605
			);
606
		});
607
		$this->registerService('UserMountCache', function (Server $c) {
608
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
609
			$listener = new UserMountCacheListener($mountCache);
610
			$listener->listen($c->getUserManager());
611
			return $mountCache;
612
		});
613
		$this->registerService('MountConfigManager', function (Server $c) {
614
			$loader = \OC\Files\Filesystem::getLoader();
615
			$mountCache = $c->query('UserMountCache');
616
			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
617
618
			// builtin providers
619
620
			$config = $c->getConfig();
621
			$manager->registerProvider(new CacheMountProvider($config));
622
			$manager->registerHomeProvider(new LocalHomeMountProvider());
623
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
624
625
			// external storage
626
			if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') {
627
				$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
628
					$c->query('AllConfig'),
629
					$c->query('UserStoragesService'),
630
					$c->query('UserGlobalStoragesService')
631
				));
632
			}
633
634
			return $manager;
635
		});
636
		$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...
637
			return new IniGetWrapper();
638
		});
639
		$this->registerService('AsyncCommandBus', function (Server $c) {
640
			$jobList = $c->getJobList();
641
			return new AsyncBus($jobList);
642
		});
643
		$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...
644
			return new TrustedDomainHelper($this->getConfig());
645
		});
646
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
647
			// IConfig and IAppManager requires a working database. This code
648
			// might however be called when ownCloud is not yet setup.
649 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...
650
				$config = $c->getConfig();
651
				$appManager = $c->getAppManager();
652
			} else {
653
				$config = null;
654
				$appManager = null;
655
			}
656
657
			return new Checker(
658
					new EnvironmentHelper(),
659
					new FileAccessHelper(),
660
					new AppLocator(),
661
					$config,
662
					$c->getMemCacheFactory(),
663
					$appManager,
664
					$c->getTempManager()
665
			);
666
		});
667
		$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...
668
			if (isset($this['urlParams'])) {
669
				$urlParams = $this['urlParams'];
670
			} else {
671
				$urlParams = [];
672
			}
673
674
			if (\defined('PHPUNIT_RUN') && PHPUNIT_RUN
675
				&& \in_array('fakeinput', \stream_get_wrappers())
676
			) {
677
				$stream = 'fakeinput://data';
678
			} else {
679
				$stream = 'php://input';
680
			}
681
682
			return new Request(
683
				[
684
					'get' => $_GET,
685
					'post' => $_POST,
686
					'files' => $_FILES,
687
					'server' => $_SERVER,
688
					'env' => $_ENV,
689
					'cookies' => $_COOKIE,
690
					'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD']))
691
						? $_SERVER['REQUEST_METHOD']
692
						: null,
693
					'urlParams' => $urlParams,
694
				],
695
				$this->getSecureRandom(),
696
				$this->getConfig(),
697
				$this->getCsrfTokenManager(),
698
				$stream
699
			);
700
		});
701
		$this->registerService('Mailer', function (Server $c) {
702
			return new Mailer(
703
				$c->getConfig(),
704
				$c->getLogger(),
705
				new \OC_Defaults()
706
			);
707
		});
708
		$this->registerService('LockingProvider', function (Server $c) {
709
			$ini = $c->getIniWrapper();
710
			$config = $c->getConfig();
711
			$ttl = $config->getSystemValue('filelocking.ttl', \max(3600, $ini->getNumeric('max_execution_time')));
712
			if ($config->getSystemValue('filelocking.enabled', true) or (\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
713
				/** @var \OC\Memcache\Factory $memcacheFactory */
714
				$memcacheFactory = $c->getMemCacheFactory();
715
				$memcache = $memcacheFactory->createLocking('lock');
716
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
717
					return new MemcacheLockingProvider($memcache, $ttl);
718
				}
719
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
720
			}
721
			return new NoopLockingProvider();
722
		});
723
		$this->registerAlias('OCP\Lock\ILockingProvider', 'LockingProvider');
724
		$this->registerService('MountManager', function () {
725
			return new \OC\Files\Mount\Manager();
726
		});
727
		$this->registerService('MimeTypeDetector', function (Server $c) {
728
			return new \OC\Files\Type\Detection(
729
				$c->getURLGenerator(),
730
				\OC::$SERVERROOT . '/config/',
731
				\OC::$SERVERROOT . '/resources/config/'
732
			);
733
		});
734
		$this->registerService('MimeTypeLoader', function (Server $c) {
735
			return new \OC\Files\Type\Loader(
736
				$c->getDatabaseConnection()
737
			);
738
		});
739
		$this->registerAlias('OCP\Files\IMimeTypeLoader', 'MimeTypeLoader');
740
		$this->registerService('NotificationManager', function (Server $c) {
741
			return new Manager($c->getEventDispatcher());
742
		});
743
		$this->registerService('CapabilitiesManager', function (Server $c) {
744
			$manager = new \OC\CapabilitiesManager();
745
			$manager->registerCapability(function () use ($c) {
746
				return new \OC\OCS\CoreCapabilities($c->getConfig());
747
			});
748
			return $manager;
749
		});
750 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...
751
			$config = $c->getConfig();
752
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
753
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
754
			$factory = new $factoryClass($this);
755
			return $factory->getManager();
756
		});
757
		$this->registerService('EventDispatcher', function () {
758
			return new EventDispatcher();
759
		});
760
		$this->registerService('CryptoWrapper', function (Server $c) {
761
			// FIXME: Instantiiated here due to cyclic dependency
762
			$request = new Request(
763
				[
764
					'get' => $_GET,
765
					'post' => $_POST,
766
					'files' => $_FILES,
767
					'server' => $_SERVER,
768
					'env' => $_ENV,
769
					'cookies' => $_COOKIE,
770
					'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD']))
771
						? $_SERVER['REQUEST_METHOD']
772
						: null,
773
				],
774
				$c->getSecureRandom(),
775
				$c->getConfig()
776
			);
777
778
			return new CryptoWrapper(
779
				$c->getConfig(),
780
				$c->getCrypto(),
781
				$c->getSecureRandom(),
782
				$request
783
			);
784
		});
785
		$this->registerService('CsrfTokenManager', function (Server $c) {
786
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
787
			$sessionStorage = new SessionStorage($c->getSession());
788
789
			return new CsrfTokenManager(
790
				$tokenGenerator,
791
				$sessionStorage
792
			);
793
		});
794
		$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...
795
			return new ContentSecurityPolicyManager();
796
		});
797
		$this->registerService('StoragesDBConfigService', function (Server $c) {
798
			return new DBConfigService(
799
				$c->getDatabaseConnection(),
800
				$c->getCrypto()
801
			);
802
		});
803
		$this->registerService('StoragesBackendService', function (Server $c) {
804
			$service = new StoragesBackendService($c->query('AllConfig'));
805
806
			// register auth mechanisms provided by core
807
			$provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [
808
				// AuthMechanism::SCHEME_NULL mechanism
809
				'OC\Files\External\Auth\NullMechanism',
810
811
				// AuthMechanism::SCHEME_BUILTIN mechanism
812
				'OC\Files\External\Auth\Builtin',
813
814
				// AuthMechanism::SCHEME_PASSWORD mechanisms
815
				'OC\Files\External\Auth\Password\Password',
816
			]);
817
818
			$service->registerAuthMechanismProvider($provider);
819
820
			// force-load the session one as it will register hooks...
821
			// TODO: obsolete it and use the TokenProvider to get the user's password from the session
822
			$sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials(
823
				$c->getSession(),
824
				$c->getCrypto()
825
			);
826
			$service->registerAuthMechanism($sessionCreds);
827
828
			return $service;
829
		});
830
		$this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService');
831
		$this->registerService('GlobalStoragesService', function (Server $c) {
832
			return new GlobalStoragesService(
833
				$c->query('StoragesBackendService'),
834
				$c->query('StoragesDBConfigService'),
835
				$c->query('UserMountCache')
836
			);
837
		});
838
		$this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService');
839 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...
840
			return new UserGlobalStoragesService(
841
				$c->query('StoragesBackendService'),
842
				$c->query('StoragesDBConfigService'),
843
				$c->query('UserSession'),
844
				$c->query('GroupManager'),
845
				$c->query('UserMountCache')
846
			);
847
		});
848
		$this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService');
849 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...
850
			return new UserStoragesService(
851
				$c->query('StoragesBackendService'),
852
				$c->query('StoragesDBConfigService'),
853
				$c->query('UserSession'),
854
				$c->query('UserMountCache')
855
			);
856
		});
857
		$this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService');
858
		$this->registerService('ShareManager', function (Server $c) {
859
			$config = $c->getConfig();
860
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
861
			/** @var \OCP\Share\IProviderFactory $factory */
862
			$factory = new $factoryClass($this);
863
864
			$manager = new \OC\Share20\Manager(
865
				$c->getLogger(),
866
				$c->getConfig(),
867
				$c->getSecureRandom(),
868
				$c->getHasher(),
869
				$c->getMountManager(),
870
				$c->getGroupManager(),
871
				$c->getL10N('core'),
872
				$factory,
873
				$c->getUserManager(),
874
				$c->getLazyRootFolder(),
875
				$c->getEventDispatcher(),
0 ignored issues
show
Compatibility introduced by
$c->getEventDispatcher() of type object<Symfony\Component...entDispatcherInterface> is not a sub-type of object<Symfony\Component...atcher\EventDispatcher>. It seems like you assume a concrete implementation of the interface Symfony\Component\EventD...ventDispatcherInterface to be always present.

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

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

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