Completed
Push — master ( 8931ba...9baa96 )
by Roeland
47:53
created

Server::__construct()   D

Complexity

Conditions 23
Paths 1

Size

Total Lines 472
Code Lines 328

Duplication

Lines 8
Ratio 1.69 %

Code Coverage

Tests 305
CRAP Score 24.0607

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 8
loc 472
ccs 305
cts 349
cp 0.8739
rs 4.6304
cc 23
eloc 328
nc 1
nop 1
crap 24.0607

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 Individual IT Services <[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 Robin Appelman <[email protected]>
15
 * @author Robin McCorkell <[email protected]>
16
 * @author Roeland Jago Douma <[email protected]>
17
 * @author Sander <[email protected]>
18
 * @author Thomas Müller <[email protected]>
19
 * @author Thomas Tanghus <[email protected]>
20
 * @author Vincent Petry <[email protected]>
21
 *
22
 * @copyright Copyright (c) 2015, ownCloud, Inc.
23
 * @license AGPL-3.0
24
 *
25
 * This code is free software: you can redistribute it and/or modify
26
 * it under the terms of the GNU Affero General Public License, version 3,
27
 * as published by the Free Software Foundation.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32
 * GNU Affero General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU Affero General Public License, version 3,
35
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
36
 *
37
 */
38
namespace OC;
39
40
use bantu\IniGetWrapper\IniGetWrapper;
41
use OC\AppFramework\Http\Request;
42
use OC\AppFramework\Db\Db;
43
use OC\AppFramework\Utility\SimpleContainer;
44
use OC\AppFramework\Utility\TimeFactory;
45
use OC\Command\AsyncBus;
46
use OC\Diagnostics\EventLogger;
47
use OC\Diagnostics\NullEventLogger;
48
use OC\Diagnostics\NullQueryLogger;
49
use OC\Diagnostics\QueryLogger;
50
use OC\Files\Node\HookConnector;
51
use OC\Files\Node\Root;
52
use OC\Files\View;
53
use OC\Http\Client\ClientService;
54
use OC\IntegrityCheck\Checker;
55
use OC\IntegrityCheck\Helpers\AppLocator;
56
use OC\IntegrityCheck\Helpers\EnvironmentHelper;
57
use OC\IntegrityCheck\Helpers\FileAccessHelper;
58
use OC\Lock\DBLockingProvider;
59
use OC\Lock\MemcacheLockingProvider;
60
use OC\Lock\NoopLockingProvider;
61
use OC\Mail\Mailer;
62
use OC\Notification\Manager;
63
use OC\Security\CertificateManager;
64
use OC\Security\Crypto;
65
use OC\Security\Hasher;
66
use OC\Security\SecureRandom;
67
use OC\Security\TrustedDomainHelper;
68
use OC\Session\CryptoWrapper;
69
use OC\Tagging\TagMapper;
70
use OCP\IServerContainer;
71
use Symfony\Component\EventDispatcher\EventDispatcher;
72
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
73
74
/**
75
 * Class Server
76
 *
77
 * @package OC
78
 *
79
 * TODO: hookup all manager classes
80
 */
81
class Server extends SimpleContainer implements IServerContainer {
82
	/** @var string */
83
	private $webRoot;
84
85
	/**
86
	 * @param string $webRoot
87
	 */
88 553
	public function __construct($webRoot) {
89 93
		parent::__construct();
90 93
		$this->webRoot = $webRoot;
91
92
		$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...
93 2
			return new ContactsManager();
94 93
		});
95
96
		$this->registerService('PreviewManager', function (Server $c) {
97 3
			return new PreviewManager($c->getConfig());
98 93
		});
99
100
		$this->registerService('EncryptionManager', function (Server $c) {
101 2
			$view = new View();
102 2
			$util = new Encryption\Util(
103 2
				$view,
104 2
				$c->getUserManager(),
105 2
				$c->getGroupManager(),
106 2
				$c->getConfig()
107 2
			);
108 2
			return new Encryption\Manager(
109 2
				$c->getConfig(),
110 2
				$c->getLogger(),
111 2
				$c->getL10N('core'),
112 2
				new View(),
113
				$util
114 2
			);
115 93
		});
116
117
		$this->registerService('EncryptionFileHelper', function (Server $c) {
118 2
			$util = new Encryption\Util(
119 2
				new View(),
120 2
				$c->getUserManager(),
121 2
				$c->getGroupManager(),
122 2
				$c->getConfig()
123 2
			);
124 2
			return new Encryption\File($util);
125 93
		});
126
127
		$this->registerService('EncryptionKeyStorage', function (Server $c) {
128 2
			$view = new View();
129 2
			$util = new Encryption\Util(
130 2
				$view,
131 2
				$c->getUserManager(),
132 2
				$c->getGroupManager(),
133 93
				$c->getConfig()
134 2
			);
135
136 2
			return new Encryption\Keys\Storage($view, $util);
137 93
		});
138
		$this->registerService('TagMapper', function(Server $c) {
139 5
			return new TagMapper($c->getDatabaseConnection());
140 93
		});
141
		$this->registerService('TagManager', function (Server $c) {
142 3
			$tagMapper = $c->query('TagMapper');
143 3
			return new TagManager($tagMapper, $c->getUserSession());
144 93
		});
145
		$this->registerService('SystemTagManager', function (Server $c) {
146
			return new SystemTag\SystemTagManager($c->getDatabaseConnection());
147 93
		});
148
		$this->registerService('SystemTagObjectMapper', function (Server $c) {
149
			return new SystemTag\SystemTagObjectMapper($c->getDatabaseConnection(), $c->getSystemTagManager());
150 93
		});
151
		$this->registerService('RootFolder', function (Server $c) {
152
			// TODO: get user and user manager from container as well
153 7
			$user = \OC_User::getUser();
154
			/** @var $c SimpleContainer */
155 7
			$userManager = $c->query('UserManager');
156 7
			$user = $userManager->get($user);
157 7
			$manager = \OC\Files\Filesystem::getMountManager();
158 7
			$view = new View();
159 7
			$root = new Root($manager, $view, $user);
160 7
			$connector = new HookConnector($root, $view);
161 7
			$connector->viewToNode();
162 7
			return $root;
163 93
		});
164
		$this->registerService('UserManager', function (Server $c) {
165 30
			$config = $c->getConfig();
166 30
			return new \OC\User\Manager($config);
167 93
		});
168
		$this->registerService('GroupManager', function (Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
169 10
			$groupManager = new \OC\Group\Manager($this->getUserManager());
170
			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
171 385
				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
172 395
			});
173
			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
174 385
				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
175 395
			});
176
			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
177 380
				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
178 390
			});
179
			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
180 380
				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
181 390
			});
182
			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
183 373
				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
184 383
			});
185
			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
186 373
				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
187
				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
188 373
				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
189 383
			});
190 10
			return $groupManager;
191 93
		});
192
		$this->registerService('UserSession', function (Server $c) {
193 14
			$manager = $c->getUserManager();
194
195 14
			$session = new \OC\Session\Memory('');
196
197 14
			$userSession = new \OC\User\Session($manager, $session);
198
			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
199 539
				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
200 553
			});
201
			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
202
				/** @var $user \OC\User\User */
203 539
				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
204 553
			});
205
			$userSession->listen('\OC\User', 'preDelete', function ($user) {
206
				/** @var $user \OC\User\User */
207 512
				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
208 526
			});
209
			$userSession->listen('\OC\User', 'postDelete', function ($user) {
210
				/** @var $user \OC\User\User */
211 512
				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
212 526
			});
213 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...
214
				/** @var $user \OC\User\User */
215
				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
216 14
			});
217 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...
218
				/** @var $user \OC\User\User */
219
				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
220 14
			});
221
			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
222 269
				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
223 283
			});
224
			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
225
				/** @var $user \OC\User\User */
226 269
				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
227 283
			});
228
			$userSession->listen('\OC\User', 'logout', function () {
229
				\OC_Hook::emit('OC_User', 'logout', array());
230 14
			});
231 14
			return $userSession;
232 93
		});
233
		$this->registerService('NavigationManager', function ($c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
234 2
			return new \OC\NavigationManager();
235 93
		});
236
		$this->registerService('AllConfig', function (Server $c) {
237 61
			return new \OC\AllConfig(
238 61
				$c->getSystemConfig()
239 61
			);
240 93
		});
241
		$this->registerService('SystemConfig', 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...
242 70
			return new \OC\SystemConfig();
243 93
		});
244
		$this->registerService('AppConfig', 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...
245 4
			return new \OC\AppConfig(\OC_DB::getConnection());
246 93
		});
247
		$this->registerService('L10NFactory', 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...
248 8
			return new \OC\L10N\Factory();
249 93
		});
250
		$this->registerService('URLGenerator', function (Server $c) {
251 2
			$config = $c->getConfig();
252 2
			$cacheFactory = $c->getMemCacheFactory();
253 2
			return new \OC\URLGenerator(
254 2
				$config,
255
				$cacheFactory
256 2
			);
257 93
		});
258
		$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...
259 2
			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...
260 93
		});
261
		$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...
262 2
			return new Cache\File();
263 93
		});
264
		$this->registerService('MemCacheFactory', function (Server $c) {
265 8
			$config = $c->getConfig();
266
267 8
			if($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
268
				$v = \OC_App::getAppVersions();
269
				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
270
				$version = implode(',', $v);
271
				$instanceId = \OC_Util::getInstanceId();
272
				$path = \OC::$SERVERROOT;
273
				$prefix = md5($instanceId.'-'.$version.'-'.$path);
274
				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
275
					$config->getSystemValue('memcache.local', null),
276
					$config->getSystemValue('memcache.distributed', null),
277
					$config->getSystemValue('memcache.locking', null)
278
				);
279
			}
280
281 8
			return new \OC\Memcache\Factory('', $c->getLogger(),
282 8
				'\\OC\\Memcache\\ArrayCache',
283 8
				'\\OC\\Memcache\\ArrayCache',
284
				'\\OC\\Memcache\\ArrayCache'
285 8
			);
286 93
		});
287
		$this->registerService('ActivityManager', function (Server $c) {
288 2
			return new ActivityManager(
289 2
				$c->getRequest(),
290 2
				$c->getUserSession(),
291 2
				$c->getConfig()
292 2
			);
293 93
		});
294
		$this->registerService('AvatarManager', function (Server $c) {
295 2
			return new AvatarManager(
296 2
				$c->getUserManager(),
297 2
				$c->getRootFolder(),
298 2
				$c->getL10N('lib')
299 2
			);
300 93
		});
301
		$this->registerService('Logger', function (Server $c) {
302 17
			$logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud');
303 17
			$logger = 'OC_Log_' . ucfirst($logClass);
304 17
			call_user_func(array($logger, 'init'));
305
306 17
			return new Log($logger);
307 93
		});
308
		$this->registerService('JobList', function (Server $c) {
309 4
			$config = $c->getConfig();
310 4
			return new \OC\BackgroundJob\JobList($c->getDatabaseConnection(), $config);
311 93
		});
312
		$this->registerService('Router', function (Server $c) {
313 2
			$cacheFactory = $c->getMemCacheFactory();
314 2
			$logger = $c->getLogger();
315 2
			if ($cacheFactory->isAvailable()) {
316 2
				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
317 2
			} else {
318
				$router = new \OC\Route\Router($logger);
319
			}
320 2
			return $router;
321 93
		});
322
		$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...
323 2
			return new Search();
324 93
		});
325
		$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...
326 9
			return new SecureRandom();
327 93
		});
328
		$this->registerService('Crypto', function (Server $c) {
329 3
			return new Crypto($c->getConfig(), $c->getSecureRandom());
330 93
		});
331
		$this->registerService('Hasher', function (Server $c) {
332 3
			return new Hasher($c->getConfig());
333 93
		});
334
		$this->registerService('DatabaseConnection', function (Server $c) {
335 12
			$factory = new \OC\DB\ConnectionFactory();
336 12
			$systemConfig = $c->getSystemConfig();
337 12
			$type = $systemConfig->getValue('dbtype', 'sqlite');
338 12
			if (!$factory->isValidType($type)) {
339
				throw new \OC\DatabaseException('Invalid database type');
340
			}
341 12
			$connectionParams = $factory->createConnectionParams($systemConfig);
342 12
			$connection = $factory->getConnection($type, $connectionParams);
343 12
			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
344 12
			return $connection;
345 93
		});
346
		$this->registerService('Db', function (Server $c) {
347 2
			return new Db($c->getDatabaseConnection());
0 ignored issues
show
Deprecated Code introduced by
The class OC\AppFramework\Db\Db has been deprecated with message: use IDBConnection directly, will be removed in ownCloud 10
Small Facade for being able to inject the database connection for tests

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

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

Loading history...
348 93
		});
349
		$this->registerService('HTTPHelper', function (Server $c) {
350 1
			$config = $c->getConfig();
351 1
			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...
352 1
				$config,
353 1
				$c->getHTTPClientService()
354 1
			);
355 93
		});
356
		$this->registerService('HttpClientService', function (Server $c) {
357 4
			$user = \OC_User::getUser();
358 4
			$uid = $user ? $user : null;
359 4
			return new ClientService(
360 4
				$c->getConfig(),
361 4
				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig())
362 4
			);
363 93
		});
364
		$this->registerService('EventLogger', function (Server $c) {
365 1
			if ($c->getSystemConfig()->getValue('debug', false)) {
366
				return new EventLogger();
367
			} else {
368 1
				return new NullEventLogger();
369
			}
370 93
		});
371
		$this->registerService('QueryLogger', function (Server $c) {
372 13
			if ($c->getSystemConfig()->getValue('debug', false)) {
373
				return new QueryLogger();
374
			} else {
375 13
				return new NullQueryLogger();
376
			}
377 93
		});
378
		$this->registerService('TempManager', function (Server $c) {
379 2
			return new TempManager(
380 2
				$c->getLogger(),
381 2
				$c->getConfig()
382 2
			);
383 93
		});
384
		$this->registerService('AppManager', function(Server $c) {
385 2
			return new \OC\App\AppManager(
386 2
				$c->getUserSession(),
387 2
				$c->getAppConfig(),
388 2
				$c->getGroupManager(),
389 2
				$c->getMemCacheFactory()
390 2
			);
391 93
		});
392
		$this->registerService('DateTimeZone', function(Server $c) {
393 5
			return new DateTimeZone(
394 5
				$c->getConfig(),
395 5
				$c->getSession()
396 5
			);
397 93
		});
398
		$this->registerService('DateTimeFormatter', function(Server $c) {
399 3
			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
400
401 3
			return new DateTimeFormatter(
402 3
				$c->getDateTimeZone()->getTimeZone(),
403 3
				$c->getL10N('lib', $language)
404 3
			);
405 93
		});
406
		$this->registerService('MountConfigManager', function () {
407 2
			$loader = \OC\Files\Filesystem::getLoader();
408 2
			return new \OC\Files\Config\MountProviderCollection($loader);
409 93
		});
410
		$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...
411 1
			return new IniGetWrapper();
412 93
		});
413
		$this->registerService('AsyncCommandBus', function (Server $c) {
414 2
			$jobList = $c->getJobList();
415 2
			return new AsyncBus($jobList);
416 93
		});
417
		$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...
418 1
			return new TrustedDomainHelper($this->getConfig());
419 93
		});
420
		$this->registerService('IntegrityCodeChecker', function (Server $c) {
421
			// IConfig and IAppManager requires a working database. This code
422
			// might however be called when ownCloud is not yet setup.
423
			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
424
				$config = $c->getConfig();
425
				$appManager = $c->getAppManager();
426
			} else {
427
				$config = null;
428
				$appManager = null;
429
			}
430
431
			return new Checker(
432
					new EnvironmentHelper(),
433
					new FileAccessHelper(),
434
					new AppLocator(),
435
					$config,
436
					$c->getMemCacheFactory(),
437
					$appManager
438
			);
439 93
		});
440
		$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...
441 4
			if (isset($this['urlParams'])) {
442
				$urlParams = $this['urlParams'];
443
			} else {
444 4
				$urlParams = [];
445
			}
446
447 4
			if ($this->getSession()->exists('requesttoken')) {
448
				$requestToken = $this->getSession()->get('requesttoken');
449
			} else {
450 4
				$requestToken = false;
451
			}
452
453 4
			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
454 4
				&& in_array('fakeinput', stream_get_wrappers())
455 4
			) {
456
				$stream = 'fakeinput://data';
457
			} else {
458 4
				$stream = 'php://input';
459
			}
460
461 4
			return new Request(
462
				[
463 4
					'get' => $_GET,
464 4
					'post' => $_POST,
465 4
					'files' => $_FILES,
466 4
					'server' => $_SERVER,
467 4
					'env' => $_ENV,
468 4
					'cookies' => $_COOKIE,
469 4
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
470 4
						? $_SERVER['REQUEST_METHOD']
471 4
						: null,
472 4
					'urlParams' => $urlParams,
473 4
					'requesttoken' => $requestToken,
474 4
				],
475 4
				$this->getSecureRandom(),
476 4
				$this->getConfig(),
477
				$stream
478 4
			);
479 93
		});
480
		$this->registerService('Mailer', function(Server $c) {
481 2
			return new Mailer(
482 2
				$c->getConfig(),
483 2
				$c->getLogger(),
484 2
				new \OC_Defaults()
485 2
			);
486 93
		});
487
		$this->registerService('OcsClient', function(Server $c) {
0 ignored issues
show
Unused Code introduced by
The parameter $c is not used and could be removed.

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

Loading history...
488 1
			return new OCSClient(
489 1
				$this->getHTTPClientService(),
490 1
				$this->getConfig(),
491 1
				$this->getLogger()
492 1
			);
493 93
		});
494
		$this->registerService('LockingProvider', function (Server $c) {
495 1
			if ($c->getConfig()->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
496
				/** @var \OC\Memcache\Factory $memcacheFactory */
497 1
				$memcacheFactory = $c->getMemCacheFactory();
498 1
				$memcache = $memcacheFactory->createLocking('lock');
499 1
				if (!($memcache instanceof \OC\Memcache\NullCache)) {
500 1
					return new MemcacheLockingProvider($memcache);
501
				}
502
				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory());
503
			}
504
			return new NoopLockingProvider();
505 93
		});
506
		$this->registerService('MountManager', function () {
507 1
			return new \OC\Files\Mount\Manager();
508 93
		});
509
		$this->registerService('MimeTypeDetector', function(Server $c) {
510 1
			return new \OC\Files\Type\Detection(
511 1
				$c->getURLGenerator(),
512 1
				\OC::$SERVERROOT . '/config/',
513
				\OC::$SERVERROOT . '/resources/config/'
514 1
				);
515 93
		});
516
		$this->registerService('MimeTypeLoader', function(Server $c) {
517 1
			return new \OC\Files\Type\Loader(
518 1
				$c->getDatabaseConnection()
519 1
			);
520 93
		});
521
		$this->registerService('NotificationManager', function() {
522 2
			return new Manager();
523 93
		});
524
		$this->registerService('CapabilitiesManager', function (Server $c) {
525 1
			$manager = new \OC\CapabilitiesManager();
526
			$manager->registerCapability(function() use ($c) {
527
				return new \OC\OCS\CoreCapabilities($c->getConfig());
528 1
			});
529 1
			return $manager;
530 93
		});
531
		$this->registerService('EventDispatcher', function() {
532
			return new EventDispatcher();
533 93
		});
534 93
		$this->registerService('CryptoWrapper', function (Server $c) {
535
			// FIXME: Instantiiated here due to cyclic dependency
536 1
			$request = new Request(
537
				[
538 1
					'get' => $_GET,
539 1
					'post' => $_POST,
540 1
					'files' => $_FILES,
541 1
					'server' => $_SERVER,
542 1
					'env' => $_ENV,
543 1
					'cookies' => $_COOKIE,
544 1
					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
545 1
						? $_SERVER['REQUEST_METHOD']
546 1
						: null,
547 1
				],
548 1
				new SecureRandom(),
549 1
				$c->getConfig()
550 1
			);
551
552 1
			return new CryptoWrapper(
553 1
				$c->getConfig(),
554 1
				$c->getCrypto(),
555 1
				$c->getSecureRandom(),
556
				$request
557 1
			);
558 93
		});
559 93
	}
560
561
	/**
562
	 * @return \OCP\Contacts\IManager
563
	 */
564 14
	public function getContactsManager() {
565 14
		return $this->query('ContactsManager');
566
	}
567
568
	/**
569
	 * @return \OC\Encryption\Manager
570
	 */
571 12
	public function getEncryptionManager() {
572 12
		return $this->query('EncryptionManager');
573
	}
574
575
	/**
576
	 * @return \OC\Encryption\File
577
	 */
578 11
	public function getEncryptionFilesHelper() {
579 11
		return $this->query('EncryptionFileHelper');
580
	}
581
582
	/**
583
	 * @return \OCP\Encryption\Keys\IStorage
584
	 */
585 11
	public function getEncryptionKeyStorage() {
586 11
		return $this->query('EncryptionKeyStorage');
587
	}
588
589
	/**
590
	 * The current request object holding all information about the request
591
	 * currently being processed is returned from this method.
592
	 * In case the current execution was not initiated by a web request null is returned
593
	 *
594
	 * @return \OCP\IRequest
595
	 */
596 262
	public function getRequest() {
597 262
		return $this->query('Request');
598
	}
599
600
	/**
601
	 * Returns the preview manager which can create preview images for a given file
602
	 *
603
	 * @return \OCP\IPreview
604
	 */
605 172
	public function getPreviewManager() {
606 172
		return $this->query('PreviewManager');
607
	}
608
609
	/**
610
	 * Returns the tag manager which can get and set tags for different object types
611
	 *
612
	 * @see \OCP\ITagManager::load()
613
	 * @return \OCP\ITagManager
614
	 */
615 27
	public function getTagManager() {
616 27
		return $this->query('TagManager');
617
	}
618
619
	/**
620
	 * Returns the system-tag manager
621
	 *
622
	 * @return \OCP\SystemTag\ISystemTagManager
623
	 *
624
	 * @since 9.0.0
625
	 */
626
	public function getSystemTagManager() {
627
		return $this->query('SystemTagManager');
628
	}
629
630
	/**
631
	 * Returns the system-tag object mapper
632
	 *
633
	 * @return \OCP\SystemTag\ISystemTagObjectMapper
634
	 *
635
	 * @since 9.0.0
636
	 */
637
	public function getSystemTagObjectMapper() {
638
		return $this->query('SystemTagObjectMapper');
639
	}
640
641
642
	/**
643
	 * Returns the avatar manager, used for avatar functionality
644
	 *
645
	 * @return \OCP\IAvatarManager
646
	 */
647
	public function getAvatarManager() {
648
		return $this->query('AvatarManager');
649
	}
650
651
	/**
652
	 * Returns the root folder of ownCloud's data directory
653
	 *
654
	 * @return \OCP\Files\IRootFolder
655
	 */
656 906
	public function getRootFolder() {
657 906
		return $this->query('RootFolder');
658
	}
659
660
	/**
661
	 * Returns a view to ownCloud's files folder
662
	 *
663
	 * @param string $userId user ID
664
	 * @return \OCP\Files\Folder
665
	 */
666 904
	public function getUserFolder($userId = null) {
667 904
		if ($userId === null) {
668 30
			$user = $this->getUserSession()->getUser();
669 30
			if (!$user) {
670
				return null;
671
			}
672 30
			$userId = $user->getUID();
673 30
		}
674 904
		$root = $this->getRootFolder();
675 904
		return $root->getUserFolder($userId);
676
	}
677
678
	/**
679
	 * Returns an app-specific view in ownClouds data directory
680
	 *
681
	 * @return \OCP\Files\Folder
682
	 */
683
	public function getAppFolder() {
684
		$dir = '/' . \OC_App::getCurrentApp();
685
		$root = $this->getRootFolder();
686
		$folder = null;
0 ignored issues
show
Unused Code introduced by
$folder is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
687
		if (!$root->nodeExists($dir)) {
688
			$folder = $root->newFolder($dir);
689
		} else {
690
			$folder = $root->get($dir);
691
		}
692
		return $folder;
693
	}
694
695
	/**
696
	 * @return \OC\User\Manager
697
	 */
698 1308
	public function getUserManager() {
699 1308
		return $this->query('UserManager');
700
	}
701
702
	/**
703
	 * @return \OC\Group\Manager
704
	 */
705 1165
	public function getGroupManager() {
706 1165
		return $this->query('GroupManager');
707
	}
708
709
	/**
710
	 * @return \OC\User\Session
711
	 */
712 1234
	public function getUserSession() {
713 1234
		return $this->query('UserSession');
714
	}
715
716
	/**
717
	 * @return \OCP\ISession
718
	 */
719 1238
	public function getSession() {
720 1238
		return $this->query('UserSession')->getSession();
721
	}
722
723
	/**
724
	 * @param \OCP\ISession $session
725
	 */
726
	public function setSession(\OCP\ISession $session) {
727
		return $this->query('UserSession')->setSession($session);
728
	}
729
730
	/**
731
	 * @return \OC\NavigationManager
732
	 */
733 1
	public function getNavigationManager() {
734 1
		return $this->query('NavigationManager');
735
	}
736
737
	/**
738
	 * @return \OCP\IConfig
739
	 */
740 1453
	public function getConfig() {
741 1453
		return $this->query('AllConfig');
742
	}
743
744
	/**
745
	 * For internal use only
746
	 *
747
	 * @return \OC\SystemConfig
748
	 */
749 339
	public function getSystemConfig() {
750 339
		return $this->query('SystemConfig');
751
	}
752
753
	/**
754
	 * Returns the app config manager
755
	 *
756
	 * @return \OCP\IAppConfig
757
	 */
758 1160
	public function getAppConfig() {
759 1160
		return $this->query('AppConfig');
760
	}
761
762
	/**
763
	 * @return \OCP\L10N\IFactory
764
	 */
765 951
	public function getL10NFactory() {
766 951
		return $this->query('L10NFactory');
767
	}
768
769
	/**
770
	 * get an L10N instance
771
	 *
772
	 * @param string $app appid
773
	 * @param string $lang
774
	 * @return \OC_L10N
775
	 */
776 950
	public function getL10N($app, $lang = null) {
777 950
		return $this->getL10NFactory()->get($app, $lang);
778
	}
779
780
	/**
781
	 * @return \OCP\IURLGenerator
782
	 */
783 87
	public function getURLGenerator() {
784 87
		return $this->query('URLGenerator');
785
	}
786
787
	/**
788
	 * @return \OCP\IHelper
789
	 */
790
	public function getHelper() {
791
		return $this->query('AppHelper');
792
	}
793
794
	/**
795
	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
796
	 * getMemCacheFactory() instead.
797
	 *
798
	 * @return \OCP\ICache
799
	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
800
	 */
801
	public function getCache() {
802
		return $this->query('UserCache');
803
	}
804
805
	/**
806
	 * Returns an \OCP\CacheFactory instance
807
	 *
808
	 * @return \OCP\ICacheFactory
809
	 */
810 112
	public function getMemCacheFactory() {
811 112
		return $this->query('MemCacheFactory');
812
	}
813
814
	/**
815
	 * Returns the current session
816
	 *
817
	 * @return \OCP\IDBConnection
818
	 */
819 1888
	public function getDatabaseConnection() {
820 1888
		return $this->query('DatabaseConnection');
821
	}
822
823
	/**
824
	 * Returns the activity manager
825
	 *
826
	 * @return \OCP\Activity\IManager
827
	 */
828 9
	public function getActivityManager() {
829 9
		return $this->query('ActivityManager');
830
	}
831
832
	/**
833
	 * Returns an job list for controlling background jobs
834
	 *
835
	 * @return \OCP\BackgroundJob\IJobList
836
	 */
837 4
	public function getJobList() {
838 4
		return $this->query('JobList');
839
	}
840
841
	/**
842
	 * Returns a logger instance
843
	 *
844
	 * @return \OCP\ILogger
845
	 */
846 965
	public function getLogger() {
847 965
		return $this->query('Logger');
848
	}
849
850
	/**
851
	 * Returns a router for generating and matching urls
852
	 *
853
	 * @return \OCP\Route\IRouter
854
	 */
855 10
	public function getRouter() {
856 10
		return $this->query('Router');
857
	}
858
859
	/**
860
	 * Returns a search instance
861
	 *
862
	 * @return \OCP\ISearch
863
	 */
864
	public function getSearch() {
865
		return $this->query('Search');
866
	}
867
868
	/**
869
	 * Returns a SecureRandom instance
870
	 *
871
	 * @return \OCP\Security\ISecureRandom
872
	 */
873 517
	public function getSecureRandom() {
874 517
		return $this->query('SecureRandom');
875
	}
876
877
	/**
878
	 * Returns a Crypto instance
879
	 *
880
	 * @return \OCP\Security\ICrypto
881
	 */
882 1
	public function getCrypto() {
883 1
		return $this->query('Crypto');
884
	}
885
886
	/**
887
	 * Returns a Hasher instance
888
	 *
889
	 * @return \OCP\Security\IHasher
890
	 */
891 50
	public function getHasher() {
892 50
		return $this->query('Hasher');
893
	}
894
895
	/**
896
	 * Returns an instance of the db facade
897
	 * @deprecated use getDatabaseConnection, will be removed in ownCloud 10
898
	 * @return \OCP\IDb
899
	 */
900
	public function getDb() {
901
		return $this->query('Db');
902
	}
903
904
	/**
905
	 * Returns an instance of the HTTP helper class
906
	 * @deprecated Use getHTTPClientService()
907
	 * @return \OC\HTTPHelper
908
	 */
909 22
	public function getHTTPHelper() {
910 22
		return $this->query('HTTPHelper');
911
	}
912
913
	/**
914
	 * Get the certificate manager for the user
915
	 *
916
	 * @param string $userId (optional) if not specified the current loggedin user is used
917
	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
918
	 */
919 8
	public function getCertificateManager($userId = null) {
920 8
		if (is_null($userId)) {
921 6
			$userSession = $this->getUserSession();
922 6
			$user = $userSession->getUser();
923 6
			if (is_null($user)) {
924
				return null;
925
			}
926 6
			$userId = $user->getUID();
927 6
		}
928 8
		return new CertificateManager($userId, new View(), $this->getConfig());
929
	}
930
931
	/**
932
	 * Returns an instance of the HTTP client service
933
	 *
934
	 * @return \OCP\Http\Client\IClientService
935
	 */
936 14
	public function getHTTPClientService() {
937 14
		return $this->query('HttpClientService');
938
	}
939
940
	/**
941
	 * Create a new event source
942
	 *
943
	 * @return \OCP\IEventSource
944
	 */
945 1
	public function createEventSource() {
946 1
		return new \OC_EventSource();
947
	}
948
949
	/**
950
	 * Get the active event logger
951
	 *
952
	 * The returned logger only logs data when debug mode is enabled
953
	 *
954
	 * @return \OCP\Diagnostics\IEventLogger
955
	 */
956 1072
	public function getEventLogger() {
957 1072
		return $this->query('EventLogger');
958
	}
959
960
	/**
961
	 * Get the active query logger
962
	 *
963
	 * The returned logger only logs data when debug mode is enabled
964
	 *
965
	 * @return \OCP\Diagnostics\IQueryLogger
966
	 */
967 12
	public function getQueryLogger() {
968 12
		return $this->query('QueryLogger');
969
	}
970
971
	/**
972
	 * Get the manager for temporary files and folders
973
	 *
974
	 * @return \OCP\ITempManager
975
	 */
976 1473
	public function getTempManager() {
977 1473
		return $this->query('TempManager');
978
	}
979
980
	/**
981
	 * Get the app manager
982
	 *
983
	 * @return \OCP\App\IAppManager
984
	 */
985 1140
	public function getAppManager() {
986 1140
		return $this->query('AppManager');
987
	}
988
989
	/**
990
	 * Creates a new mailer
991
	 *
992
	 * @return \OCP\Mail\IMailer
993
	 */
994 17
	public function getMailer() {
995 17
		return $this->query('Mailer');
996
	}
997
998
	/**
999
	 * Get the webroot
1000
	 *
1001
	 * @return string
1002
	 */
1003
	public function getWebRoot() {
1004
		return $this->webRoot;
1005
	}
1006
1007
	/**
1008
	 * @return \OC\OCSClient
1009
	 */
1010
	public function getOcsClient() {
1011
		return $this->query('OcsClient');
1012
	}
1013
1014
	/**
1015
	 * @return \OCP\IDateTimeZone
1016
	 */
1017 9
	public function getDateTimeZone() {
1018 9
		return $this->query('DateTimeZone');
1019
	}
1020
1021
	/**
1022
	 * @return \OCP\IDateTimeFormatter
1023
	 */
1024
	public function getDateTimeFormatter() {
1025
		return $this->query('DateTimeFormatter');
1026
	}
1027
1028
	/**
1029
	 * @return \OCP\Files\Config\IMountProviderCollection
1030
	 */
1031 958
	public function getMountProviderCollection(){
1032 958
		return $this->query('MountConfigManager');
1033
	}
1034
1035
	/**
1036
	 * Get the IniWrapper
1037
	 *
1038
	 * @return IniGetWrapper
1039
	 */
1040 9
	public function getIniWrapper() {
1041 9
		return $this->query('IniWrapper');
1042
	}
1043
1044
	/**
1045
	 * @return \OCP\Command\IBus
1046
	 */
1047 65
	public function getCommandBus(){
1048 65
		return $this->query('AsyncCommandBus');
1049
	}
1050
1051
	/**
1052
	 * Get the trusted domain helper
1053
	 *
1054
	 * @return TrustedDomainHelper
1055
	 */
1056
	public function getTrustedDomainHelper() {
1057
		return $this->query('TrustedDomainHelper');
1058
	}
1059
1060
	/**
1061
	 * Get the locking provider
1062
	 *
1063
	 * @return \OCP\Lock\ILockingProvider
1064
	 * @since 8.1.0
1065
	 */
1066 5843
	public function getLockingProvider() {
1067 5843
		return $this->query('LockingProvider');
1068
	}
1069
1070
	/**
1071
	 * @return \OCP\Files\Mount\IMountManager
1072
	 **/
1073 22
	function getMountManager() {
1 ignored issue
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
1074 22
		return $this->query('MountManager');
1075
	}
1076
1077
	/*
1078
	 * Get the MimeTypeDetector
1079
	 *
1080
	 * @return \OCP\Files\IMimeTypeDetector
1081
	 */
1082 860
	public function getMimeTypeDetector() {
1083 860
		return $this->query('MimeTypeDetector');
1084
	}
1085
1086
	/**
1087
	 * Get the MimeTypeLoader
1088
	 *
1089
	 * @return \OCP\Files\IMimeTypeLoader
1090
	 */
1091 1087
	public function getMimeTypeLoader() {
1092 1087
		return $this->query('MimeTypeLoader');
1093
	}
1094
1095
	/**
1096
	 * Get the manager of all the capabilities
1097
	 *
1098
	 * @return \OC\CapabilitiesManager
1099
	 */
1100 82
	public function getCapabilitiesManager() {
1101 82
		return $this->query('CapabilitiesManager');
1102
	}
1103
1104
	/**
1105
	 * Get the EventDispatcher
1106
	 *
1107
	 * @return EventDispatcherInterface
1108
	 * @since 8.2.0
1109
	 */
1110 45
	public function getEventDispatcher() {
1111 45
		return $this->query('EventDispatcher');
1112
	}
1113
1114
	/**
1115
	 * Get the Notification Manager
1116
	 *
1117
	 * @return \OC\Notification\IManager
1118
	 * @since 8.2.0
1119
	 */
1120 6
	public function getNotificationManager() {
1121 6
		return $this->query('NotificationManager');
1122
	}
1123
1124
	/**
1125
	 * @return \OC\IntegrityCheck\Checker
1126
	 */
1127
	public function getIntegrityCodeChecker() {
1128
		return $this->query('IntegrityCodeChecker');
1129
	}
1130
1131
	/**
1132
	 * @return \OC\Session\CryptoWrapper
1133
	 */
1134
	public function getSessionCryptoWrapper() {
1135
		return $this->query('CryptoWrapper');
1136
	}
1137
1138
	/**
1139
	 * Not a public API as of 8.2, wait for 9.0
1140
	 * @return \OCA\Files_External\Service\BackendService
1141
	 */
1142
	public function getStoragesBackendService() {
1143
		return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\BackendService');
1144
	}
1145
1146
	/**
1147
	 * Not a public API as of 8.2, wait for 9.0
1148
	 * @return \OCA\Files_External\Service\GlobalStoragesService
1149
	 */
1150
	public function getGlobalStoragesService() {
1151
		return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1152
	}
1153
1154
	/**
1155
	 * Not a public API as of 8.2, wait for 9.0
1156
	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1157
	 */
1158
	public function getUserGlobalStoragesService() {
1159
		return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1160
	}
1161
1162
	/**
1163
	 * Not a public API as of 8.2, wait for 9.0
1164
	 * @return \OCA\Files_External\Service\UserStoragesService
1165
	 */
1166
	public function getUserStoragesService() {
1167
		return \OC_Mount_Config::$app->getContainer()->query('OCA\\Files_External\\Service\\UserStoragesService');
1168
	}
1169
	
1170
}
1171