Completed
Pull Request — master (#7498)
by Julius
14:16
created

Server::connectDispatcher()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 37
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 1
nop 0
dl 0
loc 37
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 * @copyright Copyright (c) 2016, Lukas Reschke <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 * @author Bart Visscher <[email protected]>
8
 * @author Bernhard Posselt <[email protected]>
9
 * @author Bernhard Reiter <[email protected]>
10
 * @author Bjoern Schiessle <[email protected]>
11
 * @author Björn Schießle <[email protected]>
12
 * @author Christoph Wurst <[email protected]>
13
 * @author Christopher Schäpers <[email protected]>
14
 * @author Damjan Georgievski <[email protected]>
15
 * @author Joas Schilling <[email protected]>
16
 * @author John Molakvoæ (skjnldsv) <[email protected]>
17
 * @author Julius Haertl <[email protected]>
18
 * @author Julius Härtl <[email protected]>
19
 * @author Jörn Friedrich Dreyer <[email protected]>
20
 * @author Lukas Reschke <[email protected]>
21
 * @author Morris Jobke <[email protected]>
22
 * @author Piotr Mrówczyński <[email protected]>
23
 * @author Robin Appelman <[email protected]>
24
 * @author Robin McCorkell <[email protected]>
25
 * @author Roeland Jago Douma <[email protected]>
26
 * @author root <[email protected]>
27
 * @author Sander <[email protected]>
28
 * @author Thomas Müller <[email protected]>
29
 * @author Thomas Tanghus <[email protected]>
30
 * @author Vincent Petry <[email protected]>
31
 *
32
 * @license AGPL-3.0
33
 *
34
 * This code is free software: you can redistribute it and/or modify
35
 * it under the terms of the GNU Affero General Public License, version 3,
36
 * as published by the Free Software Foundation.
37
 *
38
 * This program is distributed in the hope that it will be useful,
39
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41
 * GNU Affero General Public License for more details.
42
 *
43
 * You should have received a copy of the GNU Affero General Public License, version 3,
44
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
45
 *
46
 */
47
48
namespace OC;
49
50
use bantu\IniGetWrapper\IniGetWrapper;
51
use OC\Accounts\AccountManager;
52
use OC\App\AppManager;
53
use OC\App\AppStore\Bundles\BundleFetcher;
54
use OC\App\AppStore\Fetcher\AppFetcher;
55
use OC\App\AppStore\Fetcher\CategoryFetcher;
56
use OC\AppFramework\Http\Request;
57
use OC\AppFramework\Utility\SimpleContainer;
58
use OC\AppFramework\Utility\TimeFactory;
59
use OC\Authentication\LoginCredentials\Store;
60
use OC\Collaboration\Collaborators\GroupPlugin;
61
use OC\Collaboration\Collaborators\MailPlugin;
62
use OC\Collaboration\Collaborators\RemotePlugin;
63
use OC\Collaboration\Collaborators\UserPlugin;
64
use OC\Command\CronBus;
65
use OC\Contacts\ContactsMenu\ActionFactory;
66
use OC\Contacts\ContactsMenu\ContactsStore;
67
use OC\Diagnostics\EventLogger;
68
use OC\Diagnostics\QueryLogger;
69
use OC\Federation\CloudIdManager;
70
use OC\Files\Config\UserMountCache;
71
use OC\Files\Config\UserMountCacheListener;
72
use OC\Files\Mount\CacheMountProvider;
73
use OC\Files\Mount\LocalHomeMountProvider;
74
use OC\Files\Mount\ObjectHomeMountProvider;
75
use OC\Files\Node\HookConnector;
76
use OC\Files\Node\LazyRoot;
77
use OC\Files\Node\Root;
78
use OC\Files\View;
79
use OC\Http\Client\ClientService;
80
use OC\IntegrityCheck\Checker;
81
use OC\IntegrityCheck\Helpers\AppLocator;
82
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
83
use OC\IntegrityCheck\Helpers\FileAccessHelper;
84
use OC\Lock\DBLockingProvider;
85
use OC\Lock\MemcacheLockingProvider;
86
use OC\Lock\NoopLockingProvider;
87
use OC\Lockdown\LockdownManager;
88
use OC\Mail\Mailer;
89
use OC\Memcache\ArrayCache;
90
use OC\Memcache\Factory;
91
use OC\Notification\Manager;
92
use OC\OCS\DiscoveryService;
93
use OC\Remote\Api\ApiFactory;
94
use OC\Remote\InstanceFactory;
95
use OC\Repair\NC11\CleanPreviewsBackgroundJob;
96
use OC\RichObjectStrings\Validator;
97
use OC\Security\Bruteforce\Throttler;
98
use OC\Security\CertificateManager;
99
use OC\Security\CSP\ContentSecurityPolicyManager;
100
use OC\Security\Crypto;
101
use OC\Security\CSP\ContentSecurityPolicyNonceManager;
102
use OC\Security\CSRF\CsrfTokenGenerator;
103
use OC\Security\CSRF\CsrfTokenManager;
104
use OC\Security\CSRF\TokenStorage\SessionStorage;
105
use OC\Security\Hasher;
106
use OC\Security\CredentialsManager;
107
use OC\Security\SecureRandom;
108
use OC\Security\TrustedDomainHelper;
109
use OC\Session\CryptoWrapper;
110
use OC\Share20\ShareHelper;
111
use OC\Tagging\TagMapper;
112
use OC\Template\SCSSCacher;
113
use OCA\Theming\ThemingDefaults;
114
115
use OCP\App\IAppManager;
116
use OCP\AppFramework\Utility\ITimeFactory;
117
use OCP\Collaboration\AutoComplete\IManager;
118
use OCP\Contacts\ContactsMenu\IContactsStore;
119
use OCP\Defaults;
120
use OCA\Theming\Util;
121
use OCP\Federation\ICloudIdManager;
122
use OCP\Authentication\LoginCredentials\IStore;
123
use OCP\Files\NotFoundException;
124
use OCP\ICacheFactory;
125
use OCP\IDBConnection;
126
use OCP\IL10N;
127
use OCP\IServerContainer;
128
use OCP\ITempManager;
129
use OCP\Contacts\ContactsMenu\IActionFactory;
130
use OCP\IUser;
131
use OCP\Lock\ILockingProvider;
132
use OCP\Remote\Api\IApiFactory;
133
use OCP\Remote\IInstanceFactory;
134
use OCP\RichObjectStrings\IValidator;
135
use OCP\Security\IContentSecurityPolicyManager;
136
use OCP\Share;
137
use OCP\Share\IShareHelper;
138
use Symfony\Component\EventDispatcher\EventDispatcher;
139
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
140
use Symfony\Component\EventDispatcher\GenericEvent;
141
142
/**
143
 * Class Server
144
 *
145
 * @package OC
146
 *
147
 * TODO: hookup all manager classes
148
 */
149
class Server extends ServerContainer implements IServerContainer {
150
	/** @var string */
151
	private $webRoot;
152
153
	/**
154
	 * @param string $webRoot
155
	 * @param \OC\Config $config
156
	 */
157
	public function __construct($webRoot, \OC\Config $config) {
0 ignored issues
show
Coding Style introduced by
__construct uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_FILES which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
Coding Style introduced by
__construct uses the super-global variable $_COOKIE which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
158
		parent::__construct();
159
		$this->webRoot = $webRoot;
160
161
		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
162
			return $c;
163
		});
164
165
		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
166
		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
167
168
		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
169
		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
170
171
		$this->registerAlias(IActionFactory::class, ActionFactory::class);
172
173
174
		$this->registerService(\OCP\IPreview::class, function (Server $c) {
175
			return new PreviewManager(
176
				$c->getConfig(),
177
				$c->getRootFolder(),
178
				$c->getAppDataDir('preview'),
179
				$c->getEventDispatcher(),
180
				$c->getSession()->get('user_id')
181
			);
182
		});
183
		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
184
185
		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
186
			return new \OC\Preview\Watcher(
187
				$c->getAppDataDir('preview')
188
			);
189
		});
190
191
		$this->registerService('EncryptionManager', function (Server $c) {
192
			$view = new View();
193
			$util = new Encryption\Util(
194
				$view,
195
				$c->getUserManager(),
196
				$c->getGroupManager(),
197
				$c->getConfig()
198
			);
199
			return new Encryption\Manager(
200
				$c->getConfig(),
201
				$c->getLogger(),
202
				$c->getL10N('core'),
203
				new View(),
204
				$util,
205
				new ArrayCache()
206
			);
207
		});
208
209 View Code Duplication
		$this->registerService('EncryptionFileHelper', function (Server $c) {
210
			$util = new Encryption\Util(
211
				new View(),
212
				$c->getUserManager(),
213
				$c->getGroupManager(),
214
				$c->getConfig()
215
			);
216
			return new Encryption\File(
217
				$util,
218
				$c->getRootFolder(),
219
				$c->getShareManager()
220
			);
221
		});
222
223 View Code Duplication
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
224
			$view = new View();
225
			$util = new Encryption\Util(
226
				$view,
227
				$c->getUserManager(),
228
				$c->getGroupManager(),
229
				$c->getConfig()
230
			);
231
232
			return new Encryption\Keys\Storage($view, $util);
233
		});
234
		$this->registerService('TagMapper', function (Server $c) {
235
			return new TagMapper($c->getDatabaseConnection());
236
		});
237
238
		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
239
			$tagMapper = $c->query('TagMapper');
240
			return new TagManager($tagMapper, $c->getUserSession());
241
		});
242
		$this->registerAlias('TagManager', \OCP\ITagManager::class);
243
244
		$this->registerService('SystemTagManagerFactory', function (Server $c) {
245
			$config = $c->getConfig();
246
			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
247
			/** @var \OC\SystemTag\ManagerFactory $factory */
248
			$factory = new $factoryClass($this);
249
			return $factory;
250
		});
251
		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
252
			return $c->query('SystemTagManagerFactory')->getManager();
253
		});
254
		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
255
256
		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
257
			return $c->query('SystemTagManagerFactory')->getObjectMapper();
258
		});
259
		$this->registerService('RootFolder', function (Server $c) {
260
			$manager = \OC\Files\Filesystem::getMountManager(null);
261
			$view = new View();
262
			$root = new Root(
263
				$manager,
264
				$view,
265
				null,
266
				$c->getUserMountCache(),
267
				$this->getLogger(),
268
				$this->getUserManager()
269
			);
270
			$connector = new HookConnector($root, $view);
271
			$connector->viewToNode();
272
273
			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
274
			$previewConnector->connectWatcher();
275
276
			return $root;
277
		});
278
		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
279
280
		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
281
			return new LazyRoot(function () use ($c) {
282
				return $c->query('RootFolder');
283
			});
284
		});
285
		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
286
287
		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
288
			$config = $c->getConfig();
289
			return new \OC\User\Manager($config);
290
		});
291
		$this->registerAlias('UserManager', \OCP\IUserManager::class);
292
293
		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
294
			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
295
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
296
				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
297
			});
298
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
299
				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
300
			});
301
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
302
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
303
			});
304
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
305
				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
306
			});
307
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
308
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
309
			});
310
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
311
				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
312
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
313
				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
314
			});
315
			return $groupManager;
316
		});
317
		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
318
319
		$this->registerService(Store::class, function (Server $c) {
320
			$session = $c->getSession();
321 View Code Duplication
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
322
				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
323
			} else {
324
				$tokenProvider = null;
325
			}
326
			$logger = $c->getLogger();
327
			return new Store($session, $logger, $tokenProvider);
328
		});
329
		$this->registerAlias(IStore::class, Store::class);
330
		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
331
			$dbConnection = $c->getDatabaseConnection();
332
			return new Authentication\Token\DefaultTokenMapper($dbConnection);
333
		});
334
		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
335
			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
336
			$crypto = $c->getCrypto();
337
			$config = $c->getConfig();
338
			$logger = $c->getLogger();
339
			$timeFactory = new TimeFactory();
340
			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
341
		});
342
		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
343
344
		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
345
			$manager = $c->getUserManager();
346
			$session = new \OC\Session\Memory('');
347
			$timeFactory = new TimeFactory();
348
			// Token providers might require a working database. This code
349
			// might however be called when ownCloud is not yet setup.
350 View Code Duplication
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
351
				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
352
			} else {
353
				$defaultTokenProvider = null;
354
			}
355
356
			$dispatcher = $c->getEventDispatcher();
357
358
			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
359
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
360
				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
361
			});
362
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
363
				/** @var $user \OC\User\User */
364
				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
365
			});
366
			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
367
				/** @var $user \OC\User\User */
368
				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
369
				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
370
			});
371
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
372
				/** @var $user \OC\User\User */
373
				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
374
			});
375 View Code Duplication
			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
376
				/** @var $user \OC\User\User */
377
				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
378
			});
379 View Code Duplication
			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
380
				/** @var $user \OC\User\User */
381
				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
382
			});
383
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
384
				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
385
			});
386 View Code Duplication
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
387
				/** @var $user \OC\User\User */
388
				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
389
			});
390 View Code Duplication
			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
391
				/** @var $user \OC\User\User */
392
				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
393
			});
394
			$userSession->listen('\OC\User', 'logout', function () {
395
				\OC_Hook::emit('OC_User', 'logout', array());
396
			});
397
			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
398
				/** @var $user \OC\User\User */
399
				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
400
				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
401
			});
402
			return $userSession;
403
		});
404
		$this->registerAlias('UserSession', \OCP\IUserSession::class);
405
406
		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
407
			return new \OC\Authentication\TwoFactorAuth\Manager(
408
				$c->getAppManager(),
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...
409
				$c->getSession(),
410
				$c->getConfig(),
411
				$c->getActivityManager(),
412
				$c->getLogger(),
413
				$c->query(\OC\Authentication\Token\IProvider::class),
414
				$c->query(ITimeFactory::class)
415
			);
416
		});
417
418
		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
419
		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
420
421
		$this->registerService(\OC\AllConfig::class, function (Server $c) {
422
			return new \OC\AllConfig(
423
				$c->getSystemConfig()
424
			);
425
		});
426
		$this->registerAlias('AllConfig', \OC\AllConfig::class);
427
		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
428
429
		$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...
430
			return new \OC\SystemConfig($config);
431
		});
432
433
		$this->registerService(\OC\AppConfig::class, function (Server $c) {
434
			return new \OC\AppConfig($c->getDatabaseConnection());
435
		});
436
		$this->registerAlias('AppConfig', \OC\AppConfig::class);
437
		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
438
439
		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
440
			return new \OC\L10N\Factory(
441
				$c->getConfig(),
442
				$c->getRequest(),
443
				$c->getUserSession(),
444
				\OC::$SERVERROOT
445
			);
446
		});
447
		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
448
449
		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
450
			$config = $c->getConfig();
451
			$cacheFactory = $c->getMemCacheFactory();
452
			$request = $c->getRequest();
453
			return new \OC\URLGenerator(
454
				$config,
455
				$cacheFactory,
456
				$request
457
			);
458
		});
459
		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
460
461
		$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...
462
			return new \OC\AppHelper();
0 ignored issues
show
Deprecated Code introduced by
The class OC\AppHelper has been deprecated with message: 8.1.0

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

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

Loading history...
463
		});
464
		$this->registerAlias('AppFetcher', AppFetcher::class);
465
		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
466
467
		$this->registerService(\OCP\ICache::class, 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...
468
			return new Cache\File();
469
		});
470
		$this->registerAlias('UserCache', \OCP\ICache::class);
471
472
		$this->registerService(Factory::class, function (Server $c) {
473
474
			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
475
				'\\OC\\Memcache\\ArrayCache',
476
				'\\OC\\Memcache\\ArrayCache',
477
				'\\OC\\Memcache\\ArrayCache'
478
			);
479
			$config = $c->getConfig();
480
			$request = $c->getRequest();
481
			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
482
483
			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
484
				$v = \OC_App::getAppVersions();
485
				$v['core'] = implode(',', \OC_Util::getVersion());
486
				$version = implode(',', $v);
487
				$instanceId = \OC_Util::getInstanceId();
488
				$path = \OC::$SERVERROOT;
489
				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl());
490
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
491
					$config->getSystemValue('memcache.local', null),
492
					$config->getSystemValue('memcache.distributed', null),
493
					$config->getSystemValue('memcache.locking', null)
494
				);
495
			}
496
			return $arrayCacheFactory;
497
498
		});
499
		$this->registerAlias('MemCacheFactory', Factory::class);
500
		$this->registerAlias(ICacheFactory::class, Factory::class);
501
502
		$this->registerService('RedisFactory', function (Server $c) {
503
			$systemConfig = $c->getSystemConfig();
504
			return new RedisFactory($systemConfig);
505
		});
506
507
		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
508
			return new \OC\Activity\Manager(
509
				$c->getRequest(),
510
				$c->getUserSession(),
511
				$c->getConfig(),
512
				$c->query(IValidator::class)
513
			);
514
		});
515
		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
516
517
		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
518
			return new \OC\Activity\EventMerger(
519
				$c->getL10N('lib')
520
			);
521
		});
522
		$this->registerAlias(IValidator::class, Validator::class);
523
524
		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
525
			return new AvatarManager(
526
				$c->getUserManager(),
527
				$c->getAppDataDir('avatar'),
528
				$c->getL10N('lib'),
529
				$c->getLogger(),
530
				$c->getConfig()
531
			);
532
		});
533
		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
534
535
		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
536
537
		$this->registerService(\OCP\ILogger::class, function (Server $c) {
538
			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
539
			$logger = Log::getLogClass($logType);
540
			call_user_func(array($logger, 'init'));
541
			$config = $this->getSystemConfig();
542
			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
543
544
			return new Log($logger, $config, null, $registry);
545
		});
546
		$this->registerAlias('Logger', \OCP\ILogger::class);
547
548
		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
549
			$config = $c->getConfig();
550
			return new \OC\BackgroundJob\JobList(
551
				$c->getDatabaseConnection(),
552
				$config,
553
				new TimeFactory()
554
			);
555
		});
556
		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
557
558
		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
559
			$cacheFactory = $c->getMemCacheFactory();
560
			$logger = $c->getLogger();
561
			if ($cacheFactory->isAvailableLowLatency()) {
0 ignored issues
show
Bug introduced by
The method isAvailableLowLatency() does not exist on OCP\ICacheFactory. Did you maybe mean isAvailable()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
562
				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
563
			} else {
564
				$router = new \OC\Route\Router($logger);
565
			}
566
			return $router;
567
		});
568
		$this->registerAlias('Router', \OCP\Route\IRouter::class);
569
570
		$this->registerService(\OCP\ISearch::class, function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
571
			return new Search();
572
		});
573
		$this->registerAlias('Search', \OCP\ISearch::class);
574
575
		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) {
576
			return new \OC\Security\RateLimiting\Limiter(
577
				$this->getUserSession(),
578
				$this->getRequest(),
579
				new \OC\AppFramework\Utility\TimeFactory(),
580
				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
581
			);
582
		});
583
		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, 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...
584
			return new \OC\Security\RateLimiting\Backend\MemoryCache(
585
				$this->getMemCacheFactory(),
586
				new \OC\AppFramework\Utility\TimeFactory()
587
			);
588
		});
589
590
		$this->registerService(\OCP\Security\ISecureRandom::class, 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...
591
			return new SecureRandom();
592
		});
593
		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
594
595
		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
596
			return new Crypto($c->getConfig(), $c->getSecureRandom());
597
		});
598
		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
599
600
		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
601
			return new Hasher($c->getConfig());
602
		});
603
		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
604
605
		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
606
			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
607
		});
608
		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
609
610
		$this->registerService(IDBConnection::class, function (Server $c) {
611
			$systemConfig = $c->getSystemConfig();
612
			$factory = new \OC\DB\ConnectionFactory($systemConfig);
613
			$type = $systemConfig->getValue('dbtype', 'sqlite');
614
			if (!$factory->isValidType($type)) {
615
				throw new \OC\DatabaseException('Invalid database type');
616
			}
617
			$connectionParams = $factory->createConnectionParams();
618
			$connection = $factory->getConnection($type, $connectionParams);
619
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
620
			return $connection;
621
		});
622
		$this->registerAlias('DatabaseConnection', IDBConnection::class);
623
624
		$this->registerService('HTTPHelper', function (Server $c) {
625
			$config = $c->getConfig();
626
			return new HTTPHelper(
0 ignored issues
show
Deprecated Code introduced by
The class OC\HTTPHelper has been deprecated with message: Use \OCP\Http\Client\IClientService

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

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

Loading history...
627
				$config,
628
				$c->getHTTPClientService()
629
			);
630
		});
631
632
		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
633
			$user = \OC_User::getUser();
634
			$uid = $user ? $user : null;
635
			return new ClientService(
636
				$c->getConfig(),
637
				new \OC\Security\CertificateManager(
638
					$uid,
639
					new View(),
640
					$c->getConfig(),
641
					$c->getLogger(),
642
					$c->getSecureRandom()
643
				)
644
			);
645
		});
646
		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
647 View Code Duplication
		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
648
			$eventLogger = new EventLogger();
649
			if ($c->getSystemConfig()->getValue('debug', false)) {
650
				// In debug mode, module is being activated by default
651
				$eventLogger->activate();
652
			}
653
			return $eventLogger;
654
		});
655
		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
656
657 View Code Duplication
		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
658
			$queryLogger = new QueryLogger();
659
			if ($c->getSystemConfig()->getValue('debug', false)) {
660
				// In debug mode, module is being activated by default
661
				$queryLogger->activate();
662
			}
663
			return $queryLogger;
664
		});
665
		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
666
667
		$this->registerService(TempManager::class, function (Server $c) {
668
			return new TempManager(
669
				$c->getLogger(),
670
				$c->getConfig()
671
			);
672
		});
673
		$this->registerAlias('TempManager', TempManager::class);
674
		$this->registerAlias(ITempManager::class, TempManager::class);
675
676
		$this->registerService(AppManager::class, function (Server $c) {
677
			return new \OC\App\AppManager(
678
				$c->getUserSession(),
679
				$c->getAppConfig(),
680
				$c->getGroupManager(),
681
				$c->getMemCacheFactory(),
682
				$c->getEventDispatcher()
683
			);
684
		});
685
		$this->registerAlias('AppManager', AppManager::class);
686
		$this->registerAlias(IAppManager::class, AppManager::class);
687
688
		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
689
			return new DateTimeZone(
690
				$c->getConfig(),
691
				$c->getSession()
692
			);
693
		});
694
		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
695
696
		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
697
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
698
699
			return new DateTimeFormatter(
700
				$c->getDateTimeZone()->getTimeZone(),
701
				$c->getL10N('lib', $language)
702
			);
703
		});
704
		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
705
706
		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
707
			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
708
			$listener = new UserMountCacheListener($mountCache);
709
			$listener->listen($c->getUserManager());
710
			return $mountCache;
711
		});
712
		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
713
714
		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
715
			$loader = \OC\Files\Filesystem::getLoader();
716
			$mountCache = $c->query('UserMountCache');
717
			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
718
719
			// builtin providers
720
721
			$config = $c->getConfig();
722
			$manager->registerProvider(new CacheMountProvider($config));
723
			$manager->registerHomeProvider(new LocalHomeMountProvider());
724
			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
725
726
			return $manager;
727
		});
728
		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
729
730
		$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...
731
			return new IniGetWrapper();
732
		});
733
		$this->registerService('AsyncCommandBus', function (Server $c) {
734
			$busClass = $c->getConfig()->getSystemValue('commandbus');
735
			if ($busClass) {
736
				list($app, $class) = explode('::', $busClass, 2);
737
				if ($c->getAppManager()->isInstalled($app)) {
738
					\OC_App::loadApp($app);
739
					return $c->query($class);
740
				} else {
741
					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
742
				}
743
			} else {
744
				$jobList = $c->getJobList();
745
				return new CronBus($jobList);
746
			}
747
		});
748
		$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...
749
			return new TrustedDomainHelper($this->getConfig());
750
		});
751
		$this->registerService('Throttler', function (Server $c) {
752
			return new Throttler(
753
				$c->getDatabaseConnection(),
754
				new TimeFactory(),
755
				$c->getLogger(),
756
				$c->getConfig()
757
			);
758
		});
759
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
760
			// IConfig and IAppManager requires a working database. This code
761
			// might however be called when ownCloud is not yet setup.
762
			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
763
				$config = $c->getConfig();
764
				$appManager = $c->getAppManager();
765
			} else {
766
				$config = null;
767
				$appManager = null;
768
			}
769
770
			return new Checker(
771
				new EnvironmentHelper(),
772
				new FileAccessHelper(),
773
				new AppLocator(),
774
				$config,
775
				$c->getMemCacheFactory(),
776
				$appManager,
777
				$c->getTempManager()
778
			);
779
		});
780
		$this->registerService(\OCP\IRequest::class, 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...
781
			if (isset($this['urlParams'])) {
782
				$urlParams = $this['urlParams'];
783
			} else {
784
				$urlParams = [];
785
			}
786
787
			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
788
				&& in_array('fakeinput', stream_get_wrappers())
789
			) {
790
				$stream = 'fakeinput://data';
791
			} else {
792
				$stream = 'php://input';
793
			}
794
795
			return new Request(
796
				[
797
					'get' => $_GET,
798
					'post' => $_POST,
799
					'files' => $_FILES,
800
					'server' => $_SERVER,
801
					'env' => $_ENV,
802
					'cookies' => $_COOKIE,
803
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
804
						? $_SERVER['REQUEST_METHOD']
805
						: null,
806
					'urlParams' => $urlParams,
807
				],
808
				$this->getSecureRandom(),
809
				$this->getConfig(),
810
				$this->getCsrfTokenManager(),
811
				$stream
812
			);
813
		});
814
		$this->registerAlias('Request', \OCP\IRequest::class);
815
816
		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
817
			return new Mailer(
818
				$c->getConfig(),
819
				$c->getLogger(),
820
				$c->query(Defaults::class),
821
				$c->getURLGenerator(),
822
				$c->getL10N('lib')
823
			);
824
		});
825
		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
826
827
		$this->registerService('LDAPProvider', function (Server $c) {
828
			$config = $c->getConfig();
829
			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
830
			if (is_null($factoryClass)) {
831
				throw new \Exception('ldapProviderFactory not set');
832
			}
833
			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
834
			$factory = new $factoryClass($this);
835
			return $factory->getLDAPProvider();
836
		});
837
		$this->registerService(ILockingProvider::class, function (Server $c) {
838
			$ini = $c->getIniWrapper();
839
			$config = $c->getConfig();
840
			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
841
			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
842
				/** @var \OC\Memcache\Factory $memcacheFactory */
843
				$memcacheFactory = $c->getMemCacheFactory();
844
				$memcache = $memcacheFactory->createLocking('lock');
845
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
846
					return new MemcacheLockingProvider($memcache, $ttl);
847
				}
848
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
849
			}
850
			return new NoopLockingProvider();
851
		});
852
		$this->registerAlias('LockingProvider', ILockingProvider::class);
853
854
		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
855
			return new \OC\Files\Mount\Manager();
856
		});
857
		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
858
859
		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
860
			return new \OC\Files\Type\Detection(
861
				$c->getURLGenerator(),
862
				\OC::$configDir,
863
				\OC::$SERVERROOT . '/resources/config/'
864
			);
865
		});
866
		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
867
868
		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
869
			return new \OC\Files\Type\Loader(
870
				$c->getDatabaseConnection()
871
			);
872
		});
873
		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
874
		$this->registerService(BundleFetcher::class, function () {
875
			return new BundleFetcher($this->getL10N('lib'));
876
		});
877
		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
878
			return new Manager(
879
				$c->query(IValidator::class)
880
			);
881
		});
882
		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
883
884
		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
885
			$manager = new \OC\CapabilitiesManager($c->getLogger());
886
			$manager->registerCapability(function () use ($c) {
887
				return new \OC\OCS\CoreCapabilities($c->getConfig());
888
			});
889
			$manager->registerCapability(function () use ($c) {
890
				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
891
			});
892
			return $manager;
893
		});
894
		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
895
896
		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
897
			$config = $c->getConfig();
898
			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
899
			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
900
			$factory = new $factoryClass($this);
901
			$manager = $factory->getManager();
902
903
			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
904
				$manager = $c->getUserManager();
905
				$user = $manager->get($id);
906
				if(is_null($user)) {
907
					$l = $c->getL10N('core');
908
					$displayName = $l->t('Unknown user');
909
				} else {
910
					$displayName = $user->getDisplayName();
911
				}
912
				return $displayName;
913
			});
914
915
			return $manager;
916
		});
917
		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
918
919
		$this->registerService('ThemingDefaults', function (Server $c) {
920
			/*
921
			 * Dark magic for autoloader.
922
			 * If we do a class_exists it will try to load the class which will
923
			 * make composer cache the result. Resulting in errors when enabling
924
			 * the theming app.
925
			 */
926
			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
927
			if (isset($prefixes['OCA\\Theming\\'])) {
928
				$classExists = true;
929
			} else {
930
				$classExists = false;
931
			}
932
933
			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
934
				return new ThemingDefaults(
935
					$c->getConfig(),
936
					$c->getL10N('theming'),
937
					$c->getURLGenerator(),
938
					$c->getAppDataDir('theming'),
939
					$c->getMemCacheFactory(),
940
					new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')),
941
					$this->getAppManager()
942
				);
943
			}
944
			return new \OC_Defaults();
945
		});
946
		$this->registerService(SCSSCacher::class, function (Server $c) {
947
			/** @var Factory $cacheFactory */
948
			$cacheFactory = $c->query(Factory::class);
949
			return new SCSSCacher(
950
				$c->getLogger(),
951
				$c->query(\OC\Files\AppData\Factory::class),
952
				$c->getURLGenerator(),
953
				$c->getConfig(),
954
				$c->getThemingDefaults(),
955
				\OC::$SERVERROOT,
956
				$cacheFactory->createDistributed('SCSS')
957
			);
958
		});
959
		$this->registerService(EventDispatcher::class, function () {
960
			return new EventDispatcher();
961
		});
962
		$this->registerAlias('EventDispatcher', EventDispatcher::class);
963
		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
964
965
		$this->registerService('CryptoWrapper', function (Server $c) {
966
			// FIXME: Instantiiated here due to cyclic dependency
967
			$request = new Request(
968
				[
969
					'get' => $_GET,
970
					'post' => $_POST,
971
					'files' => $_FILES,
972
					'server' => $_SERVER,
973
					'env' => $_ENV,
974
					'cookies' => $_COOKIE,
975
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
976
						? $_SERVER['REQUEST_METHOD']
977
						: null,
978
				],
979
				$c->getSecureRandom(),
980
				$c->getConfig()
981
			);
982
983
			return new CryptoWrapper(
984
				$c->getConfig(),
985
				$c->getCrypto(),
986
				$c->getSecureRandom(),
987
				$request
988
			);
989
		});
990
		$this->registerService('CsrfTokenManager', function (Server $c) {
991
			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
992
993
			return new CsrfTokenManager(
994
				$tokenGenerator,
995
				$c->query(SessionStorage::class)
996
			);
997
		});
998
		$this->registerService(SessionStorage::class, function (Server $c) {
999
			return new SessionStorage($c->getSession());
1000
		});
1001
		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1002
			return new ContentSecurityPolicyManager();
1003
		});
1004
		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1005
1006
		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1007
			return new ContentSecurityPolicyNonceManager(
1008
				$c->getCsrfTokenManager(),
1009
				$c->getRequest()
1010
			);
1011
		});
1012
1013
		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1014
			$config = $c->getConfig();
1015
			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
1016
			/** @var \OCP\Share\IProviderFactory $factory */
1017
			$factory = new $factoryClass($this);
1018
1019
			$manager = new \OC\Share20\Manager(
1020
				$c->getLogger(),
1021
				$c->getConfig(),
1022
				$c->getSecureRandom(),
1023
				$c->getHasher(),
1024
				$c->getMountManager(),
1025
				$c->getGroupManager(),
1026
				$c->getL10N('lib'),
1027
				$c->getL10NFactory(),
1028
				$factory,
1029
				$c->getUserManager(),
1030
				$c->getLazyRootFolder(),
1031
				$c->getEventDispatcher(),
1032
				$c->getMailer(),
1033
				$c->getURLGenerator(),
1034
				$c->getThemingDefaults()
1035
			);
1036
1037
			return $manager;
1038
		});
1039
		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1040
1041
		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1042
			$instance = new Collaboration\Collaborators\Search($c);
1043
1044
			// register default plugins
1045
			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1046
			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1047
			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1048
			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1049
1050
			return $instance;
1051
		});
1052
		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1053
1054
		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1055
1056
		$this->registerService('SettingsManager', function (Server $c) {
1057
			$manager = new \OC\Settings\Manager(
1058
				$c->getLogger(),
1059
				$c->getDatabaseConnection(),
1060
				$c->getL10N('lib'),
1061
				$c->getConfig(),
1062
				$c->getEncryptionManager(),
1063
				$c->getUserManager(),
1064
				$c->getLockingProvider(),
1065
				$c->getRequest(),
1066
				new \OC\Settings\Mapper($c->getDatabaseConnection()),
1067
				$c->getURLGenerator(),
1068
				$c->query(AccountManager::class),
1069
				$c->getGroupManager(),
1070
				$c->getL10NFactory(),
1071
				$c->getThemingDefaults(),
1072
				$c->getAppManager()
1073
			);
1074
			return $manager;
1075
		});
1076
		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1077
			return new \OC\Files\AppData\Factory(
1078
				$c->getRootFolder(),
1079
				$c->getSystemConfig()
1080
			);
1081
		});
1082
1083
		$this->registerService('LockdownManager', function (Server $c) {
1084
			return new LockdownManager(function () use ($c) {
1085
				return $c->getSession();
1086
			});
1087
		});
1088
1089
		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1090
			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1091
		});
1092
1093
		$this->registerService(ICloudIdManager::class, function (Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1094
			return new CloudIdManager();
1095
		});
1096
1097
		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1098
		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1099
1100
		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1101
		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1102
1103
		$this->registerService(Defaults::class, function (Server $c) {
1104
			return new Defaults(
1105
				$c->getThemingDefaults()
1106
			);
1107
		});
1108
		$this->registerAlias('Defaults', \OCP\Defaults::class);
1109
1110
		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1111
			return $c->query(\OCP\IUserSession::class)->getSession();
1112
		});
1113
1114
		$this->registerService(IShareHelper::class, function (Server $c) {
1115
			return new ShareHelper(
1116
				$c->query(\OCP\Share\IManager::class)
1117
			);
1118
		});
1119
1120
		$this->registerService(Installer::class, function(Server $c) {
1121
			return new Installer(
1122
				$c->getAppFetcher(),
1123
				$c->getHTTPClientService(),
1124
				$c->getTempManager(),
1125
				$c->getLogger(),
1126
				$c->getConfig()
1127
			);
1128
		});
1129
1130
		$this->registerService(IApiFactory::class, function(Server $c) {
1131
			return new ApiFactory($c->getHTTPClientService());
1132
		});
1133
1134
		$this->registerService(IInstanceFactory::class, function(Server $c) {
1135
			$memcacheFactory = $c->getMemCacheFactory();
1136
			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1137
		});
1138
1139
		$this->registerService(IContactsStore::class, function(Server $c) {
1140
			return new ContactsStore(
1141
				$c->getContactsManager(),
1142
				$c->getConfig(),
1143
				$c->getUserManager(),
1144
				$c->getGroupManager()
1145
			);
1146
		});
1147
		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1148
1149
		$this->connectDispatcher();
1150
	}
1151
1152
	/**
1153
	 * @return \OCP\Calendar\IManager
1154
	 */
1155
	public function getCalendarManager() {
1156
		return $this->query('CalendarManager');
1157
	}
1158
1159
	private function connectDispatcher() {
1160
		$dispatcher = $this->getEventDispatcher();
1161
1162
		// Delete avatar on user deletion
1163
		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1164
			$logger = $this->getLogger();
1165
			$manager = $this->getAvatarManager();
1166
			/** @var IUser $user */
1167
			$user = $e->getSubject();
1168
1169
			try {
1170
				$avatar = $manager->getAvatar($user->getUID());
1171
				$avatar->remove();
1172
			} catch (NotFoundException $e) {
1173
				// no avatar to remove
1174
			} catch (\Exception $e) {
1175
				// Ignore exceptions
1176
				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1177
			}
1178
		});
1179
1180
		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1181
			$manager = $this->getAvatarManager();
1182
			/** @var IUser $user */
1183
			$user = $e->getSubject();
0 ignored issues
show
Bug introduced by
The method getSubject() does not seem to exist on object<OCP\Files\NotFoundException>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1184
			$feature = $e->getArgument('feature');
0 ignored issues
show
Bug introduced by
The method getArgument() does not seem to exist on object<OCP\Files\NotFoundException>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1185
			$oldValue = $e->getArgument('oldValue');
0 ignored issues
show
Bug introduced by
The method getArgument() does not seem to exist on object<OCP\Files\NotFoundException>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1186
			$value = $e->getArgument('value');
0 ignored issues
show
Bug introduced by
The method getArgument() does not seem to exist on object<OCP\Files\NotFoundException>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1187
1188
			try {
1189
				$avatar = $manager->getAvatar($user->getUID());
1190
				$avatar->userChanged($feature, $oldValue, $value);
1191
			} catch (NotFoundException $e) {
1192
				// no avatar to remove
1193
			}
1194
		});
1195
	}
1196
1197
	/**
1198
	 * @return \OCP\Contacts\IManager
1199
	 */
1200
	public function getContactsManager() {
1201
		return $this->query('ContactsManager');
1202
	}
1203
1204
	/**
1205
	 * @return \OC\Encryption\Manager
1206
	 */
1207
	public function getEncryptionManager() {
1208
		return $this->query('EncryptionManager');
1209
	}
1210
1211
	/**
1212
	 * @return \OC\Encryption\File
1213
	 */
1214
	public function getEncryptionFilesHelper() {
1215
		return $this->query('EncryptionFileHelper');
1216
	}
1217
1218
	/**
1219
	 * @return \OCP\Encryption\Keys\IStorage
1220
	 */
1221
	public function getEncryptionKeyStorage() {
1222
		return $this->query('EncryptionKeyStorage');
1223
	}
1224
1225
	/**
1226
	 * The current request object holding all information about the request
1227
	 * currently being processed is returned from this method.
1228
	 * In case the current execution was not initiated by a web request null is returned
1229
	 *
1230
	 * @return \OCP\IRequest
1231
	 */
1232
	public function getRequest() {
1233
		return $this->query('Request');
1234
	}
1235
1236
	/**
1237
	 * Returns the preview manager which can create preview images for a given file
1238
	 *
1239
	 * @return \OCP\IPreview
1240
	 */
1241
	public function getPreviewManager() {
1242
		return $this->query('PreviewManager');
1243
	}
1244
1245
	/**
1246
	 * Returns the tag manager which can get and set tags for different object types
1247
	 *
1248
	 * @see \OCP\ITagManager::load()
1249
	 * @return \OCP\ITagManager
1250
	 */
1251
	public function getTagManager() {
1252
		return $this->query('TagManager');
1253
	}
1254
1255
	/**
1256
	 * Returns the system-tag manager
1257
	 *
1258
	 * @return \OCP\SystemTag\ISystemTagManager
1259
	 *
1260
	 * @since 9.0.0
1261
	 */
1262
	public function getSystemTagManager() {
1263
		return $this->query('SystemTagManager');
1264
	}
1265
1266
	/**
1267
	 * Returns the system-tag object mapper
1268
	 *
1269
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1270
	 *
1271
	 * @since 9.0.0
1272
	 */
1273
	public function getSystemTagObjectMapper() {
1274
		return $this->query('SystemTagObjectMapper');
1275
	}
1276
1277
	/**
1278
	 * Returns the avatar manager, used for avatar functionality
1279
	 *
1280
	 * @return \OCP\IAvatarManager
1281
	 */
1282
	public function getAvatarManager() {
1283
		return $this->query('AvatarManager');
1284
	}
1285
1286
	/**
1287
	 * Returns the root folder of ownCloud's data directory
1288
	 *
1289
	 * @return \OCP\Files\IRootFolder
1290
	 */
1291
	public function getRootFolder() {
1292
		return $this->query('LazyRootFolder');
1293
	}
1294
1295
	/**
1296
	 * Returns the root folder of ownCloud's data directory
1297
	 * This is the lazy variant so this gets only initialized once it
1298
	 * is actually used.
1299
	 *
1300
	 * @return \OCP\Files\IRootFolder
1301
	 */
1302
	public function getLazyRootFolder() {
1303
		return $this->query('LazyRootFolder');
1304
	}
1305
1306
	/**
1307
	 * Returns a view to ownCloud's files folder
1308
	 *
1309
	 * @param string $userId user ID
1310
	 * @return \OCP\Files\Folder|null
1311
	 */
1312
	public function getUserFolder($userId = null) {
1313 View Code Duplication
		if ($userId === null) {
1314
			$user = $this->getUserSession()->getUser();
1315
			if (!$user) {
1316
				return null;
1317
			}
1318
			$userId = $user->getUID();
1319
		}
1320
		$root = $this->getRootFolder();
1321
		return $root->getUserFolder($userId);
1322
	}
1323
1324
	/**
1325
	 * Returns an app-specific view in ownClouds data directory
1326
	 *
1327
	 * @return \OCP\Files\Folder
1328
	 * @deprecated since 9.2.0 use IAppData
1329
	 */
1330
	public function getAppFolder() {
1331
		$dir = '/' . \OC_App::getCurrentApp();
1332
		$root = $this->getRootFolder();
1333
		if (!$root->nodeExists($dir)) {
1334
			$folder = $root->newFolder($dir);
1335
		} else {
1336
			$folder = $root->get($dir);
1337
		}
1338
		return $folder;
1339
	}
1340
1341
	/**
1342
	 * @return \OC\User\Manager
1343
	 */
1344
	public function getUserManager() {
1345
		return $this->query('UserManager');
1346
	}
1347
1348
	/**
1349
	 * @return \OC\Group\Manager
1350
	 */
1351
	public function getGroupManager() {
1352
		return $this->query('GroupManager');
1353
	}
1354
1355
	/**
1356
	 * @return \OC\User\Session
1357
	 */
1358
	public function getUserSession() {
1359
		return $this->query('UserSession');
1360
	}
1361
1362
	/**
1363
	 * @return \OCP\ISession
1364
	 */
1365
	public function getSession() {
1366
		return $this->query('UserSession')->getSession();
1367
	}
1368
1369
	/**
1370
	 * @param \OCP\ISession $session
1371
	 */
1372
	public function setSession(\OCP\ISession $session) {
1373
		$this->query(SessionStorage::class)->setSession($session);
1374
		$this->query('UserSession')->setSession($session);
1375
		$this->query(Store::class)->setSession($session);
1376
	}
1377
1378
	/**
1379
	 * @return \OC\Authentication\TwoFactorAuth\Manager
1380
	 */
1381
	public function getTwoFactorAuthManager() {
1382
		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1383
	}
1384
1385
	/**
1386
	 * @return \OC\NavigationManager
1387
	 */
1388
	public function getNavigationManager() {
1389
		return $this->query('NavigationManager');
1390
	}
1391
1392
	/**
1393
	 * @return \OCP\IConfig
1394
	 */
1395
	public function getConfig() {
1396
		return $this->query('AllConfig');
1397
	}
1398
1399
	/**
1400
	 * @return \OC\SystemConfig
1401
	 */
1402
	public function getSystemConfig() {
1403
		return $this->query('SystemConfig');
1404
	}
1405
1406
	/**
1407
	 * Returns the app config manager
1408
	 *
1409
	 * @return \OCP\IAppConfig
1410
	 */
1411
	public function getAppConfig() {
1412
		return $this->query('AppConfig');
1413
	}
1414
1415
	/**
1416
	 * @return \OCP\L10N\IFactory
1417
	 */
1418
	public function getL10NFactory() {
1419
		return $this->query('L10NFactory');
1420
	}
1421
1422
	/**
1423
	 * get an L10N instance
1424
	 *
1425
	 * @param string $app appid
1426
	 * @param string $lang
1427
	 * @return IL10N
1428
	 */
1429
	public function getL10N($app, $lang = null) {
1430
		return $this->getL10NFactory()->get($app, $lang);
1431
	}
1432
1433
	/**
1434
	 * @return \OCP\IURLGenerator
1435
	 */
1436
	public function getURLGenerator() {
1437
		return $this->query('URLGenerator');
1438
	}
1439
1440
	/**
1441
	 * @return \OCP\IHelper
1442
	 */
1443
	public function getHelper() {
1444
		return $this->query('AppHelper');
1445
	}
1446
1447
	/**
1448
	 * @return AppFetcher
1449
	 */
1450
	public function getAppFetcher() {
1451
		return $this->query(AppFetcher::class);
1452
	}
1453
1454
	/**
1455
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1456
	 * getMemCacheFactory() instead.
1457
	 *
1458
	 * @return \OCP\ICache
1459
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1460
	 */
1461
	public function getCache() {
1462
		return $this->query('UserCache');
1463
	}
1464
1465
	/**
1466
	 * Returns an \OCP\CacheFactory instance
1467
	 *
1468
	 * @return \OCP\ICacheFactory
1469
	 */
1470
	public function getMemCacheFactory() {
1471
		return $this->query('MemCacheFactory');
1472
	}
1473
1474
	/**
1475
	 * Returns an \OC\RedisFactory instance
1476
	 *
1477
	 * @return \OC\RedisFactory
1478
	 */
1479
	public function getGetRedisFactory() {
1480
		return $this->query('RedisFactory');
1481
	}
1482
1483
1484
	/**
1485
	 * Returns the current session
1486
	 *
1487
	 * @return \OCP\IDBConnection
1488
	 */
1489
	public function getDatabaseConnection() {
1490
		return $this->query('DatabaseConnection');
1491
	}
1492
1493
	/**
1494
	 * Returns the activity manager
1495
	 *
1496
	 * @return \OCP\Activity\IManager
1497
	 */
1498
	public function getActivityManager() {
1499
		return $this->query('ActivityManager');
1500
	}
1501
1502
	/**
1503
	 * Returns an job list for controlling background jobs
1504
	 *
1505
	 * @return \OCP\BackgroundJob\IJobList
1506
	 */
1507
	public function getJobList() {
1508
		return $this->query('JobList');
1509
	}
1510
1511
	/**
1512
	 * Returns a logger instance
1513
	 *
1514
	 * @return \OCP\ILogger
1515
	 */
1516
	public function getLogger() {
1517
		return $this->query('Logger');
1518
	}
1519
1520
	/**
1521
	 * Returns a router for generating and matching urls
1522
	 *
1523
	 * @return \OCP\Route\IRouter
1524
	 */
1525
	public function getRouter() {
1526
		return $this->query('Router');
1527
	}
1528
1529
	/**
1530
	 * Returns a search instance
1531
	 *
1532
	 * @return \OCP\ISearch
1533
	 */
1534
	public function getSearch() {
1535
		return $this->query('Search');
1536
	}
1537
1538
	/**
1539
	 * Returns a SecureRandom instance
1540
	 *
1541
	 * @return \OCP\Security\ISecureRandom
1542
	 */
1543
	public function getSecureRandom() {
1544
		return $this->query('SecureRandom');
1545
	}
1546
1547
	/**
1548
	 * Returns a Crypto instance
1549
	 *
1550
	 * @return \OCP\Security\ICrypto
1551
	 */
1552
	public function getCrypto() {
1553
		return $this->query('Crypto');
1554
	}
1555
1556
	/**
1557
	 * Returns a Hasher instance
1558
	 *
1559
	 * @return \OCP\Security\IHasher
1560
	 */
1561
	public function getHasher() {
1562
		return $this->query('Hasher');
1563
	}
1564
1565
	/**
1566
	 * Returns a CredentialsManager instance
1567
	 *
1568
	 * @return \OCP\Security\ICredentialsManager
1569
	 */
1570
	public function getCredentialsManager() {
1571
		return $this->query('CredentialsManager');
1572
	}
1573
1574
	/**
1575
	 * Returns an instance of the HTTP helper class
1576
	 *
1577
	 * @deprecated Use getHTTPClientService()
1578
	 * @return \OC\HTTPHelper
1579
	 */
1580
	public function getHTTPHelper() {
1581
		return $this->query('HTTPHelper');
1582
	}
1583
1584
	/**
1585
	 * Get the certificate manager for the user
1586
	 *
1587
	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1588
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1589
	 */
1590
	public function getCertificateManager($userId = '') {
1591 View Code Duplication
		if ($userId === '') {
1592
			$userSession = $this->getUserSession();
1593
			$user = $userSession->getUser();
1594
			if (is_null($user)) {
1595
				return null;
1596
			}
1597
			$userId = $user->getUID();
1598
		}
1599
		return new CertificateManager(
1600
			$userId,
1601
			new View(),
1602
			$this->getConfig(),
1603
			$this->getLogger(),
1604
			$this->getSecureRandom()
1605
		);
1606
	}
1607
1608
	/**
1609
	 * Returns an instance of the HTTP client service
1610
	 *
1611
	 * @return \OCP\Http\Client\IClientService
1612
	 */
1613
	public function getHTTPClientService() {
1614
		return $this->query('HttpClientService');
1615
	}
1616
1617
	/**
1618
	 * Create a new event source
1619
	 *
1620
	 * @return \OCP\IEventSource
1621
	 */
1622
	public function createEventSource() {
1623
		return new \OC_EventSource();
1624
	}
1625
1626
	/**
1627
	 * Get the active event logger
1628
	 *
1629
	 * The returned logger only logs data when debug mode is enabled
1630
	 *
1631
	 * @return \OCP\Diagnostics\IEventLogger
1632
	 */
1633
	public function getEventLogger() {
1634
		return $this->query('EventLogger');
1635
	}
1636
1637
	/**
1638
	 * Get the active query logger
1639
	 *
1640
	 * The returned logger only logs data when debug mode is enabled
1641
	 *
1642
	 * @return \OCP\Diagnostics\IQueryLogger
1643
	 */
1644
	public function getQueryLogger() {
1645
		return $this->query('QueryLogger');
1646
	}
1647
1648
	/**
1649
	 * Get the manager for temporary files and folders
1650
	 *
1651
	 * @return \OCP\ITempManager
1652
	 */
1653
	public function getTempManager() {
1654
		return $this->query('TempManager');
1655
	}
1656
1657
	/**
1658
	 * Get the app manager
1659
	 *
1660
	 * @return \OCP\App\IAppManager
1661
	 */
1662
	public function getAppManager() {
1663
		return $this->query('AppManager');
1664
	}
1665
1666
	/**
1667
	 * Creates a new mailer
1668
	 *
1669
	 * @return \OCP\Mail\IMailer
1670
	 */
1671
	public function getMailer() {
1672
		return $this->query('Mailer');
1673
	}
1674
1675
	/**
1676
	 * Get the webroot
1677
	 *
1678
	 * @return string
1679
	 */
1680
	public function getWebRoot() {
1681
		return $this->webRoot;
1682
	}
1683
1684
	/**
1685
	 * @return \OC\OCSClient
1686
	 */
1687
	public function getOcsClient() {
1688
		return $this->query('OcsClient');
1689
	}
1690
1691
	/**
1692
	 * @return \OCP\IDateTimeZone
1693
	 */
1694
	public function getDateTimeZone() {
1695
		return $this->query('DateTimeZone');
1696
	}
1697
1698
	/**
1699
	 * @return \OCP\IDateTimeFormatter
1700
	 */
1701
	public function getDateTimeFormatter() {
1702
		return $this->query('DateTimeFormatter');
1703
	}
1704
1705
	/**
1706
	 * @return \OCP\Files\Config\IMountProviderCollection
1707
	 */
1708
	public function getMountProviderCollection() {
1709
		return $this->query('MountConfigManager');
1710
	}
1711
1712
	/**
1713
	 * Get the IniWrapper
1714
	 *
1715
	 * @return IniGetWrapper
1716
	 */
1717
	public function getIniWrapper() {
1718
		return $this->query('IniWrapper');
1719
	}
1720
1721
	/**
1722
	 * @return \OCP\Command\IBus
1723
	 */
1724
	public function getCommandBus() {
1725
		return $this->query('AsyncCommandBus');
1726
	}
1727
1728
	/**
1729
	 * Get the trusted domain helper
1730
	 *
1731
	 * @return TrustedDomainHelper
1732
	 */
1733
	public function getTrustedDomainHelper() {
1734
		return $this->query('TrustedDomainHelper');
1735
	}
1736
1737
	/**
1738
	 * Get the locking provider
1739
	 *
1740
	 * @return \OCP\Lock\ILockingProvider
1741
	 * @since 8.1.0
1742
	 */
1743
	public function getLockingProvider() {
1744
		return $this->query('LockingProvider');
1745
	}
1746
1747
	/**
1748
	 * @return \OCP\Files\Mount\IMountManager
1749
	 **/
1750
	function getMountManager() {
1751
		return $this->query('MountManager');
1752
	}
1753
1754
	/** @return \OCP\Files\Config\IUserMountCache */
1755
	function getUserMountCache() {
1756
		return $this->query('UserMountCache');
1757
	}
1758
1759
	/**
1760
	 * Get the MimeTypeDetector
1761
	 *
1762
	 * @return \OCP\Files\IMimeTypeDetector
1763
	 */
1764
	public function getMimeTypeDetector() {
1765
		return $this->query('MimeTypeDetector');
1766
	}
1767
1768
	/**
1769
	 * Get the MimeTypeLoader
1770
	 *
1771
	 * @return \OCP\Files\IMimeTypeLoader
1772
	 */
1773
	public function getMimeTypeLoader() {
1774
		return $this->query('MimeTypeLoader');
1775
	}
1776
1777
	/**
1778
	 * Get the manager of all the capabilities
1779
	 *
1780
	 * @return \OC\CapabilitiesManager
1781
	 */
1782
	public function getCapabilitiesManager() {
1783
		return $this->query('CapabilitiesManager');
1784
	}
1785
1786
	/**
1787
	 * Get the EventDispatcher
1788
	 *
1789
	 * @return EventDispatcherInterface
1790
	 * @since 8.2.0
1791
	 */
1792
	public function getEventDispatcher() {
1793
		return $this->query('EventDispatcher');
1794
	}
1795
1796
	/**
1797
	 * Get the Notification Manager
1798
	 *
1799
	 * @return \OCP\Notification\IManager
1800
	 * @since 8.2.0
1801
	 */
1802
	public function getNotificationManager() {
1803
		return $this->query('NotificationManager');
1804
	}
1805
1806
	/**
1807
	 * @return \OCP\Comments\ICommentsManager
1808
	 */
1809
	public function getCommentsManager() {
1810
		return $this->query('CommentsManager');
1811
	}
1812
1813
	/**
1814
	 * @return \OCA\Theming\ThemingDefaults
1815
	 */
1816
	public function getThemingDefaults() {
1817
		return $this->query('ThemingDefaults');
1818
	}
1819
1820
	/**
1821
	 * @return \OC\IntegrityCheck\Checker
1822
	 */
1823
	public function getIntegrityCodeChecker() {
1824
		return $this->query('IntegrityCodeChecker');
1825
	}
1826
1827
	/**
1828
	 * @return \OC\Session\CryptoWrapper
1829
	 */
1830
	public function getSessionCryptoWrapper() {
1831
		return $this->query('CryptoWrapper');
1832
	}
1833
1834
	/**
1835
	 * @return CsrfTokenManager
1836
	 */
1837
	public function getCsrfTokenManager() {
1838
		return $this->query('CsrfTokenManager');
1839
	}
1840
1841
	/**
1842
	 * @return Throttler
1843
	 */
1844
	public function getBruteForceThrottler() {
1845
		return $this->query('Throttler');
1846
	}
1847
1848
	/**
1849
	 * @return IContentSecurityPolicyManager
1850
	 */
1851
	public function getContentSecurityPolicyManager() {
1852
		return $this->query('ContentSecurityPolicyManager');
1853
	}
1854
1855
	/**
1856
	 * @return ContentSecurityPolicyNonceManager
1857
	 */
1858
	public function getContentSecurityPolicyNonceManager() {
1859
		return $this->query('ContentSecurityPolicyNonceManager');
1860
	}
1861
1862
	/**
1863
	 * Not a public API as of 8.2, wait for 9.0
1864
	 *
1865
	 * @return \OCA\Files_External\Service\BackendService
1866
	 */
1867
	public function getStoragesBackendService() {
1868
		return $this->query('OCA\\Files_External\\Service\\BackendService');
1869
	}
1870
1871
	/**
1872
	 * Not a public API as of 8.2, wait for 9.0
1873
	 *
1874
	 * @return \OCA\Files_External\Service\GlobalStoragesService
1875
	 */
1876
	public function getGlobalStoragesService() {
1877
		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1878
	}
1879
1880
	/**
1881
	 * Not a public API as of 8.2, wait for 9.0
1882
	 *
1883
	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1884
	 */
1885
	public function getUserGlobalStoragesService() {
1886
		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1887
	}
1888
1889
	/**
1890
	 * Not a public API as of 8.2, wait for 9.0
1891
	 *
1892
	 * @return \OCA\Files_External\Service\UserStoragesService
1893
	 */
1894
	public function getUserStoragesService() {
1895
		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1896
	}
1897
1898
	/**
1899
	 * @return \OCP\Share\IManager
1900
	 */
1901
	public function getShareManager() {
1902
		return $this->query('ShareManager');
1903
	}
1904
1905
	/**
1906
	 * @return \OCP\Collaboration\Collaborators\ISearch
1907
	 */
1908
	public function getCollaboratorSearch() {
1909
		return $this->query('CollaboratorSearch');
1910
	}
1911
1912
	/**
1913
	 * @return \OCP\Collaboration\AutoComplete\IManager
1914
	 */
1915
	public function getAutoCompleteManager(){
1916
		return $this->query(IManager::class);
1917
	}
1918
1919
	/**
1920
	 * Returns the LDAP Provider
1921
	 *
1922
	 * @return \OCP\LDAP\ILDAPProvider
1923
	 */
1924
	public function getLDAPProvider() {
1925
		return $this->query('LDAPProvider');
1926
	}
1927
1928
	/**
1929
	 * @return \OCP\Settings\IManager
1930
	 */
1931
	public function getSettingsManager() {
1932
		return $this->query('SettingsManager');
1933
	}
1934
1935
	/**
1936
	 * @return \OCP\Files\IAppData
1937
	 */
1938
	public function getAppDataDir($app) {
1939
		/** @var \OC\Files\AppData\Factory $factory */
1940
		$factory = $this->query(\OC\Files\AppData\Factory::class);
1941
		return $factory->get($app);
1942
	}
1943
1944
	/**
1945
	 * @return \OCP\Lockdown\ILockdownManager
1946
	 */
1947
	public function getLockdownManager() {
1948
		return $this->query('LockdownManager');
1949
	}
1950
1951
	/**
1952
	 * @return \OCP\Federation\ICloudIdManager
1953
	 */
1954
	public function getCloudIdManager() {
1955
		return $this->query(ICloudIdManager::class);
1956
	}
1957
1958
	/**
1959
	 * @return \OCP\Remote\Api\IApiFactory
1960
	 */
1961
	public function getRemoteApiFactory() {
1962
		return $this->query(IApiFactory::class);
1963
	}
1964
1965
	/**
1966
	 * @return \OCP\Remote\IInstanceFactory
1967
	 */
1968
	public function getRemoteInstanceFactory() {
1969
		return $this->query(IInstanceFactory::class);
1970
	}
1971
}
1972