Completed
Pull Request — master (#4336)
by Lukas
23:47 queued 09:54
created
lib/private/Server.php 2 patches
Indentation   +1609 added lines, -1609 removed lines patch added patch discarded remove patch
@@ -117,1618 +117,1618 @@
 block discarded – undo
117 117
  * TODO: hookup all manager classes
118 118
  */
119 119
 class Server extends ServerContainer implements IServerContainer {
120
-	/** @var string */
121
-	private $webRoot;
122
-
123
-	/**
124
-	 * @param string $webRoot
125
-	 * @param \OC\Config $config
126
-	 */
127
-	public function __construct($webRoot, \OC\Config $config) {
128
-		parent::__construct();
129
-		$this->webRoot = $webRoot;
130
-
131
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
-
134
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
135
-			return new PreviewManager(
136
-				$c->getConfig(),
137
-				$c->getRootFolder(),
138
-				$c->getAppDataDir('preview'),
139
-				$c->getEventDispatcher(),
140
-				$c->getSession()->get('user_id')
141
-			);
142
-		});
143
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
-
145
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
-			return new \OC\Preview\Watcher(
147
-				$c->getAppDataDir('preview')
148
-			);
149
-		});
150
-
151
-		$this->registerService('EncryptionManager', function (Server $c) {
152
-			$view = new View();
153
-			$util = new Encryption\Util(
154
-				$view,
155
-				$c->getUserManager(),
156
-				$c->getGroupManager(),
157
-				$c->getConfig()
158
-			);
159
-			return new Encryption\Manager(
160
-				$c->getConfig(),
161
-				$c->getLogger(),
162
-				$c->getL10N('core'),
163
-				new View(),
164
-				$util,
165
-				new ArrayCache()
166
-			);
167
-		});
168
-
169
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
170
-			$util = new Encryption\Util(
171
-				new View(),
172
-				$c->getUserManager(),
173
-				$c->getGroupManager(),
174
-				$c->getConfig()
175
-			);
176
-			return new Encryption\File($util);
177
-		});
178
-
179
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
180
-			$view = new View();
181
-			$util = new Encryption\Util(
182
-				$view,
183
-				$c->getUserManager(),
184
-				$c->getGroupManager(),
185
-				$c->getConfig()
186
-			);
187
-
188
-			return new Encryption\Keys\Storage($view, $util);
189
-		});
190
-		$this->registerService('TagMapper', function (Server $c) {
191
-			return new TagMapper($c->getDatabaseConnection());
192
-		});
193
-
194
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
-			$tagMapper = $c->query('TagMapper');
196
-			return new TagManager($tagMapper, $c->getUserSession());
197
-		});
198
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
199
-
200
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
201
-			$config = $c->getConfig();
202
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
-			/** @var \OC\SystemTag\ManagerFactory $factory */
204
-			$factory = new $factoryClass($this);
205
-			return $factory;
206
-		});
207
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
-			return $c->query('SystemTagManagerFactory')->getManager();
209
-		});
210
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
-
212
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
-		});
215
-		$this->registerService('RootFolder', function (Server $c) {
216
-			$manager = \OC\Files\Filesystem::getMountManager(null);
217
-			$view = new View();
218
-			$root = new Root(
219
-				$manager,
220
-				$view,
221
-				null,
222
-				$c->getUserMountCache(),
223
-				$this->getLogger(),
224
-				$this->getUserManager()
225
-			);
226
-			$connector = new HookConnector($root, $view);
227
-			$connector->viewToNode();
228
-
229
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
-			$previewConnector->connectWatcher();
231
-
232
-			return $root;
233
-		});
234
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
-
236
-		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
-			return new LazyRoot(function() use ($c) {
238
-				return $c->query('RootFolder');
239
-			});
240
-		});
241
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
-
243
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
-			$config = $c->getConfig();
245
-			return new \OC\User\Manager($config);
246
-		});
247
-		$this->registerAlias('UserManager', \OCP\IUserManager::class);
248
-
249
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
-			});
254
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
-			});
257
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
-			});
260
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
-			});
263
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
-			});
266
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
-			});
271
-			return $groupManager;
272
-		});
273
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
-
275
-		$this->registerService(Store::class, function(Server $c) {
276
-			$session = $c->getSession();
277
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
-				$tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
-			} else {
280
-				$tokenProvider = null;
281
-			}
282
-			$logger = $c->getLogger();
283
-			return new Store($session, $logger, $tokenProvider);
284
-		});
285
-		$this->registerAlias(IStore::class, Store::class);
286
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
-			$dbConnection = $c->getDatabaseConnection();
288
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
-		});
290
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
-			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
-			$crypto = $c->getCrypto();
293
-			$config = $c->getConfig();
294
-			$logger = $c->getLogger();
295
-			$timeFactory = new TimeFactory();
296
-			return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
-		});
298
-		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
-
300
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
-			$manager = $c->getUserManager();
302
-			$session = new \OC\Session\Memory('');
303
-			$timeFactory = new TimeFactory();
304
-			// Token providers might require a working database. This code
305
-			// might however be called when ownCloud is not yet setup.
306
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
-				$defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
-			} else {
309
-				$defaultTokenProvider = null;
310
-			}
311
-
312
-			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
-			});
316
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
-				/** @var $user \OC\User\User */
318
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
-			});
320
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
321
-				/** @var $user \OC\User\User */
322
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
-			});
324
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
325
-				/** @var $user \OC\User\User */
326
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
-			});
328
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
-				/** @var $user \OC\User\User */
330
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
-			});
332
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
-				/** @var $user \OC\User\User */
334
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
-			});
336
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
-			});
339
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
-				/** @var $user \OC\User\User */
341
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
-			});
343
-			$userSession->listen('\OC\User', 'logout', function () {
344
-				\OC_Hook::emit('OC_User', 'logout', array());
345
-			});
346
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
-				/** @var $user \OC\User\User */
348
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
-			});
350
-			return $userSession;
351
-		});
352
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
353
-
354
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
-			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
-		});
357
-
358
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360
-
361
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
362
-			return new \OC\AllConfig(
363
-				$c->getSystemConfig()
364
-			);
365
-		});
366
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
367
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368
-
369
-		$this->registerService('SystemConfig', function ($c) use ($config) {
370
-			return new \OC\SystemConfig($config);
371
-		});
372
-
373
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
374
-			return new \OC\AppConfig($c->getDatabaseConnection());
375
-		});
376
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
377
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378
-
379
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
380
-			return new \OC\L10N\Factory(
381
-				$c->getConfig(),
382
-				$c->getRequest(),
383
-				$c->getUserSession(),
384
-				\OC::$SERVERROOT
385
-			);
386
-		});
387
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388
-
389
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
390
-			$config = $c->getConfig();
391
-			$cacheFactory = $c->getMemCacheFactory();
392
-			return new \OC\URLGenerator(
393
-				$config,
394
-				$cacheFactory
395
-			);
396
-		});
397
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398
-
399
-		$this->registerService('AppHelper', function ($c) {
400
-			return new \OC\AppHelper();
401
-		});
402
-		$this->registerService('AppFetcher', function ($c) {
403
-			return new AppFetcher(
404
-				$this->getAppDataDir('appstore'),
405
-				$this->getHTTPClientService(),
406
-				$this->query(TimeFactory::class),
407
-				$this->getConfig()
408
-			);
409
-		});
410
-		$this->registerService('CategoryFetcher', function ($c) {
411
-			return new CategoryFetcher(
412
-				$this->getAppDataDir('appstore'),
413
-				$this->getHTTPClientService(),
414
-				$this->query(TimeFactory::class),
415
-				$this->getConfig()
416
-			);
417
-		});
418
-
419
-		$this->registerService(\OCP\ICache::class, function ($c) {
420
-			return new Cache\File();
421
-		});
422
-		$this->registerAlias('UserCache', \OCP\ICache::class);
423
-
424
-		$this->registerService(Factory::class, function (Server $c) {
425
-			$config = $c->getConfig();
426
-
427
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428
-				$v = \OC_App::getAppVersions();
429
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
430
-				$version = implode(',', $v);
431
-				$instanceId = \OC_Util::getInstanceId();
432
-				$path = \OC::$SERVERROOT;
433
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
434
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435
-					$config->getSystemValue('memcache.local', null),
436
-					$config->getSystemValue('memcache.distributed', null),
437
-					$config->getSystemValue('memcache.locking', null)
438
-				);
439
-			}
440
-
441
-			return new \OC\Memcache\Factory('', $c->getLogger(),
442
-				'\\OC\\Memcache\\ArrayCache',
443
-				'\\OC\\Memcache\\ArrayCache',
444
-				'\\OC\\Memcache\\ArrayCache'
445
-			);
446
-		});
447
-		$this->registerAlias('MemCacheFactory', Factory::class);
448
-		$this->registerAlias(ICacheFactory::class, Factory::class);
449
-
450
-		$this->registerService('RedisFactory', function (Server $c) {
451
-			$systemConfig = $c->getSystemConfig();
452
-			return new RedisFactory($systemConfig);
453
-		});
454
-
455
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
456
-			return new \OC\Activity\Manager(
457
-				$c->getRequest(),
458
-				$c->getUserSession(),
459
-				$c->getConfig(),
460
-				$c->query(IValidator::class)
461
-			);
462
-		});
463
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464
-
465
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
466
-			return new \OC\Activity\EventMerger(
467
-				$c->getL10N('lib')
468
-			);
469
-		});
470
-		$this->registerAlias(IValidator::class, Validator::class);
471
-
472
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
473
-			return new AvatarManager(
474
-				$c->getUserManager(),
475
-				$c->getAppDataDir('avatar'),
476
-				$c->getL10N('lib'),
477
-				$c->getLogger(),
478
-				$c->getConfig()
479
-			);
480
-		});
481
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482
-
483
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
484
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485
-			$logger = Log::getLogClass($logType);
486
-			call_user_func(array($logger, 'init'));
487
-
488
-			return new Log($logger);
489
-		});
490
-		$this->registerAlias('Logger', \OCP\ILogger::class);
491
-
492
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
493
-			$config = $c->getConfig();
494
-			return new \OC\BackgroundJob\JobList(
495
-				$c->getDatabaseConnection(),
496
-				$config,
497
-				new TimeFactory()
498
-			);
499
-		});
500
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501
-
502
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
503
-			$cacheFactory = $c->getMemCacheFactory();
504
-			$logger = $c->getLogger();
505
-			if ($cacheFactory->isAvailable()) {
506
-				$router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
507
-			} else {
508
-				$router = new \OC\Route\Router($logger);
509
-			}
510
-			return $router;
511
-		});
512
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
513
-
514
-		$this->registerService(\OCP\ISearch::class, function ($c) {
515
-			return new Search();
516
-		});
517
-		$this->registerAlias('Search', \OCP\ISearch::class);
518
-
519
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
520
-			return new \OC\Security\RateLimiting\Limiter(
521
-				$this->getUserSession(),
522
-				$this->getRequest(),
523
-				new \OC\AppFramework\Utility\TimeFactory(),
524
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
525
-			);
526
-		});
527
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
528
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
529
-				$this->getMemCacheFactory(),
530
-				new \OC\AppFramework\Utility\TimeFactory()
531
-			);
532
-		});
533
-
534
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
535
-			return new SecureRandom();
536
-		});
537
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538
-
539
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
540
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
541
-		});
542
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543
-
544
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
545
-			return new Hasher($c->getConfig());
546
-		});
547
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548
-
549
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
550
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551
-		});
552
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553
-
554
-		$this->registerService(IDBConnection::class, function (Server $c) {
555
-			$systemConfig = $c->getSystemConfig();
556
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
557
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
558
-			if (!$factory->isValidType($type)) {
559
-				throw new \OC\DatabaseException('Invalid database type');
560
-			}
561
-			$connectionParams = $factory->createConnectionParams();
562
-			$connection = $factory->getConnection($type, $connectionParams);
563
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
564
-			return $connection;
565
-		});
566
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
567
-
568
-		$this->registerService('HTTPHelper', function (Server $c) {
569
-			$config = $c->getConfig();
570
-			return new HTTPHelper(
571
-				$config,
572
-				$c->getHTTPClientService()
573
-			);
574
-		});
575
-
576
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
577
-			$user = \OC_User::getUser();
578
-			$uid = $user ? $user : null;
579
-			return new ClientService(
580
-				$c->getConfig(),
581
-				new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
582
-			);
583
-		});
584
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585
-
586
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
587
-			if ($c->getSystemConfig()->getValue('debug', false)) {
588
-				return new EventLogger();
589
-			} else {
590
-				return new NullEventLogger();
591
-			}
592
-		});
593
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594
-
595
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
596
-			if ($c->getSystemConfig()->getValue('debug', false)) {
597
-				return new QueryLogger();
598
-			} else {
599
-				return new NullQueryLogger();
600
-			}
601
-		});
602
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603
-
604
-		$this->registerService(TempManager::class, function (Server $c) {
605
-			return new TempManager(
606
-				$c->getLogger(),
607
-				$c->getConfig()
608
-			);
609
-		});
610
-		$this->registerAlias('TempManager', TempManager::class);
611
-		$this->registerAlias(ITempManager::class, TempManager::class);
612
-
613
-		$this->registerService(AppManager::class, function (Server $c) {
614
-			return new \OC\App\AppManager(
615
-				$c->getUserSession(),
616
-				$c->getAppConfig(),
617
-				$c->getGroupManager(),
618
-				$c->getMemCacheFactory(),
619
-				$c->getEventDispatcher()
620
-			);
621
-		});
622
-		$this->registerAlias('AppManager', AppManager::class);
623
-		$this->registerAlias(IAppManager::class, AppManager::class);
624
-
625
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
626
-			return new DateTimeZone(
627
-				$c->getConfig(),
628
-				$c->getSession()
629
-			);
630
-		});
631
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632
-
633
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
634
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635
-
636
-			return new DateTimeFormatter(
637
-				$c->getDateTimeZone()->getTimeZone(),
638
-				$c->getL10N('lib', $language)
639
-			);
640
-		});
641
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642
-
643
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
644
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645
-			$listener = new UserMountCacheListener($mountCache);
646
-			$listener->listen($c->getUserManager());
647
-			return $mountCache;
648
-		});
649
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650
-
651
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
652
-			$loader = \OC\Files\Filesystem::getLoader();
653
-			$mountCache = $c->query('UserMountCache');
654
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655
-
656
-			// builtin providers
657
-
658
-			$config = $c->getConfig();
659
-			$manager->registerProvider(new CacheMountProvider($config));
660
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
661
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
662
-
663
-			return $manager;
664
-		});
665
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666
-
667
-		$this->registerService('IniWrapper', function ($c) {
668
-			return new IniGetWrapper();
669
-		});
670
-		$this->registerService('AsyncCommandBus', function (Server $c) {
671
-			$jobList = $c->getJobList();
672
-			return new AsyncBus($jobList);
673
-		});
674
-		$this->registerService('TrustedDomainHelper', function ($c) {
675
-			return new TrustedDomainHelper($this->getConfig());
676
-		});
677
-		$this->registerService('Throttler', function(Server $c) {
678
-			return new Throttler(
679
-				$c->getDatabaseConnection(),
680
-				new TimeFactory(),
681
-				$c->getLogger(),
682
-				$c->getConfig()
683
-			);
684
-		});
685
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
686
-			// IConfig and IAppManager requires a working database. This code
687
-			// might however be called when ownCloud is not yet setup.
688
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
689
-				$config = $c->getConfig();
690
-				$appManager = $c->getAppManager();
691
-			} else {
692
-				$config = null;
693
-				$appManager = null;
694
-			}
695
-
696
-			return new Checker(
697
-					new EnvironmentHelper(),
698
-					new FileAccessHelper(),
699
-					new AppLocator(),
700
-					$config,
701
-					$c->getMemCacheFactory(),
702
-					$appManager,
703
-					$c->getTempManager()
704
-			);
705
-		});
706
-		$this->registerService(\OCP\IRequest::class, function ($c) {
707
-			if (isset($this['urlParams'])) {
708
-				$urlParams = $this['urlParams'];
709
-			} else {
710
-				$urlParams = [];
711
-			}
712
-
713
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
714
-				&& in_array('fakeinput', stream_get_wrappers())
715
-			) {
716
-				$stream = 'fakeinput://data';
717
-			} else {
718
-				$stream = 'php://input';
719
-			}
720
-
721
-			return new Request(
722
-				[
723
-					'get' => $_GET,
724
-					'post' => $_POST,
725
-					'files' => $_FILES,
726
-					'server' => $_SERVER,
727
-					'env' => $_ENV,
728
-					'cookies' => $_COOKIE,
729
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
730
-						? $_SERVER['REQUEST_METHOD']
731
-						: null,
732
-					'urlParams' => $urlParams,
733
-				],
734
-				$this->getSecureRandom(),
735
-				$this->getConfig(),
736
-				$this->getCsrfTokenManager(),
737
-				$stream
738
-			);
739
-		});
740
-		$this->registerAlias('Request', \OCP\IRequest::class);
741
-
742
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
743
-			return new Mailer(
744
-				$c->getConfig(),
745
-				$c->getLogger(),
746
-				$c->query(Defaults::class),
747
-				$c->getURLGenerator(),
748
-				$c->getL10N('lib')
749
-			);
750
-		});
751
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
752
-
753
-		$this->registerService('LDAPProvider', function(Server $c) {
754
-			$config = $c->getConfig();
755
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
-			if(is_null($factoryClass)) {
757
-				throw new \Exception('ldapProviderFactory not set');
758
-			}
759
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760
-			$factory = new $factoryClass($this);
761
-			return $factory->getLDAPProvider();
762
-		});
763
-		$this->registerService('LockingProvider', function (Server $c) {
764
-			$ini = $c->getIniWrapper();
765
-			$config = $c->getConfig();
766
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
767
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
768
-				/** @var \OC\Memcache\Factory $memcacheFactory */
769
-				$memcacheFactory = $c->getMemCacheFactory();
770
-				$memcache = $memcacheFactory->createLocking('lock');
771
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
772
-					return new MemcacheLockingProvider($memcache, $ttl);
773
-				}
774
-				return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
775
-			}
776
-			return new NoopLockingProvider();
777
-		});
778
-
779
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
780
-			return new \OC\Files\Mount\Manager();
781
-		});
782
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783
-
784
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
785
-			return new \OC\Files\Type\Detection(
786
-				$c->getURLGenerator(),
787
-				\OC::$configDir,
788
-				\OC::$SERVERROOT . '/resources/config/'
789
-			);
790
-		});
791
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792
-
793
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
794
-			return new \OC\Files\Type\Loader(
795
-				$c->getDatabaseConnection()
796
-			);
797
-		});
798
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799
-
800
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
801
-			return new Manager(
802
-				$c->query(IValidator::class)
803
-			);
804
-		});
805
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806
-
807
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
808
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
809
-			$manager->registerCapability(function () use ($c) {
810
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
811
-			});
812
-			return $manager;
813
-		});
814
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
815
-
816
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
817
-			$config = $c->getConfig();
818
-			$factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
819
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
820
-			$factory = new $factoryClass($this);
821
-			return $factory->getManager();
822
-		});
823
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
824
-
825
-		$this->registerService('ThemingDefaults', function(Server $c) {
826
-			/*
120
+    /** @var string */
121
+    private $webRoot;
122
+
123
+    /**
124
+     * @param string $webRoot
125
+     * @param \OC\Config $config
126
+     */
127
+    public function __construct($webRoot, \OC\Config $config) {
128
+        parent::__construct();
129
+        $this->webRoot = $webRoot;
130
+
131
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133
+
134
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
135
+            return new PreviewManager(
136
+                $c->getConfig(),
137
+                $c->getRootFolder(),
138
+                $c->getAppDataDir('preview'),
139
+                $c->getEventDispatcher(),
140
+                $c->getSession()->get('user_id')
141
+            );
142
+        });
143
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
144
+
145
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
146
+            return new \OC\Preview\Watcher(
147
+                $c->getAppDataDir('preview')
148
+            );
149
+        });
150
+
151
+        $this->registerService('EncryptionManager', function (Server $c) {
152
+            $view = new View();
153
+            $util = new Encryption\Util(
154
+                $view,
155
+                $c->getUserManager(),
156
+                $c->getGroupManager(),
157
+                $c->getConfig()
158
+            );
159
+            return new Encryption\Manager(
160
+                $c->getConfig(),
161
+                $c->getLogger(),
162
+                $c->getL10N('core'),
163
+                new View(),
164
+                $util,
165
+                new ArrayCache()
166
+            );
167
+        });
168
+
169
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
170
+            $util = new Encryption\Util(
171
+                new View(),
172
+                $c->getUserManager(),
173
+                $c->getGroupManager(),
174
+                $c->getConfig()
175
+            );
176
+            return new Encryption\File($util);
177
+        });
178
+
179
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
180
+            $view = new View();
181
+            $util = new Encryption\Util(
182
+                $view,
183
+                $c->getUserManager(),
184
+                $c->getGroupManager(),
185
+                $c->getConfig()
186
+            );
187
+
188
+            return new Encryption\Keys\Storage($view, $util);
189
+        });
190
+        $this->registerService('TagMapper', function (Server $c) {
191
+            return new TagMapper($c->getDatabaseConnection());
192
+        });
193
+
194
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
195
+            $tagMapper = $c->query('TagMapper');
196
+            return new TagManager($tagMapper, $c->getUserSession());
197
+        });
198
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
199
+
200
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
201
+            $config = $c->getConfig();
202
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203
+            /** @var \OC\SystemTag\ManagerFactory $factory */
204
+            $factory = new $factoryClass($this);
205
+            return $factory;
206
+        });
207
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
208
+            return $c->query('SystemTagManagerFactory')->getManager();
209
+        });
210
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211
+
212
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
213
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
214
+        });
215
+        $this->registerService('RootFolder', function (Server $c) {
216
+            $manager = \OC\Files\Filesystem::getMountManager(null);
217
+            $view = new View();
218
+            $root = new Root(
219
+                $manager,
220
+                $view,
221
+                null,
222
+                $c->getUserMountCache(),
223
+                $this->getLogger(),
224
+                $this->getUserManager()
225
+            );
226
+            $connector = new HookConnector($root, $view);
227
+            $connector->viewToNode();
228
+
229
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
230
+            $previewConnector->connectWatcher();
231
+
232
+            return $root;
233
+        });
234
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
235
+
236
+        $this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
237
+            return new LazyRoot(function() use ($c) {
238
+                return $c->query('RootFolder');
239
+            });
240
+        });
241
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242
+
243
+        $this->registerService(\OCP\IUserManager::class, function (Server $c) {
244
+            $config = $c->getConfig();
245
+            return new \OC\User\Manager($config);
246
+        });
247
+        $this->registerAlias('UserManager', \OCP\IUserManager::class);
248
+
249
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
250
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
252
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253
+            });
254
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
255
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256
+            });
257
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
258
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259
+            });
260
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
261
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262
+            });
263
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
264
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265
+            });
266
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
267
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
270
+            });
271
+            return $groupManager;
272
+        });
273
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
274
+
275
+        $this->registerService(Store::class, function(Server $c) {
276
+            $session = $c->getSession();
277
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
278
+                $tokenProvider = $c->query('OC\Authentication\Token\IProvider');
279
+            } else {
280
+                $tokenProvider = null;
281
+            }
282
+            $logger = $c->getLogger();
283
+            return new Store($session, $logger, $tokenProvider);
284
+        });
285
+        $this->registerAlias(IStore::class, Store::class);
286
+        $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
287
+            $dbConnection = $c->getDatabaseConnection();
288
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
289
+        });
290
+        $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
291
+            $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292
+            $crypto = $c->getCrypto();
293
+            $config = $c->getConfig();
294
+            $logger = $c->getLogger();
295
+            $timeFactory = new TimeFactory();
296
+            return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory);
297
+        });
298
+        $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299
+
300
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
301
+            $manager = $c->getUserManager();
302
+            $session = new \OC\Session\Memory('');
303
+            $timeFactory = new TimeFactory();
304
+            // Token providers might require a working database. This code
305
+            // might however be called when ownCloud is not yet setup.
306
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
307
+                $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider');
308
+            } else {
309
+                $defaultTokenProvider = null;
310
+            }
311
+
312
+            $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
314
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315
+            });
316
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
317
+                /** @var $user \OC\User\User */
318
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319
+            });
320
+            $userSession->listen('\OC\User', 'preDelete', function ($user) {
321
+                /** @var $user \OC\User\User */
322
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323
+            });
324
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
325
+                /** @var $user \OC\User\User */
326
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327
+            });
328
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
329
+                /** @var $user \OC\User\User */
330
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331
+            });
332
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
333
+                /** @var $user \OC\User\User */
334
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335
+            });
336
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
337
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338
+            });
339
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
340
+                /** @var $user \OC\User\User */
341
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342
+            });
343
+            $userSession->listen('\OC\User', 'logout', function () {
344
+                \OC_Hook::emit('OC_User', 'logout', array());
345
+            });
346
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
347
+                /** @var $user \OC\User\User */
348
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349
+            });
350
+            return $userSession;
351
+        });
352
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
353
+
354
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
355
+            return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356
+        });
357
+
358
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360
+
361
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
362
+            return new \OC\AllConfig(
363
+                $c->getSystemConfig()
364
+            );
365
+        });
366
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
367
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368
+
369
+        $this->registerService('SystemConfig', function ($c) use ($config) {
370
+            return new \OC\SystemConfig($config);
371
+        });
372
+
373
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
374
+            return new \OC\AppConfig($c->getDatabaseConnection());
375
+        });
376
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
377
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378
+
379
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
380
+            return new \OC\L10N\Factory(
381
+                $c->getConfig(),
382
+                $c->getRequest(),
383
+                $c->getUserSession(),
384
+                \OC::$SERVERROOT
385
+            );
386
+        });
387
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388
+
389
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
390
+            $config = $c->getConfig();
391
+            $cacheFactory = $c->getMemCacheFactory();
392
+            return new \OC\URLGenerator(
393
+                $config,
394
+                $cacheFactory
395
+            );
396
+        });
397
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398
+
399
+        $this->registerService('AppHelper', function ($c) {
400
+            return new \OC\AppHelper();
401
+        });
402
+        $this->registerService('AppFetcher', function ($c) {
403
+            return new AppFetcher(
404
+                $this->getAppDataDir('appstore'),
405
+                $this->getHTTPClientService(),
406
+                $this->query(TimeFactory::class),
407
+                $this->getConfig()
408
+            );
409
+        });
410
+        $this->registerService('CategoryFetcher', function ($c) {
411
+            return new CategoryFetcher(
412
+                $this->getAppDataDir('appstore'),
413
+                $this->getHTTPClientService(),
414
+                $this->query(TimeFactory::class),
415
+                $this->getConfig()
416
+            );
417
+        });
418
+
419
+        $this->registerService(\OCP\ICache::class, function ($c) {
420
+            return new Cache\File();
421
+        });
422
+        $this->registerAlias('UserCache', \OCP\ICache::class);
423
+
424
+        $this->registerService(Factory::class, function (Server $c) {
425
+            $config = $c->getConfig();
426
+
427
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428
+                $v = \OC_App::getAppVersions();
429
+                $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
430
+                $version = implode(',', $v);
431
+                $instanceId = \OC_Util::getInstanceId();
432
+                $path = \OC::$SERVERROOT;
433
+                $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
434
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435
+                    $config->getSystemValue('memcache.local', null),
436
+                    $config->getSystemValue('memcache.distributed', null),
437
+                    $config->getSystemValue('memcache.locking', null)
438
+                );
439
+            }
440
+
441
+            return new \OC\Memcache\Factory('', $c->getLogger(),
442
+                '\\OC\\Memcache\\ArrayCache',
443
+                '\\OC\\Memcache\\ArrayCache',
444
+                '\\OC\\Memcache\\ArrayCache'
445
+            );
446
+        });
447
+        $this->registerAlias('MemCacheFactory', Factory::class);
448
+        $this->registerAlias(ICacheFactory::class, Factory::class);
449
+
450
+        $this->registerService('RedisFactory', function (Server $c) {
451
+            $systemConfig = $c->getSystemConfig();
452
+            return new RedisFactory($systemConfig);
453
+        });
454
+
455
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
456
+            return new \OC\Activity\Manager(
457
+                $c->getRequest(),
458
+                $c->getUserSession(),
459
+                $c->getConfig(),
460
+                $c->query(IValidator::class)
461
+            );
462
+        });
463
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464
+
465
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
466
+            return new \OC\Activity\EventMerger(
467
+                $c->getL10N('lib')
468
+            );
469
+        });
470
+        $this->registerAlias(IValidator::class, Validator::class);
471
+
472
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
473
+            return new AvatarManager(
474
+                $c->getUserManager(),
475
+                $c->getAppDataDir('avatar'),
476
+                $c->getL10N('lib'),
477
+                $c->getLogger(),
478
+                $c->getConfig()
479
+            );
480
+        });
481
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482
+
483
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
484
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485
+            $logger = Log::getLogClass($logType);
486
+            call_user_func(array($logger, 'init'));
487
+
488
+            return new Log($logger);
489
+        });
490
+        $this->registerAlias('Logger', \OCP\ILogger::class);
491
+
492
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
493
+            $config = $c->getConfig();
494
+            return new \OC\BackgroundJob\JobList(
495
+                $c->getDatabaseConnection(),
496
+                $config,
497
+                new TimeFactory()
498
+            );
499
+        });
500
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501
+
502
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
503
+            $cacheFactory = $c->getMemCacheFactory();
504
+            $logger = $c->getLogger();
505
+            if ($cacheFactory->isAvailable()) {
506
+                $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger);
507
+            } else {
508
+                $router = new \OC\Route\Router($logger);
509
+            }
510
+            return $router;
511
+        });
512
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
513
+
514
+        $this->registerService(\OCP\ISearch::class, function ($c) {
515
+            return new Search();
516
+        });
517
+        $this->registerAlias('Search', \OCP\ISearch::class);
518
+
519
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function($c) {
520
+            return new \OC\Security\RateLimiting\Limiter(
521
+                $this->getUserSession(),
522
+                $this->getRequest(),
523
+                new \OC\AppFramework\Utility\TimeFactory(),
524
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
525
+            );
526
+        });
527
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
528
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
529
+                $this->getMemCacheFactory(),
530
+                new \OC\AppFramework\Utility\TimeFactory()
531
+            );
532
+        });
533
+
534
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
535
+            return new SecureRandom();
536
+        });
537
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538
+
539
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
540
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
541
+        });
542
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543
+
544
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
545
+            return new Hasher($c->getConfig());
546
+        });
547
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548
+
549
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
550
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551
+        });
552
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553
+
554
+        $this->registerService(IDBConnection::class, function (Server $c) {
555
+            $systemConfig = $c->getSystemConfig();
556
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
557
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
558
+            if (!$factory->isValidType($type)) {
559
+                throw new \OC\DatabaseException('Invalid database type');
560
+            }
561
+            $connectionParams = $factory->createConnectionParams();
562
+            $connection = $factory->getConnection($type, $connectionParams);
563
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
564
+            return $connection;
565
+        });
566
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
567
+
568
+        $this->registerService('HTTPHelper', function (Server $c) {
569
+            $config = $c->getConfig();
570
+            return new HTTPHelper(
571
+                $config,
572
+                $c->getHTTPClientService()
573
+            );
574
+        });
575
+
576
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
577
+            $user = \OC_User::getUser();
578
+            $uid = $user ? $user : null;
579
+            return new ClientService(
580
+                $c->getConfig(),
581
+                new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger())
582
+            );
583
+        });
584
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585
+
586
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
587
+            if ($c->getSystemConfig()->getValue('debug', false)) {
588
+                return new EventLogger();
589
+            } else {
590
+                return new NullEventLogger();
591
+            }
592
+        });
593
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594
+
595
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
596
+            if ($c->getSystemConfig()->getValue('debug', false)) {
597
+                return new QueryLogger();
598
+            } else {
599
+                return new NullQueryLogger();
600
+            }
601
+        });
602
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603
+
604
+        $this->registerService(TempManager::class, function (Server $c) {
605
+            return new TempManager(
606
+                $c->getLogger(),
607
+                $c->getConfig()
608
+            );
609
+        });
610
+        $this->registerAlias('TempManager', TempManager::class);
611
+        $this->registerAlias(ITempManager::class, TempManager::class);
612
+
613
+        $this->registerService(AppManager::class, function (Server $c) {
614
+            return new \OC\App\AppManager(
615
+                $c->getUserSession(),
616
+                $c->getAppConfig(),
617
+                $c->getGroupManager(),
618
+                $c->getMemCacheFactory(),
619
+                $c->getEventDispatcher()
620
+            );
621
+        });
622
+        $this->registerAlias('AppManager', AppManager::class);
623
+        $this->registerAlias(IAppManager::class, AppManager::class);
624
+
625
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
626
+            return new DateTimeZone(
627
+                $c->getConfig(),
628
+                $c->getSession()
629
+            );
630
+        });
631
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632
+
633
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
634
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635
+
636
+            return new DateTimeFormatter(
637
+                $c->getDateTimeZone()->getTimeZone(),
638
+                $c->getL10N('lib', $language)
639
+            );
640
+        });
641
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642
+
643
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
644
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645
+            $listener = new UserMountCacheListener($mountCache);
646
+            $listener->listen($c->getUserManager());
647
+            return $mountCache;
648
+        });
649
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650
+
651
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
652
+            $loader = \OC\Files\Filesystem::getLoader();
653
+            $mountCache = $c->query('UserMountCache');
654
+            $manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655
+
656
+            // builtin providers
657
+
658
+            $config = $c->getConfig();
659
+            $manager->registerProvider(new CacheMountProvider($config));
660
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
661
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
662
+
663
+            return $manager;
664
+        });
665
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666
+
667
+        $this->registerService('IniWrapper', function ($c) {
668
+            return new IniGetWrapper();
669
+        });
670
+        $this->registerService('AsyncCommandBus', function (Server $c) {
671
+            $jobList = $c->getJobList();
672
+            return new AsyncBus($jobList);
673
+        });
674
+        $this->registerService('TrustedDomainHelper', function ($c) {
675
+            return new TrustedDomainHelper($this->getConfig());
676
+        });
677
+        $this->registerService('Throttler', function(Server $c) {
678
+            return new Throttler(
679
+                $c->getDatabaseConnection(),
680
+                new TimeFactory(),
681
+                $c->getLogger(),
682
+                $c->getConfig()
683
+            );
684
+        });
685
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
686
+            // IConfig and IAppManager requires a working database. This code
687
+            // might however be called when ownCloud is not yet setup.
688
+            if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
689
+                $config = $c->getConfig();
690
+                $appManager = $c->getAppManager();
691
+            } else {
692
+                $config = null;
693
+                $appManager = null;
694
+            }
695
+
696
+            return new Checker(
697
+                    new EnvironmentHelper(),
698
+                    new FileAccessHelper(),
699
+                    new AppLocator(),
700
+                    $config,
701
+                    $c->getMemCacheFactory(),
702
+                    $appManager,
703
+                    $c->getTempManager()
704
+            );
705
+        });
706
+        $this->registerService(\OCP\IRequest::class, function ($c) {
707
+            if (isset($this['urlParams'])) {
708
+                $urlParams = $this['urlParams'];
709
+            } else {
710
+                $urlParams = [];
711
+            }
712
+
713
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
714
+                && in_array('fakeinput', stream_get_wrappers())
715
+            ) {
716
+                $stream = 'fakeinput://data';
717
+            } else {
718
+                $stream = 'php://input';
719
+            }
720
+
721
+            return new Request(
722
+                [
723
+                    'get' => $_GET,
724
+                    'post' => $_POST,
725
+                    'files' => $_FILES,
726
+                    'server' => $_SERVER,
727
+                    'env' => $_ENV,
728
+                    'cookies' => $_COOKIE,
729
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
730
+                        ? $_SERVER['REQUEST_METHOD']
731
+                        : null,
732
+                    'urlParams' => $urlParams,
733
+                ],
734
+                $this->getSecureRandom(),
735
+                $this->getConfig(),
736
+                $this->getCsrfTokenManager(),
737
+                $stream
738
+            );
739
+        });
740
+        $this->registerAlias('Request', \OCP\IRequest::class);
741
+
742
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
743
+            return new Mailer(
744
+                $c->getConfig(),
745
+                $c->getLogger(),
746
+                $c->query(Defaults::class),
747
+                $c->getURLGenerator(),
748
+                $c->getL10N('lib')
749
+            );
750
+        });
751
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
752
+
753
+        $this->registerService('LDAPProvider', function(Server $c) {
754
+            $config = $c->getConfig();
755
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
+            if(is_null($factoryClass)) {
757
+                throw new \Exception('ldapProviderFactory not set');
758
+            }
759
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760
+            $factory = new $factoryClass($this);
761
+            return $factory->getLDAPProvider();
762
+        });
763
+        $this->registerService('LockingProvider', function (Server $c) {
764
+            $ini = $c->getIniWrapper();
765
+            $config = $c->getConfig();
766
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
767
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
768
+                /** @var \OC\Memcache\Factory $memcacheFactory */
769
+                $memcacheFactory = $c->getMemCacheFactory();
770
+                $memcache = $memcacheFactory->createLocking('lock');
771
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
772
+                    return new MemcacheLockingProvider($memcache, $ttl);
773
+                }
774
+                return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl);
775
+            }
776
+            return new NoopLockingProvider();
777
+        });
778
+
779
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
780
+            return new \OC\Files\Mount\Manager();
781
+        });
782
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783
+
784
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
785
+            return new \OC\Files\Type\Detection(
786
+                $c->getURLGenerator(),
787
+                \OC::$configDir,
788
+                \OC::$SERVERROOT . '/resources/config/'
789
+            );
790
+        });
791
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792
+
793
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
794
+            return new \OC\Files\Type\Loader(
795
+                $c->getDatabaseConnection()
796
+            );
797
+        });
798
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799
+
800
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
801
+            return new Manager(
802
+                $c->query(IValidator::class)
803
+            );
804
+        });
805
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806
+
807
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
808
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
809
+            $manager->registerCapability(function () use ($c) {
810
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
811
+            });
812
+            return $manager;
813
+        });
814
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
815
+
816
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
817
+            $config = $c->getConfig();
818
+            $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory');
819
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
820
+            $factory = new $factoryClass($this);
821
+            return $factory->getManager();
822
+        });
823
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
824
+
825
+        $this->registerService('ThemingDefaults', function(Server $c) {
826
+            /*
827 827
 			 * Dark magic for autoloader.
828 828
 			 * If we do a class_exists it will try to load the class which will
829 829
 			 * make composer cache the result. Resulting in errors when enabling
830 830
 			 * the theming app.
831 831
 			 */
832
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
833
-			if (isset($prefixes['OCA\\Theming\\'])) {
834
-				$classExists = true;
835
-			} else {
836
-				$classExists = false;
837
-			}
838
-
839
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
840
-				return new ThemingDefaults(
841
-					$c->getConfig(),
842
-					$c->getL10N('theming'),
843
-					$c->getURLGenerator(),
844
-					new \OC_Defaults(),
845
-					$c->getAppDataDir('theming'),
846
-					$c->getMemCacheFactory()
847
-				);
848
-			}
849
-			return new \OC_Defaults();
850
-		});
851
-		$this->registerService(EventDispatcher::class, function () {
852
-			return new EventDispatcher();
853
-		});
854
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
855
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856
-
857
-		$this->registerService('CryptoWrapper', function (Server $c) {
858
-			// FIXME: Instantiiated here due to cyclic dependency
859
-			$request = new Request(
860
-				[
861
-					'get' => $_GET,
862
-					'post' => $_POST,
863
-					'files' => $_FILES,
864
-					'server' => $_SERVER,
865
-					'env' => $_ENV,
866
-					'cookies' => $_COOKIE,
867
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
868
-						? $_SERVER['REQUEST_METHOD']
869
-						: null,
870
-				],
871
-				$c->getSecureRandom(),
872
-				$c->getConfig()
873
-			);
874
-
875
-			return new CryptoWrapper(
876
-				$c->getConfig(),
877
-				$c->getCrypto(),
878
-				$c->getSecureRandom(),
879
-				$request
880
-			);
881
-		});
882
-		$this->registerService('CsrfTokenManager', function (Server $c) {
883
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884
-
885
-			return new CsrfTokenManager(
886
-				$tokenGenerator,
887
-				$c->query(SessionStorage::class)
888
-			);
889
-		});
890
-		$this->registerService(SessionStorage::class, function (Server $c) {
891
-			return new SessionStorage($c->getSession());
892
-		});
893
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
894
-			return new ContentSecurityPolicyManager();
895
-		});
896
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
897
-
898
-		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
899
-			return new ContentSecurityPolicyNonceManager(
900
-				$c->getCsrfTokenManager(),
901
-				$c->getRequest()
902
-			);
903
-		});
904
-
905
-		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
906
-			$config = $c->getConfig();
907
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
908
-			/** @var \OCP\Share\IProviderFactory $factory */
909
-			$factory = new $factoryClass($this);
910
-
911
-			$manager = new \OC\Share20\Manager(
912
-				$c->getLogger(),
913
-				$c->getConfig(),
914
-				$c->getSecureRandom(),
915
-				$c->getHasher(),
916
-				$c->getMountManager(),
917
-				$c->getGroupManager(),
918
-				$c->getL10N('core'),
919
-				$factory,
920
-				$c->getUserManager(),
921
-				$c->getLazyRootFolder(),
922
-				$c->getEventDispatcher()
923
-			);
924
-
925
-			return $manager;
926
-		});
927
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
928
-
929
-		$this->registerService('SettingsManager', function(Server $c) {
930
-			$manager = new \OC\Settings\Manager(
931
-				$c->getLogger(),
932
-				$c->getDatabaseConnection(),
933
-				$c->getL10N('lib'),
934
-				$c->getConfig(),
935
-				$c->getEncryptionManager(),
936
-				$c->getUserManager(),
937
-				$c->getLockingProvider(),
938
-				$c->getRequest(),
939
-				new \OC\Settings\Mapper($c->getDatabaseConnection()),
940
-				$c->getURLGenerator()
941
-			);
942
-			return $manager;
943
-		});
944
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
945
-			return new \OC\Files\AppData\Factory(
946
-				$c->getRootFolder(),
947
-				$c->getSystemConfig()
948
-			);
949
-		});
950
-
951
-		$this->registerService('LockdownManager', function (Server $c) {
952
-			return new LockdownManager(function() use ($c) {
953
-				return $c->getSession();
954
-			});
955
-		});
956
-
957
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
958
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959
-		});
960
-
961
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
962
-			return new CloudIdManager();
963
-		});
964
-
965
-		/* To trick DI since we don't extend the DIContainer here */
966
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
967
-			return new CleanPreviewsBackgroundJob(
968
-				$c->getRootFolder(),
969
-				$c->getLogger(),
970
-				$c->getJobList(),
971
-				new TimeFactory()
972
-			);
973
-		});
974
-
975
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
976
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
977
-
978
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980
-
981
-		$this->registerService(Defaults::class, function (Server $c) {
982
-			return new Defaults(
983
-				$c->getThemingDefaults()
984
-			);
985
-		});
986
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
987
-
988
-		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
989
-			return $c->query(\OCP\IUserSession::class)->getSession();
990
-		});
991
-	}
992
-
993
-	/**
994
-	 * @return \OCP\Contacts\IManager
995
-	 */
996
-	public function getContactsManager() {
997
-		return $this->query('ContactsManager');
998
-	}
999
-
1000
-	/**
1001
-	 * @return \OC\Encryption\Manager
1002
-	 */
1003
-	public function getEncryptionManager() {
1004
-		return $this->query('EncryptionManager');
1005
-	}
1006
-
1007
-	/**
1008
-	 * @return \OC\Encryption\File
1009
-	 */
1010
-	public function getEncryptionFilesHelper() {
1011
-		return $this->query('EncryptionFileHelper');
1012
-	}
1013
-
1014
-	/**
1015
-	 * @return \OCP\Encryption\Keys\IStorage
1016
-	 */
1017
-	public function getEncryptionKeyStorage() {
1018
-		return $this->query('EncryptionKeyStorage');
1019
-	}
1020
-
1021
-	/**
1022
-	 * The current request object holding all information about the request
1023
-	 * currently being processed is returned from this method.
1024
-	 * In case the current execution was not initiated by a web request null is returned
1025
-	 *
1026
-	 * @return \OCP\IRequest
1027
-	 */
1028
-	public function getRequest() {
1029
-		return $this->query('Request');
1030
-	}
1031
-
1032
-	/**
1033
-	 * Returns the preview manager which can create preview images for a given file
1034
-	 *
1035
-	 * @return \OCP\IPreview
1036
-	 */
1037
-	public function getPreviewManager() {
1038
-		return $this->query('PreviewManager');
1039
-	}
1040
-
1041
-	/**
1042
-	 * Returns the tag manager which can get and set tags for different object types
1043
-	 *
1044
-	 * @see \OCP\ITagManager::load()
1045
-	 * @return \OCP\ITagManager
1046
-	 */
1047
-	public function getTagManager() {
1048
-		return $this->query('TagManager');
1049
-	}
1050
-
1051
-	/**
1052
-	 * Returns the system-tag manager
1053
-	 *
1054
-	 * @return \OCP\SystemTag\ISystemTagManager
1055
-	 *
1056
-	 * @since 9.0.0
1057
-	 */
1058
-	public function getSystemTagManager() {
1059
-		return $this->query('SystemTagManager');
1060
-	}
1061
-
1062
-	/**
1063
-	 * Returns the system-tag object mapper
1064
-	 *
1065
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1066
-	 *
1067
-	 * @since 9.0.0
1068
-	 */
1069
-	public function getSystemTagObjectMapper() {
1070
-		return $this->query('SystemTagObjectMapper');
1071
-	}
1072
-
1073
-	/**
1074
-	 * Returns the avatar manager, used for avatar functionality
1075
-	 *
1076
-	 * @return \OCP\IAvatarManager
1077
-	 */
1078
-	public function getAvatarManager() {
1079
-		return $this->query('AvatarManager');
1080
-	}
1081
-
1082
-	/**
1083
-	 * Returns the root folder of ownCloud's data directory
1084
-	 *
1085
-	 * @return \OCP\Files\IRootFolder
1086
-	 */
1087
-	public function getRootFolder() {
1088
-		return $this->query('LazyRootFolder');
1089
-	}
1090
-
1091
-	/**
1092
-	 * Returns the root folder of ownCloud's data directory
1093
-	 * This is the lazy variant so this gets only initialized once it
1094
-	 * is actually used.
1095
-	 *
1096
-	 * @return \OCP\Files\IRootFolder
1097
-	 */
1098
-	public function getLazyRootFolder() {
1099
-		return $this->query('LazyRootFolder');
1100
-	}
1101
-
1102
-	/**
1103
-	 * Returns a view to ownCloud's files folder
1104
-	 *
1105
-	 * @param string $userId user ID
1106
-	 * @return \OCP\Files\Folder|null
1107
-	 */
1108
-	public function getUserFolder($userId = null) {
1109
-		if ($userId === null) {
1110
-			$user = $this->getUserSession()->getUser();
1111
-			if (!$user) {
1112
-				return null;
1113
-			}
1114
-			$userId = $user->getUID();
1115
-		}
1116
-		$root = $this->getRootFolder();
1117
-		return $root->getUserFolder($userId);
1118
-	}
1119
-
1120
-	/**
1121
-	 * Returns an app-specific view in ownClouds data directory
1122
-	 *
1123
-	 * @return \OCP\Files\Folder
1124
-	 * @deprecated since 9.2.0 use IAppData
1125
-	 */
1126
-	public function getAppFolder() {
1127
-		$dir = '/' . \OC_App::getCurrentApp();
1128
-		$root = $this->getRootFolder();
1129
-		if (!$root->nodeExists($dir)) {
1130
-			$folder = $root->newFolder($dir);
1131
-		} else {
1132
-			$folder = $root->get($dir);
1133
-		}
1134
-		return $folder;
1135
-	}
1136
-
1137
-	/**
1138
-	 * @return \OC\User\Manager
1139
-	 */
1140
-	public function getUserManager() {
1141
-		return $this->query('UserManager');
1142
-	}
1143
-
1144
-	/**
1145
-	 * @return \OC\Group\Manager
1146
-	 */
1147
-	public function getGroupManager() {
1148
-		return $this->query('GroupManager');
1149
-	}
1150
-
1151
-	/**
1152
-	 * @return \OC\User\Session
1153
-	 */
1154
-	public function getUserSession() {
1155
-		return $this->query('UserSession');
1156
-	}
1157
-
1158
-	/**
1159
-	 * @return \OCP\ISession
1160
-	 */
1161
-	public function getSession() {
1162
-		return $this->query('UserSession')->getSession();
1163
-	}
1164
-
1165
-	/**
1166
-	 * @param \OCP\ISession $session
1167
-	 */
1168
-	public function setSession(\OCP\ISession $session) {
1169
-		$this->query(SessionStorage::class)->setSession($session);
1170
-		$this->query('UserSession')->setSession($session);
1171
-		$this->query(Store::class)->setSession($session);
1172
-	}
1173
-
1174
-	/**
1175
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1176
-	 */
1177
-	public function getTwoFactorAuthManager() {
1178
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1179
-	}
1180
-
1181
-	/**
1182
-	 * @return \OC\NavigationManager
1183
-	 */
1184
-	public function getNavigationManager() {
1185
-		return $this->query('NavigationManager');
1186
-	}
1187
-
1188
-	/**
1189
-	 * @return \OCP\IConfig
1190
-	 */
1191
-	public function getConfig() {
1192
-		return $this->query('AllConfig');
1193
-	}
1194
-
1195
-	/**
1196
-	 * @internal For internal use only
1197
-	 * @return \OC\SystemConfig
1198
-	 */
1199
-	public function getSystemConfig() {
1200
-		return $this->query('SystemConfig');
1201
-	}
1202
-
1203
-	/**
1204
-	 * Returns the app config manager
1205
-	 *
1206
-	 * @return \OCP\IAppConfig
1207
-	 */
1208
-	public function getAppConfig() {
1209
-		return $this->query('AppConfig');
1210
-	}
1211
-
1212
-	/**
1213
-	 * @return \OCP\L10N\IFactory
1214
-	 */
1215
-	public function getL10NFactory() {
1216
-		return $this->query('L10NFactory');
1217
-	}
1218
-
1219
-	/**
1220
-	 * get an L10N instance
1221
-	 *
1222
-	 * @param string $app appid
1223
-	 * @param string $lang
1224
-	 * @return IL10N
1225
-	 */
1226
-	public function getL10N($app, $lang = null) {
1227
-		return $this->getL10NFactory()->get($app, $lang);
1228
-	}
1229
-
1230
-	/**
1231
-	 * @return \OCP\IURLGenerator
1232
-	 */
1233
-	public function getURLGenerator() {
1234
-		return $this->query('URLGenerator');
1235
-	}
1236
-
1237
-	/**
1238
-	 * @return \OCP\IHelper
1239
-	 */
1240
-	public function getHelper() {
1241
-		return $this->query('AppHelper');
1242
-	}
1243
-
1244
-	/**
1245
-	 * @return AppFetcher
1246
-	 */
1247
-	public function getAppFetcher() {
1248
-		return $this->query('AppFetcher');
1249
-	}
1250
-
1251
-	/**
1252
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1253
-	 * getMemCacheFactory() instead.
1254
-	 *
1255
-	 * @return \OCP\ICache
1256
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1257
-	 */
1258
-	public function getCache() {
1259
-		return $this->query('UserCache');
1260
-	}
1261
-
1262
-	/**
1263
-	 * Returns an \OCP\CacheFactory instance
1264
-	 *
1265
-	 * @return \OCP\ICacheFactory
1266
-	 */
1267
-	public function getMemCacheFactory() {
1268
-		return $this->query('MemCacheFactory');
1269
-	}
1270
-
1271
-	/**
1272
-	 * Returns an \OC\RedisFactory instance
1273
-	 *
1274
-	 * @return \OC\RedisFactory
1275
-	 */
1276
-	public function getGetRedisFactory() {
1277
-		return $this->query('RedisFactory');
1278
-	}
1279
-
1280
-
1281
-	/**
1282
-	 * Returns the current session
1283
-	 *
1284
-	 * @return \OCP\IDBConnection
1285
-	 */
1286
-	public function getDatabaseConnection() {
1287
-		return $this->query('DatabaseConnection');
1288
-	}
1289
-
1290
-	/**
1291
-	 * Returns the activity manager
1292
-	 *
1293
-	 * @return \OCP\Activity\IManager
1294
-	 */
1295
-	public function getActivityManager() {
1296
-		return $this->query('ActivityManager');
1297
-	}
1298
-
1299
-	/**
1300
-	 * Returns an job list for controlling background jobs
1301
-	 *
1302
-	 * @return \OCP\BackgroundJob\IJobList
1303
-	 */
1304
-	public function getJobList() {
1305
-		return $this->query('JobList');
1306
-	}
1307
-
1308
-	/**
1309
-	 * Returns a logger instance
1310
-	 *
1311
-	 * @return \OCP\ILogger
1312
-	 */
1313
-	public function getLogger() {
1314
-		return $this->query('Logger');
1315
-	}
1316
-
1317
-	/**
1318
-	 * Returns a router for generating and matching urls
1319
-	 *
1320
-	 * @return \OCP\Route\IRouter
1321
-	 */
1322
-	public function getRouter() {
1323
-		return $this->query('Router');
1324
-	}
1325
-
1326
-	/**
1327
-	 * Returns a search instance
1328
-	 *
1329
-	 * @return \OCP\ISearch
1330
-	 */
1331
-	public function getSearch() {
1332
-		return $this->query('Search');
1333
-	}
1334
-
1335
-	/**
1336
-	 * Returns a SecureRandom instance
1337
-	 *
1338
-	 * @return \OCP\Security\ISecureRandom
1339
-	 */
1340
-	public function getSecureRandom() {
1341
-		return $this->query('SecureRandom');
1342
-	}
1343
-
1344
-	/**
1345
-	 * Returns a Crypto instance
1346
-	 *
1347
-	 * @return \OCP\Security\ICrypto
1348
-	 */
1349
-	public function getCrypto() {
1350
-		return $this->query('Crypto');
1351
-	}
1352
-
1353
-	/**
1354
-	 * Returns a Hasher instance
1355
-	 *
1356
-	 * @return \OCP\Security\IHasher
1357
-	 */
1358
-	public function getHasher() {
1359
-		return $this->query('Hasher');
1360
-	}
1361
-
1362
-	/**
1363
-	 * Returns a CredentialsManager instance
1364
-	 *
1365
-	 * @return \OCP\Security\ICredentialsManager
1366
-	 */
1367
-	public function getCredentialsManager() {
1368
-		return $this->query('CredentialsManager');
1369
-	}
1370
-
1371
-	/**
1372
-	 * Returns an instance of the HTTP helper class
1373
-	 *
1374
-	 * @deprecated Use getHTTPClientService()
1375
-	 * @return \OC\HTTPHelper
1376
-	 */
1377
-	public function getHTTPHelper() {
1378
-		return $this->query('HTTPHelper');
1379
-	}
1380
-
1381
-	/**
1382
-	 * Get the certificate manager for the user
1383
-	 *
1384
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1385
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1386
-	 */
1387
-	public function getCertificateManager($userId = '') {
1388
-		if ($userId === '') {
1389
-			$userSession = $this->getUserSession();
1390
-			$user = $userSession->getUser();
1391
-			if (is_null($user)) {
1392
-				return null;
1393
-			}
1394
-			$userId = $user->getUID();
1395
-		}
1396
-		return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1397
-	}
1398
-
1399
-	/**
1400
-	 * Returns an instance of the HTTP client service
1401
-	 *
1402
-	 * @return \OCP\Http\Client\IClientService
1403
-	 */
1404
-	public function getHTTPClientService() {
1405
-		return $this->query('HttpClientService');
1406
-	}
1407
-
1408
-	/**
1409
-	 * Create a new event source
1410
-	 *
1411
-	 * @return \OCP\IEventSource
1412
-	 */
1413
-	public function createEventSource() {
1414
-		return new \OC_EventSource();
1415
-	}
1416
-
1417
-	/**
1418
-	 * Get the active event logger
1419
-	 *
1420
-	 * The returned logger only logs data when debug mode is enabled
1421
-	 *
1422
-	 * @return \OCP\Diagnostics\IEventLogger
1423
-	 */
1424
-	public function getEventLogger() {
1425
-		return $this->query('EventLogger');
1426
-	}
1427
-
1428
-	/**
1429
-	 * Get the active query logger
1430
-	 *
1431
-	 * The returned logger only logs data when debug mode is enabled
1432
-	 *
1433
-	 * @return \OCP\Diagnostics\IQueryLogger
1434
-	 */
1435
-	public function getQueryLogger() {
1436
-		return $this->query('QueryLogger');
1437
-	}
1438
-
1439
-	/**
1440
-	 * Get the manager for temporary files and folders
1441
-	 *
1442
-	 * @return \OCP\ITempManager
1443
-	 */
1444
-	public function getTempManager() {
1445
-		return $this->query('TempManager');
1446
-	}
1447
-
1448
-	/**
1449
-	 * Get the app manager
1450
-	 *
1451
-	 * @return \OCP\App\IAppManager
1452
-	 */
1453
-	public function getAppManager() {
1454
-		return $this->query('AppManager');
1455
-	}
1456
-
1457
-	/**
1458
-	 * Creates a new mailer
1459
-	 *
1460
-	 * @return \OCP\Mail\IMailer
1461
-	 */
1462
-	public function getMailer() {
1463
-		return $this->query('Mailer');
1464
-	}
1465
-
1466
-	/**
1467
-	 * Get the webroot
1468
-	 *
1469
-	 * @return string
1470
-	 */
1471
-	public function getWebRoot() {
1472
-		return $this->webRoot;
1473
-	}
1474
-
1475
-	/**
1476
-	 * @return \OC\OCSClient
1477
-	 */
1478
-	public function getOcsClient() {
1479
-		return $this->query('OcsClient');
1480
-	}
1481
-
1482
-	/**
1483
-	 * @return \OCP\IDateTimeZone
1484
-	 */
1485
-	public function getDateTimeZone() {
1486
-		return $this->query('DateTimeZone');
1487
-	}
1488
-
1489
-	/**
1490
-	 * @return \OCP\IDateTimeFormatter
1491
-	 */
1492
-	public function getDateTimeFormatter() {
1493
-		return $this->query('DateTimeFormatter');
1494
-	}
1495
-
1496
-	/**
1497
-	 * @return \OCP\Files\Config\IMountProviderCollection
1498
-	 */
1499
-	public function getMountProviderCollection() {
1500
-		return $this->query('MountConfigManager');
1501
-	}
1502
-
1503
-	/**
1504
-	 * Get the IniWrapper
1505
-	 *
1506
-	 * @return IniGetWrapper
1507
-	 */
1508
-	public function getIniWrapper() {
1509
-		return $this->query('IniWrapper');
1510
-	}
1511
-
1512
-	/**
1513
-	 * @return \OCP\Command\IBus
1514
-	 */
1515
-	public function getCommandBus() {
1516
-		return $this->query('AsyncCommandBus');
1517
-	}
1518
-
1519
-	/**
1520
-	 * Get the trusted domain helper
1521
-	 *
1522
-	 * @return TrustedDomainHelper
1523
-	 */
1524
-	public function getTrustedDomainHelper() {
1525
-		return $this->query('TrustedDomainHelper');
1526
-	}
1527
-
1528
-	/**
1529
-	 * Get the locking provider
1530
-	 *
1531
-	 * @return \OCP\Lock\ILockingProvider
1532
-	 * @since 8.1.0
1533
-	 */
1534
-	public function getLockingProvider() {
1535
-		return $this->query('LockingProvider');
1536
-	}
1537
-
1538
-	/**
1539
-	 * @return \OCP\Files\Mount\IMountManager
1540
-	 **/
1541
-	function getMountManager() {
1542
-		return $this->query('MountManager');
1543
-	}
1544
-
1545
-	/** @return \OCP\Files\Config\IUserMountCache */
1546
-	function getUserMountCache() {
1547
-		return $this->query('UserMountCache');
1548
-	}
1549
-
1550
-	/**
1551
-	 * Get the MimeTypeDetector
1552
-	 *
1553
-	 * @return \OCP\Files\IMimeTypeDetector
1554
-	 */
1555
-	public function getMimeTypeDetector() {
1556
-		return $this->query('MimeTypeDetector');
1557
-	}
1558
-
1559
-	/**
1560
-	 * Get the MimeTypeLoader
1561
-	 *
1562
-	 * @return \OCP\Files\IMimeTypeLoader
1563
-	 */
1564
-	public function getMimeTypeLoader() {
1565
-		return $this->query('MimeTypeLoader');
1566
-	}
1567
-
1568
-	/**
1569
-	 * Get the manager of all the capabilities
1570
-	 *
1571
-	 * @return \OC\CapabilitiesManager
1572
-	 */
1573
-	public function getCapabilitiesManager() {
1574
-		return $this->query('CapabilitiesManager');
1575
-	}
1576
-
1577
-	/**
1578
-	 * Get the EventDispatcher
1579
-	 *
1580
-	 * @return EventDispatcherInterface
1581
-	 * @since 8.2.0
1582
-	 */
1583
-	public function getEventDispatcher() {
1584
-		return $this->query('EventDispatcher');
1585
-	}
1586
-
1587
-	/**
1588
-	 * Get the Notification Manager
1589
-	 *
1590
-	 * @return \OCP\Notification\IManager
1591
-	 * @since 8.2.0
1592
-	 */
1593
-	public function getNotificationManager() {
1594
-		return $this->query('NotificationManager');
1595
-	}
1596
-
1597
-	/**
1598
-	 * @return \OCP\Comments\ICommentsManager
1599
-	 */
1600
-	public function getCommentsManager() {
1601
-		return $this->query('CommentsManager');
1602
-	}
1603
-
1604
-	/**
1605
-	 * @return \OCA\Theming\ThemingDefaults
1606
-	 */
1607
-	public function getThemingDefaults() {
1608
-		return $this->query('ThemingDefaults');
1609
-	}
1610
-
1611
-	/**
1612
-	 * @return \OC\IntegrityCheck\Checker
1613
-	 */
1614
-	public function getIntegrityCodeChecker() {
1615
-		return $this->query('IntegrityCodeChecker');
1616
-	}
1617
-
1618
-	/**
1619
-	 * @return \OC\Session\CryptoWrapper
1620
-	 */
1621
-	public function getSessionCryptoWrapper() {
1622
-		return $this->query('CryptoWrapper');
1623
-	}
1624
-
1625
-	/**
1626
-	 * @return CsrfTokenManager
1627
-	 */
1628
-	public function getCsrfTokenManager() {
1629
-		return $this->query('CsrfTokenManager');
1630
-	}
1631
-
1632
-	/**
1633
-	 * @return Throttler
1634
-	 */
1635
-	public function getBruteForceThrottler() {
1636
-		return $this->query('Throttler');
1637
-	}
1638
-
1639
-	/**
1640
-	 * @return IContentSecurityPolicyManager
1641
-	 */
1642
-	public function getContentSecurityPolicyManager() {
1643
-		return $this->query('ContentSecurityPolicyManager');
1644
-	}
1645
-
1646
-	/**
1647
-	 * @return ContentSecurityPolicyNonceManager
1648
-	 */
1649
-	public function getContentSecurityPolicyNonceManager() {
1650
-		return $this->query('ContentSecurityPolicyNonceManager');
1651
-	}
1652
-
1653
-	/**
1654
-	 * Not a public API as of 8.2, wait for 9.0
1655
-	 *
1656
-	 * @return \OCA\Files_External\Service\BackendService
1657
-	 */
1658
-	public function getStoragesBackendService() {
1659
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1660
-	}
1661
-
1662
-	/**
1663
-	 * Not a public API as of 8.2, wait for 9.0
1664
-	 *
1665
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1666
-	 */
1667
-	public function getGlobalStoragesService() {
1668
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1669
-	}
1670
-
1671
-	/**
1672
-	 * Not a public API as of 8.2, wait for 9.0
1673
-	 *
1674
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1675
-	 */
1676
-	public function getUserGlobalStoragesService() {
1677
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1678
-	}
1679
-
1680
-	/**
1681
-	 * Not a public API as of 8.2, wait for 9.0
1682
-	 *
1683
-	 * @return \OCA\Files_External\Service\UserStoragesService
1684
-	 */
1685
-	public function getUserStoragesService() {
1686
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1687
-	}
1688
-
1689
-	/**
1690
-	 * @return \OCP\Share\IManager
1691
-	 */
1692
-	public function getShareManager() {
1693
-		return $this->query('ShareManager');
1694
-	}
1695
-
1696
-	/**
1697
-	 * Returns the LDAP Provider
1698
-	 *
1699
-	 * @return \OCP\LDAP\ILDAPProvider
1700
-	 */
1701
-	public function getLDAPProvider() {
1702
-		return $this->query('LDAPProvider');
1703
-	}
1704
-
1705
-	/**
1706
-	 * @return \OCP\Settings\IManager
1707
-	 */
1708
-	public function getSettingsManager() {
1709
-		return $this->query('SettingsManager');
1710
-	}
1711
-
1712
-	/**
1713
-	 * @return \OCP\Files\IAppData
1714
-	 */
1715
-	public function getAppDataDir($app) {
1716
-		/** @var \OC\Files\AppData\Factory $factory */
1717
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1718
-		return $factory->get($app);
1719
-	}
1720
-
1721
-	/**
1722
-	 * @return \OCP\Lockdown\ILockdownManager
1723
-	 */
1724
-	public function getLockdownManager() {
1725
-		return $this->query('LockdownManager');
1726
-	}
1727
-
1728
-	/**
1729
-	 * @return \OCP\Federation\ICloudIdManager
1730
-	 */
1731
-	public function getCloudIdManager() {
1732
-		return $this->query(ICloudIdManager::class);
1733
-	}
832
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
833
+            if (isset($prefixes['OCA\\Theming\\'])) {
834
+                $classExists = true;
835
+            } else {
836
+                $classExists = false;
837
+            }
838
+
839
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) {
840
+                return new ThemingDefaults(
841
+                    $c->getConfig(),
842
+                    $c->getL10N('theming'),
843
+                    $c->getURLGenerator(),
844
+                    new \OC_Defaults(),
845
+                    $c->getAppDataDir('theming'),
846
+                    $c->getMemCacheFactory()
847
+                );
848
+            }
849
+            return new \OC_Defaults();
850
+        });
851
+        $this->registerService(EventDispatcher::class, function () {
852
+            return new EventDispatcher();
853
+        });
854
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
855
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856
+
857
+        $this->registerService('CryptoWrapper', function (Server $c) {
858
+            // FIXME: Instantiiated here due to cyclic dependency
859
+            $request = new Request(
860
+                [
861
+                    'get' => $_GET,
862
+                    'post' => $_POST,
863
+                    'files' => $_FILES,
864
+                    'server' => $_SERVER,
865
+                    'env' => $_ENV,
866
+                    'cookies' => $_COOKIE,
867
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
868
+                        ? $_SERVER['REQUEST_METHOD']
869
+                        : null,
870
+                ],
871
+                $c->getSecureRandom(),
872
+                $c->getConfig()
873
+            );
874
+
875
+            return new CryptoWrapper(
876
+                $c->getConfig(),
877
+                $c->getCrypto(),
878
+                $c->getSecureRandom(),
879
+                $request
880
+            );
881
+        });
882
+        $this->registerService('CsrfTokenManager', function (Server $c) {
883
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884
+
885
+            return new CsrfTokenManager(
886
+                $tokenGenerator,
887
+                $c->query(SessionStorage::class)
888
+            );
889
+        });
890
+        $this->registerService(SessionStorage::class, function (Server $c) {
891
+            return new SessionStorage($c->getSession());
892
+        });
893
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
894
+            return new ContentSecurityPolicyManager();
895
+        });
896
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
897
+
898
+        $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
899
+            return new ContentSecurityPolicyNonceManager(
900
+                $c->getCsrfTokenManager(),
901
+                $c->getRequest()
902
+            );
903
+        });
904
+
905
+        $this->registerService(\OCP\Share\IManager::class, function(Server $c) {
906
+            $config = $c->getConfig();
907
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory');
908
+            /** @var \OCP\Share\IProviderFactory $factory */
909
+            $factory = new $factoryClass($this);
910
+
911
+            $manager = new \OC\Share20\Manager(
912
+                $c->getLogger(),
913
+                $c->getConfig(),
914
+                $c->getSecureRandom(),
915
+                $c->getHasher(),
916
+                $c->getMountManager(),
917
+                $c->getGroupManager(),
918
+                $c->getL10N('core'),
919
+                $factory,
920
+                $c->getUserManager(),
921
+                $c->getLazyRootFolder(),
922
+                $c->getEventDispatcher()
923
+            );
924
+
925
+            return $manager;
926
+        });
927
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
928
+
929
+        $this->registerService('SettingsManager', function(Server $c) {
930
+            $manager = new \OC\Settings\Manager(
931
+                $c->getLogger(),
932
+                $c->getDatabaseConnection(),
933
+                $c->getL10N('lib'),
934
+                $c->getConfig(),
935
+                $c->getEncryptionManager(),
936
+                $c->getUserManager(),
937
+                $c->getLockingProvider(),
938
+                $c->getRequest(),
939
+                new \OC\Settings\Mapper($c->getDatabaseConnection()),
940
+                $c->getURLGenerator()
941
+            );
942
+            return $manager;
943
+        });
944
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
945
+            return new \OC\Files\AppData\Factory(
946
+                $c->getRootFolder(),
947
+                $c->getSystemConfig()
948
+            );
949
+        });
950
+
951
+        $this->registerService('LockdownManager', function (Server $c) {
952
+            return new LockdownManager(function() use ($c) {
953
+                return $c->getSession();
954
+            });
955
+        });
956
+
957
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
958
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959
+        });
960
+
961
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
962
+            return new CloudIdManager();
963
+        });
964
+
965
+        /* To trick DI since we don't extend the DIContainer here */
966
+        $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
967
+            return new CleanPreviewsBackgroundJob(
968
+                $c->getRootFolder(),
969
+                $c->getLogger(),
970
+                $c->getJobList(),
971
+                new TimeFactory()
972
+            );
973
+        });
974
+
975
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
976
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
977
+
978
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980
+
981
+        $this->registerService(Defaults::class, function (Server $c) {
982
+            return new Defaults(
983
+                $c->getThemingDefaults()
984
+            );
985
+        });
986
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
987
+
988
+        $this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
989
+            return $c->query(\OCP\IUserSession::class)->getSession();
990
+        });
991
+    }
992
+
993
+    /**
994
+     * @return \OCP\Contacts\IManager
995
+     */
996
+    public function getContactsManager() {
997
+        return $this->query('ContactsManager');
998
+    }
999
+
1000
+    /**
1001
+     * @return \OC\Encryption\Manager
1002
+     */
1003
+    public function getEncryptionManager() {
1004
+        return $this->query('EncryptionManager');
1005
+    }
1006
+
1007
+    /**
1008
+     * @return \OC\Encryption\File
1009
+     */
1010
+    public function getEncryptionFilesHelper() {
1011
+        return $this->query('EncryptionFileHelper');
1012
+    }
1013
+
1014
+    /**
1015
+     * @return \OCP\Encryption\Keys\IStorage
1016
+     */
1017
+    public function getEncryptionKeyStorage() {
1018
+        return $this->query('EncryptionKeyStorage');
1019
+    }
1020
+
1021
+    /**
1022
+     * The current request object holding all information about the request
1023
+     * currently being processed is returned from this method.
1024
+     * In case the current execution was not initiated by a web request null is returned
1025
+     *
1026
+     * @return \OCP\IRequest
1027
+     */
1028
+    public function getRequest() {
1029
+        return $this->query('Request');
1030
+    }
1031
+
1032
+    /**
1033
+     * Returns the preview manager which can create preview images for a given file
1034
+     *
1035
+     * @return \OCP\IPreview
1036
+     */
1037
+    public function getPreviewManager() {
1038
+        return $this->query('PreviewManager');
1039
+    }
1040
+
1041
+    /**
1042
+     * Returns the tag manager which can get and set tags for different object types
1043
+     *
1044
+     * @see \OCP\ITagManager::load()
1045
+     * @return \OCP\ITagManager
1046
+     */
1047
+    public function getTagManager() {
1048
+        return $this->query('TagManager');
1049
+    }
1050
+
1051
+    /**
1052
+     * Returns the system-tag manager
1053
+     *
1054
+     * @return \OCP\SystemTag\ISystemTagManager
1055
+     *
1056
+     * @since 9.0.0
1057
+     */
1058
+    public function getSystemTagManager() {
1059
+        return $this->query('SystemTagManager');
1060
+    }
1061
+
1062
+    /**
1063
+     * Returns the system-tag object mapper
1064
+     *
1065
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1066
+     *
1067
+     * @since 9.0.0
1068
+     */
1069
+    public function getSystemTagObjectMapper() {
1070
+        return $this->query('SystemTagObjectMapper');
1071
+    }
1072
+
1073
+    /**
1074
+     * Returns the avatar manager, used for avatar functionality
1075
+     *
1076
+     * @return \OCP\IAvatarManager
1077
+     */
1078
+    public function getAvatarManager() {
1079
+        return $this->query('AvatarManager');
1080
+    }
1081
+
1082
+    /**
1083
+     * Returns the root folder of ownCloud's data directory
1084
+     *
1085
+     * @return \OCP\Files\IRootFolder
1086
+     */
1087
+    public function getRootFolder() {
1088
+        return $this->query('LazyRootFolder');
1089
+    }
1090
+
1091
+    /**
1092
+     * Returns the root folder of ownCloud's data directory
1093
+     * This is the lazy variant so this gets only initialized once it
1094
+     * is actually used.
1095
+     *
1096
+     * @return \OCP\Files\IRootFolder
1097
+     */
1098
+    public function getLazyRootFolder() {
1099
+        return $this->query('LazyRootFolder');
1100
+    }
1101
+
1102
+    /**
1103
+     * Returns a view to ownCloud's files folder
1104
+     *
1105
+     * @param string $userId user ID
1106
+     * @return \OCP\Files\Folder|null
1107
+     */
1108
+    public function getUserFolder($userId = null) {
1109
+        if ($userId === null) {
1110
+            $user = $this->getUserSession()->getUser();
1111
+            if (!$user) {
1112
+                return null;
1113
+            }
1114
+            $userId = $user->getUID();
1115
+        }
1116
+        $root = $this->getRootFolder();
1117
+        return $root->getUserFolder($userId);
1118
+    }
1119
+
1120
+    /**
1121
+     * Returns an app-specific view in ownClouds data directory
1122
+     *
1123
+     * @return \OCP\Files\Folder
1124
+     * @deprecated since 9.2.0 use IAppData
1125
+     */
1126
+    public function getAppFolder() {
1127
+        $dir = '/' . \OC_App::getCurrentApp();
1128
+        $root = $this->getRootFolder();
1129
+        if (!$root->nodeExists($dir)) {
1130
+            $folder = $root->newFolder($dir);
1131
+        } else {
1132
+            $folder = $root->get($dir);
1133
+        }
1134
+        return $folder;
1135
+    }
1136
+
1137
+    /**
1138
+     * @return \OC\User\Manager
1139
+     */
1140
+    public function getUserManager() {
1141
+        return $this->query('UserManager');
1142
+    }
1143
+
1144
+    /**
1145
+     * @return \OC\Group\Manager
1146
+     */
1147
+    public function getGroupManager() {
1148
+        return $this->query('GroupManager');
1149
+    }
1150
+
1151
+    /**
1152
+     * @return \OC\User\Session
1153
+     */
1154
+    public function getUserSession() {
1155
+        return $this->query('UserSession');
1156
+    }
1157
+
1158
+    /**
1159
+     * @return \OCP\ISession
1160
+     */
1161
+    public function getSession() {
1162
+        return $this->query('UserSession')->getSession();
1163
+    }
1164
+
1165
+    /**
1166
+     * @param \OCP\ISession $session
1167
+     */
1168
+    public function setSession(\OCP\ISession $session) {
1169
+        $this->query(SessionStorage::class)->setSession($session);
1170
+        $this->query('UserSession')->setSession($session);
1171
+        $this->query(Store::class)->setSession($session);
1172
+    }
1173
+
1174
+    /**
1175
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1176
+     */
1177
+    public function getTwoFactorAuthManager() {
1178
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1179
+    }
1180
+
1181
+    /**
1182
+     * @return \OC\NavigationManager
1183
+     */
1184
+    public function getNavigationManager() {
1185
+        return $this->query('NavigationManager');
1186
+    }
1187
+
1188
+    /**
1189
+     * @return \OCP\IConfig
1190
+     */
1191
+    public function getConfig() {
1192
+        return $this->query('AllConfig');
1193
+    }
1194
+
1195
+    /**
1196
+     * @internal For internal use only
1197
+     * @return \OC\SystemConfig
1198
+     */
1199
+    public function getSystemConfig() {
1200
+        return $this->query('SystemConfig');
1201
+    }
1202
+
1203
+    /**
1204
+     * Returns the app config manager
1205
+     *
1206
+     * @return \OCP\IAppConfig
1207
+     */
1208
+    public function getAppConfig() {
1209
+        return $this->query('AppConfig');
1210
+    }
1211
+
1212
+    /**
1213
+     * @return \OCP\L10N\IFactory
1214
+     */
1215
+    public function getL10NFactory() {
1216
+        return $this->query('L10NFactory');
1217
+    }
1218
+
1219
+    /**
1220
+     * get an L10N instance
1221
+     *
1222
+     * @param string $app appid
1223
+     * @param string $lang
1224
+     * @return IL10N
1225
+     */
1226
+    public function getL10N($app, $lang = null) {
1227
+        return $this->getL10NFactory()->get($app, $lang);
1228
+    }
1229
+
1230
+    /**
1231
+     * @return \OCP\IURLGenerator
1232
+     */
1233
+    public function getURLGenerator() {
1234
+        return $this->query('URLGenerator');
1235
+    }
1236
+
1237
+    /**
1238
+     * @return \OCP\IHelper
1239
+     */
1240
+    public function getHelper() {
1241
+        return $this->query('AppHelper');
1242
+    }
1243
+
1244
+    /**
1245
+     * @return AppFetcher
1246
+     */
1247
+    public function getAppFetcher() {
1248
+        return $this->query('AppFetcher');
1249
+    }
1250
+
1251
+    /**
1252
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1253
+     * getMemCacheFactory() instead.
1254
+     *
1255
+     * @return \OCP\ICache
1256
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1257
+     */
1258
+    public function getCache() {
1259
+        return $this->query('UserCache');
1260
+    }
1261
+
1262
+    /**
1263
+     * Returns an \OCP\CacheFactory instance
1264
+     *
1265
+     * @return \OCP\ICacheFactory
1266
+     */
1267
+    public function getMemCacheFactory() {
1268
+        return $this->query('MemCacheFactory');
1269
+    }
1270
+
1271
+    /**
1272
+     * Returns an \OC\RedisFactory instance
1273
+     *
1274
+     * @return \OC\RedisFactory
1275
+     */
1276
+    public function getGetRedisFactory() {
1277
+        return $this->query('RedisFactory');
1278
+    }
1279
+
1280
+
1281
+    /**
1282
+     * Returns the current session
1283
+     *
1284
+     * @return \OCP\IDBConnection
1285
+     */
1286
+    public function getDatabaseConnection() {
1287
+        return $this->query('DatabaseConnection');
1288
+    }
1289
+
1290
+    /**
1291
+     * Returns the activity manager
1292
+     *
1293
+     * @return \OCP\Activity\IManager
1294
+     */
1295
+    public function getActivityManager() {
1296
+        return $this->query('ActivityManager');
1297
+    }
1298
+
1299
+    /**
1300
+     * Returns an job list for controlling background jobs
1301
+     *
1302
+     * @return \OCP\BackgroundJob\IJobList
1303
+     */
1304
+    public function getJobList() {
1305
+        return $this->query('JobList');
1306
+    }
1307
+
1308
+    /**
1309
+     * Returns a logger instance
1310
+     *
1311
+     * @return \OCP\ILogger
1312
+     */
1313
+    public function getLogger() {
1314
+        return $this->query('Logger');
1315
+    }
1316
+
1317
+    /**
1318
+     * Returns a router for generating and matching urls
1319
+     *
1320
+     * @return \OCP\Route\IRouter
1321
+     */
1322
+    public function getRouter() {
1323
+        return $this->query('Router');
1324
+    }
1325
+
1326
+    /**
1327
+     * Returns a search instance
1328
+     *
1329
+     * @return \OCP\ISearch
1330
+     */
1331
+    public function getSearch() {
1332
+        return $this->query('Search');
1333
+    }
1334
+
1335
+    /**
1336
+     * Returns a SecureRandom instance
1337
+     *
1338
+     * @return \OCP\Security\ISecureRandom
1339
+     */
1340
+    public function getSecureRandom() {
1341
+        return $this->query('SecureRandom');
1342
+    }
1343
+
1344
+    /**
1345
+     * Returns a Crypto instance
1346
+     *
1347
+     * @return \OCP\Security\ICrypto
1348
+     */
1349
+    public function getCrypto() {
1350
+        return $this->query('Crypto');
1351
+    }
1352
+
1353
+    /**
1354
+     * Returns a Hasher instance
1355
+     *
1356
+     * @return \OCP\Security\IHasher
1357
+     */
1358
+    public function getHasher() {
1359
+        return $this->query('Hasher');
1360
+    }
1361
+
1362
+    /**
1363
+     * Returns a CredentialsManager instance
1364
+     *
1365
+     * @return \OCP\Security\ICredentialsManager
1366
+     */
1367
+    public function getCredentialsManager() {
1368
+        return $this->query('CredentialsManager');
1369
+    }
1370
+
1371
+    /**
1372
+     * Returns an instance of the HTTP helper class
1373
+     *
1374
+     * @deprecated Use getHTTPClientService()
1375
+     * @return \OC\HTTPHelper
1376
+     */
1377
+    public function getHTTPHelper() {
1378
+        return $this->query('HTTPHelper');
1379
+    }
1380
+
1381
+    /**
1382
+     * Get the certificate manager for the user
1383
+     *
1384
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1385
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1386
+     */
1387
+    public function getCertificateManager($userId = '') {
1388
+        if ($userId === '') {
1389
+            $userSession = $this->getUserSession();
1390
+            $user = $userSession->getUser();
1391
+            if (is_null($user)) {
1392
+                return null;
1393
+            }
1394
+            $userId = $user->getUID();
1395
+        }
1396
+        return new CertificateManager($userId, new View(), $this->getConfig(), $this->getLogger());
1397
+    }
1398
+
1399
+    /**
1400
+     * Returns an instance of the HTTP client service
1401
+     *
1402
+     * @return \OCP\Http\Client\IClientService
1403
+     */
1404
+    public function getHTTPClientService() {
1405
+        return $this->query('HttpClientService');
1406
+    }
1407
+
1408
+    /**
1409
+     * Create a new event source
1410
+     *
1411
+     * @return \OCP\IEventSource
1412
+     */
1413
+    public function createEventSource() {
1414
+        return new \OC_EventSource();
1415
+    }
1416
+
1417
+    /**
1418
+     * Get the active event logger
1419
+     *
1420
+     * The returned logger only logs data when debug mode is enabled
1421
+     *
1422
+     * @return \OCP\Diagnostics\IEventLogger
1423
+     */
1424
+    public function getEventLogger() {
1425
+        return $this->query('EventLogger');
1426
+    }
1427
+
1428
+    /**
1429
+     * Get the active query logger
1430
+     *
1431
+     * The returned logger only logs data when debug mode is enabled
1432
+     *
1433
+     * @return \OCP\Diagnostics\IQueryLogger
1434
+     */
1435
+    public function getQueryLogger() {
1436
+        return $this->query('QueryLogger');
1437
+    }
1438
+
1439
+    /**
1440
+     * Get the manager for temporary files and folders
1441
+     *
1442
+     * @return \OCP\ITempManager
1443
+     */
1444
+    public function getTempManager() {
1445
+        return $this->query('TempManager');
1446
+    }
1447
+
1448
+    /**
1449
+     * Get the app manager
1450
+     *
1451
+     * @return \OCP\App\IAppManager
1452
+     */
1453
+    public function getAppManager() {
1454
+        return $this->query('AppManager');
1455
+    }
1456
+
1457
+    /**
1458
+     * Creates a new mailer
1459
+     *
1460
+     * @return \OCP\Mail\IMailer
1461
+     */
1462
+    public function getMailer() {
1463
+        return $this->query('Mailer');
1464
+    }
1465
+
1466
+    /**
1467
+     * Get the webroot
1468
+     *
1469
+     * @return string
1470
+     */
1471
+    public function getWebRoot() {
1472
+        return $this->webRoot;
1473
+    }
1474
+
1475
+    /**
1476
+     * @return \OC\OCSClient
1477
+     */
1478
+    public function getOcsClient() {
1479
+        return $this->query('OcsClient');
1480
+    }
1481
+
1482
+    /**
1483
+     * @return \OCP\IDateTimeZone
1484
+     */
1485
+    public function getDateTimeZone() {
1486
+        return $this->query('DateTimeZone');
1487
+    }
1488
+
1489
+    /**
1490
+     * @return \OCP\IDateTimeFormatter
1491
+     */
1492
+    public function getDateTimeFormatter() {
1493
+        return $this->query('DateTimeFormatter');
1494
+    }
1495
+
1496
+    /**
1497
+     * @return \OCP\Files\Config\IMountProviderCollection
1498
+     */
1499
+    public function getMountProviderCollection() {
1500
+        return $this->query('MountConfigManager');
1501
+    }
1502
+
1503
+    /**
1504
+     * Get the IniWrapper
1505
+     *
1506
+     * @return IniGetWrapper
1507
+     */
1508
+    public function getIniWrapper() {
1509
+        return $this->query('IniWrapper');
1510
+    }
1511
+
1512
+    /**
1513
+     * @return \OCP\Command\IBus
1514
+     */
1515
+    public function getCommandBus() {
1516
+        return $this->query('AsyncCommandBus');
1517
+    }
1518
+
1519
+    /**
1520
+     * Get the trusted domain helper
1521
+     *
1522
+     * @return TrustedDomainHelper
1523
+     */
1524
+    public function getTrustedDomainHelper() {
1525
+        return $this->query('TrustedDomainHelper');
1526
+    }
1527
+
1528
+    /**
1529
+     * Get the locking provider
1530
+     *
1531
+     * @return \OCP\Lock\ILockingProvider
1532
+     * @since 8.1.0
1533
+     */
1534
+    public function getLockingProvider() {
1535
+        return $this->query('LockingProvider');
1536
+    }
1537
+
1538
+    /**
1539
+     * @return \OCP\Files\Mount\IMountManager
1540
+     **/
1541
+    function getMountManager() {
1542
+        return $this->query('MountManager');
1543
+    }
1544
+
1545
+    /** @return \OCP\Files\Config\IUserMountCache */
1546
+    function getUserMountCache() {
1547
+        return $this->query('UserMountCache');
1548
+    }
1549
+
1550
+    /**
1551
+     * Get the MimeTypeDetector
1552
+     *
1553
+     * @return \OCP\Files\IMimeTypeDetector
1554
+     */
1555
+    public function getMimeTypeDetector() {
1556
+        return $this->query('MimeTypeDetector');
1557
+    }
1558
+
1559
+    /**
1560
+     * Get the MimeTypeLoader
1561
+     *
1562
+     * @return \OCP\Files\IMimeTypeLoader
1563
+     */
1564
+    public function getMimeTypeLoader() {
1565
+        return $this->query('MimeTypeLoader');
1566
+    }
1567
+
1568
+    /**
1569
+     * Get the manager of all the capabilities
1570
+     *
1571
+     * @return \OC\CapabilitiesManager
1572
+     */
1573
+    public function getCapabilitiesManager() {
1574
+        return $this->query('CapabilitiesManager');
1575
+    }
1576
+
1577
+    /**
1578
+     * Get the EventDispatcher
1579
+     *
1580
+     * @return EventDispatcherInterface
1581
+     * @since 8.2.0
1582
+     */
1583
+    public function getEventDispatcher() {
1584
+        return $this->query('EventDispatcher');
1585
+    }
1586
+
1587
+    /**
1588
+     * Get the Notification Manager
1589
+     *
1590
+     * @return \OCP\Notification\IManager
1591
+     * @since 8.2.0
1592
+     */
1593
+    public function getNotificationManager() {
1594
+        return $this->query('NotificationManager');
1595
+    }
1596
+
1597
+    /**
1598
+     * @return \OCP\Comments\ICommentsManager
1599
+     */
1600
+    public function getCommentsManager() {
1601
+        return $this->query('CommentsManager');
1602
+    }
1603
+
1604
+    /**
1605
+     * @return \OCA\Theming\ThemingDefaults
1606
+     */
1607
+    public function getThemingDefaults() {
1608
+        return $this->query('ThemingDefaults');
1609
+    }
1610
+
1611
+    /**
1612
+     * @return \OC\IntegrityCheck\Checker
1613
+     */
1614
+    public function getIntegrityCodeChecker() {
1615
+        return $this->query('IntegrityCodeChecker');
1616
+    }
1617
+
1618
+    /**
1619
+     * @return \OC\Session\CryptoWrapper
1620
+     */
1621
+    public function getSessionCryptoWrapper() {
1622
+        return $this->query('CryptoWrapper');
1623
+    }
1624
+
1625
+    /**
1626
+     * @return CsrfTokenManager
1627
+     */
1628
+    public function getCsrfTokenManager() {
1629
+        return $this->query('CsrfTokenManager');
1630
+    }
1631
+
1632
+    /**
1633
+     * @return Throttler
1634
+     */
1635
+    public function getBruteForceThrottler() {
1636
+        return $this->query('Throttler');
1637
+    }
1638
+
1639
+    /**
1640
+     * @return IContentSecurityPolicyManager
1641
+     */
1642
+    public function getContentSecurityPolicyManager() {
1643
+        return $this->query('ContentSecurityPolicyManager');
1644
+    }
1645
+
1646
+    /**
1647
+     * @return ContentSecurityPolicyNonceManager
1648
+     */
1649
+    public function getContentSecurityPolicyNonceManager() {
1650
+        return $this->query('ContentSecurityPolicyNonceManager');
1651
+    }
1652
+
1653
+    /**
1654
+     * Not a public API as of 8.2, wait for 9.0
1655
+     *
1656
+     * @return \OCA\Files_External\Service\BackendService
1657
+     */
1658
+    public function getStoragesBackendService() {
1659
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1660
+    }
1661
+
1662
+    /**
1663
+     * Not a public API as of 8.2, wait for 9.0
1664
+     *
1665
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1666
+     */
1667
+    public function getGlobalStoragesService() {
1668
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1669
+    }
1670
+
1671
+    /**
1672
+     * Not a public API as of 8.2, wait for 9.0
1673
+     *
1674
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1675
+     */
1676
+    public function getUserGlobalStoragesService() {
1677
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1678
+    }
1679
+
1680
+    /**
1681
+     * Not a public API as of 8.2, wait for 9.0
1682
+     *
1683
+     * @return \OCA\Files_External\Service\UserStoragesService
1684
+     */
1685
+    public function getUserStoragesService() {
1686
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1687
+    }
1688
+
1689
+    /**
1690
+     * @return \OCP\Share\IManager
1691
+     */
1692
+    public function getShareManager() {
1693
+        return $this->query('ShareManager');
1694
+    }
1695
+
1696
+    /**
1697
+     * Returns the LDAP Provider
1698
+     *
1699
+     * @return \OCP\LDAP\ILDAPProvider
1700
+     */
1701
+    public function getLDAPProvider() {
1702
+        return $this->query('LDAPProvider');
1703
+    }
1704
+
1705
+    /**
1706
+     * @return \OCP\Settings\IManager
1707
+     */
1708
+    public function getSettingsManager() {
1709
+        return $this->query('SettingsManager');
1710
+    }
1711
+
1712
+    /**
1713
+     * @return \OCP\Files\IAppData
1714
+     */
1715
+    public function getAppDataDir($app) {
1716
+        /** @var \OC\Files\AppData\Factory $factory */
1717
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1718
+        return $factory->get($app);
1719
+    }
1720
+
1721
+    /**
1722
+     * @return \OCP\Lockdown\ILockdownManager
1723
+     */
1724
+    public function getLockdownManager() {
1725
+        return $this->query('LockdownManager');
1726
+    }
1727
+
1728
+    /**
1729
+     * @return \OCP\Federation\ICloudIdManager
1730
+     */
1731
+    public function getCloudIdManager() {
1732
+        return $this->query(ICloudIdManager::class);
1733
+    }
1734 1734
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
 		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
132 132
 		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
133 133
 
134
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
134
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
135 135
 			return new PreviewManager(
136 136
 				$c->getConfig(),
137 137
 				$c->getRootFolder(),
@@ -142,13 +142,13 @@  discard block
 block discarded – undo
142 142
 		});
143 143
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
144 144
 
145
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
145
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
146 146
 			return new \OC\Preview\Watcher(
147 147
 				$c->getAppDataDir('preview')
148 148
 			);
149 149
 		});
150 150
 
151
-		$this->registerService('EncryptionManager', function (Server $c) {
151
+		$this->registerService('EncryptionManager', function(Server $c) {
152 152
 			$view = new View();
153 153
 			$util = new Encryption\Util(
154 154
 				$view,
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
 			);
167 167
 		});
168 168
 
169
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
169
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
170 170
 			$util = new Encryption\Util(
171 171
 				new View(),
172 172
 				$c->getUserManager(),
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			return new Encryption\File($util);
177 177
 		});
178 178
 
179
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
179
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
180 180
 			$view = new View();
181 181
 			$util = new Encryption\Util(
182 182
 				$view,
@@ -187,32 +187,32 @@  discard block
 block discarded – undo
187 187
 
188 188
 			return new Encryption\Keys\Storage($view, $util);
189 189
 		});
190
-		$this->registerService('TagMapper', function (Server $c) {
190
+		$this->registerService('TagMapper', function(Server $c) {
191 191
 			return new TagMapper($c->getDatabaseConnection());
192 192
 		});
193 193
 
194
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
194
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
195 195
 			$tagMapper = $c->query('TagMapper');
196 196
 			return new TagManager($tagMapper, $c->getUserSession());
197 197
 		});
198 198
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
199 199
 
200
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
200
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
201 201
 			$config = $c->getConfig();
202 202
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory');
203 203
 			/** @var \OC\SystemTag\ManagerFactory $factory */
204 204
 			$factory = new $factoryClass($this);
205 205
 			return $factory;
206 206
 		});
207
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
207
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
208 208
 			return $c->query('SystemTagManagerFactory')->getManager();
209 209
 		});
210 210
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
211 211
 
212
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
212
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
213 213
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
214 214
 		});
215
-		$this->registerService('RootFolder', function (Server $c) {
215
+		$this->registerService('RootFolder', function(Server $c) {
216 216
 			$manager = \OC\Files\Filesystem::getMountManager(null);
217 217
 			$view = new View();
218 218
 			$root = new Root(
@@ -240,30 +240,30 @@  discard block
 block discarded – undo
240 240
 		});
241 241
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
242 242
 
243
-		$this->registerService(\OCP\IUserManager::class, function (Server $c) {
243
+		$this->registerService(\OCP\IUserManager::class, function(Server $c) {
244 244
 			$config = $c->getConfig();
245 245
 			return new \OC\User\Manager($config);
246 246
 		});
247 247
 		$this->registerAlias('UserManager', \OCP\IUserManager::class);
248 248
 
249
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
249
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
250 250
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
251
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
251
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
252 252
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
253 253
 			});
254
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
254
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
255 255
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
256 256
 			});
257
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
257
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
258 258
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
259 259
 			});
260
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
260
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
261 261
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
262 262
 			});
263
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
263
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
264 264
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
265 265
 			});
266
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
266
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
267 267
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
268 268
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
269 269
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 			return new Store($session, $logger, $tokenProvider);
284 284
 		});
285 285
 		$this->registerAlias(IStore::class, Store::class);
286
-		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) {
286
+		$this->registerService('OC\Authentication\Token\DefaultTokenMapper', function(Server $c) {
287 287
 			$dbConnection = $c->getDatabaseConnection();
288 288
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
289 289
 		});
290
-		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) {
290
+		$this->registerService('OC\Authentication\Token\DefaultTokenProvider', function(Server $c) {
291 291
 			$mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper');
292 292
 			$crypto = $c->getCrypto();
293 293
 			$config = $c->getConfig();
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
 		});
298 298
 		$this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider');
299 299
 
300
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
300
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
301 301
 			$manager = $c->getUserManager();
302 302
 			$session = new \OC\Session\Memory('');
303 303
 			$timeFactory = new TimeFactory();
@@ -310,40 +310,40 @@  discard block
 block discarded – undo
310 310
 			}
311 311
 
312 312
 			$userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager());
313
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
313
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
314 314
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
315 315
 			});
316
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
316
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
317 317
 				/** @var $user \OC\User\User */
318 318
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
319 319
 			});
320
-			$userSession->listen('\OC\User', 'preDelete', function ($user) {
320
+			$userSession->listen('\OC\User', 'preDelete', function($user) {
321 321
 				/** @var $user \OC\User\User */
322 322
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
323 323
 			});
324
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
324
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
325 325
 				/** @var $user \OC\User\User */
326 326
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
327 327
 			});
328
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
328
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
329 329
 				/** @var $user \OC\User\User */
330 330
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
331 331
 			});
332
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
332
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
333 333
 				/** @var $user \OC\User\User */
334 334
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
335 335
 			});
336
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
336
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
337 337
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
338 338
 			});
339
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
339
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
340 340
 				/** @var $user \OC\User\User */
341 341
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
342 342
 			});
343
-			$userSession->listen('\OC\User', 'logout', function () {
343
+			$userSession->listen('\OC\User', 'logout', function() {
344 344
 				\OC_Hook::emit('OC_User', 'logout', array());
345 345
 			});
346
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) {
346
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value) {
347 347
 				/** @var $user \OC\User\User */
348 348
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value));
349 349
 			});
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
 		});
352 352
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
353 353
 
354
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
354
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
355 355
 			return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger());
356 356
 		});
357 357
 
358 358
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
359 359
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
360 360
 
361
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
361
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
362 362
 			return new \OC\AllConfig(
363 363
 				$c->getSystemConfig()
364 364
 			);
@@ -366,17 +366,17 @@  discard block
 block discarded – undo
366 366
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
367 367
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
368 368
 
369
-		$this->registerService('SystemConfig', function ($c) use ($config) {
369
+		$this->registerService('SystemConfig', function($c) use ($config) {
370 370
 			return new \OC\SystemConfig($config);
371 371
 		});
372 372
 
373
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
373
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
374 374
 			return new \OC\AppConfig($c->getDatabaseConnection());
375 375
 		});
376 376
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
377 377
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
378 378
 
379
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
379
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
380 380
 			return new \OC\L10N\Factory(
381 381
 				$c->getConfig(),
382 382
 				$c->getRequest(),
@@ -386,7 +386,7 @@  discard block
 block discarded – undo
386 386
 		});
387 387
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
388 388
 
389
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
389
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
390 390
 			$config = $c->getConfig();
391 391
 			$cacheFactory = $c->getMemCacheFactory();
392 392
 			return new \OC\URLGenerator(
@@ -396,10 +396,10 @@  discard block
 block discarded – undo
396 396
 		});
397 397
 		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
398 398
 
399
-		$this->registerService('AppHelper', function ($c) {
399
+		$this->registerService('AppHelper', function($c) {
400 400
 			return new \OC\AppHelper();
401 401
 		});
402
-		$this->registerService('AppFetcher', function ($c) {
402
+		$this->registerService('AppFetcher', function($c) {
403 403
 			return new AppFetcher(
404 404
 				$this->getAppDataDir('appstore'),
405 405
 				$this->getHTTPClientService(),
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 				$this->getConfig()
408 408
 			);
409 409
 		});
410
-		$this->registerService('CategoryFetcher', function ($c) {
410
+		$this->registerService('CategoryFetcher', function($c) {
411 411
 			return new CategoryFetcher(
412 412
 				$this->getAppDataDir('appstore'),
413 413
 				$this->getHTTPClientService(),
@@ -416,21 +416,21 @@  discard block
 block discarded – undo
416 416
 			);
417 417
 		});
418 418
 
419
-		$this->registerService(\OCP\ICache::class, function ($c) {
419
+		$this->registerService(\OCP\ICache::class, function($c) {
420 420
 			return new Cache\File();
421 421
 		});
422 422
 		$this->registerAlias('UserCache', \OCP\ICache::class);
423 423
 
424
-		$this->registerService(Factory::class, function (Server $c) {
424
+		$this->registerService(Factory::class, function(Server $c) {
425 425
 			$config = $c->getConfig();
426 426
 
427 427
 			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
428 428
 				$v = \OC_App::getAppVersions();
429
-				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php'));
429
+				$v['core'] = md5(file_get_contents(\OC::$SERVERROOT.'/version.php'));
430 430
 				$version = implode(',', $v);
431 431
 				$instanceId = \OC_Util::getInstanceId();
432 432
 				$path = \OC::$SERVERROOT;
433
-				$prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT);
433
+				$prefix = md5($instanceId.'-'.$version.'-'.$path.'-'.\OC::$WEBROOT);
434 434
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
435 435
 					$config->getSystemValue('memcache.local', null),
436 436
 					$config->getSystemValue('memcache.distributed', null),
@@ -447,12 +447,12 @@  discard block
 block discarded – undo
447 447
 		$this->registerAlias('MemCacheFactory', Factory::class);
448 448
 		$this->registerAlias(ICacheFactory::class, Factory::class);
449 449
 
450
-		$this->registerService('RedisFactory', function (Server $c) {
450
+		$this->registerService('RedisFactory', function(Server $c) {
451 451
 			$systemConfig = $c->getSystemConfig();
452 452
 			return new RedisFactory($systemConfig);
453 453
 		});
454 454
 
455
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
455
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
456 456
 			return new \OC\Activity\Manager(
457 457
 				$c->getRequest(),
458 458
 				$c->getUserSession(),
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
 		});
463 463
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
464 464
 
465
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
465
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
466 466
 			return new \OC\Activity\EventMerger(
467 467
 				$c->getL10N('lib')
468 468
 			);
469 469
 		});
470 470
 		$this->registerAlias(IValidator::class, Validator::class);
471 471
 
472
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
472
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
473 473
 			return new AvatarManager(
474 474
 				$c->getUserManager(),
475 475
 				$c->getAppDataDir('avatar'),
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
 		});
481 481
 		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
482 482
 
483
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
483
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
484 484
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
485 485
 			$logger = Log::getLogClass($logType);
486 486
 			call_user_func(array($logger, 'init'));
@@ -489,7 +489,7 @@  discard block
 block discarded – undo
489 489
 		});
490 490
 		$this->registerAlias('Logger', \OCP\ILogger::class);
491 491
 
492
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
492
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
493 493
 			$config = $c->getConfig();
494 494
 			return new \OC\BackgroundJob\JobList(
495 495
 				$c->getDatabaseConnection(),
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
 		});
500 500
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
501 501
 
502
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
502
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
503 503
 			$cacheFactory = $c->getMemCacheFactory();
504 504
 			$logger = $c->getLogger();
505 505
 			if ($cacheFactory->isAvailable()) {
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		});
512 512
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
513 513
 
514
-		$this->registerService(\OCP\ISearch::class, function ($c) {
514
+		$this->registerService(\OCP\ISearch::class, function($c) {
515 515
 			return new Search();
516 516
 		});
517 517
 		$this->registerAlias('Search', \OCP\ISearch::class);
@@ -531,27 +531,27 @@  discard block
 block discarded – undo
531 531
 			);
532 532
 		});
533 533
 
534
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
534
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
535 535
 			return new SecureRandom();
536 536
 		});
537 537
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
538 538
 
539
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
539
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
540 540
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
541 541
 		});
542 542
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
543 543
 
544
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
544
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
545 545
 			return new Hasher($c->getConfig());
546 546
 		});
547 547
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
548 548
 
549
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
549
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
550 550
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
551 551
 		});
552 552
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
553 553
 
554
-		$this->registerService(IDBConnection::class, function (Server $c) {
554
+		$this->registerService(IDBConnection::class, function(Server $c) {
555 555
 			$systemConfig = $c->getSystemConfig();
556 556
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
557 557
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -565,7 +565,7 @@  discard block
 block discarded – undo
565 565
 		});
566 566
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
567 567
 
568
-		$this->registerService('HTTPHelper', function (Server $c) {
568
+		$this->registerService('HTTPHelper', function(Server $c) {
569 569
 			$config = $c->getConfig();
570 570
 			return new HTTPHelper(
571 571
 				$config,
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
 			);
574 574
 		});
575 575
 
576
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
576
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
577 577
 			$user = \OC_User::getUser();
578 578
 			$uid = $user ? $user : null;
579 579
 			return new ClientService(
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
 		});
584 584
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
585 585
 
586
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
586
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
587 587
 			if ($c->getSystemConfig()->getValue('debug', false)) {
588 588
 				return new EventLogger();
589 589
 			} else {
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 		});
593 593
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
594 594
 
595
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
595
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
596 596
 			if ($c->getSystemConfig()->getValue('debug', false)) {
597 597
 				return new QueryLogger();
598 598
 			} else {
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
 		});
602 602
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
603 603
 
604
-		$this->registerService(TempManager::class, function (Server $c) {
604
+		$this->registerService(TempManager::class, function(Server $c) {
605 605
 			return new TempManager(
606 606
 				$c->getLogger(),
607 607
 				$c->getConfig()
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
 		$this->registerAlias('TempManager', TempManager::class);
611 611
 		$this->registerAlias(ITempManager::class, TempManager::class);
612 612
 
613
-		$this->registerService(AppManager::class, function (Server $c) {
613
+		$this->registerService(AppManager::class, function(Server $c) {
614 614
 			return new \OC\App\AppManager(
615 615
 				$c->getUserSession(),
616 616
 				$c->getAppConfig(),
@@ -622,7 +622,7 @@  discard block
 block discarded – undo
622 622
 		$this->registerAlias('AppManager', AppManager::class);
623 623
 		$this->registerAlias(IAppManager::class, AppManager::class);
624 624
 
625
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
625
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
626 626
 			return new DateTimeZone(
627 627
 				$c->getConfig(),
628 628
 				$c->getSession()
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 		});
631 631
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
632 632
 
633
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
633
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
634 634
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
635 635
 
636 636
 			return new DateTimeFormatter(
@@ -640,7 +640,7 @@  discard block
 block discarded – undo
640 640
 		});
641 641
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
642 642
 
643
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
643
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
644 644
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
645 645
 			$listener = new UserMountCacheListener($mountCache);
646 646
 			$listener->listen($c->getUserManager());
@@ -648,10 +648,10 @@  discard block
 block discarded – undo
648 648
 		});
649 649
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
650 650
 
651
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
651
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
652 652
 			$loader = \OC\Files\Filesystem::getLoader();
653 653
 			$mountCache = $c->query('UserMountCache');
654
-			$manager =  new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
654
+			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
655 655
 
656 656
 			// builtin providers
657 657
 
@@ -664,14 +664,14 @@  discard block
 block discarded – undo
664 664
 		});
665 665
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
666 666
 
667
-		$this->registerService('IniWrapper', function ($c) {
667
+		$this->registerService('IniWrapper', function($c) {
668 668
 			return new IniGetWrapper();
669 669
 		});
670
-		$this->registerService('AsyncCommandBus', function (Server $c) {
670
+		$this->registerService('AsyncCommandBus', function(Server $c) {
671 671
 			$jobList = $c->getJobList();
672 672
 			return new AsyncBus($jobList);
673 673
 		});
674
-		$this->registerService('TrustedDomainHelper', function ($c) {
674
+		$this->registerService('TrustedDomainHelper', function($c) {
675 675
 			return new TrustedDomainHelper($this->getConfig());
676 676
 		});
677 677
 		$this->registerService('Throttler', function(Server $c) {
@@ -682,10 +682,10 @@  discard block
 block discarded – undo
682 682
 				$c->getConfig()
683 683
 			);
684 684
 		});
685
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
685
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
686 686
 			// IConfig and IAppManager requires a working database. This code
687 687
 			// might however be called when ownCloud is not yet setup.
688
-			if(\OC::$server->getSystemConfig()->getValue('installed', false)) {
688
+			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
689 689
 				$config = $c->getConfig();
690 690
 				$appManager = $c->getAppManager();
691 691
 			} else {
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 					$c->getTempManager()
704 704
 			);
705 705
 		});
706
-		$this->registerService(\OCP\IRequest::class, function ($c) {
706
+		$this->registerService(\OCP\IRequest::class, function($c) {
707 707
 			if (isset($this['urlParams'])) {
708 708
 				$urlParams = $this['urlParams'];
709 709
 			} else {
@@ -739,7 +739,7 @@  discard block
 block discarded – undo
739 739
 		});
740 740
 		$this->registerAlias('Request', \OCP\IRequest::class);
741 741
 
742
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
742
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
743 743
 			return new Mailer(
744 744
 				$c->getConfig(),
745 745
 				$c->getLogger(),
@@ -753,14 +753,14 @@  discard block
 block discarded – undo
753 753
 		$this->registerService('LDAPProvider', function(Server $c) {
754 754
 			$config = $c->getConfig();
755 755
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
756
-			if(is_null($factoryClass)) {
756
+			if (is_null($factoryClass)) {
757 757
 				throw new \Exception('ldapProviderFactory not set');
758 758
 			}
759 759
 			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
760 760
 			$factory = new $factoryClass($this);
761 761
 			return $factory->getLDAPProvider();
762 762
 		});
763
-		$this->registerService('LockingProvider', function (Server $c) {
763
+		$this->registerService('LockingProvider', function(Server $c) {
764 764
 			$ini = $c->getIniWrapper();
765 765
 			$config = $c->getConfig();
766 766
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -776,37 +776,37 @@  discard block
 block discarded – undo
776 776
 			return new NoopLockingProvider();
777 777
 		});
778 778
 
779
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
779
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
780 780
 			return new \OC\Files\Mount\Manager();
781 781
 		});
782 782
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
783 783
 
784
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
784
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
785 785
 			return new \OC\Files\Type\Detection(
786 786
 				$c->getURLGenerator(),
787 787
 				\OC::$configDir,
788
-				\OC::$SERVERROOT . '/resources/config/'
788
+				\OC::$SERVERROOT.'/resources/config/'
789 789
 			);
790 790
 		});
791 791
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
792 792
 
793
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
793
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
794 794
 			return new \OC\Files\Type\Loader(
795 795
 				$c->getDatabaseConnection()
796 796
 			);
797 797
 		});
798 798
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
799 799
 
800
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
800
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
801 801
 			return new Manager(
802 802
 				$c->query(IValidator::class)
803 803
 			);
804 804
 		});
805 805
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
806 806
 
807
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
807
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
808 808
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
809
-			$manager->registerCapability(function () use ($c) {
809
+			$manager->registerCapability(function() use ($c) {
810 810
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
811 811
 			});
812 812
 			return $manager;
@@ -848,13 +848,13 @@  discard block
 block discarded – undo
848 848
 			}
849 849
 			return new \OC_Defaults();
850 850
 		});
851
-		$this->registerService(EventDispatcher::class, function () {
851
+		$this->registerService(EventDispatcher::class, function() {
852 852
 			return new EventDispatcher();
853 853
 		});
854 854
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
855 855
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
856 856
 
857
-		$this->registerService('CryptoWrapper', function (Server $c) {
857
+		$this->registerService('CryptoWrapper', function(Server $c) {
858 858
 			// FIXME: Instantiiated here due to cyclic dependency
859 859
 			$request = new Request(
860 860
 				[
@@ -879,7 +879,7 @@  discard block
 block discarded – undo
879 879
 				$request
880 880
 			);
881 881
 		});
882
-		$this->registerService('CsrfTokenManager', function (Server $c) {
882
+		$this->registerService('CsrfTokenManager', function(Server $c) {
883 883
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
884 884
 
885 885
 			return new CsrfTokenManager(
@@ -887,10 +887,10 @@  discard block
 block discarded – undo
887 887
 				$c->query(SessionStorage::class)
888 888
 			);
889 889
 		});
890
-		$this->registerService(SessionStorage::class, function (Server $c) {
890
+		$this->registerService(SessionStorage::class, function(Server $c) {
891 891
 			return new SessionStorage($c->getSession());
892 892
 		});
893
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
893
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
894 894
 			return new ContentSecurityPolicyManager();
895 895
 		});
896 896
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
@@ -941,29 +941,29 @@  discard block
 block discarded – undo
941 941
 			);
942 942
 			return $manager;
943 943
 		});
944
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
944
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
945 945
 			return new \OC\Files\AppData\Factory(
946 946
 				$c->getRootFolder(),
947 947
 				$c->getSystemConfig()
948 948
 			);
949 949
 		});
950 950
 
951
-		$this->registerService('LockdownManager', function (Server $c) {
951
+		$this->registerService('LockdownManager', function(Server $c) {
952 952
 			return new LockdownManager(function() use ($c) {
953 953
 				return $c->getSession();
954 954
 			});
955 955
 		});
956 956
 
957
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
957
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
958 958
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
959 959
 		});
960 960
 
961
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
961
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
962 962
 			return new CloudIdManager();
963 963
 		});
964 964
 
965 965
 		/* To trick DI since we don't extend the DIContainer here */
966
-		$this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) {
966
+		$this->registerService(CleanPreviewsBackgroundJob::class, function(Server $c) {
967 967
 			return new CleanPreviewsBackgroundJob(
968 968
 				$c->getRootFolder(),
969 969
 				$c->getLogger(),
@@ -978,7 +978,7 @@  discard block
 block discarded – undo
978 978
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
979 979
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
980 980
 
981
-		$this->registerService(Defaults::class, function (Server $c) {
981
+		$this->registerService(Defaults::class, function(Server $c) {
982 982
 			return new Defaults(
983 983
 				$c->getThemingDefaults()
984 984
 			);
@@ -1124,7 +1124,7 @@  discard block
 block discarded – undo
1124 1124
 	 * @deprecated since 9.2.0 use IAppData
1125 1125
 	 */
1126 1126
 	public function getAppFolder() {
1127
-		$dir = '/' . \OC_App::getCurrentApp();
1127
+		$dir = '/'.\OC_App::getCurrentApp();
1128 1128
 		$root = $this->getRootFolder();
1129 1129
 		if (!$root->nodeExists($dir)) {
1130 1130
 			$folder = $root->newFolder($dir);
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -25,7 +25,6 @@
 block discarded – undo
25 25
 use OC\Security\RateLimiting\Exception\RateLimitExceededException;
26 26
 use OC\Security\RateLimiting\Limiter;
27 27
 use OCP\AppFramework\Http\JSONResponse;
28
-use OCP\AppFramework\Http\Response;
29 28
 use OCP\AppFramework\Http\TemplateResponse;
30 29
 use OCP\AppFramework\Middleware;
31 30
 use OCP\IRequest;
Please login to merge, or discard this patch.
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -48,87 +48,87 @@
 block discarded – undo
48 48
  * @package OC\AppFramework\Middleware\Security
49 49
  */
50 50
 class RateLimitingMiddleware extends Middleware {
51
-	/** @var IRequest $request */
52
-	private $request;
53
-	/** @var IUserSession */
54
-	private $userSession;
55
-	/** @var ControllerMethodReflector */
56
-	private $reflector;
57
-	/** @var Limiter */
58
-	private $limiter;
51
+    /** @var IRequest $request */
52
+    private $request;
53
+    /** @var IUserSession */
54
+    private $userSession;
55
+    /** @var ControllerMethodReflector */
56
+    private $reflector;
57
+    /** @var Limiter */
58
+    private $limiter;
59 59
 
60
-	/**
61
-	 * @param IRequest $request
62
-	 * @param IUserSession $userSession
63
-	 * @param ControllerMethodReflector $reflector
64
-	 * @param Limiter $limiter
65
-	 */
66
-	public function __construct(IRequest $request,
67
-								IUserSession $userSession,
68
-								ControllerMethodReflector $reflector,
69
-								Limiter $limiter) {
70
-		$this->request = $request;
71
-		$this->userSession = $userSession;
72
-		$this->reflector = $reflector;
73
-		$this->limiter = $limiter;
74
-	}
60
+    /**
61
+     * @param IRequest $request
62
+     * @param IUserSession $userSession
63
+     * @param ControllerMethodReflector $reflector
64
+     * @param Limiter $limiter
65
+     */
66
+    public function __construct(IRequest $request,
67
+                                IUserSession $userSession,
68
+                                ControllerMethodReflector $reflector,
69
+                                Limiter $limiter) {
70
+        $this->request = $request;
71
+        $this->userSession = $userSession;
72
+        $this->reflector = $reflector;
73
+        $this->limiter = $limiter;
74
+    }
75 75
 
76
-	/**
77
-	 * {@inheritDoc}
78
-	 * @throws RateLimitExceededException
79
-	 */
80
-	public function beforeController($controller, $methodName) {
81
-		parent::beforeController($controller, $methodName);
76
+    /**
77
+     * {@inheritDoc}
78
+     * @throws RateLimitExceededException
79
+     */
80
+    public function beforeController($controller, $methodName) {
81
+        parent::beforeController($controller, $methodName);
82 82
 
83
-		$anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit');
84
-		$anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period');
85
-		$userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit');
86
-		$userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period');
87
-		$rateLimitIdentifier = get_class($controller) . '::' . $methodName;
88
-		if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
89
-			$this->limiter->registerUserRequest(
90
-				$rateLimitIdentifier,
91
-				$userLimit,
92
-				$userPeriod,
93
-				$this->userSession->getUser()
94
-			);
95
-		} elseif ($anonLimit !== '' && $anonPeriod !== '') {
96
-			$this->limiter->registerAnonRequest(
97
-				$rateLimitIdentifier,
98
-				$anonLimit,
99
-				$anonPeriod,
100
-				$this->request->getRemoteAddress()
101
-			);
102
-		}
103
-	}
83
+        $anonLimit = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'limit');
84
+        $anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period');
85
+        $userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit');
86
+        $userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period');
87
+        $rateLimitIdentifier = get_class($controller) . '::' . $methodName;
88
+        if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
89
+            $this->limiter->registerUserRequest(
90
+                $rateLimitIdentifier,
91
+                $userLimit,
92
+                $userPeriod,
93
+                $this->userSession->getUser()
94
+            );
95
+        } elseif ($anonLimit !== '' && $anonPeriod !== '') {
96
+            $this->limiter->registerAnonRequest(
97
+                $rateLimitIdentifier,
98
+                $anonLimit,
99
+                $anonPeriod,
100
+                $this->request->getRemoteAddress()
101
+            );
102
+        }
103
+    }
104 104
 
105
-	/**
106
-	 * {@inheritDoc}
107
-	 */
108
-	public function afterException($controller, $methodName, \Exception $exception) {
109
-		if($exception instanceof RateLimitExceededException) {
110
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
111
-				$response = new JSONResponse(
112
-					[
113
-						'message' => $exception->getMessage(),
114
-					],
115
-					$exception->getCode()
116
-				);
117
-			} else {
118
-					$response = new TemplateResponse(
119
-						'core',
120
-						'403',
121
-							[
122
-								'file' => $exception->getMessage()
123
-							],
124
-						'guest'
125
-					);
126
-					$response->setStatus($exception->getCode());
127
-			}
105
+    /**
106
+     * {@inheritDoc}
107
+     */
108
+    public function afterException($controller, $methodName, \Exception $exception) {
109
+        if($exception instanceof RateLimitExceededException) {
110
+            if (stripos($this->request->getHeader('Accept'),'html') === false) {
111
+                $response = new JSONResponse(
112
+                    [
113
+                        'message' => $exception->getMessage(),
114
+                    ],
115
+                    $exception->getCode()
116
+                );
117
+            } else {
118
+                    $response = new TemplateResponse(
119
+                        'core',
120
+                        '403',
121
+                            [
122
+                                'file' => $exception->getMessage()
123
+                            ],
124
+                        'guest'
125
+                    );
126
+                    $response->setStatus($exception->getCode());
127
+            }
128 128
 
129
-			return $response;
130
-		}
129
+            return $response;
130
+        }
131 131
 
132
-		throw $exception;
133
-	}
132
+        throw $exception;
133
+    }
134 134
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -84,8 +84,8 @@  discard block
 block discarded – undo
84 84
 		$anonPeriod = $this->reflector->getAnnotationParameter('AnonRateThrottle', 'period');
85 85
 		$userLimit = $this->reflector->getAnnotationParameter('UserRateThrottle', 'limit');
86 86
 		$userPeriod = $this->reflector->getAnnotationParameter('UserRateThrottle', 'period');
87
-		$rateLimitIdentifier = get_class($controller) . '::' . $methodName;
88
-		if($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
87
+		$rateLimitIdentifier = get_class($controller).'::'.$methodName;
88
+		if ($userLimit !== '' && $userPeriod !== '' && $this->userSession->isLoggedIn()) {
89 89
 			$this->limiter->registerUserRequest(
90 90
 				$rateLimitIdentifier,
91 91
 				$userLimit,
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	 * {@inheritDoc}
107 107
 	 */
108 108
 	public function afterException($controller, $methodName, \Exception $exception) {
109
-		if($exception instanceof RateLimitExceededException) {
110
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
109
+		if ($exception instanceof RateLimitExceededException) {
110
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
111 111
 				$response = new JSONResponse(
112 112
 					[
113 113
 						'message' => $exception->getMessage(),
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 2 patches
Indentation   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -64,219 +64,219 @@
 block discarded – undo
64 64
  * check fails
65 65
  */
66 66
 class SecurityMiddleware extends Middleware {
67
-	/** @var INavigationManager */
68
-	private $navigationManager;
69
-	/** @var IRequest */
70
-	private $request;
71
-	/** @var ControllerMethodReflector */
72
-	private $reflector;
73
-	/** @var string */
74
-	private $appName;
75
-	/** @var IURLGenerator */
76
-	private $urlGenerator;
77
-	/** @var ILogger */
78
-	private $logger;
79
-	/** @var ISession */
80
-	private $session;
81
-	/** @var bool */
82
-	private $isLoggedIn;
83
-	/** @var bool */
84
-	private $isAdminUser;
85
-	/** @var ContentSecurityPolicyManager */
86
-	private $contentSecurityPolicyManager;
87
-	/** @var CsrfTokenManager */
88
-	private $csrfTokenManager;
89
-	/** @var ContentSecurityPolicyNonceManager */
90
-	private $cspNonceManager;
91
-	/** @var Throttler */
92
-	private $throttler;
67
+    /** @var INavigationManager */
68
+    private $navigationManager;
69
+    /** @var IRequest */
70
+    private $request;
71
+    /** @var ControllerMethodReflector */
72
+    private $reflector;
73
+    /** @var string */
74
+    private $appName;
75
+    /** @var IURLGenerator */
76
+    private $urlGenerator;
77
+    /** @var ILogger */
78
+    private $logger;
79
+    /** @var ISession */
80
+    private $session;
81
+    /** @var bool */
82
+    private $isLoggedIn;
83
+    /** @var bool */
84
+    private $isAdminUser;
85
+    /** @var ContentSecurityPolicyManager */
86
+    private $contentSecurityPolicyManager;
87
+    /** @var CsrfTokenManager */
88
+    private $csrfTokenManager;
89
+    /** @var ContentSecurityPolicyNonceManager */
90
+    private $cspNonceManager;
91
+    /** @var Throttler */
92
+    private $throttler;
93 93
 
94
-	/**
95
-	 * @param IRequest $request
96
-	 * @param ControllerMethodReflector $reflector
97
-	 * @param INavigationManager $navigationManager
98
-	 * @param IURLGenerator $urlGenerator
99
-	 * @param ILogger $logger
100
-	 * @param ISession $session
101
-	 * @param string $appName
102
-	 * @param bool $isLoggedIn
103
-	 * @param bool $isAdminUser
104
-	 * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
105
-	 * @param CSRFTokenManager $csrfTokenManager
106
-	 * @param ContentSecurityPolicyNonceManager $cspNonceManager
107
-	 * @param Throttler $throttler
108
-	 */
109
-	public function __construct(IRequest $request,
110
-								ControllerMethodReflector $reflector,
111
-								INavigationManager $navigationManager,
112
-								IURLGenerator $urlGenerator,
113
-								ILogger $logger,
114
-								ISession $session,
115
-								$appName,
116
-								$isLoggedIn,
117
-								$isAdminUser,
118
-								ContentSecurityPolicyManager $contentSecurityPolicyManager,
119
-								CsrfTokenManager $csrfTokenManager,
120
-								ContentSecurityPolicyNonceManager $cspNonceManager,
121
-								Throttler $throttler) {
122
-		$this->navigationManager = $navigationManager;
123
-		$this->request = $request;
124
-		$this->reflector = $reflector;
125
-		$this->appName = $appName;
126
-		$this->urlGenerator = $urlGenerator;
127
-		$this->logger = $logger;
128
-		$this->session = $session;
129
-		$this->isLoggedIn = $isLoggedIn;
130
-		$this->isAdminUser = $isAdminUser;
131
-		$this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
132
-		$this->csrfTokenManager = $csrfTokenManager;
133
-		$this->cspNonceManager = $cspNonceManager;
134
-		$this->throttler = $throttler;
135
-	}
94
+    /**
95
+     * @param IRequest $request
96
+     * @param ControllerMethodReflector $reflector
97
+     * @param INavigationManager $navigationManager
98
+     * @param IURLGenerator $urlGenerator
99
+     * @param ILogger $logger
100
+     * @param ISession $session
101
+     * @param string $appName
102
+     * @param bool $isLoggedIn
103
+     * @param bool $isAdminUser
104
+     * @param ContentSecurityPolicyManager $contentSecurityPolicyManager
105
+     * @param CSRFTokenManager $csrfTokenManager
106
+     * @param ContentSecurityPolicyNonceManager $cspNonceManager
107
+     * @param Throttler $throttler
108
+     */
109
+    public function __construct(IRequest $request,
110
+                                ControllerMethodReflector $reflector,
111
+                                INavigationManager $navigationManager,
112
+                                IURLGenerator $urlGenerator,
113
+                                ILogger $logger,
114
+                                ISession $session,
115
+                                $appName,
116
+                                $isLoggedIn,
117
+                                $isAdminUser,
118
+                                ContentSecurityPolicyManager $contentSecurityPolicyManager,
119
+                                CsrfTokenManager $csrfTokenManager,
120
+                                ContentSecurityPolicyNonceManager $cspNonceManager,
121
+                                Throttler $throttler) {
122
+        $this->navigationManager = $navigationManager;
123
+        $this->request = $request;
124
+        $this->reflector = $reflector;
125
+        $this->appName = $appName;
126
+        $this->urlGenerator = $urlGenerator;
127
+        $this->logger = $logger;
128
+        $this->session = $session;
129
+        $this->isLoggedIn = $isLoggedIn;
130
+        $this->isAdminUser = $isAdminUser;
131
+        $this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
132
+        $this->csrfTokenManager = $csrfTokenManager;
133
+        $this->cspNonceManager = $cspNonceManager;
134
+        $this->throttler = $throttler;
135
+    }
136 136
 
137 137
 
138
-	/**
139
-	 * This runs all the security checks before a method call. The
140
-	 * security checks are determined by inspecting the controller method
141
-	 * annotations
142
-	 * @param Controller $controller the controller
143
-	 * @param string $methodName the name of the method
144
-	 * @throws SecurityException when a security check fails
145
-	 */
146
-	public function beforeController($controller, $methodName) {
138
+    /**
139
+     * This runs all the security checks before a method call. The
140
+     * security checks are determined by inspecting the controller method
141
+     * annotations
142
+     * @param Controller $controller the controller
143
+     * @param string $methodName the name of the method
144
+     * @throws SecurityException when a security check fails
145
+     */
146
+    public function beforeController($controller, $methodName) {
147 147
 
148
-		// this will set the current navigation entry of the app, use this only
149
-		// for normal HTML requests and not for AJAX requests
150
-		$this->navigationManager->setActiveEntry($this->appName);
148
+        // this will set the current navigation entry of the app, use this only
149
+        // for normal HTML requests and not for AJAX requests
150
+        $this->navigationManager->setActiveEntry($this->appName);
151 151
 
152
-		// security checks
153
-		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
154
-		if(!$isPublicPage) {
155
-			if(!$this->isLoggedIn) {
156
-				throw new NotLoggedInException();
157
-			}
152
+        // security checks
153
+        $isPublicPage = $this->reflector->hasAnnotation('PublicPage');
154
+        if(!$isPublicPage) {
155
+            if(!$this->isLoggedIn) {
156
+                throw new NotLoggedInException();
157
+            }
158 158
 
159
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
160
-				if(!$this->isAdminUser) {
161
-					throw new NotAdminException();
162
-				}
163
-			}
164
-		}
159
+            if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
160
+                if(!$this->isAdminUser) {
161
+                    throw new NotAdminException();
162
+                }
163
+            }
164
+        }
165 165
 
166
-		if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
167
-			$lastConfirm = (int) $this->session->get('last-password-confirm');
168
-			if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay
169
-				throw new NotConfirmedException();
170
-			}
171
-		}
166
+        if ($this->reflector->hasAnnotation('PasswordConfirmationRequired')) {
167
+            $lastConfirm = (int) $this->session->get('last-password-confirm');
168
+            if ($lastConfirm < (time() - (30 * 60 + 15))) { // allow 15 seconds delay
169
+                throw new NotConfirmedException();
170
+            }
171
+        }
172 172
 
173
-		// Check for strict cookie requirement
174
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
175
-			if(!$this->request->passesStrictCookieCheck()) {
176
-				throw new StrictCookieMissingException();
177
-			}
178
-		}
179
-		// CSRF check - also registers the CSRF token since the session may be closed later
180
-		Util::callRegister();
181
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
182
-			/*
173
+        // Check for strict cookie requirement
174
+        if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
175
+            if(!$this->request->passesStrictCookieCheck()) {
176
+                throw new StrictCookieMissingException();
177
+            }
178
+        }
179
+        // CSRF check - also registers the CSRF token since the session may be closed later
180
+        Util::callRegister();
181
+        if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
182
+            /*
183 183
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
184 184
 			 * hacks around that we have no full token auth in place yet and we
185 185
 			 * do want to offer CSRF checks for web requests.
186 186
 			 */
187
-			if(!$this->request->passesCSRFCheck() && !(
188
-					$controller instanceof OCSController &&
189
-					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
190
-				throw new CrossSiteRequestForgeryException();
191
-			}
192
-		}
187
+            if(!$this->request->passesCSRFCheck() && !(
188
+                    $controller instanceof OCSController &&
189
+                    $this->request->getHeader('OCS-APIREQUEST') === 'true')) {
190
+                throw new CrossSiteRequestForgeryException();
191
+            }
192
+        }
193 193
 
194
-		if($this->reflector->hasAnnotation('BruteForceProtection')) {
195
-			$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
196
-			$this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);
197
-			$this->throttler->registerAttempt($action, $this->request->getRemoteAddress());
198
-		}
194
+        if($this->reflector->hasAnnotation('BruteForceProtection')) {
195
+            $action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
196
+            $this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);
197
+            $this->throttler->registerAttempt($action, $this->request->getRemoteAddress());
198
+        }
199 199
 
200
-		/**
201
-		 * FIXME: Use DI once available
202
-		 * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
203
-		 * The getAppPath() check is here since components such as settings also use the AppFramework and
204
-		 * therefore won't pass this check.
205
-		 */
206
-		if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
207
-			throw new AppNotEnabledException();
208
-		}
200
+        /**
201
+         * FIXME: Use DI once available
202
+         * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
203
+         * The getAppPath() check is here since components such as settings also use the AppFramework and
204
+         * therefore won't pass this check.
205
+         */
206
+        if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
207
+            throw new AppNotEnabledException();
208
+        }
209 209
 
210
-	}
210
+    }
211 211
 
212
-	/**
213
-	 * Performs the default CSP modifications that may be injected by other
214
-	 * applications
215
-	 *
216
-	 * @param Controller $controller
217
-	 * @param string $methodName
218
-	 * @param Response $response
219
-	 * @return Response
220
-	 */
221
-	public function afterController($controller, $methodName, Response $response) {
222
-		$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
212
+    /**
213
+     * Performs the default CSP modifications that may be injected by other
214
+     * applications
215
+     *
216
+     * @param Controller $controller
217
+     * @param string $methodName
218
+     * @param Response $response
219
+     * @return Response
220
+     */
221
+    public function afterController($controller, $methodName, Response $response) {
222
+        $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
223 223
 
224
-		if (get_class($policy) === EmptyContentSecurityPolicy::class) {
225
-			return $response;
226
-		}
224
+        if (get_class($policy) === EmptyContentSecurityPolicy::class) {
225
+            return $response;
226
+        }
227 227
 
228
-		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
229
-		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
228
+        $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
229
+        $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
230 230
 
231
-		if($this->cspNonceManager->browserSupportsCspV3()) {
232
-			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
233
-		}
231
+        if($this->cspNonceManager->browserSupportsCspV3()) {
232
+            $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
233
+        }
234 234
 
235
-		$response->setContentSecurityPolicy($defaultPolicy);
235
+        $response->setContentSecurityPolicy($defaultPolicy);
236 236
 
237
-		return $response;
238
-	}
237
+        return $response;
238
+    }
239 239
 
240
-	/**
241
-	 * If an SecurityException is being caught, ajax requests return a JSON error
242
-	 * response and non ajax requests redirect to the index
243
-	 * @param Controller $controller the controller that is being called
244
-	 * @param string $methodName the name of the method that will be called on
245
-	 *                           the controller
246
-	 * @param \Exception $exception the thrown exception
247
-	 * @throws \Exception the passed in exception if it can't handle it
248
-	 * @return Response a Response object or null in case that the exception could not be handled
249
-	 */
250
-	public function afterException($controller, $methodName, \Exception $exception) {
251
-		if($exception instanceof SecurityException) {
252
-			if($exception instanceof StrictCookieMissingException) {
253
-				return new RedirectResponse(\OC::$WEBROOT);
254
- 			}
255
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
256
-				$response = new JSONResponse(
257
-					array('message' => $exception->getMessage()),
258
-					$exception->getCode()
259
-				);
260
-			} else {
261
-				if($exception instanceof NotLoggedInException) {
262
-					$url = $this->urlGenerator->linkToRoute(
263
-						'core.login.showLoginForm',
264
-						[
265
-							'redirect_url' => $this->request->server['REQUEST_URI'],
266
-						]
267
-					);
268
-					$response = new RedirectResponse($url);
269
-				} else {
270
-					$response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
271
-					$response->setStatus($exception->getCode());
272
-				}
273
-			}
240
+    /**
241
+     * If an SecurityException is being caught, ajax requests return a JSON error
242
+     * response and non ajax requests redirect to the index
243
+     * @param Controller $controller the controller that is being called
244
+     * @param string $methodName the name of the method that will be called on
245
+     *                           the controller
246
+     * @param \Exception $exception the thrown exception
247
+     * @throws \Exception the passed in exception if it can't handle it
248
+     * @return Response a Response object or null in case that the exception could not be handled
249
+     */
250
+    public function afterException($controller, $methodName, \Exception $exception) {
251
+        if($exception instanceof SecurityException) {
252
+            if($exception instanceof StrictCookieMissingException) {
253
+                return new RedirectResponse(\OC::$WEBROOT);
254
+                }
255
+            if (stripos($this->request->getHeader('Accept'),'html') === false) {
256
+                $response = new JSONResponse(
257
+                    array('message' => $exception->getMessage()),
258
+                    $exception->getCode()
259
+                );
260
+            } else {
261
+                if($exception instanceof NotLoggedInException) {
262
+                    $url = $this->urlGenerator->linkToRoute(
263
+                        'core.login.showLoginForm',
264
+                        [
265
+                            'redirect_url' => $this->request->server['REQUEST_URI'],
266
+                        ]
267
+                    );
268
+                    $response = new RedirectResponse($url);
269
+                } else {
270
+                    $response = new TemplateResponse('core', '403', ['file' => $exception->getMessage()], 'guest');
271
+                    $response->setStatus($exception->getCode());
272
+                }
273
+            }
274 274
 
275
-			$this->logger->debug($exception->getMessage());
276
-			return $response;
277
-		}
275
+            $this->logger->debug($exception->getMessage());
276
+            return $response;
277
+        }
278 278
 
279
-		throw $exception;
280
-	}
279
+        throw $exception;
280
+    }
281 281
 
282 282
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
 
152 152
 		// security checks
153 153
 		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
154
-		if(!$isPublicPage) {
155
-			if(!$this->isLoggedIn) {
154
+		if (!$isPublicPage) {
155
+			if (!$this->isLoggedIn) {
156 156
 				throw new NotLoggedInException();
157 157
 			}
158 158
 
159
-			if(!$this->reflector->hasAnnotation('NoAdminRequired')) {
160
-				if(!$this->isAdminUser) {
159
+			if (!$this->reflector->hasAnnotation('NoAdminRequired')) {
160
+				if (!$this->isAdminUser) {
161 161
 					throw new NotAdminException();
162 162
 				}
163 163
 			}
@@ -171,27 +171,27 @@  discard block
 block discarded – undo
171 171
 		}
172 172
 
173 173
 		// Check for strict cookie requirement
174
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
175
-			if(!$this->request->passesStrictCookieCheck()) {
174
+		if ($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
175
+			if (!$this->request->passesStrictCookieCheck()) {
176 176
 				throw new StrictCookieMissingException();
177 177
 			}
178 178
 		}
179 179
 		// CSRF check - also registers the CSRF token since the session may be closed later
180 180
 		Util::callRegister();
181
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
181
+		if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
182 182
 			/*
183 183
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
184 184
 			 * hacks around that we have no full token auth in place yet and we
185 185
 			 * do want to offer CSRF checks for web requests.
186 186
 			 */
187
-			if(!$this->request->passesCSRFCheck() && !(
187
+			if (!$this->request->passesCSRFCheck() && !(
188 188
 					$controller instanceof OCSController &&
189 189
 					$this->request->getHeader('OCS-APIREQUEST') === 'true')) {
190 190
 				throw new CrossSiteRequestForgeryException();
191 191
 			}
192 192
 		}
193 193
 
194
-		if($this->reflector->hasAnnotation('BruteForceProtection')) {
194
+		if ($this->reflector->hasAnnotation('BruteForceProtection')) {
195 195
 			$action = $this->reflector->getAnnotationParameter('BruteForceProtection', 'action');
196 196
 			$this->throttler->sleepDelay($this->request->getRemoteAddress(), $action);
197 197
 			$this->throttler->registerAttempt($action, $this->request->getRemoteAddress());
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		 * The getAppPath() check is here since components such as settings also use the AppFramework and
204 204
 		 * therefore won't pass this check.
205 205
 		 */
206
-		if(\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
206
+		if (\OC_App::getAppPath($this->appName) !== false && !\OC_App::isEnabled($this->appName)) {
207 207
 			throw new AppNotEnabledException();
208 208
 		}
209 209
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
229 229
 		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
230 230
 
231
-		if($this->cspNonceManager->browserSupportsCspV3()) {
231
+		if ($this->cspNonceManager->browserSupportsCspV3()) {
232 232
 			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
233 233
 		}
234 234
 
@@ -248,17 +248,17 @@  discard block
 block discarded – undo
248 248
 	 * @return Response a Response object or null in case that the exception could not be handled
249 249
 	 */
250 250
 	public function afterException($controller, $methodName, \Exception $exception) {
251
-		if($exception instanceof SecurityException) {
252
-			if($exception instanceof StrictCookieMissingException) {
251
+		if ($exception instanceof SecurityException) {
252
+			if ($exception instanceof StrictCookieMissingException) {
253 253
 				return new RedirectResponse(\OC::$WEBROOT);
254 254
  			}
255
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
255
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
256 256
 				$response = new JSONResponse(
257 257
 					array('message' => $exception->getMessage()),
258 258
 					$exception->getCode()
259 259
 				);
260 260
 			} else {
261
-				if($exception instanceof NotLoggedInException) {
261
+				if ($exception instanceof NotLoggedInException) {
262 262
 					$url = $this->urlGenerator->linkToRoute(
263 263
 						'core.login.showLoginForm',
264 264
 						[
Please login to merge, or discard this patch.
lib/private/AppFramework/DependencyInjection/DIContainer.php 2 patches
Indentation   +361 added lines, -361 removed lines patch added patch discarded remove patch
@@ -62,365 +62,365 @@
 block discarded – undo
62 62
 
63 63
 class DIContainer extends SimpleContainer implements IAppContainer {
64 64
 
65
-	/**
66
-	 * @var array
67
-	 */
68
-	private $middleWares = array();
69
-
70
-	/** @var ServerContainer */
71
-	private $server;
72
-
73
-	/**
74
-	 * Put your class dependencies in here
75
-	 * @param string $appName the name of the app
76
-	 * @param array $urlParams
77
-	 * @param ServerContainer $server
78
-	 */
79
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
80
-		parent::__construct();
81
-		$this['AppName'] = $appName;
82
-		$this['urlParams'] = $urlParams;
83
-
84
-		/** @var \OC\ServerContainer $server */
85
-		if ($server === null) {
86
-			$server = \OC::$server;
87
-		}
88
-		$this->server = $server;
89
-		$this->server->registerAppContainer($appName, $this);
90
-
91
-		// aliases
92
-		$this->registerAlias('appName', 'AppName');
93
-		$this->registerAlias('webRoot', 'WebRoot');
94
-		$this->registerAlias('userId', 'UserId');
95
-
96
-		/**
97
-		 * Core services
98
-		 */
99
-		$this->registerService(IOutput::class, function($c){
100
-			return new Output($this->getServer()->getWebRoot());
101
-		});
102
-
103
-		$this->registerService(Folder::class, function() {
104
-			return $this->getServer()->getUserFolder();
105
-		});
106
-
107
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
108
-			return $this->getServer()->getAppDataDir($c->query('AppName'));
109
-		});
110
-
111
-		$this->registerService(IL10N::class, function($c) {
112
-			return $this->getServer()->getL10N($c->query('AppName'));
113
-		});
114
-
115
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
116
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
117
-
118
-		$this->registerService(IRequest::class, function() {
119
-			return $this->getServer()->query(IRequest::class);
120
-		});
121
-		$this->registerAlias('Request', IRequest::class);
122
-
123
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
124
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
125
-
126
-		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
127
-
128
-		$this->registerService(IServerContainer::class, function ($c) {
129
-			return $this->getServer();
130
-		});
131
-		$this->registerAlias('ServerContainer', IServerContainer::class);
132
-
133
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
134
-			return $c->query('OCA\WorkflowEngine\Manager');
135
-		});
136
-
137
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
138
-			return $c;
139
-		});
140
-
141
-		// commonly used attributes
142
-		$this->registerService('UserId', function ($c) {
143
-			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
144
-		});
145
-
146
-		$this->registerService('WebRoot', function ($c) {
147
-			return $c->query('ServerContainer')->getWebRoot();
148
-		});
149
-
150
-		$this->registerService('fromMailAddress', function() {
151
-			return Util::getDefaultEmailAddress('no-reply');
152
-		});
153
-
154
-		$this->registerService('OC_Defaults', function ($c) {
155
-			return $c->getServer()->getThemingDefaults();
156
-		});
157
-
158
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
159
-			return $this->getServer()->getEncryptionManager();
160
-		});
161
-
162
-		$this->registerService(IValidator::class, function($c) {
163
-			return $c->query(Validator::class);
164
-		});
165
-
166
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
167
-			return new \OC\Security\IdentityProof\Manager(
168
-				$this->getServer()->getAppDataDir('identityproof'),
169
-				$this->getServer()->getCrypto()
170
-			);
171
-		});
172
-
173
-		/**
174
-		 * App Framework APIs
175
-		 */
176
-		$this->registerService('API', function($c){
177
-			$c->query('OCP\\ILogger')->debug(
178
-				'Accessing the API class is deprecated! Use the appropriate ' .
179
-				'services instead!'
180
-			);
181
-			return new API($c['AppName']);
182
-		});
183
-
184
-		$this->registerService('Protocol', function($c){
185
-			/** @var \OC\Server $server */
186
-			$server = $c->query('ServerContainer');
187
-			$protocol = $server->getRequest()->getHttpProtocol();
188
-			return new Http($_SERVER, $protocol);
189
-		});
190
-
191
-		$this->registerService('Dispatcher', function($c) {
192
-			return new Dispatcher(
193
-				$c['Protocol'],
194
-				$c['MiddlewareDispatcher'],
195
-				$c['ControllerMethodReflector'],
196
-				$c['Request']
197
-			);
198
-		});
199
-
200
-		/**
201
-		 * App Framework default arguments
202
-		 */
203
-		$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
204
-		$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
205
-		$this->registerParameter('corsMaxAge', 1728000);
206
-
207
-		/**
208
-		 * Middleware
209
-		 */
210
-		$app = $this;
211
-		$this->registerService('SecurityMiddleware', function($c) use ($app){
212
-			/** @var \OC\Server $server */
213
-			$server = $app->getServer();
214
-
215
-			return new SecurityMiddleware(
216
-				$c['Request'],
217
-				$c['ControllerMethodReflector'],
218
-				$server->getNavigationManager(),
219
-				$server->getURLGenerator(),
220
-				$server->getLogger(),
221
-				$server->getSession(),
222
-				$c['AppName'],
223
-				$app->isLoggedIn(),
224
-				$app->isAdminUser(),
225
-				$server->getContentSecurityPolicyManager(),
226
-				$server->getCsrfTokenManager(),
227
-				$server->getContentSecurityPolicyNonceManager(),
228
-				$server->getBruteForceThrottler()
229
-			);
230
-
231
-		});
232
-
233
-		$this->registerService('RateLimitingMiddleware', function($c) use ($app) {
234
-			/** @var \OC\Server $server */
235
-			$server = $app->getServer();
236
-
237
-			return new RateLimitingMiddleware(
238
-				$server->getRequest(),
239
-				$server->getUserSession(),
240
-				$c['ControllerMethodReflector'],
241
-				$c->query(OC\Security\RateLimiting\Limiter::class)
242
-			);
243
-		});
244
-
245
-		$this->registerService('CORSMiddleware', function($c) {
246
-			return new CORSMiddleware(
247
-				$c['Request'],
248
-				$c['ControllerMethodReflector'],
249
-				$c->query(IUserSession::class),
250
-				$c->getServer()->getBruteForceThrottler()
251
-			);
252
-		});
253
-
254
-		$this->registerService('SessionMiddleware', function($c) use ($app) {
255
-			return new SessionMiddleware(
256
-				$c['Request'],
257
-				$c['ControllerMethodReflector'],
258
-				$app->getServer()->getSession()
259
-			);
260
-		});
261
-
262
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
263
-			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
264
-			$userSession = $app->getServer()->getUserSession();
265
-			$session = $app->getServer()->getSession();
266
-			$urlGenerator = $app->getServer()->getURLGenerator();
267
-			$reflector = $c['ControllerMethodReflector'];
268
-			$request = $app->getServer()->getRequest();
269
-			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
270
-		});
271
-
272
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
273
-			return new OCSMiddleware(
274
-				$c['Request']
275
-			);
276
-		});
277
-
278
-		$middleWares = &$this->middleWares;
279
-		$this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
280
-			$dispatcher = new MiddlewareDispatcher();
281
-			$dispatcher->registerMiddleware($c['CORSMiddleware']);
282
-			$dispatcher->registerMiddleware($c['OCSMiddleware']);
283
-			$dispatcher->registerMiddleware($c['SecurityMiddleware']);
284
-			$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
285
-			$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
286
-
287
-			foreach($middleWares as $middleWare) {
288
-				$dispatcher->registerMiddleware($c[$middleWare]);
289
-			}
290
-
291
-			$dispatcher->registerMiddleware($c['SessionMiddleware']);
292
-			return $dispatcher;
293
-		});
294
-
295
-	}
296
-
297
-
298
-	/**
299
-	 * @deprecated implements only deprecated methods
300
-	 * @return IApi
301
-	 */
302
-	function getCoreApi()
303
-	{
304
-		return $this->query('API');
305
-	}
306
-
307
-	/**
308
-	 * @return \OCP\IServerContainer
309
-	 */
310
-	function getServer()
311
-	{
312
-		return $this->server;
313
-	}
314
-
315
-	/**
316
-	 * @param string $middleWare
317
-	 * @return boolean|null
318
-	 */
319
-	function registerMiddleWare($middleWare) {
320
-		array_push($this->middleWares, $middleWare);
321
-	}
322
-
323
-	/**
324
-	 * used to return the appname of the set application
325
-	 * @return string the name of your application
326
-	 */
327
-	function getAppName() {
328
-		return $this->query('AppName');
329
-	}
330
-
331
-	/**
332
-	 * @deprecated use IUserSession->isLoggedIn()
333
-	 * @return boolean
334
-	 */
335
-	function isLoggedIn() {
336
-		return \OC::$server->getUserSession()->isLoggedIn();
337
-	}
338
-
339
-	/**
340
-	 * @deprecated use IGroupManager->isAdmin($userId)
341
-	 * @return boolean
342
-	 */
343
-	function isAdminUser() {
344
-		$uid = $this->getUserId();
345
-		return \OC_User::isAdminUser($uid);
346
-	}
347
-
348
-	private function getUserId() {
349
-		return $this->getServer()->getSession()->get('user_id');
350
-	}
351
-
352
-	/**
353
-	 * @deprecated use the ILogger instead
354
-	 * @param string $message
355
-	 * @param string $level
356
-	 * @return mixed
357
-	 */
358
-	function log($message, $level) {
359
-		switch($level){
360
-			case 'debug':
361
-				$level = \OCP\Util::DEBUG;
362
-				break;
363
-			case 'info':
364
-				$level = \OCP\Util::INFO;
365
-				break;
366
-			case 'warn':
367
-				$level = \OCP\Util::WARN;
368
-				break;
369
-			case 'fatal':
370
-				$level = \OCP\Util::FATAL;
371
-				break;
372
-			default:
373
-				$level = \OCP\Util::ERROR;
374
-				break;
375
-		}
376
-		\OCP\Util::writeLog($this->getAppName(), $message, $level);
377
-	}
378
-
379
-	/**
380
-	 * Register a capability
381
-	 *
382
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
383
-	 */
384
-	public function registerCapability($serviceName) {
385
-		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
386
-			return $this->query($serviceName);
387
-		});
388
-	}
389
-
390
-	/**
391
-	 * @param string $name
392
-	 * @return mixed
393
-	 * @throws QueryException if the query could not be resolved
394
-	 */
395
-	public function query($name) {
396
-		try {
397
-			return $this->queryNoFallback($name);
398
-		} catch (QueryException $e) {
399
-			return $this->getServer()->query($name);
400
-		}
401
-	}
402
-
403
-	/**
404
-	 * @param string $name
405
-	 * @return mixed
406
-	 * @throws QueryException if the query could not be resolved
407
-	 */
408
-	public function queryNoFallback($name) {
409
-		$name = $this->sanitizeName($name);
410
-
411
-		if ($this->offsetExists($name)) {
412
-			return parent::query($name);
413
-		} else {
414
-			if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
415
-				return parent::query($name);
416
-			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
417
-				return parent::query($name);
418
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
419
-				return parent::query($name);
420
-			}
421
-		}
422
-
423
-		throw new QueryException('Could not resolve ' . $name . '!' .
424
-			' Class can not be instantiated');
425
-	}
65
+    /**
66
+     * @var array
67
+     */
68
+    private $middleWares = array();
69
+
70
+    /** @var ServerContainer */
71
+    private $server;
72
+
73
+    /**
74
+     * Put your class dependencies in here
75
+     * @param string $appName the name of the app
76
+     * @param array $urlParams
77
+     * @param ServerContainer $server
78
+     */
79
+    public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
80
+        parent::__construct();
81
+        $this['AppName'] = $appName;
82
+        $this['urlParams'] = $urlParams;
83
+
84
+        /** @var \OC\ServerContainer $server */
85
+        if ($server === null) {
86
+            $server = \OC::$server;
87
+        }
88
+        $this->server = $server;
89
+        $this->server->registerAppContainer($appName, $this);
90
+
91
+        // aliases
92
+        $this->registerAlias('appName', 'AppName');
93
+        $this->registerAlias('webRoot', 'WebRoot');
94
+        $this->registerAlias('userId', 'UserId');
95
+
96
+        /**
97
+         * Core services
98
+         */
99
+        $this->registerService(IOutput::class, function($c){
100
+            return new Output($this->getServer()->getWebRoot());
101
+        });
102
+
103
+        $this->registerService(Folder::class, function() {
104
+            return $this->getServer()->getUserFolder();
105
+        });
106
+
107
+        $this->registerService(IAppData::class, function (SimpleContainer $c) {
108
+            return $this->getServer()->getAppDataDir($c->query('AppName'));
109
+        });
110
+
111
+        $this->registerService(IL10N::class, function($c) {
112
+            return $this->getServer()->getL10N($c->query('AppName'));
113
+        });
114
+
115
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
116
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
117
+
118
+        $this->registerService(IRequest::class, function() {
119
+            return $this->getServer()->query(IRequest::class);
120
+        });
121
+        $this->registerAlias('Request', IRequest::class);
122
+
123
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
124
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
125
+
126
+        $this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
127
+
128
+        $this->registerService(IServerContainer::class, function ($c) {
129
+            return $this->getServer();
130
+        });
131
+        $this->registerAlias('ServerContainer', IServerContainer::class);
132
+
133
+        $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
134
+            return $c->query('OCA\WorkflowEngine\Manager');
135
+        });
136
+
137
+        $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
138
+            return $c;
139
+        });
140
+
141
+        // commonly used attributes
142
+        $this->registerService('UserId', function ($c) {
143
+            return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
144
+        });
145
+
146
+        $this->registerService('WebRoot', function ($c) {
147
+            return $c->query('ServerContainer')->getWebRoot();
148
+        });
149
+
150
+        $this->registerService('fromMailAddress', function() {
151
+            return Util::getDefaultEmailAddress('no-reply');
152
+        });
153
+
154
+        $this->registerService('OC_Defaults', function ($c) {
155
+            return $c->getServer()->getThemingDefaults();
156
+        });
157
+
158
+        $this->registerService('OCP\Encryption\IManager', function ($c) {
159
+            return $this->getServer()->getEncryptionManager();
160
+        });
161
+
162
+        $this->registerService(IValidator::class, function($c) {
163
+            return $c->query(Validator::class);
164
+        });
165
+
166
+        $this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
167
+            return new \OC\Security\IdentityProof\Manager(
168
+                $this->getServer()->getAppDataDir('identityproof'),
169
+                $this->getServer()->getCrypto()
170
+            );
171
+        });
172
+
173
+        /**
174
+         * App Framework APIs
175
+         */
176
+        $this->registerService('API', function($c){
177
+            $c->query('OCP\\ILogger')->debug(
178
+                'Accessing the API class is deprecated! Use the appropriate ' .
179
+                'services instead!'
180
+            );
181
+            return new API($c['AppName']);
182
+        });
183
+
184
+        $this->registerService('Protocol', function($c){
185
+            /** @var \OC\Server $server */
186
+            $server = $c->query('ServerContainer');
187
+            $protocol = $server->getRequest()->getHttpProtocol();
188
+            return new Http($_SERVER, $protocol);
189
+        });
190
+
191
+        $this->registerService('Dispatcher', function($c) {
192
+            return new Dispatcher(
193
+                $c['Protocol'],
194
+                $c['MiddlewareDispatcher'],
195
+                $c['ControllerMethodReflector'],
196
+                $c['Request']
197
+            );
198
+        });
199
+
200
+        /**
201
+         * App Framework default arguments
202
+         */
203
+        $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
204
+        $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
205
+        $this->registerParameter('corsMaxAge', 1728000);
206
+
207
+        /**
208
+         * Middleware
209
+         */
210
+        $app = $this;
211
+        $this->registerService('SecurityMiddleware', function($c) use ($app){
212
+            /** @var \OC\Server $server */
213
+            $server = $app->getServer();
214
+
215
+            return new SecurityMiddleware(
216
+                $c['Request'],
217
+                $c['ControllerMethodReflector'],
218
+                $server->getNavigationManager(),
219
+                $server->getURLGenerator(),
220
+                $server->getLogger(),
221
+                $server->getSession(),
222
+                $c['AppName'],
223
+                $app->isLoggedIn(),
224
+                $app->isAdminUser(),
225
+                $server->getContentSecurityPolicyManager(),
226
+                $server->getCsrfTokenManager(),
227
+                $server->getContentSecurityPolicyNonceManager(),
228
+                $server->getBruteForceThrottler()
229
+            );
230
+
231
+        });
232
+
233
+        $this->registerService('RateLimitingMiddleware', function($c) use ($app) {
234
+            /** @var \OC\Server $server */
235
+            $server = $app->getServer();
236
+
237
+            return new RateLimitingMiddleware(
238
+                $server->getRequest(),
239
+                $server->getUserSession(),
240
+                $c['ControllerMethodReflector'],
241
+                $c->query(OC\Security\RateLimiting\Limiter::class)
242
+            );
243
+        });
244
+
245
+        $this->registerService('CORSMiddleware', function($c) {
246
+            return new CORSMiddleware(
247
+                $c['Request'],
248
+                $c['ControllerMethodReflector'],
249
+                $c->query(IUserSession::class),
250
+                $c->getServer()->getBruteForceThrottler()
251
+            );
252
+        });
253
+
254
+        $this->registerService('SessionMiddleware', function($c) use ($app) {
255
+            return new SessionMiddleware(
256
+                $c['Request'],
257
+                $c['ControllerMethodReflector'],
258
+                $app->getServer()->getSession()
259
+            );
260
+        });
261
+
262
+        $this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
263
+            $twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
264
+            $userSession = $app->getServer()->getUserSession();
265
+            $session = $app->getServer()->getSession();
266
+            $urlGenerator = $app->getServer()->getURLGenerator();
267
+            $reflector = $c['ControllerMethodReflector'];
268
+            $request = $app->getServer()->getRequest();
269
+            return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
270
+        });
271
+
272
+        $this->registerService('OCSMiddleware', function (SimpleContainer $c) {
273
+            return new OCSMiddleware(
274
+                $c['Request']
275
+            );
276
+        });
277
+
278
+        $middleWares = &$this->middleWares;
279
+        $this->registerService('MiddlewareDispatcher', function($c) use (&$middleWares) {
280
+            $dispatcher = new MiddlewareDispatcher();
281
+            $dispatcher->registerMiddleware($c['CORSMiddleware']);
282
+            $dispatcher->registerMiddleware($c['OCSMiddleware']);
283
+            $dispatcher->registerMiddleware($c['SecurityMiddleware']);
284
+            $dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
285
+            $dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
286
+
287
+            foreach($middleWares as $middleWare) {
288
+                $dispatcher->registerMiddleware($c[$middleWare]);
289
+            }
290
+
291
+            $dispatcher->registerMiddleware($c['SessionMiddleware']);
292
+            return $dispatcher;
293
+        });
294
+
295
+    }
296
+
297
+
298
+    /**
299
+     * @deprecated implements only deprecated methods
300
+     * @return IApi
301
+     */
302
+    function getCoreApi()
303
+    {
304
+        return $this->query('API');
305
+    }
306
+
307
+    /**
308
+     * @return \OCP\IServerContainer
309
+     */
310
+    function getServer()
311
+    {
312
+        return $this->server;
313
+    }
314
+
315
+    /**
316
+     * @param string $middleWare
317
+     * @return boolean|null
318
+     */
319
+    function registerMiddleWare($middleWare) {
320
+        array_push($this->middleWares, $middleWare);
321
+    }
322
+
323
+    /**
324
+     * used to return the appname of the set application
325
+     * @return string the name of your application
326
+     */
327
+    function getAppName() {
328
+        return $this->query('AppName');
329
+    }
330
+
331
+    /**
332
+     * @deprecated use IUserSession->isLoggedIn()
333
+     * @return boolean
334
+     */
335
+    function isLoggedIn() {
336
+        return \OC::$server->getUserSession()->isLoggedIn();
337
+    }
338
+
339
+    /**
340
+     * @deprecated use IGroupManager->isAdmin($userId)
341
+     * @return boolean
342
+     */
343
+    function isAdminUser() {
344
+        $uid = $this->getUserId();
345
+        return \OC_User::isAdminUser($uid);
346
+    }
347
+
348
+    private function getUserId() {
349
+        return $this->getServer()->getSession()->get('user_id');
350
+    }
351
+
352
+    /**
353
+     * @deprecated use the ILogger instead
354
+     * @param string $message
355
+     * @param string $level
356
+     * @return mixed
357
+     */
358
+    function log($message, $level) {
359
+        switch($level){
360
+            case 'debug':
361
+                $level = \OCP\Util::DEBUG;
362
+                break;
363
+            case 'info':
364
+                $level = \OCP\Util::INFO;
365
+                break;
366
+            case 'warn':
367
+                $level = \OCP\Util::WARN;
368
+                break;
369
+            case 'fatal':
370
+                $level = \OCP\Util::FATAL;
371
+                break;
372
+            default:
373
+                $level = \OCP\Util::ERROR;
374
+                break;
375
+        }
376
+        \OCP\Util::writeLog($this->getAppName(), $message, $level);
377
+    }
378
+
379
+    /**
380
+     * Register a capability
381
+     *
382
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
383
+     */
384
+    public function registerCapability($serviceName) {
385
+        $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
386
+            return $this->query($serviceName);
387
+        });
388
+    }
389
+
390
+    /**
391
+     * @param string $name
392
+     * @return mixed
393
+     * @throws QueryException if the query could not be resolved
394
+     */
395
+    public function query($name) {
396
+        try {
397
+            return $this->queryNoFallback($name);
398
+        } catch (QueryException $e) {
399
+            return $this->getServer()->query($name);
400
+        }
401
+    }
402
+
403
+    /**
404
+     * @param string $name
405
+     * @return mixed
406
+     * @throws QueryException if the query could not be resolved
407
+     */
408
+    public function queryNoFallback($name) {
409
+        $name = $this->sanitizeName($name);
410
+
411
+        if ($this->offsetExists($name)) {
412
+            return parent::query($name);
413
+        } else {
414
+            if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
415
+                return parent::query($name);
416
+            } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
417
+                return parent::query($name);
418
+            } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
419
+                return parent::query($name);
420
+            }
421
+        }
422
+
423
+        throw new QueryException('Could not resolve ' . $name . '!' .
424
+            ' Class can not be instantiated');
425
+    }
426 426
 }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @param array $urlParams
77 77
 	 * @param ServerContainer $server
78 78
 	 */
79
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
79
+	public function __construct($appName, $urlParams = array(), ServerContainer $server = null) {
80 80
 		parent::__construct();
81 81
 		$this['AppName'] = $appName;
82 82
 		$this['urlParams'] = $urlParams;
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		/**
97 97
 		 * Core services
98 98
 		 */
99
-		$this->registerService(IOutput::class, function($c){
99
+		$this->registerService(IOutput::class, function($c) {
100 100
 			return new Output($this->getServer()->getWebRoot());
101 101
 		});
102 102
 
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 			return $this->getServer()->getUserFolder();
105 105
 		});
106 106
 
107
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
107
+		$this->registerService(IAppData::class, function(SimpleContainer $c) {
108 108
 			return $this->getServer()->getAppDataDir($c->query('AppName'));
109 109
 		});
110 110
 
@@ -125,25 +125,25 @@  discard block
 block discarded – undo
125 125
 
126 126
 		$this->registerAlias(\OC\User\Session::class, \OCP\IUserSession::class);
127 127
 
128
-		$this->registerService(IServerContainer::class, function ($c) {
128
+		$this->registerService(IServerContainer::class, function($c) {
129 129
 			return $this->getServer();
130 130
 		});
131 131
 		$this->registerAlias('ServerContainer', IServerContainer::class);
132 132
 
133
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
133
+		$this->registerService(\OCP\WorkflowEngine\IManager::class, function($c) {
134 134
 			return $c->query('OCA\WorkflowEngine\Manager');
135 135
 		});
136 136
 
137
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
137
+		$this->registerService(\OCP\AppFramework\IAppContainer::class, function($c) {
138 138
 			return $c;
139 139
 		});
140 140
 
141 141
 		// commonly used attributes
142
-		$this->registerService('UserId', function ($c) {
142
+		$this->registerService('UserId', function($c) {
143 143
 			return $c->query('OCP\\IUserSession')->getSession()->get('user_id');
144 144
 		});
145 145
 
146
-		$this->registerService('WebRoot', function ($c) {
146
+		$this->registerService('WebRoot', function($c) {
147 147
 			return $c->query('ServerContainer')->getWebRoot();
148 148
 		});
149 149
 
@@ -151,11 +151,11 @@  discard block
 block discarded – undo
151 151
 			return Util::getDefaultEmailAddress('no-reply');
152 152
 		});
153 153
 
154
-		$this->registerService('OC_Defaults', function ($c) {
154
+		$this->registerService('OC_Defaults', function($c) {
155 155
 			return $c->getServer()->getThemingDefaults();
156 156
 		});
157 157
 
158
-		$this->registerService('OCP\Encryption\IManager', function ($c) {
158
+		$this->registerService('OCP\Encryption\IManager', function($c) {
159 159
 			return $this->getServer()->getEncryptionManager();
160 160
 		});
161 161
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 			return $c->query(Validator::class);
164 164
 		});
165 165
 
166
-		$this->registerService(\OC\Security\IdentityProof\Manager::class, function ($c) {
166
+		$this->registerService(\OC\Security\IdentityProof\Manager::class, function($c) {
167 167
 			return new \OC\Security\IdentityProof\Manager(
168 168
 				$this->getServer()->getAppDataDir('identityproof'),
169 169
 				$this->getServer()->getCrypto()
@@ -173,15 +173,15 @@  discard block
 block discarded – undo
173 173
 		/**
174 174
 		 * App Framework APIs
175 175
 		 */
176
-		$this->registerService('API', function($c){
176
+		$this->registerService('API', function($c) {
177 177
 			$c->query('OCP\\ILogger')->debug(
178
-				'Accessing the API class is deprecated! Use the appropriate ' .
178
+				'Accessing the API class is deprecated! Use the appropriate '.
179 179
 				'services instead!'
180 180
 			);
181 181
 			return new API($c['AppName']);
182 182
 		});
183 183
 
184
-		$this->registerService('Protocol', function($c){
184
+		$this->registerService('Protocol', function($c) {
185 185
 			/** @var \OC\Server $server */
186 186
 			$server = $c->query('ServerContainer');
187 187
 			$protocol = $server->getRequest()->getHttpProtocol();
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 			);
260 260
 		});
261 261
 
262
-		$this->registerService('TwoFactorMiddleware', function (SimpleContainer $c) use ($app) {
262
+		$this->registerService('TwoFactorMiddleware', function(SimpleContainer $c) use ($app) {
263 263
 			$twoFactorManager = $c->getServer()->getTwoFactorAuthManager();
264 264
 			$userSession = $app->getServer()->getUserSession();
265 265
 			$session = $app->getServer()->getSession();
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 			return new TwoFactorMiddleware($twoFactorManager, $userSession, $session, $urlGenerator, $reflector, $request);
270 270
 		});
271 271
 
272
-		$this->registerService('OCSMiddleware', function (SimpleContainer $c) {
272
+		$this->registerService('OCSMiddleware', function(SimpleContainer $c) {
273 273
 			return new OCSMiddleware(
274 274
 				$c['Request']
275 275
 			);
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
 			$dispatcher->registerMiddleWare($c['TwoFactorMiddleware']);
285 285
 			$dispatcher->registerMiddleware($c['RateLimitingMiddleware']);
286 286
 
287
-			foreach($middleWares as $middleWare) {
287
+			foreach ($middleWares as $middleWare) {
288 288
 				$dispatcher->registerMiddleware($c[$middleWare]);
289 289
 			}
290 290
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
 	 * @return mixed
357 357
 	 */
358 358
 	function log($message, $level) {
359
-		switch($level){
359
+		switch ($level) {
360 360
 			case 'debug':
361 361
 				$level = \OCP\Util::DEBUG;
362 362
 				break;
@@ -415,12 +415,12 @@  discard block
 block discarded – undo
415 415
 				return parent::query($name);
416 416
 			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
417 417
 				return parent::query($name);
418
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
418
+			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']).'\\') === 0) {
419 419
 				return parent::query($name);
420 420
 			}
421 421
 		}
422 422
 
423
-		throw new QueryException('Could not resolve ' . $name . '!' .
423
+		throw new QueryException('Could not resolve '.$name.'!'.
424 424
 			' Class can not be instantiated');
425 425
 	}
426 426
 }
Please login to merge, or discard this patch.
lib/private/Security/RateLimiting/Backend/MemoryCache.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
  * @package OC\Security\RateLimiting\Backend
33 33
  */
34 34
 class MemoryCache implements IBackend {
35
-	/** @var ICache */
36
-	private $cache;
37
-	/** @var ITimeFactory */
38
-	private $timeFactory;
35
+    /** @var ICache */
36
+    private $cache;
37
+    /** @var ITimeFactory */
38
+    private $timeFactory;
39 39
 
40
-	/**
41
-	 * @param ICacheFactory $cacheFactory
42
-	 * @param ITimeFactory $timeFactory
43
-	 */
44
-	public function __construct(ICacheFactory $cacheFactory,
45
-								ITimeFactory $timeFactory) {
46
-		$this->cache = $cacheFactory->create(__CLASS__);
47
-		$this->timeFactory = $timeFactory;
48
-	}
40
+    /**
41
+     * @param ICacheFactory $cacheFactory
42
+     * @param ITimeFactory $timeFactory
43
+     */
44
+    public function __construct(ICacheFactory $cacheFactory,
45
+                                ITimeFactory $timeFactory) {
46
+        $this->cache = $cacheFactory->create(__CLASS__);
47
+        $this->timeFactory = $timeFactory;
48
+    }
49 49
 
50
-	/**
51
-	 * @param string $methodIdentifier
52
-	 * @param string $userIdentifier
53
-	 * @return string
54
-	 */
55
-	private function hash($methodIdentifier,
56
-						  $userIdentifier) {
57
-		return hash('sha512', $methodIdentifier . $userIdentifier);
58
-	}
50
+    /**
51
+     * @param string $methodIdentifier
52
+     * @param string $userIdentifier
53
+     * @return string
54
+     */
55
+    private function hash($methodIdentifier,
56
+                            $userIdentifier) {
57
+        return hash('sha512', $methodIdentifier . $userIdentifier);
58
+    }
59 59
 
60
-	/**
61
-	 * @param string $identifier
62
-	 * @return array
63
-	 */
64
-	private function getExistingAttempts($identifier) {
65
-		$cachedAttempts = json_decode($this->cache->get($identifier), true);
66
-		if(is_array($cachedAttempts)) {
67
-			return $cachedAttempts;
68
-		}
60
+    /**
61
+     * @param string $identifier
62
+     * @return array
63
+     */
64
+    private function getExistingAttempts($identifier) {
65
+        $cachedAttempts = json_decode($this->cache->get($identifier), true);
66
+        if(is_array($cachedAttempts)) {
67
+            return $cachedAttempts;
68
+        }
69 69
 
70
-		return [];
71
-	}
70
+        return [];
71
+    }
72 72
 
73
-	/**
74
-	 * {@inheritDoc}
75
-	 */
76
-	public function getAttempts($methodIdentifier,
77
-								$userIdentifier,
78
-								$seconds) {
79
-		$identifier = $this->hash($methodIdentifier, $userIdentifier);
80
-		$existingAttempts = $this->getExistingAttempts($identifier);
73
+    /**
74
+     * {@inheritDoc}
75
+     */
76
+    public function getAttempts($methodIdentifier,
77
+                                $userIdentifier,
78
+                                $seconds) {
79
+        $identifier = $this->hash($methodIdentifier, $userIdentifier);
80
+        $existingAttempts = $this->getExistingAttempts($identifier);
81 81
 
82
-		$count = 0;
83
-		$currentTime = $this->timeFactory->getTime();
84
-		/** @var array $existingAttempts */
85
-		foreach ($existingAttempts as $attempt) {
86
-			if(($attempt + $seconds) > $currentTime) {
87
-				$count++;
88
-			}
89
-		}
82
+        $count = 0;
83
+        $currentTime = $this->timeFactory->getTime();
84
+        /** @var array $existingAttempts */
85
+        foreach ($existingAttempts as $attempt) {
86
+            if(($attempt + $seconds) > $currentTime) {
87
+                $count++;
88
+            }
89
+        }
90 90
 
91
-		return $count;
92
-	}
91
+        return $count;
92
+    }
93 93
 
94
-	/**
95
-	 * {@inheritDoc}
96
-	 */
97
-	public function registerAttempt($methodIdentifier,
98
-									$userIdentifier,
99
-									$period) {
100
-		$identifier = $this->hash($methodIdentifier, $userIdentifier);
101
-		$existingAttempts = $this->getExistingAttempts($identifier);
102
-		$currentTime = $this->timeFactory->getTime();
94
+    /**
95
+     * {@inheritDoc}
96
+     */
97
+    public function registerAttempt($methodIdentifier,
98
+                                    $userIdentifier,
99
+                                    $period) {
100
+        $identifier = $this->hash($methodIdentifier, $userIdentifier);
101
+        $existingAttempts = $this->getExistingAttempts($identifier);
102
+        $currentTime = $this->timeFactory->getTime();
103 103
 
104
-		// Unset all attempts older than $period
105
-		foreach ($existingAttempts as $key => $attempt) {
106
-			if(($attempt + $period) < $currentTime) {
107
-				unset($existingAttempts[$key]);
108
-			}
109
-		}
110
-		$existingAttempts = array_values($existingAttempts);
104
+        // Unset all attempts older than $period
105
+        foreach ($existingAttempts as $key => $attempt) {
106
+            if(($attempt + $period) < $currentTime) {
107
+                unset($existingAttempts[$key]);
108
+            }
109
+        }
110
+        $existingAttempts = array_values($existingAttempts);
111 111
 
112
-		// Store the new attempt
113
-		$existingAttempts[] = (string)$currentTime;
114
-		$this->cache->set($identifier, json_encode($existingAttempts));
115
-	}
112
+        // Store the new attempt
113
+        $existingAttempts[] = (string)$currentTime;
114
+        $this->cache->set($identifier, json_encode($existingAttempts));
115
+    }
116 116
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 */
55 55
 	private function hash($methodIdentifier,
56 56
 						  $userIdentifier) {
57
-		return hash('sha512', $methodIdentifier . $userIdentifier);
57
+		return hash('sha512', $methodIdentifier.$userIdentifier);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 */
64 64
 	private function getExistingAttempts($identifier) {
65 65
 		$cachedAttempts = json_decode($this->cache->get($identifier), true);
66
-		if(is_array($cachedAttempts)) {
66
+		if (is_array($cachedAttempts)) {
67 67
 			return $cachedAttempts;
68 68
 		}
69 69
 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		$currentTime = $this->timeFactory->getTime();
84 84
 		/** @var array $existingAttempts */
85 85
 		foreach ($existingAttempts as $attempt) {
86
-			if(($attempt + $seconds) > $currentTime) {
86
+			if (($attempt + $seconds) > $currentTime) {
87 87
 				$count++;
88 88
 			}
89 89
 		}
@@ -103,14 +103,14 @@  discard block
 block discarded – undo
103 103
 
104 104
 		// Unset all attempts older than $period
105 105
 		foreach ($existingAttempts as $key => $attempt) {
106
-			if(($attempt + $period) < $currentTime) {
106
+			if (($attempt + $period) < $currentTime) {
107 107
 				unset($existingAttempts[$key]);
108 108
 			}
109 109
 		}
110 110
 		$existingAttempts = array_values($existingAttempts);
111 111
 
112 112
 		// Store the new attempt
113
-		$existingAttempts[] = (string)$currentTime;
113
+		$existingAttempts[] = (string) $currentTime;
114 114
 		$this->cache->set($identifier, json_encode($existingAttempts));
115 115
 	}
116 116
 }
Please login to merge, or discard this patch.
lib/private/Security/RateLimiting/Backend/IBackend.php 1 patch
Indentation   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -29,26 +29,26 @@
 block discarded – undo
29 29
  * @package OC\Security\RateLimiting\Backend
30 30
  */
31 31
 interface IBackend {
32
-	/**
33
-	 * Gets the amount of attempts within the last specified seconds
34
-	 *
35
-	 * @param string $methodIdentifier Identifier for the method
36
-	 * @param string $userIdentifier Identifier for the user
37
-	 * @param int $seconds Seconds to look back at
38
-	 * @return int
39
-	 */
40
-	public function getAttempts($methodIdentifier,
41
-								$userIdentifier,
42
-								$seconds);
32
+    /**
33
+     * Gets the amount of attempts within the last specified seconds
34
+     *
35
+     * @param string $methodIdentifier Identifier for the method
36
+     * @param string $userIdentifier Identifier for the user
37
+     * @param int $seconds Seconds to look back at
38
+     * @return int
39
+     */
40
+    public function getAttempts($methodIdentifier,
41
+                                $userIdentifier,
42
+                                $seconds);
43 43
 
44
-	/**
45
-	 * Registers an attempt
46
-	 *
47
-	 * @param string $methodIdentifier Identifier for the method
48
-	 * @param string $userIdentifier Identifier for the user
49
-	 * @param int $period Period in seconds how long this attempt should be stored
50
-	 */
51
-	public function registerAttempt($methodIdentifier,
52
-									$userIdentifier,
53
-									$period);
44
+    /**
45
+     * Registers an attempt
46
+     *
47
+     * @param string $methodIdentifier Identifier for the method
48
+     * @param string $userIdentifier Identifier for the user
49
+     * @param int $period Period in seconds how long this attempt should be stored
50
+     */
51
+    public function registerAttempt($methodIdentifier,
52
+                                    $userIdentifier,
53
+                                    $period);
54 54
 }
Please login to merge, or discard this patch.