Completed
Pull Request — master (#9345)
by Björn
23:58
created
lib/public/Federation/ICloudFederationProviderManager.php 1 patch
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -32,76 +32,76 @@
 block discarded – undo
32 32
  */
33 33
 interface ICloudFederationProviderManager {
34 34
 
35
-	/**
36
-	 * Registers an callback function which must return an cloud federation provider
37
-	 *
38
-	 * @param string $resourceType which resource type does the provider handles
39
-	 * @param string $displayName user facing name of the federated share provider
40
-	 * @param callable $callback
41
-	 * @throws Exceptions\ProviderAlreadyExistsException
42
-	 *
43
-	 * @since 14.0.0
44
-	 */
45
-	public function addCloudFederationProvider($resourceType, $displayName, callable $callback);
35
+    /**
36
+     * Registers an callback function which must return an cloud federation provider
37
+     *
38
+     * @param string $resourceType which resource type does the provider handles
39
+     * @param string $displayName user facing name of the federated share provider
40
+     * @param callable $callback
41
+     * @throws Exceptions\ProviderAlreadyExistsException
42
+     *
43
+     * @since 14.0.0
44
+     */
45
+    public function addCloudFederationProvider($resourceType, $displayName, callable $callback);
46 46
 
47
-	/**
48
-	 * remove cloud federation provider
49
-	 *
50
-	 * @param string $resourceType
51
-	 *
52
-	 * @since 14.0.0
53
-	 */
54
-	public function removeCloudFederationProvider($resourceType);
47
+    /**
48
+     * remove cloud federation provider
49
+     *
50
+     * @param string $resourceType
51
+     *
52
+     * @since 14.0.0
53
+     */
54
+    public function removeCloudFederationProvider($resourceType);
55 55
 
56
-	/**
57
-	 * get a list of all cloudFederationProviders
58
-	 *
59
-	 * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]]
60
-	 *
61
-	 * @since 14.0.0
62
-	 */
63
-	public function getAllCloudFederationProviders();
56
+    /**
57
+     * get a list of all cloudFederationProviders
58
+     *
59
+     * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]]
60
+     *
61
+     * @since 14.0.0
62
+     */
63
+    public function getAllCloudFederationProviders();
64 64
 
65
-	/**
66
-	 * get a specific cloud federation provider
67
-	 *
68
-	 * @param string $resourceType
69
-	 * @return ICloudFederationProvider
70
-	 * @throws Exceptions\ProviderDoesNotExistsException;
71
-	 *
72
-	 * @since 14.0.0
73
-	 */
74
-	public function getCloudFederationProvider($resourceType);
65
+    /**
66
+     * get a specific cloud federation provider
67
+     *
68
+     * @param string $resourceType
69
+     * @return ICloudFederationProvider
70
+     * @throws Exceptions\ProviderDoesNotExistsException;
71
+     *
72
+     * @since 14.0.0
73
+     */
74
+    public function getCloudFederationProvider($resourceType);
75 75
 
76
-	/**
77
-	 * send federated share
78
-	 *
79
-	 * @param ICloudFederationShare $share
80
-	 * @return bool
81
-	 *
82
-	 * @since 14.0.0
83
-	 */
84
-	public function sendShare(ICloudFederationShare $share);
76
+    /**
77
+     * send federated share
78
+     *
79
+     * @param ICloudFederationShare $share
80
+     * @return bool
81
+     *
82
+     * @since 14.0.0
83
+     */
84
+    public function sendShare(ICloudFederationShare $share);
85 85
 
86
-	/**
87
-	 * send notification about existing share
88
-	 *
89
-	 * @param string $url
90
-	 * @param ICloudFederationNotification $notification
91
-	 * @return mixed
92
-	 *
93
-	 * @since 14.0.0
94
-	 */
95
-	public function sendNotification($url, ICloudFederationNotification $notification);
86
+    /**
87
+     * send notification about existing share
88
+     *
89
+     * @param string $url
90
+     * @param ICloudFederationNotification $notification
91
+     * @return mixed
92
+     *
93
+     * @since 14.0.0
94
+     */
95
+    public function sendNotification($url, ICloudFederationNotification $notification);
96 96
 
97
-	/**
98
-	 * check if the new cloud federation API is ready to be used
99
-	 *
100
-	 * @return bool
101
-	 *
102
-	 * @since 14.0.0
103
-	 */
104
-	public function isReady();
97
+    /**
98
+     * check if the new cloud federation API is ready to be used
99
+     *
100
+     * @return bool
101
+     *
102
+     * @since 14.0.0
103
+     */
104
+    public function isReady();
105 105
 
106 106
 
107 107
 }
Please login to merge, or discard this patch.
apps/cloud_federation_api/lib/Config.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -35,23 +35,23 @@
 block discarded – undo
35 35
  */
36 36
 class Config {
37 37
 
38
-	/** @var ICloudFederationProviderManager */
39
-	private $cloudFederationProviderManager;
40
-
41
-	public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
42
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
43
-	}
44
-
45
-	/**
46
-	 * get a list of supported share types
47
-	 *
48
-	 * @param string $resourceType
49
-	 * @return array
50
-	 * @throws \OCP\Federation\Exceptions\ProviderDoesNotExistsException
51
-	 */
52
-	public function getSupportedShareTypes($resourceType) {
53
-		$provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
54
-		return $provider->getSupportedShareTypes();
55
-	}
38
+    /** @var ICloudFederationProviderManager */
39
+    private $cloudFederationProviderManager;
40
+
41
+    public function __construct(ICloudFederationProviderManager $cloudFederationProviderManager) {
42
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
43
+    }
44
+
45
+    /**
46
+     * get a list of supported share types
47
+     *
48
+     * @param string $resourceType
49
+     * @return array
50
+     * @throws \OCP\Federation\Exceptions\ProviderDoesNotExistsException
51
+     */
52
+    public function getSupportedShareTypes($resourceType) {
53
+        $provider = $this->cloudFederationProviderManager->getCloudFederationProvider($resourceType);
54
+        return $provider->getSupportedShareTypes();
55
+    }
56 56
 
57 57
 }
Please login to merge, or discard this patch.
lib/private/Server.php 2 patches
Indentation   +1852 added lines, -1852 removed lines patch added patch discarded remove patch
@@ -158,1861 +158,1861 @@
 block discarded – undo
158 158
  * TODO: hookup all manager classes
159 159
  */
160 160
 class Server extends ServerContainer implements IServerContainer {
161
-	/** @var string */
162
-	private $webRoot;
163
-
164
-	/**
165
-	 * @param string $webRoot
166
-	 * @param \OC\Config $config
167
-	 */
168
-	public function __construct($webRoot, \OC\Config $config) {
169
-		parent::__construct();
170
-		$this->webRoot = $webRoot;
171
-
172
-		// To find out if we are running from CLI or not
173
-		$this->registerParameter('isCLI', \OC::$CLI);
174
-
175
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
176
-			return $c;
177
-		});
178
-
179
-		$this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
180
-		$this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
181
-
182
-		$this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
183
-		$this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
184
-
185
-		$this->registerAlias(IActionFactory::class, ActionFactory::class);
186
-
187
-
188
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
189
-			return new PreviewManager(
190
-				$c->getConfig(),
191
-				$c->getRootFolder(),
192
-				$c->getAppDataDir('preview'),
193
-				$c->getEventDispatcher(),
194
-				$c->getSession()->get('user_id')
195
-			);
196
-		});
197
-		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
198
-
199
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
200
-			return new \OC\Preview\Watcher(
201
-				$c->getAppDataDir('preview')
202
-			);
203
-		});
204
-
205
-		$this->registerService('EncryptionManager', function (Server $c) {
206
-			$view = new View();
207
-			$util = new Encryption\Util(
208
-				$view,
209
-				$c->getUserManager(),
210
-				$c->getGroupManager(),
211
-				$c->getConfig()
212
-			);
213
-			return new Encryption\Manager(
214
-				$c->getConfig(),
215
-				$c->getLogger(),
216
-				$c->getL10N('core'),
217
-				new View(),
218
-				$util,
219
-				new ArrayCache()
220
-			);
221
-		});
222
-
223
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
224
-			$util = new Encryption\Util(
225
-				new View(),
226
-				$c->getUserManager(),
227
-				$c->getGroupManager(),
228
-				$c->getConfig()
229
-			);
230
-			return new Encryption\File(
231
-				$util,
232
-				$c->getRootFolder(),
233
-				$c->getShareManager()
234
-			);
235
-		});
236
-
237
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
238
-			$view = new View();
239
-			$util = new Encryption\Util(
240
-				$view,
241
-				$c->getUserManager(),
242
-				$c->getGroupManager(),
243
-				$c->getConfig()
244
-			);
245
-
246
-			return new Encryption\Keys\Storage($view, $util);
247
-		});
248
-		$this->registerService('TagMapper', function (Server $c) {
249
-			return new TagMapper($c->getDatabaseConnection());
250
-		});
251
-
252
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
253
-			$tagMapper = $c->query('TagMapper');
254
-			return new TagManager($tagMapper, $c->getUserSession());
255
-		});
256
-		$this->registerAlias('TagManager', \OCP\ITagManager::class);
257
-
258
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
259
-			$config = $c->getConfig();
260
-			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
261
-			return new $factoryClass($this);
262
-		});
263
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
264
-			return $c->query('SystemTagManagerFactory')->getManager();
265
-		});
266
-		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
267
-
268
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
269
-			return $c->query('SystemTagManagerFactory')->getObjectMapper();
270
-		});
271
-		$this->registerService('RootFolder', function (Server $c) {
272
-			$manager = \OC\Files\Filesystem::getMountManager(null);
273
-			$view = new View();
274
-			$root = new Root(
275
-				$manager,
276
-				$view,
277
-				null,
278
-				$c->getUserMountCache(),
279
-				$this->getLogger(),
280
-				$this->getUserManager()
281
-			);
282
-			$connector = new HookConnector($root, $view);
283
-			$connector->viewToNode();
284
-
285
-			$previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
286
-			$previewConnector->connectWatcher();
287
-
288
-			return $root;
289
-		});
290
-		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
291
-
292
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
293
-			return new LazyRoot(function () use ($c) {
294
-				return $c->query('RootFolder');
295
-			});
296
-		});
297
-		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
298
-
299
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
300
-			$config = $c->getConfig();
301
-			return new \OC\User\Manager($config);
302
-		});
303
-		$this->registerAlias('UserManager', \OC\User\Manager::class);
304
-		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
305
-
306
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
307
-			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
308
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
309
-				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
310
-			});
311
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
312
-				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
313
-			});
314
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
315
-				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
316
-			});
317
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
318
-				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
319
-			});
320
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
321
-				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
322
-			});
323
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
324
-				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
325
-				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
326
-				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
327
-			});
328
-			return $groupManager;
329
-		});
330
-		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
331
-
332
-		$this->registerService(Store::class, function (Server $c) {
333
-			$session = $c->getSession();
334
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
335
-				$tokenProvider = $c->query(IProvider::class);
336
-			} else {
337
-				$tokenProvider = null;
338
-			}
339
-			$logger = $c->getLogger();
340
-			return new Store($session, $logger, $tokenProvider);
341
-		});
342
-		$this->registerAlias(IStore::class, Store::class);
343
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
344
-			$dbConnection = $c->getDatabaseConnection();
345
-			return new Authentication\Token\DefaultTokenMapper($dbConnection);
346
-		});
347
-		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
348
-
349
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
350
-			$manager = $c->getUserManager();
351
-			$session = new \OC\Session\Memory('');
352
-			$timeFactory = new TimeFactory();
353
-			// Token providers might require a working database. This code
354
-			// might however be called when ownCloud is not yet setup.
355
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
356
-				$defaultTokenProvider = $c->query(IProvider::class);
357
-			} else {
358
-				$defaultTokenProvider = null;
359
-			}
360
-
361
-			$dispatcher = $c->getEventDispatcher();
362
-
363
-			$userSession = new \OC\User\Session(
364
-				$manager,
365
-				$session,
366
-				$timeFactory,
367
-				$defaultTokenProvider,
368
-				$c->getConfig(),
369
-				$c->getSecureRandom(),
370
-				$c->getLockdownManager(),
371
-				$c->getLogger()
372
-			);
373
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
374
-				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
375
-			});
376
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
377
-				/** @var $user \OC\User\User */
378
-				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
379
-			});
380
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
381
-				/** @var $user \OC\User\User */
382
-				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
383
-				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
384
-			});
385
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
386
-				/** @var $user \OC\User\User */
387
-				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
388
-			});
389
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
390
-				/** @var $user \OC\User\User */
391
-				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
392
-			});
393
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
394
-				/** @var $user \OC\User\User */
395
-				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
396
-			});
397
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
398
-				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
399
-			});
400
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
401
-				/** @var $user \OC\User\User */
402
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
403
-			});
404
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
405
-				/** @var $user \OC\User\User */
406
-				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
407
-			});
408
-			$userSession->listen('\OC\User', 'logout', function () {
409
-				\OC_Hook::emit('OC_User', 'logout', array());
410
-			});
411
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
412
-				/** @var $user \OC\User\User */
413
-				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
414
-				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
415
-			});
416
-			return $userSession;
417
-		});
418
-		$this->registerAlias('UserSession', \OCP\IUserSession::class);
419
-
420
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
421
-			return new \OC\Authentication\TwoFactorAuth\Manager(
422
-				$c->getAppManager(),
423
-				$c->getSession(),
424
-				$c->getConfig(),
425
-				$c->getActivityManager(),
426
-				$c->getLogger(),
427
-				$c->query(IProvider::class),
428
-				$c->query(ITimeFactory::class),
429
-				$c->query(EventDispatcherInterface::class)
430
-			);
431
-		});
432
-
433
-		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
434
-		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
435
-
436
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
437
-			return new \OC\AllConfig(
438
-				$c->getSystemConfig()
439
-			);
440
-		});
441
-		$this->registerAlias('AllConfig', \OC\AllConfig::class);
442
-		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
443
-
444
-		$this->registerService('SystemConfig', function ($c) use ($config) {
445
-			return new \OC\SystemConfig($config);
446
-		});
447
-
448
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
449
-			return new \OC\AppConfig($c->getDatabaseConnection());
450
-		});
451
-		$this->registerAlias('AppConfig', \OC\AppConfig::class);
452
-		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
453
-
454
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
455
-			return new \OC\L10N\Factory(
456
-				$c->getConfig(),
457
-				$c->getRequest(),
458
-				$c->getUserSession(),
459
-				\OC::$SERVERROOT
460
-			);
461
-		});
462
-		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
463
-
464
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
465
-			$config = $c->getConfig();
466
-			$cacheFactory = $c->getMemCacheFactory();
467
-			$request = $c->getRequest();
468
-			return new \OC\URLGenerator(
469
-				$config,
470
-				$cacheFactory,
471
-				$request
472
-			);
473
-		});
474
-		$this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
475
-
476
-		$this->registerAlias('AppFetcher', AppFetcher::class);
477
-		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
478
-
479
-		$this->registerService(\OCP\ICache::class, function ($c) {
480
-			return new Cache\File();
481
-		});
482
-		$this->registerAlias('UserCache', \OCP\ICache::class);
483
-
484
-		$this->registerService(Factory::class, function (Server $c) {
485
-
486
-			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
487
-				ArrayCache::class,
488
-				ArrayCache::class,
489
-				ArrayCache::class
490
-			);
491
-			$config = $c->getConfig();
492
-			$request = $c->getRequest();
493
-			$urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
494
-
495
-			if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
496
-				$v = \OC_App::getAppVersions();
497
-				$v['core'] = implode(',', \OC_Util::getVersion());
498
-				$version = implode(',', $v);
499
-				$instanceId = \OC_Util::getInstanceId();
500
-				$path = \OC::$SERVERROOT;
501
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
502
-				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
503
-					$config->getSystemValue('memcache.local', null),
504
-					$config->getSystemValue('memcache.distributed', null),
505
-					$config->getSystemValue('memcache.locking', null)
506
-				);
507
-			}
508
-			return $arrayCacheFactory;
509
-
510
-		});
511
-		$this->registerAlias('MemCacheFactory', Factory::class);
512
-		$this->registerAlias(ICacheFactory::class, Factory::class);
513
-
514
-		$this->registerService('RedisFactory', function (Server $c) {
515
-			$systemConfig = $c->getSystemConfig();
516
-			return new RedisFactory($systemConfig);
517
-		});
518
-
519
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
520
-			return new \OC\Activity\Manager(
521
-				$c->getRequest(),
522
-				$c->getUserSession(),
523
-				$c->getConfig(),
524
-				$c->query(IValidator::class)
525
-			);
526
-		});
527
-		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
528
-
529
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
530
-			return new \OC\Activity\EventMerger(
531
-				$c->getL10N('lib')
532
-			);
533
-		});
534
-		$this->registerAlias(IValidator::class, Validator::class);
535
-
536
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
537
-			return new AvatarManager(
538
-				$c->query(\OC\User\Manager::class),
539
-				$c->getAppDataDir('avatar'),
540
-				$c->getL10N('lib'),
541
-				$c->getLogger(),
542
-				$c->getConfig()
543
-			);
544
-		});
545
-		$this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
546
-
547
-		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
548
-
549
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
550
-			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
551
-			$factory = new LogFactory($c, $this->getSystemConfig());
552
-			$logger = $factory->get($logType);
553
-			$registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
554
-
555
-			return new Log($logger, $this->getSystemConfig(), null, $registry);
556
-		});
557
-		$this->registerAlias('Logger', \OCP\ILogger::class);
558
-
559
-		$this->registerService(ILogFactory::class, function (Server $c) {
560
-			return new LogFactory($c, $this->getSystemConfig());
561
-		});
562
-
563
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
564
-			$config = $c->getConfig();
565
-			return new \OC\BackgroundJob\JobList(
566
-				$c->getDatabaseConnection(),
567
-				$config,
568
-				new TimeFactory()
569
-			);
570
-		});
571
-		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
572
-
573
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
574
-			$cacheFactory = $c->getMemCacheFactory();
575
-			$logger = $c->getLogger();
576
-			if ($cacheFactory->isLocalCacheAvailable()) {
577
-				$router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
578
-			} else {
579
-				$router = new \OC\Route\Router($logger);
580
-			}
581
-			return $router;
582
-		});
583
-		$this->registerAlias('Router', \OCP\Route\IRouter::class);
584
-
585
-		$this->registerService(\OCP\ISearch::class, function ($c) {
586
-			return new Search();
587
-		});
588
-		$this->registerAlias('Search', \OCP\ISearch::class);
589
-
590
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
591
-			return new \OC\Security\RateLimiting\Limiter(
592
-				$this->getUserSession(),
593
-				$this->getRequest(),
594
-				new \OC\AppFramework\Utility\TimeFactory(),
595
-				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
596
-			);
597
-		});
598
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
599
-			return new \OC\Security\RateLimiting\Backend\MemoryCache(
600
-				$this->getMemCacheFactory(),
601
-				new \OC\AppFramework\Utility\TimeFactory()
602
-			);
603
-		});
604
-
605
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
606
-			return new SecureRandom();
607
-		});
608
-		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
609
-
610
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
611
-			return new Crypto($c->getConfig(), $c->getSecureRandom());
612
-		});
613
-		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
614
-
615
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
616
-			return new Hasher($c->getConfig());
617
-		});
618
-		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
619
-
620
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
621
-			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
622
-		});
623
-		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
624
-
625
-		$this->registerService(IDBConnection::class, function (Server $c) {
626
-			$systemConfig = $c->getSystemConfig();
627
-			$factory = new \OC\DB\ConnectionFactory($systemConfig);
628
-			$type = $systemConfig->getValue('dbtype', 'sqlite');
629
-			if (!$factory->isValidType($type)) {
630
-				throw new \OC\DatabaseException('Invalid database type');
631
-			}
632
-			$connectionParams = $factory->createConnectionParams();
633
-			$connection = $factory->getConnection($type, $connectionParams);
634
-			$connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
635
-			return $connection;
636
-		});
637
-		$this->registerAlias('DatabaseConnection', IDBConnection::class);
638
-
639
-
640
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
641
-			$user = \OC_User::getUser();
642
-			$uid = $user ? $user : null;
643
-			return new ClientService(
644
-				$c->getConfig(),
645
-				new \OC\Security\CertificateManager(
646
-					$uid,
647
-					new View(),
648
-					$c->getConfig(),
649
-					$c->getLogger(),
650
-					$c->getSecureRandom()
651
-				)
652
-			);
653
-		});
654
-		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
655
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
656
-			$eventLogger = new EventLogger();
657
-			if ($c->getSystemConfig()->getValue('debug', false)) {
658
-				// In debug mode, module is being activated by default
659
-				$eventLogger->activate();
660
-			}
661
-			return $eventLogger;
662
-		});
663
-		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
664
-
665
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
666
-			$queryLogger = new QueryLogger();
667
-			if ($c->getSystemConfig()->getValue('debug', false)) {
668
-				// In debug mode, module is being activated by default
669
-				$queryLogger->activate();
670
-			}
671
-			return $queryLogger;
672
-		});
673
-		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
674
-
675
-		$this->registerService(TempManager::class, function (Server $c) {
676
-			return new TempManager(
677
-				$c->getLogger(),
678
-				$c->getConfig()
679
-			);
680
-		});
681
-		$this->registerAlias('TempManager', TempManager::class);
682
-		$this->registerAlias(ITempManager::class, TempManager::class);
683
-
684
-		$this->registerService(AppManager::class, function (Server $c) {
685
-			return new \OC\App\AppManager(
686
-				$c->getUserSession(),
687
-				$c->query(\OC\AppConfig::class),
688
-				$c->getGroupManager(),
689
-				$c->getMemCacheFactory(),
690
-				$c->getEventDispatcher()
691
-			);
692
-		});
693
-		$this->registerAlias('AppManager', AppManager::class);
694
-		$this->registerAlias(IAppManager::class, AppManager::class);
695
-
696
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
697
-			return new DateTimeZone(
698
-				$c->getConfig(),
699
-				$c->getSession()
700
-			);
701
-		});
702
-		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
703
-
704
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
705
-			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
706
-
707
-			return new DateTimeFormatter(
708
-				$c->getDateTimeZone()->getTimeZone(),
709
-				$c->getL10N('lib', $language)
710
-			);
711
-		});
712
-		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
713
-
714
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
715
-			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
716
-			$listener = new UserMountCacheListener($mountCache);
717
-			$listener->listen($c->getUserManager());
718
-			return $mountCache;
719
-		});
720
-		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
721
-
722
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
723
-			$loader = \OC\Files\Filesystem::getLoader();
724
-			$mountCache = $c->query('UserMountCache');
725
-			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
726
-
727
-			// builtin providers
728
-
729
-			$config = $c->getConfig();
730
-			$manager->registerProvider(new CacheMountProvider($config));
731
-			$manager->registerHomeProvider(new LocalHomeMountProvider());
732
-			$manager->registerHomeProvider(new ObjectHomeMountProvider($config));
733
-
734
-			return $manager;
735
-		});
736
-		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
737
-
738
-		$this->registerService('IniWrapper', function ($c) {
739
-			return new IniGetWrapper();
740
-		});
741
-		$this->registerService('AsyncCommandBus', function (Server $c) {
742
-			$busClass = $c->getConfig()->getSystemValue('commandbus');
743
-			if ($busClass) {
744
-				list($app, $class) = explode('::', $busClass, 2);
745
-				if ($c->getAppManager()->isInstalled($app)) {
746
-					\OC_App::loadApp($app);
747
-					return $c->query($class);
748
-				} else {
749
-					throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
750
-				}
751
-			} else {
752
-				$jobList = $c->getJobList();
753
-				return new CronBus($jobList);
754
-			}
755
-		});
756
-		$this->registerService('TrustedDomainHelper', function ($c) {
757
-			return new TrustedDomainHelper($this->getConfig());
758
-		});
759
-		$this->registerService('Throttler', function (Server $c) {
760
-			return new Throttler(
761
-				$c->getDatabaseConnection(),
762
-				new TimeFactory(),
763
-				$c->getLogger(),
764
-				$c->getConfig()
765
-			);
766
-		});
767
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
768
-			// IConfig and IAppManager requires a working database. This code
769
-			// might however be called when ownCloud is not yet setup.
770
-			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
771
-				$config = $c->getConfig();
772
-				$appManager = $c->getAppManager();
773
-			} else {
774
-				$config = null;
775
-				$appManager = null;
776
-			}
777
-
778
-			return new Checker(
779
-				new EnvironmentHelper(),
780
-				new FileAccessHelper(),
781
-				new AppLocator(),
782
-				$config,
783
-				$c->getMemCacheFactory(),
784
-				$appManager,
785
-				$c->getTempManager()
786
-			);
787
-		});
788
-		$this->registerService(\OCP\IRequest::class, function ($c) {
789
-			if (isset($this['urlParams'])) {
790
-				$urlParams = $this['urlParams'];
791
-			} else {
792
-				$urlParams = [];
793
-			}
794
-
795
-			if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
796
-				&& in_array('fakeinput', stream_get_wrappers())
797
-			) {
798
-				$stream = 'fakeinput://data';
799
-			} else {
800
-				$stream = 'php://input';
801
-			}
802
-
803
-			return new Request(
804
-				[
805
-					'get' => $_GET,
806
-					'post' => $_POST,
807
-					'files' => $_FILES,
808
-					'server' => $_SERVER,
809
-					'env' => $_ENV,
810
-					'cookies' => $_COOKIE,
811
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
812
-						? $_SERVER['REQUEST_METHOD']
813
-						: '',
814
-					'urlParams' => $urlParams,
815
-				],
816
-				$this->getSecureRandom(),
817
-				$this->getConfig(),
818
-				$this->getCsrfTokenManager(),
819
-				$stream
820
-			);
821
-		});
822
-		$this->registerAlias('Request', \OCP\IRequest::class);
823
-
824
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
825
-			return new Mailer(
826
-				$c->getConfig(),
827
-				$c->getLogger(),
828
-				$c->query(Defaults::class),
829
-				$c->getURLGenerator(),
830
-				$c->getL10N('lib')
831
-			);
832
-		});
833
-		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
834
-
835
-		$this->registerService('LDAPProvider', function (Server $c) {
836
-			$config = $c->getConfig();
837
-			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
838
-			if (is_null($factoryClass)) {
839
-				throw new \Exception('ldapProviderFactory not set');
840
-			}
841
-			/** @var \OCP\LDAP\ILDAPProviderFactory $factory */
842
-			$factory = new $factoryClass($this);
843
-			return $factory->getLDAPProvider();
844
-		});
845
-		$this->registerService(ILockingProvider::class, function (Server $c) {
846
-			$ini = $c->getIniWrapper();
847
-			$config = $c->getConfig();
848
-			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
849
-			if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
850
-				/** @var \OC\Memcache\Factory $memcacheFactory */
851
-				$memcacheFactory = $c->getMemCacheFactory();
852
-				$memcache = $memcacheFactory->createLocking('lock');
853
-				if (!($memcache instanceof \OC\Memcache\NullCache)) {
854
-					return new MemcacheLockingProvider($memcache, $ttl);
855
-				}
856
-				return new DBLockingProvider(
857
-					$c->getDatabaseConnection(),
858
-					$c->getLogger(),
859
-					new TimeFactory(),
860
-					$ttl,
861
-					!\OC::$CLI
862
-				);
863
-			}
864
-			return new NoopLockingProvider();
865
-		});
866
-		$this->registerAlias('LockingProvider', ILockingProvider::class);
867
-
868
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
869
-			return new \OC\Files\Mount\Manager();
870
-		});
871
-		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
872
-
873
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
874
-			return new \OC\Files\Type\Detection(
875
-				$c->getURLGenerator(),
876
-				\OC::$configDir,
877
-				\OC::$SERVERROOT . '/resources/config/'
878
-			);
879
-		});
880
-		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
881
-
882
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
883
-			return new \OC\Files\Type\Loader(
884
-				$c->getDatabaseConnection()
885
-			);
886
-		});
887
-		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
888
-		$this->registerService(BundleFetcher::class, function () {
889
-			return new BundleFetcher($this->getL10N('lib'));
890
-		});
891
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
892
-			return new Manager(
893
-				$c->query(IValidator::class)
894
-			);
895
-		});
896
-		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
897
-
898
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
899
-			$manager = new \OC\CapabilitiesManager($c->getLogger());
900
-			$manager->registerCapability(function () use ($c) {
901
-				return new \OC\OCS\CoreCapabilities($c->getConfig());
902
-			});
903
-			$manager->registerCapability(function () use ($c) {
904
-				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
905
-			});
906
-			return $manager;
907
-		});
908
-		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
909
-
910
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
911
-			$config = $c->getConfig();
912
-			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
913
-			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
914
-			$factory = new $factoryClass($this);
915
-			$manager = $factory->getManager();
916
-
917
-			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
918
-				$manager = $c->getUserManager();
919
-				$user = $manager->get($id);
920
-				if(is_null($user)) {
921
-					$l = $c->getL10N('core');
922
-					$displayName = $l->t('Unknown user');
923
-				} else {
924
-					$displayName = $user->getDisplayName();
925
-				}
926
-				return $displayName;
927
-			});
928
-
929
-			return $manager;
930
-		});
931
-		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
932
-
933
-		$this->registerService('ThemingDefaults', function (Server $c) {
934
-			/*
161
+    /** @var string */
162
+    private $webRoot;
163
+
164
+    /**
165
+     * @param string $webRoot
166
+     * @param \OC\Config $config
167
+     */
168
+    public function __construct($webRoot, \OC\Config $config) {
169
+        parent::__construct();
170
+        $this->webRoot = $webRoot;
171
+
172
+        // To find out if we are running from CLI or not
173
+        $this->registerParameter('isCLI', \OC::$CLI);
174
+
175
+        $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
176
+            return $c;
177
+        });
178
+
179
+        $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class);
180
+        $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class);
181
+
182
+        $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class);
183
+        $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class);
184
+
185
+        $this->registerAlias(IActionFactory::class, ActionFactory::class);
186
+
187
+
188
+        $this->registerService(\OCP\IPreview::class, function (Server $c) {
189
+            return new PreviewManager(
190
+                $c->getConfig(),
191
+                $c->getRootFolder(),
192
+                $c->getAppDataDir('preview'),
193
+                $c->getEventDispatcher(),
194
+                $c->getSession()->get('user_id')
195
+            );
196
+        });
197
+        $this->registerAlias('PreviewManager', \OCP\IPreview::class);
198
+
199
+        $this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
200
+            return new \OC\Preview\Watcher(
201
+                $c->getAppDataDir('preview')
202
+            );
203
+        });
204
+
205
+        $this->registerService('EncryptionManager', function (Server $c) {
206
+            $view = new View();
207
+            $util = new Encryption\Util(
208
+                $view,
209
+                $c->getUserManager(),
210
+                $c->getGroupManager(),
211
+                $c->getConfig()
212
+            );
213
+            return new Encryption\Manager(
214
+                $c->getConfig(),
215
+                $c->getLogger(),
216
+                $c->getL10N('core'),
217
+                new View(),
218
+                $util,
219
+                new ArrayCache()
220
+            );
221
+        });
222
+
223
+        $this->registerService('EncryptionFileHelper', function (Server $c) {
224
+            $util = new Encryption\Util(
225
+                new View(),
226
+                $c->getUserManager(),
227
+                $c->getGroupManager(),
228
+                $c->getConfig()
229
+            );
230
+            return new Encryption\File(
231
+                $util,
232
+                $c->getRootFolder(),
233
+                $c->getShareManager()
234
+            );
235
+        });
236
+
237
+        $this->registerService('EncryptionKeyStorage', function (Server $c) {
238
+            $view = new View();
239
+            $util = new Encryption\Util(
240
+                $view,
241
+                $c->getUserManager(),
242
+                $c->getGroupManager(),
243
+                $c->getConfig()
244
+            );
245
+
246
+            return new Encryption\Keys\Storage($view, $util);
247
+        });
248
+        $this->registerService('TagMapper', function (Server $c) {
249
+            return new TagMapper($c->getDatabaseConnection());
250
+        });
251
+
252
+        $this->registerService(\OCP\ITagManager::class, function (Server $c) {
253
+            $tagMapper = $c->query('TagMapper');
254
+            return new TagManager($tagMapper, $c->getUserSession());
255
+        });
256
+        $this->registerAlias('TagManager', \OCP\ITagManager::class);
257
+
258
+        $this->registerService('SystemTagManagerFactory', function (Server $c) {
259
+            $config = $c->getConfig();
260
+            $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
261
+            return new $factoryClass($this);
262
+        });
263
+        $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
264
+            return $c->query('SystemTagManagerFactory')->getManager();
265
+        });
266
+        $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
267
+
268
+        $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
269
+            return $c->query('SystemTagManagerFactory')->getObjectMapper();
270
+        });
271
+        $this->registerService('RootFolder', function (Server $c) {
272
+            $manager = \OC\Files\Filesystem::getMountManager(null);
273
+            $view = new View();
274
+            $root = new Root(
275
+                $manager,
276
+                $view,
277
+                null,
278
+                $c->getUserMountCache(),
279
+                $this->getLogger(),
280
+                $this->getUserManager()
281
+            );
282
+            $connector = new HookConnector($root, $view);
283
+            $connector->viewToNode();
284
+
285
+            $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig());
286
+            $previewConnector->connectWatcher();
287
+
288
+            return $root;
289
+        });
290
+        $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
291
+
292
+        $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
293
+            return new LazyRoot(function () use ($c) {
294
+                return $c->query('RootFolder');
295
+            });
296
+        });
297
+        $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
298
+
299
+        $this->registerService(\OC\User\Manager::class, function (Server $c) {
300
+            $config = $c->getConfig();
301
+            return new \OC\User\Manager($config);
302
+        });
303
+        $this->registerAlias('UserManager', \OC\User\Manager::class);
304
+        $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
305
+
306
+        $this->registerService(\OCP\IGroupManager::class, function (Server $c) {
307
+            $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
308
+            $groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
309
+                \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
310
+            });
311
+            $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
312
+                \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
313
+            });
314
+            $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
315
+                \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
316
+            });
317
+            $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
318
+                \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
319
+            });
320
+            $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
321
+                \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
322
+            });
323
+            $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
324
+                \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
325
+                //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
326
+                \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
327
+            });
328
+            return $groupManager;
329
+        });
330
+        $this->registerAlias('GroupManager', \OCP\IGroupManager::class);
331
+
332
+        $this->registerService(Store::class, function (Server $c) {
333
+            $session = $c->getSession();
334
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
335
+                $tokenProvider = $c->query(IProvider::class);
336
+            } else {
337
+                $tokenProvider = null;
338
+            }
339
+            $logger = $c->getLogger();
340
+            return new Store($session, $logger, $tokenProvider);
341
+        });
342
+        $this->registerAlias(IStore::class, Store::class);
343
+        $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
344
+            $dbConnection = $c->getDatabaseConnection();
345
+            return new Authentication\Token\DefaultTokenMapper($dbConnection);
346
+        });
347
+        $this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
348
+
349
+        $this->registerService(\OCP\IUserSession::class, function (Server $c) {
350
+            $manager = $c->getUserManager();
351
+            $session = new \OC\Session\Memory('');
352
+            $timeFactory = new TimeFactory();
353
+            // Token providers might require a working database. This code
354
+            // might however be called when ownCloud is not yet setup.
355
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
356
+                $defaultTokenProvider = $c->query(IProvider::class);
357
+            } else {
358
+                $defaultTokenProvider = null;
359
+            }
360
+
361
+            $dispatcher = $c->getEventDispatcher();
362
+
363
+            $userSession = new \OC\User\Session(
364
+                $manager,
365
+                $session,
366
+                $timeFactory,
367
+                $defaultTokenProvider,
368
+                $c->getConfig(),
369
+                $c->getSecureRandom(),
370
+                $c->getLockdownManager(),
371
+                $c->getLogger()
372
+            );
373
+            $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
374
+                \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
375
+            });
376
+            $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
377
+                /** @var $user \OC\User\User */
378
+                \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
379
+            });
380
+            $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
381
+                /** @var $user \OC\User\User */
382
+                \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
383
+                $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
384
+            });
385
+            $userSession->listen('\OC\User', 'postDelete', function ($user) {
386
+                /** @var $user \OC\User\User */
387
+                \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
388
+            });
389
+            $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
390
+                /** @var $user \OC\User\User */
391
+                \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
392
+            });
393
+            $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
394
+                /** @var $user \OC\User\User */
395
+                \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
396
+            });
397
+            $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
398
+                \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
399
+            });
400
+            $userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
401
+                /** @var $user \OC\User\User */
402
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
403
+            });
404
+            $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
405
+                /** @var $user \OC\User\User */
406
+                \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
407
+            });
408
+            $userSession->listen('\OC\User', 'logout', function () {
409
+                \OC_Hook::emit('OC_User', 'logout', array());
410
+            });
411
+            $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
412
+                /** @var $user \OC\User\User */
413
+                \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
414
+                $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
415
+            });
416
+            return $userSession;
417
+        });
418
+        $this->registerAlias('UserSession', \OCP\IUserSession::class);
419
+
420
+        $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
421
+            return new \OC\Authentication\TwoFactorAuth\Manager(
422
+                $c->getAppManager(),
423
+                $c->getSession(),
424
+                $c->getConfig(),
425
+                $c->getActivityManager(),
426
+                $c->getLogger(),
427
+                $c->query(IProvider::class),
428
+                $c->query(ITimeFactory::class),
429
+                $c->query(EventDispatcherInterface::class)
430
+            );
431
+        });
432
+
433
+        $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
434
+        $this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
435
+
436
+        $this->registerService(\OC\AllConfig::class, function (Server $c) {
437
+            return new \OC\AllConfig(
438
+                $c->getSystemConfig()
439
+            );
440
+        });
441
+        $this->registerAlias('AllConfig', \OC\AllConfig::class);
442
+        $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
443
+
444
+        $this->registerService('SystemConfig', function ($c) use ($config) {
445
+            return new \OC\SystemConfig($config);
446
+        });
447
+
448
+        $this->registerService(\OC\AppConfig::class, function (Server $c) {
449
+            return new \OC\AppConfig($c->getDatabaseConnection());
450
+        });
451
+        $this->registerAlias('AppConfig', \OC\AppConfig::class);
452
+        $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
453
+
454
+        $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
455
+            return new \OC\L10N\Factory(
456
+                $c->getConfig(),
457
+                $c->getRequest(),
458
+                $c->getUserSession(),
459
+                \OC::$SERVERROOT
460
+            );
461
+        });
462
+        $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
463
+
464
+        $this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
465
+            $config = $c->getConfig();
466
+            $cacheFactory = $c->getMemCacheFactory();
467
+            $request = $c->getRequest();
468
+            return new \OC\URLGenerator(
469
+                $config,
470
+                $cacheFactory,
471
+                $request
472
+            );
473
+        });
474
+        $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class);
475
+
476
+        $this->registerAlias('AppFetcher', AppFetcher::class);
477
+        $this->registerAlias('CategoryFetcher', CategoryFetcher::class);
478
+
479
+        $this->registerService(\OCP\ICache::class, function ($c) {
480
+            return new Cache\File();
481
+        });
482
+        $this->registerAlias('UserCache', \OCP\ICache::class);
483
+
484
+        $this->registerService(Factory::class, function (Server $c) {
485
+
486
+            $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
487
+                ArrayCache::class,
488
+                ArrayCache::class,
489
+                ArrayCache::class
490
+            );
491
+            $config = $c->getConfig();
492
+            $request = $c->getRequest();
493
+            $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request);
494
+
495
+            if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
496
+                $v = \OC_App::getAppVersions();
497
+                $v['core'] = implode(',', \OC_Util::getVersion());
498
+                $version = implode(',', $v);
499
+                $instanceId = \OC_Util::getInstanceId();
500
+                $path = \OC::$SERVERROOT;
501
+                $prefix = md5($instanceId . '-' . $version . '-' . $path);
502
+                return new \OC\Memcache\Factory($prefix, $c->getLogger(),
503
+                    $config->getSystemValue('memcache.local', null),
504
+                    $config->getSystemValue('memcache.distributed', null),
505
+                    $config->getSystemValue('memcache.locking', null)
506
+                );
507
+            }
508
+            return $arrayCacheFactory;
509
+
510
+        });
511
+        $this->registerAlias('MemCacheFactory', Factory::class);
512
+        $this->registerAlias(ICacheFactory::class, Factory::class);
513
+
514
+        $this->registerService('RedisFactory', function (Server $c) {
515
+            $systemConfig = $c->getSystemConfig();
516
+            return new RedisFactory($systemConfig);
517
+        });
518
+
519
+        $this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
520
+            return new \OC\Activity\Manager(
521
+                $c->getRequest(),
522
+                $c->getUserSession(),
523
+                $c->getConfig(),
524
+                $c->query(IValidator::class)
525
+            );
526
+        });
527
+        $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
528
+
529
+        $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
530
+            return new \OC\Activity\EventMerger(
531
+                $c->getL10N('lib')
532
+            );
533
+        });
534
+        $this->registerAlias(IValidator::class, Validator::class);
535
+
536
+        $this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
537
+            return new AvatarManager(
538
+                $c->query(\OC\User\Manager::class),
539
+                $c->getAppDataDir('avatar'),
540
+                $c->getL10N('lib'),
541
+                $c->getLogger(),
542
+                $c->getConfig()
543
+            );
544
+        });
545
+        $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class);
546
+
547
+        $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
548
+
549
+        $this->registerService(\OCP\ILogger::class, function (Server $c) {
550
+            $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
551
+            $factory = new LogFactory($c, $this->getSystemConfig());
552
+            $logger = $factory->get($logType);
553
+            $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class);
554
+
555
+            return new Log($logger, $this->getSystemConfig(), null, $registry);
556
+        });
557
+        $this->registerAlias('Logger', \OCP\ILogger::class);
558
+
559
+        $this->registerService(ILogFactory::class, function (Server $c) {
560
+            return new LogFactory($c, $this->getSystemConfig());
561
+        });
562
+
563
+        $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
564
+            $config = $c->getConfig();
565
+            return new \OC\BackgroundJob\JobList(
566
+                $c->getDatabaseConnection(),
567
+                $config,
568
+                new TimeFactory()
569
+            );
570
+        });
571
+        $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
572
+
573
+        $this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
574
+            $cacheFactory = $c->getMemCacheFactory();
575
+            $logger = $c->getLogger();
576
+            if ($cacheFactory->isLocalCacheAvailable()) {
577
+                $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger);
578
+            } else {
579
+                $router = new \OC\Route\Router($logger);
580
+            }
581
+            return $router;
582
+        });
583
+        $this->registerAlias('Router', \OCP\Route\IRouter::class);
584
+
585
+        $this->registerService(\OCP\ISearch::class, function ($c) {
586
+            return new Search();
587
+        });
588
+        $this->registerAlias('Search', \OCP\ISearch::class);
589
+
590
+        $this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
591
+            return new \OC\Security\RateLimiting\Limiter(
592
+                $this->getUserSession(),
593
+                $this->getRequest(),
594
+                new \OC\AppFramework\Utility\TimeFactory(),
595
+                $c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
596
+            );
597
+        });
598
+        $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
599
+            return new \OC\Security\RateLimiting\Backend\MemoryCache(
600
+                $this->getMemCacheFactory(),
601
+                new \OC\AppFramework\Utility\TimeFactory()
602
+            );
603
+        });
604
+
605
+        $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
606
+            return new SecureRandom();
607
+        });
608
+        $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
609
+
610
+        $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
611
+            return new Crypto($c->getConfig(), $c->getSecureRandom());
612
+        });
613
+        $this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
614
+
615
+        $this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
616
+            return new Hasher($c->getConfig());
617
+        });
618
+        $this->registerAlias('Hasher', \OCP\Security\IHasher::class);
619
+
620
+        $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
621
+            return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
622
+        });
623
+        $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
624
+
625
+        $this->registerService(IDBConnection::class, function (Server $c) {
626
+            $systemConfig = $c->getSystemConfig();
627
+            $factory = new \OC\DB\ConnectionFactory($systemConfig);
628
+            $type = $systemConfig->getValue('dbtype', 'sqlite');
629
+            if (!$factory->isValidType($type)) {
630
+                throw new \OC\DatabaseException('Invalid database type');
631
+            }
632
+            $connectionParams = $factory->createConnectionParams();
633
+            $connection = $factory->getConnection($type, $connectionParams);
634
+            $connection->getConfiguration()->setSQLLogger($c->getQueryLogger());
635
+            return $connection;
636
+        });
637
+        $this->registerAlias('DatabaseConnection', IDBConnection::class);
638
+
639
+
640
+        $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
641
+            $user = \OC_User::getUser();
642
+            $uid = $user ? $user : null;
643
+            return new ClientService(
644
+                $c->getConfig(),
645
+                new \OC\Security\CertificateManager(
646
+                    $uid,
647
+                    new View(),
648
+                    $c->getConfig(),
649
+                    $c->getLogger(),
650
+                    $c->getSecureRandom()
651
+                )
652
+            );
653
+        });
654
+        $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
655
+        $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
656
+            $eventLogger = new EventLogger();
657
+            if ($c->getSystemConfig()->getValue('debug', false)) {
658
+                // In debug mode, module is being activated by default
659
+                $eventLogger->activate();
660
+            }
661
+            return $eventLogger;
662
+        });
663
+        $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
664
+
665
+        $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
666
+            $queryLogger = new QueryLogger();
667
+            if ($c->getSystemConfig()->getValue('debug', false)) {
668
+                // In debug mode, module is being activated by default
669
+                $queryLogger->activate();
670
+            }
671
+            return $queryLogger;
672
+        });
673
+        $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
674
+
675
+        $this->registerService(TempManager::class, function (Server $c) {
676
+            return new TempManager(
677
+                $c->getLogger(),
678
+                $c->getConfig()
679
+            );
680
+        });
681
+        $this->registerAlias('TempManager', TempManager::class);
682
+        $this->registerAlias(ITempManager::class, TempManager::class);
683
+
684
+        $this->registerService(AppManager::class, function (Server $c) {
685
+            return new \OC\App\AppManager(
686
+                $c->getUserSession(),
687
+                $c->query(\OC\AppConfig::class),
688
+                $c->getGroupManager(),
689
+                $c->getMemCacheFactory(),
690
+                $c->getEventDispatcher()
691
+            );
692
+        });
693
+        $this->registerAlias('AppManager', AppManager::class);
694
+        $this->registerAlias(IAppManager::class, AppManager::class);
695
+
696
+        $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
697
+            return new DateTimeZone(
698
+                $c->getConfig(),
699
+                $c->getSession()
700
+            );
701
+        });
702
+        $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
703
+
704
+        $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
705
+            $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
706
+
707
+            return new DateTimeFormatter(
708
+                $c->getDateTimeZone()->getTimeZone(),
709
+                $c->getL10N('lib', $language)
710
+            );
711
+        });
712
+        $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
713
+
714
+        $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
715
+            $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
716
+            $listener = new UserMountCacheListener($mountCache);
717
+            $listener->listen($c->getUserManager());
718
+            return $mountCache;
719
+        });
720
+        $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
721
+
722
+        $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
723
+            $loader = \OC\Files\Filesystem::getLoader();
724
+            $mountCache = $c->query('UserMountCache');
725
+            $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
726
+
727
+            // builtin providers
728
+
729
+            $config = $c->getConfig();
730
+            $manager->registerProvider(new CacheMountProvider($config));
731
+            $manager->registerHomeProvider(new LocalHomeMountProvider());
732
+            $manager->registerHomeProvider(new ObjectHomeMountProvider($config));
733
+
734
+            return $manager;
735
+        });
736
+        $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
737
+
738
+        $this->registerService('IniWrapper', function ($c) {
739
+            return new IniGetWrapper();
740
+        });
741
+        $this->registerService('AsyncCommandBus', function (Server $c) {
742
+            $busClass = $c->getConfig()->getSystemValue('commandbus');
743
+            if ($busClass) {
744
+                list($app, $class) = explode('::', $busClass, 2);
745
+                if ($c->getAppManager()->isInstalled($app)) {
746
+                    \OC_App::loadApp($app);
747
+                    return $c->query($class);
748
+                } else {
749
+                    throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled");
750
+                }
751
+            } else {
752
+                $jobList = $c->getJobList();
753
+                return new CronBus($jobList);
754
+            }
755
+        });
756
+        $this->registerService('TrustedDomainHelper', function ($c) {
757
+            return new TrustedDomainHelper($this->getConfig());
758
+        });
759
+        $this->registerService('Throttler', function (Server $c) {
760
+            return new Throttler(
761
+                $c->getDatabaseConnection(),
762
+                new TimeFactory(),
763
+                $c->getLogger(),
764
+                $c->getConfig()
765
+            );
766
+        });
767
+        $this->registerService('IntegrityCodeChecker', function (Server $c) {
768
+            // IConfig and IAppManager requires a working database. This code
769
+            // might however be called when ownCloud is not yet setup.
770
+            if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
771
+                $config = $c->getConfig();
772
+                $appManager = $c->getAppManager();
773
+            } else {
774
+                $config = null;
775
+                $appManager = null;
776
+            }
777
+
778
+            return new Checker(
779
+                new EnvironmentHelper(),
780
+                new FileAccessHelper(),
781
+                new AppLocator(),
782
+                $config,
783
+                $c->getMemCacheFactory(),
784
+                $appManager,
785
+                $c->getTempManager()
786
+            );
787
+        });
788
+        $this->registerService(\OCP\IRequest::class, function ($c) {
789
+            if (isset($this['urlParams'])) {
790
+                $urlParams = $this['urlParams'];
791
+            } else {
792
+                $urlParams = [];
793
+            }
794
+
795
+            if (defined('PHPUNIT_RUN') && PHPUNIT_RUN
796
+                && in_array('fakeinput', stream_get_wrappers())
797
+            ) {
798
+                $stream = 'fakeinput://data';
799
+            } else {
800
+                $stream = 'php://input';
801
+            }
802
+
803
+            return new Request(
804
+                [
805
+                    'get' => $_GET,
806
+                    'post' => $_POST,
807
+                    'files' => $_FILES,
808
+                    'server' => $_SERVER,
809
+                    'env' => $_ENV,
810
+                    'cookies' => $_COOKIE,
811
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
812
+                        ? $_SERVER['REQUEST_METHOD']
813
+                        : '',
814
+                    'urlParams' => $urlParams,
815
+                ],
816
+                $this->getSecureRandom(),
817
+                $this->getConfig(),
818
+                $this->getCsrfTokenManager(),
819
+                $stream
820
+            );
821
+        });
822
+        $this->registerAlias('Request', \OCP\IRequest::class);
823
+
824
+        $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
825
+            return new Mailer(
826
+                $c->getConfig(),
827
+                $c->getLogger(),
828
+                $c->query(Defaults::class),
829
+                $c->getURLGenerator(),
830
+                $c->getL10N('lib')
831
+            );
832
+        });
833
+        $this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
834
+
835
+        $this->registerService('LDAPProvider', function (Server $c) {
836
+            $config = $c->getConfig();
837
+            $factoryClass = $config->getSystemValue('ldapProviderFactory', null);
838
+            if (is_null($factoryClass)) {
839
+                throw new \Exception('ldapProviderFactory not set');
840
+            }
841
+            /** @var \OCP\LDAP\ILDAPProviderFactory $factory */
842
+            $factory = new $factoryClass($this);
843
+            return $factory->getLDAPProvider();
844
+        });
845
+        $this->registerService(ILockingProvider::class, function (Server $c) {
846
+            $ini = $c->getIniWrapper();
847
+            $config = $c->getConfig();
848
+            $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
849
+            if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) {
850
+                /** @var \OC\Memcache\Factory $memcacheFactory */
851
+                $memcacheFactory = $c->getMemCacheFactory();
852
+                $memcache = $memcacheFactory->createLocking('lock');
853
+                if (!($memcache instanceof \OC\Memcache\NullCache)) {
854
+                    return new MemcacheLockingProvider($memcache, $ttl);
855
+                }
856
+                return new DBLockingProvider(
857
+                    $c->getDatabaseConnection(),
858
+                    $c->getLogger(),
859
+                    new TimeFactory(),
860
+                    $ttl,
861
+                    !\OC::$CLI
862
+                );
863
+            }
864
+            return new NoopLockingProvider();
865
+        });
866
+        $this->registerAlias('LockingProvider', ILockingProvider::class);
867
+
868
+        $this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
869
+            return new \OC\Files\Mount\Manager();
870
+        });
871
+        $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
872
+
873
+        $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
874
+            return new \OC\Files\Type\Detection(
875
+                $c->getURLGenerator(),
876
+                \OC::$configDir,
877
+                \OC::$SERVERROOT . '/resources/config/'
878
+            );
879
+        });
880
+        $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
881
+
882
+        $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
883
+            return new \OC\Files\Type\Loader(
884
+                $c->getDatabaseConnection()
885
+            );
886
+        });
887
+        $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
888
+        $this->registerService(BundleFetcher::class, function () {
889
+            return new BundleFetcher($this->getL10N('lib'));
890
+        });
891
+        $this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
892
+            return new Manager(
893
+                $c->query(IValidator::class)
894
+            );
895
+        });
896
+        $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
897
+
898
+        $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
899
+            $manager = new \OC\CapabilitiesManager($c->getLogger());
900
+            $manager->registerCapability(function () use ($c) {
901
+                return new \OC\OCS\CoreCapabilities($c->getConfig());
902
+            });
903
+            $manager->registerCapability(function () use ($c) {
904
+                return $c->query(\OC\Security\Bruteforce\Capabilities::class);
905
+            });
906
+            return $manager;
907
+        });
908
+        $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
909
+
910
+        $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
911
+            $config = $c->getConfig();
912
+            $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
913
+            /** @var \OCP\Comments\ICommentsManagerFactory $factory */
914
+            $factory = new $factoryClass($this);
915
+            $manager = $factory->getManager();
916
+
917
+            $manager->registerDisplayNameResolver('user', function($id) use ($c) {
918
+                $manager = $c->getUserManager();
919
+                $user = $manager->get($id);
920
+                if(is_null($user)) {
921
+                    $l = $c->getL10N('core');
922
+                    $displayName = $l->t('Unknown user');
923
+                } else {
924
+                    $displayName = $user->getDisplayName();
925
+                }
926
+                return $displayName;
927
+            });
928
+
929
+            return $manager;
930
+        });
931
+        $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
932
+
933
+        $this->registerService('ThemingDefaults', function (Server $c) {
934
+            /*
935 935
 			 * Dark magic for autoloader.
936 936
 			 * If we do a class_exists it will try to load the class which will
937 937
 			 * make composer cache the result. Resulting in errors when enabling
938 938
 			 * the theming app.
939 939
 			 */
940
-			$prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
941
-			if (isset($prefixes['OCA\\Theming\\'])) {
942
-				$classExists = true;
943
-			} else {
944
-				$classExists = false;
945
-			}
946
-
947
-			if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
948
-				return new ThemingDefaults(
949
-					$c->getConfig(),
950
-					$c->getL10N('theming'),
951
-					$c->getURLGenerator(),
952
-					$c->getMemCacheFactory(),
953
-					new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
954
-					new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
955
-					$c->getAppManager()
956
-				);
957
-			}
958
-			return new \OC_Defaults();
959
-		});
960
-		$this->registerService(SCSSCacher::class, function (Server $c) {
961
-			/** @var Factory $cacheFactory */
962
-			$cacheFactory = $c->query(Factory::class);
963
-			return new SCSSCacher(
964
-				$c->getLogger(),
965
-				$c->query(\OC\Files\AppData\Factory::class),
966
-				$c->getURLGenerator(),
967
-				$c->getConfig(),
968
-				$c->getThemingDefaults(),
969
-				\OC::$SERVERROOT,
970
-				$this->getMemCacheFactory()
971
-			);
972
-		});
973
-		$this->registerService(JSCombiner::class, function (Server $c) {
974
-			/** @var Factory $cacheFactory */
975
-			$cacheFactory = $c->query(Factory::class);
976
-			return new JSCombiner(
977
-				$c->getAppDataDir('js'),
978
-				$c->getURLGenerator(),
979
-				$this->getMemCacheFactory(),
980
-				$c->getSystemConfig(),
981
-				$c->getLogger()
982
-			);
983
-		});
984
-		$this->registerService(EventDispatcher::class, function () {
985
-			return new EventDispatcher();
986
-		});
987
-		$this->registerAlias('EventDispatcher', EventDispatcher::class);
988
-		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
989
-
990
-		$this->registerService('CryptoWrapper', function (Server $c) {
991
-			// FIXME: Instantiiated here due to cyclic dependency
992
-			$request = new Request(
993
-				[
994
-					'get' => $_GET,
995
-					'post' => $_POST,
996
-					'files' => $_FILES,
997
-					'server' => $_SERVER,
998
-					'env' => $_ENV,
999
-					'cookies' => $_COOKIE,
1000
-					'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1001
-						? $_SERVER['REQUEST_METHOD']
1002
-						: null,
1003
-				],
1004
-				$c->getSecureRandom(),
1005
-				$c->getConfig()
1006
-			);
1007
-
1008
-			return new CryptoWrapper(
1009
-				$c->getConfig(),
1010
-				$c->getCrypto(),
1011
-				$c->getSecureRandom(),
1012
-				$request
1013
-			);
1014
-		});
1015
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1016
-			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1017
-
1018
-			return new CsrfTokenManager(
1019
-				$tokenGenerator,
1020
-				$c->query(SessionStorage::class)
1021
-			);
1022
-		});
1023
-		$this->registerService(SessionStorage::class, function (Server $c) {
1024
-			return new SessionStorage($c->getSession());
1025
-		});
1026
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1027
-			return new ContentSecurityPolicyManager();
1028
-		});
1029
-		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1030
-
1031
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1032
-			return new ContentSecurityPolicyNonceManager(
1033
-				$c->getCsrfTokenManager(),
1034
-				$c->getRequest()
1035
-			);
1036
-		});
1037
-
1038
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1039
-			$config = $c->getConfig();
1040
-			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1041
-			/** @var \OCP\Share\IProviderFactory $factory */
1042
-			$factory = new $factoryClass($this);
1043
-
1044
-			$manager = new \OC\Share20\Manager(
1045
-				$c->getLogger(),
1046
-				$c->getConfig(),
1047
-				$c->getSecureRandom(),
1048
-				$c->getHasher(),
1049
-				$c->getMountManager(),
1050
-				$c->getGroupManager(),
1051
-				$c->getL10N('lib'),
1052
-				$c->getL10NFactory(),
1053
-				$factory,
1054
-				$c->getUserManager(),
1055
-				$c->getLazyRootFolder(),
1056
-				$c->getEventDispatcher(),
1057
-				$c->getMailer(),
1058
-				$c->getURLGenerator(),
1059
-				$c->getThemingDefaults()
1060
-			);
1061
-
1062
-			return $manager;
1063
-		});
1064
-		$this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1065
-
1066
-		$this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1067
-			$instance = new Collaboration\Collaborators\Search($c);
1068
-
1069
-			// register default plugins
1070
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1071
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1072
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1073
-			$instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1074
-
1075
-			return $instance;
1076
-		});
1077
-		$this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1078
-
1079
-		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1080
-
1081
-		$this->registerService('SettingsManager', function (Server $c) {
1082
-			$manager = new \OC\Settings\Manager(
1083
-				$c->getLogger(),
1084
-				$c->getDatabaseConnection(),
1085
-				$c->getL10N('lib'),
1086
-				$c->getConfig(),
1087
-				$c->getEncryptionManager(),
1088
-				$c->getUserManager(),
1089
-				$c->getLockingProvider(),
1090
-				$c->getRequest(),
1091
-				$c->getURLGenerator(),
1092
-				$c->query(AccountManager::class),
1093
-				$c->getGroupManager(),
1094
-				$c->getL10NFactory(),
1095
-				$c->getAppManager()
1096
-			);
1097
-			return $manager;
1098
-		});
1099
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1100
-			return new \OC\Files\AppData\Factory(
1101
-				$c->getRootFolder(),
1102
-				$c->getSystemConfig()
1103
-			);
1104
-		});
1105
-
1106
-		$this->registerService('LockdownManager', function (Server $c) {
1107
-			return new LockdownManager(function () use ($c) {
1108
-				return $c->getSession();
1109
-			});
1110
-		});
1111
-
1112
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1113
-			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1114
-		});
1115
-
1116
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1117
-			return new CloudIdManager();
1118
-		});
1119
-
1120
-		$this->registerService(IConfig::class, function (Server $c) {
1121
-			return new GlobalScale\Config($c->getConfig());
1122
-		});
1123
-
1124
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1125
-			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1126
-		});
1127
-
1128
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1129
-			return new CloudFederationFactory();
1130
-		});
1131
-
1132
-		$this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1133
-		$this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1134
-
1135
-		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1136
-		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1137
-
1138
-		$this->registerService(Defaults::class, function (Server $c) {
1139
-			return new Defaults(
1140
-				$c->getThemingDefaults()
1141
-			);
1142
-		});
1143
-		$this->registerAlias('Defaults', \OCP\Defaults::class);
1144
-
1145
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1146
-			return $c->query(\OCP\IUserSession::class)->getSession();
1147
-		});
1148
-
1149
-		$this->registerService(IShareHelper::class, function (Server $c) {
1150
-			return new ShareHelper(
1151
-				$c->query(\OCP\Share\IManager::class)
1152
-			);
1153
-		});
1154
-
1155
-		$this->registerService(Installer::class, function(Server $c) {
1156
-			return new Installer(
1157
-				$c->getAppFetcher(),
1158
-				$c->getHTTPClientService(),
1159
-				$c->getTempManager(),
1160
-				$c->getLogger(),
1161
-				$c->getConfig()
1162
-			);
1163
-		});
1164
-
1165
-		$this->registerService(IApiFactory::class, function(Server $c) {
1166
-			return new ApiFactory($c->getHTTPClientService());
1167
-		});
1168
-
1169
-		$this->registerService(IInstanceFactory::class, function(Server $c) {
1170
-			$memcacheFactory = $c->getMemCacheFactory();
1171
-			return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1172
-		});
1173
-
1174
-		$this->registerService(IContactsStore::class, function(Server $c) {
1175
-			return new ContactsStore(
1176
-				$c->getContactsManager(),
1177
-				$c->getConfig(),
1178
-				$c->getUserManager(),
1179
-				$c->getGroupManager()
1180
-			);
1181
-		});
1182
-		$this->registerAlias(IContactsStore::class, ContactsStore::class);
1183
-
1184
-		$this->connectDispatcher();
1185
-	}
1186
-
1187
-	/**
1188
-	 * @return \OCP\Calendar\IManager
1189
-	 */
1190
-	public function getCalendarManager() {
1191
-		return $this->query('CalendarManager');
1192
-	}
1193
-
1194
-	private function connectDispatcher() {
1195
-		$dispatcher = $this->getEventDispatcher();
1196
-
1197
-		// Delete avatar on user deletion
1198
-		$dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1199
-			$logger = $this->getLogger();
1200
-			$manager = $this->getAvatarManager();
1201
-			/** @var IUser $user */
1202
-			$user = $e->getSubject();
1203
-
1204
-			try {
1205
-				$avatar = $manager->getAvatar($user->getUID());
1206
-				$avatar->remove();
1207
-			} catch (NotFoundException $e) {
1208
-				// no avatar to remove
1209
-			} catch (\Exception $e) {
1210
-				// Ignore exceptions
1211
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1212
-			}
1213
-		});
1214
-
1215
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1216
-			$manager = $this->getAvatarManager();
1217
-			/** @var IUser $user */
1218
-			$user = $e->getSubject();
1219
-			$feature = $e->getArgument('feature');
1220
-			$oldValue = $e->getArgument('oldValue');
1221
-			$value = $e->getArgument('value');
1222
-
1223
-			try {
1224
-				$avatar = $manager->getAvatar($user->getUID());
1225
-				$avatar->userChanged($feature, $oldValue, $value);
1226
-			} catch (NotFoundException $e) {
1227
-				// no avatar to remove
1228
-			}
1229
-		});
1230
-	}
1231
-
1232
-	/**
1233
-	 * @return \OCP\Contacts\IManager
1234
-	 */
1235
-	public function getContactsManager() {
1236
-		return $this->query('ContactsManager');
1237
-	}
1238
-
1239
-	/**
1240
-	 * @return \OC\Encryption\Manager
1241
-	 */
1242
-	public function getEncryptionManager() {
1243
-		return $this->query('EncryptionManager');
1244
-	}
1245
-
1246
-	/**
1247
-	 * @return \OC\Encryption\File
1248
-	 */
1249
-	public function getEncryptionFilesHelper() {
1250
-		return $this->query('EncryptionFileHelper');
1251
-	}
1252
-
1253
-	/**
1254
-	 * @return \OCP\Encryption\Keys\IStorage
1255
-	 */
1256
-	public function getEncryptionKeyStorage() {
1257
-		return $this->query('EncryptionKeyStorage');
1258
-	}
1259
-
1260
-	/**
1261
-	 * The current request object holding all information about the request
1262
-	 * currently being processed is returned from this method.
1263
-	 * In case the current execution was not initiated by a web request null is returned
1264
-	 *
1265
-	 * @return \OCP\IRequest
1266
-	 */
1267
-	public function getRequest() {
1268
-		return $this->query('Request');
1269
-	}
1270
-
1271
-	/**
1272
-	 * Returns the preview manager which can create preview images for a given file
1273
-	 *
1274
-	 * @return \OCP\IPreview
1275
-	 */
1276
-	public function getPreviewManager() {
1277
-		return $this->query('PreviewManager');
1278
-	}
1279
-
1280
-	/**
1281
-	 * Returns the tag manager which can get and set tags for different object types
1282
-	 *
1283
-	 * @see \OCP\ITagManager::load()
1284
-	 * @return \OCP\ITagManager
1285
-	 */
1286
-	public function getTagManager() {
1287
-		return $this->query('TagManager');
1288
-	}
1289
-
1290
-	/**
1291
-	 * Returns the system-tag manager
1292
-	 *
1293
-	 * @return \OCP\SystemTag\ISystemTagManager
1294
-	 *
1295
-	 * @since 9.0.0
1296
-	 */
1297
-	public function getSystemTagManager() {
1298
-		return $this->query('SystemTagManager');
1299
-	}
1300
-
1301
-	/**
1302
-	 * Returns the system-tag object mapper
1303
-	 *
1304
-	 * @return \OCP\SystemTag\ISystemTagObjectMapper
1305
-	 *
1306
-	 * @since 9.0.0
1307
-	 */
1308
-	public function getSystemTagObjectMapper() {
1309
-		return $this->query('SystemTagObjectMapper');
1310
-	}
1311
-
1312
-	/**
1313
-	 * Returns the avatar manager, used for avatar functionality
1314
-	 *
1315
-	 * @return \OCP\IAvatarManager
1316
-	 */
1317
-	public function getAvatarManager() {
1318
-		return $this->query('AvatarManager');
1319
-	}
1320
-
1321
-	/**
1322
-	 * Returns the root folder of ownCloud's data directory
1323
-	 *
1324
-	 * @return \OCP\Files\IRootFolder
1325
-	 */
1326
-	public function getRootFolder() {
1327
-		return $this->query('LazyRootFolder');
1328
-	}
1329
-
1330
-	/**
1331
-	 * Returns the root folder of ownCloud's data directory
1332
-	 * This is the lazy variant so this gets only initialized once it
1333
-	 * is actually used.
1334
-	 *
1335
-	 * @return \OCP\Files\IRootFolder
1336
-	 */
1337
-	public function getLazyRootFolder() {
1338
-		return $this->query('LazyRootFolder');
1339
-	}
1340
-
1341
-	/**
1342
-	 * Returns a view to ownCloud's files folder
1343
-	 *
1344
-	 * @param string $userId user ID
1345
-	 * @return \OCP\Files\Folder|null
1346
-	 */
1347
-	public function getUserFolder($userId = null) {
1348
-		if ($userId === null) {
1349
-			$user = $this->getUserSession()->getUser();
1350
-			if (!$user) {
1351
-				return null;
1352
-			}
1353
-			$userId = $user->getUID();
1354
-		}
1355
-		$root = $this->getRootFolder();
1356
-		return $root->getUserFolder($userId);
1357
-	}
1358
-
1359
-	/**
1360
-	 * Returns an app-specific view in ownClouds data directory
1361
-	 *
1362
-	 * @return \OCP\Files\Folder
1363
-	 * @deprecated since 9.2.0 use IAppData
1364
-	 */
1365
-	public function getAppFolder() {
1366
-		$dir = '/' . \OC_App::getCurrentApp();
1367
-		$root = $this->getRootFolder();
1368
-		if (!$root->nodeExists($dir)) {
1369
-			$folder = $root->newFolder($dir);
1370
-		} else {
1371
-			$folder = $root->get($dir);
1372
-		}
1373
-		return $folder;
1374
-	}
1375
-
1376
-	/**
1377
-	 * @return \OC\User\Manager
1378
-	 */
1379
-	public function getUserManager() {
1380
-		return $this->query('UserManager');
1381
-	}
1382
-
1383
-	/**
1384
-	 * @return \OC\Group\Manager
1385
-	 */
1386
-	public function getGroupManager() {
1387
-		return $this->query('GroupManager');
1388
-	}
1389
-
1390
-	/**
1391
-	 * @return \OC\User\Session
1392
-	 */
1393
-	public function getUserSession() {
1394
-		return $this->query('UserSession');
1395
-	}
1396
-
1397
-	/**
1398
-	 * @return \OCP\ISession
1399
-	 */
1400
-	public function getSession() {
1401
-		return $this->query('UserSession')->getSession();
1402
-	}
1403
-
1404
-	/**
1405
-	 * @param \OCP\ISession $session
1406
-	 */
1407
-	public function setSession(\OCP\ISession $session) {
1408
-		$this->query(SessionStorage::class)->setSession($session);
1409
-		$this->query('UserSession')->setSession($session);
1410
-		$this->query(Store::class)->setSession($session);
1411
-	}
1412
-
1413
-	/**
1414
-	 * @return \OC\Authentication\TwoFactorAuth\Manager
1415
-	 */
1416
-	public function getTwoFactorAuthManager() {
1417
-		return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1418
-	}
1419
-
1420
-	/**
1421
-	 * @return \OC\NavigationManager
1422
-	 */
1423
-	public function getNavigationManager() {
1424
-		return $this->query('NavigationManager');
1425
-	}
1426
-
1427
-	/**
1428
-	 * @return \OCP\IConfig
1429
-	 */
1430
-	public function getConfig() {
1431
-		return $this->query('AllConfig');
1432
-	}
1433
-
1434
-	/**
1435
-	 * @return \OC\SystemConfig
1436
-	 */
1437
-	public function getSystemConfig() {
1438
-		return $this->query('SystemConfig');
1439
-	}
1440
-
1441
-	/**
1442
-	 * Returns the app config manager
1443
-	 *
1444
-	 * @return \OCP\IAppConfig
1445
-	 */
1446
-	public function getAppConfig() {
1447
-		return $this->query('AppConfig');
1448
-	}
1449
-
1450
-	/**
1451
-	 * @return \OCP\L10N\IFactory
1452
-	 */
1453
-	public function getL10NFactory() {
1454
-		return $this->query('L10NFactory');
1455
-	}
1456
-
1457
-	/**
1458
-	 * get an L10N instance
1459
-	 *
1460
-	 * @param string $app appid
1461
-	 * @param string $lang
1462
-	 * @return IL10N
1463
-	 */
1464
-	public function getL10N($app, $lang = null) {
1465
-		return $this->getL10NFactory()->get($app, $lang);
1466
-	}
1467
-
1468
-	/**
1469
-	 * @return \OCP\IURLGenerator
1470
-	 */
1471
-	public function getURLGenerator() {
1472
-		return $this->query('URLGenerator');
1473
-	}
1474
-
1475
-	/**
1476
-	 * @return AppFetcher
1477
-	 */
1478
-	public function getAppFetcher() {
1479
-		return $this->query(AppFetcher::class);
1480
-	}
1481
-
1482
-	/**
1483
-	 * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1484
-	 * getMemCacheFactory() instead.
1485
-	 *
1486
-	 * @return \OCP\ICache
1487
-	 * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1488
-	 */
1489
-	public function getCache() {
1490
-		return $this->query('UserCache');
1491
-	}
1492
-
1493
-	/**
1494
-	 * Returns an \OCP\CacheFactory instance
1495
-	 *
1496
-	 * @return \OCP\ICacheFactory
1497
-	 */
1498
-	public function getMemCacheFactory() {
1499
-		return $this->query('MemCacheFactory');
1500
-	}
1501
-
1502
-	/**
1503
-	 * Returns an \OC\RedisFactory instance
1504
-	 *
1505
-	 * @return \OC\RedisFactory
1506
-	 */
1507
-	public function getGetRedisFactory() {
1508
-		return $this->query('RedisFactory');
1509
-	}
1510
-
1511
-
1512
-	/**
1513
-	 * Returns the current session
1514
-	 *
1515
-	 * @return \OCP\IDBConnection
1516
-	 */
1517
-	public function getDatabaseConnection() {
1518
-		return $this->query('DatabaseConnection');
1519
-	}
1520
-
1521
-	/**
1522
-	 * Returns the activity manager
1523
-	 *
1524
-	 * @return \OCP\Activity\IManager
1525
-	 */
1526
-	public function getActivityManager() {
1527
-		return $this->query('ActivityManager');
1528
-	}
1529
-
1530
-	/**
1531
-	 * Returns an job list for controlling background jobs
1532
-	 *
1533
-	 * @return \OCP\BackgroundJob\IJobList
1534
-	 */
1535
-	public function getJobList() {
1536
-		return $this->query('JobList');
1537
-	}
1538
-
1539
-	/**
1540
-	 * Returns a logger instance
1541
-	 *
1542
-	 * @return \OCP\ILogger
1543
-	 */
1544
-	public function getLogger() {
1545
-		return $this->query('Logger');
1546
-	}
1547
-
1548
-	/**
1549
-	 * @return ILogFactory
1550
-	 * @throws \OCP\AppFramework\QueryException
1551
-	 */
1552
-	public function getLogFactory() {
1553
-		return $this->query(ILogFactory::class);
1554
-	}
1555
-
1556
-	/**
1557
-	 * Returns a router for generating and matching urls
1558
-	 *
1559
-	 * @return \OCP\Route\IRouter
1560
-	 */
1561
-	public function getRouter() {
1562
-		return $this->query('Router');
1563
-	}
1564
-
1565
-	/**
1566
-	 * Returns a search instance
1567
-	 *
1568
-	 * @return \OCP\ISearch
1569
-	 */
1570
-	public function getSearch() {
1571
-		return $this->query('Search');
1572
-	}
1573
-
1574
-	/**
1575
-	 * Returns a SecureRandom instance
1576
-	 *
1577
-	 * @return \OCP\Security\ISecureRandom
1578
-	 */
1579
-	public function getSecureRandom() {
1580
-		return $this->query('SecureRandom');
1581
-	}
1582
-
1583
-	/**
1584
-	 * Returns a Crypto instance
1585
-	 *
1586
-	 * @return \OCP\Security\ICrypto
1587
-	 */
1588
-	public function getCrypto() {
1589
-		return $this->query('Crypto');
1590
-	}
1591
-
1592
-	/**
1593
-	 * Returns a Hasher instance
1594
-	 *
1595
-	 * @return \OCP\Security\IHasher
1596
-	 */
1597
-	public function getHasher() {
1598
-		return $this->query('Hasher');
1599
-	}
1600
-
1601
-	/**
1602
-	 * Returns a CredentialsManager instance
1603
-	 *
1604
-	 * @return \OCP\Security\ICredentialsManager
1605
-	 */
1606
-	public function getCredentialsManager() {
1607
-		return $this->query('CredentialsManager');
1608
-	}
1609
-
1610
-	/**
1611
-	 * Get the certificate manager for the user
1612
-	 *
1613
-	 * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1614
-	 * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1615
-	 */
1616
-	public function getCertificateManager($userId = '') {
1617
-		if ($userId === '') {
1618
-			$userSession = $this->getUserSession();
1619
-			$user = $userSession->getUser();
1620
-			if (is_null($user)) {
1621
-				return null;
1622
-			}
1623
-			$userId = $user->getUID();
1624
-		}
1625
-		return new CertificateManager(
1626
-			$userId,
1627
-			new View(),
1628
-			$this->getConfig(),
1629
-			$this->getLogger(),
1630
-			$this->getSecureRandom()
1631
-		);
1632
-	}
1633
-
1634
-	/**
1635
-	 * Returns an instance of the HTTP client service
1636
-	 *
1637
-	 * @return \OCP\Http\Client\IClientService
1638
-	 */
1639
-	public function getHTTPClientService() {
1640
-		return $this->query('HttpClientService');
1641
-	}
1642
-
1643
-	/**
1644
-	 * Create a new event source
1645
-	 *
1646
-	 * @return \OCP\IEventSource
1647
-	 */
1648
-	public function createEventSource() {
1649
-		return new \OC_EventSource();
1650
-	}
1651
-
1652
-	/**
1653
-	 * Get the active event logger
1654
-	 *
1655
-	 * The returned logger only logs data when debug mode is enabled
1656
-	 *
1657
-	 * @return \OCP\Diagnostics\IEventLogger
1658
-	 */
1659
-	public function getEventLogger() {
1660
-		return $this->query('EventLogger');
1661
-	}
1662
-
1663
-	/**
1664
-	 * Get the active query logger
1665
-	 *
1666
-	 * The returned logger only logs data when debug mode is enabled
1667
-	 *
1668
-	 * @return \OCP\Diagnostics\IQueryLogger
1669
-	 */
1670
-	public function getQueryLogger() {
1671
-		return $this->query('QueryLogger');
1672
-	}
1673
-
1674
-	/**
1675
-	 * Get the manager for temporary files and folders
1676
-	 *
1677
-	 * @return \OCP\ITempManager
1678
-	 */
1679
-	public function getTempManager() {
1680
-		return $this->query('TempManager');
1681
-	}
1682
-
1683
-	/**
1684
-	 * Get the app manager
1685
-	 *
1686
-	 * @return \OCP\App\IAppManager
1687
-	 */
1688
-	public function getAppManager() {
1689
-		return $this->query('AppManager');
1690
-	}
1691
-
1692
-	/**
1693
-	 * Creates a new mailer
1694
-	 *
1695
-	 * @return \OCP\Mail\IMailer
1696
-	 */
1697
-	public function getMailer() {
1698
-		return $this->query('Mailer');
1699
-	}
1700
-
1701
-	/**
1702
-	 * Get the webroot
1703
-	 *
1704
-	 * @return string
1705
-	 */
1706
-	public function getWebRoot() {
1707
-		return $this->webRoot;
1708
-	}
1709
-
1710
-	/**
1711
-	 * @return \OC\OCSClient
1712
-	 */
1713
-	public function getOcsClient() {
1714
-		return $this->query('OcsClient');
1715
-	}
1716
-
1717
-	/**
1718
-	 * @return \OCP\IDateTimeZone
1719
-	 */
1720
-	public function getDateTimeZone() {
1721
-		return $this->query('DateTimeZone');
1722
-	}
1723
-
1724
-	/**
1725
-	 * @return \OCP\IDateTimeFormatter
1726
-	 */
1727
-	public function getDateTimeFormatter() {
1728
-		return $this->query('DateTimeFormatter');
1729
-	}
1730
-
1731
-	/**
1732
-	 * @return \OCP\Files\Config\IMountProviderCollection
1733
-	 */
1734
-	public function getMountProviderCollection() {
1735
-		return $this->query('MountConfigManager');
1736
-	}
1737
-
1738
-	/**
1739
-	 * Get the IniWrapper
1740
-	 *
1741
-	 * @return IniGetWrapper
1742
-	 */
1743
-	public function getIniWrapper() {
1744
-		return $this->query('IniWrapper');
1745
-	}
1746
-
1747
-	/**
1748
-	 * @return \OCP\Command\IBus
1749
-	 */
1750
-	public function getCommandBus() {
1751
-		return $this->query('AsyncCommandBus');
1752
-	}
1753
-
1754
-	/**
1755
-	 * Get the trusted domain helper
1756
-	 *
1757
-	 * @return TrustedDomainHelper
1758
-	 */
1759
-	public function getTrustedDomainHelper() {
1760
-		return $this->query('TrustedDomainHelper');
1761
-	}
1762
-
1763
-	/**
1764
-	 * Get the locking provider
1765
-	 *
1766
-	 * @return \OCP\Lock\ILockingProvider
1767
-	 * @since 8.1.0
1768
-	 */
1769
-	public function getLockingProvider() {
1770
-		return $this->query('LockingProvider');
1771
-	}
1772
-
1773
-	/**
1774
-	 * @return \OCP\Files\Mount\IMountManager
1775
-	 **/
1776
-	function getMountManager() {
1777
-		return $this->query('MountManager');
1778
-	}
1779
-
1780
-	/** @return \OCP\Files\Config\IUserMountCache */
1781
-	function getUserMountCache() {
1782
-		return $this->query('UserMountCache');
1783
-	}
1784
-
1785
-	/**
1786
-	 * Get the MimeTypeDetector
1787
-	 *
1788
-	 * @return \OCP\Files\IMimeTypeDetector
1789
-	 */
1790
-	public function getMimeTypeDetector() {
1791
-		return $this->query('MimeTypeDetector');
1792
-	}
1793
-
1794
-	/**
1795
-	 * Get the MimeTypeLoader
1796
-	 *
1797
-	 * @return \OCP\Files\IMimeTypeLoader
1798
-	 */
1799
-	public function getMimeTypeLoader() {
1800
-		return $this->query('MimeTypeLoader');
1801
-	}
1802
-
1803
-	/**
1804
-	 * Get the manager of all the capabilities
1805
-	 *
1806
-	 * @return \OC\CapabilitiesManager
1807
-	 */
1808
-	public function getCapabilitiesManager() {
1809
-		return $this->query('CapabilitiesManager');
1810
-	}
1811
-
1812
-	/**
1813
-	 * Get the EventDispatcher
1814
-	 *
1815
-	 * @return EventDispatcherInterface
1816
-	 * @since 8.2.0
1817
-	 */
1818
-	public function getEventDispatcher() {
1819
-		return $this->query('EventDispatcher');
1820
-	}
1821
-
1822
-	/**
1823
-	 * Get the Notification Manager
1824
-	 *
1825
-	 * @return \OCP\Notification\IManager
1826
-	 * @since 8.2.0
1827
-	 */
1828
-	public function getNotificationManager() {
1829
-		return $this->query('NotificationManager');
1830
-	}
1831
-
1832
-	/**
1833
-	 * @return \OCP\Comments\ICommentsManager
1834
-	 */
1835
-	public function getCommentsManager() {
1836
-		return $this->query('CommentsManager');
1837
-	}
1838
-
1839
-	/**
1840
-	 * @return \OCA\Theming\ThemingDefaults
1841
-	 */
1842
-	public function getThemingDefaults() {
1843
-		return $this->query('ThemingDefaults');
1844
-	}
1845
-
1846
-	/**
1847
-	 * @return \OC\IntegrityCheck\Checker
1848
-	 */
1849
-	public function getIntegrityCodeChecker() {
1850
-		return $this->query('IntegrityCodeChecker');
1851
-	}
1852
-
1853
-	/**
1854
-	 * @return \OC\Session\CryptoWrapper
1855
-	 */
1856
-	public function getSessionCryptoWrapper() {
1857
-		return $this->query('CryptoWrapper');
1858
-	}
1859
-
1860
-	/**
1861
-	 * @return CsrfTokenManager
1862
-	 */
1863
-	public function getCsrfTokenManager() {
1864
-		return $this->query('CsrfTokenManager');
1865
-	}
1866
-
1867
-	/**
1868
-	 * @return Throttler
1869
-	 */
1870
-	public function getBruteForceThrottler() {
1871
-		return $this->query('Throttler');
1872
-	}
1873
-
1874
-	/**
1875
-	 * @return IContentSecurityPolicyManager
1876
-	 */
1877
-	public function getContentSecurityPolicyManager() {
1878
-		return $this->query('ContentSecurityPolicyManager');
1879
-	}
1880
-
1881
-	/**
1882
-	 * @return ContentSecurityPolicyNonceManager
1883
-	 */
1884
-	public function getContentSecurityPolicyNonceManager() {
1885
-		return $this->query('ContentSecurityPolicyNonceManager');
1886
-	}
1887
-
1888
-	/**
1889
-	 * Not a public API as of 8.2, wait for 9.0
1890
-	 *
1891
-	 * @return \OCA\Files_External\Service\BackendService
1892
-	 */
1893
-	public function getStoragesBackendService() {
1894
-		return $this->query('OCA\\Files_External\\Service\\BackendService');
1895
-	}
1896
-
1897
-	/**
1898
-	 * Not a public API as of 8.2, wait for 9.0
1899
-	 *
1900
-	 * @return \OCA\Files_External\Service\GlobalStoragesService
1901
-	 */
1902
-	public function getGlobalStoragesService() {
1903
-		return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1904
-	}
1905
-
1906
-	/**
1907
-	 * Not a public API as of 8.2, wait for 9.0
1908
-	 *
1909
-	 * @return \OCA\Files_External\Service\UserGlobalStoragesService
1910
-	 */
1911
-	public function getUserGlobalStoragesService() {
1912
-		return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1913
-	}
1914
-
1915
-	/**
1916
-	 * Not a public API as of 8.2, wait for 9.0
1917
-	 *
1918
-	 * @return \OCA\Files_External\Service\UserStoragesService
1919
-	 */
1920
-	public function getUserStoragesService() {
1921
-		return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1922
-	}
1923
-
1924
-	/**
1925
-	 * @return \OCP\Share\IManager
1926
-	 */
1927
-	public function getShareManager() {
1928
-		return $this->query('ShareManager');
1929
-	}
1930
-
1931
-	/**
1932
-	 * @return \OCP\Collaboration\Collaborators\ISearch
1933
-	 */
1934
-	public function getCollaboratorSearch() {
1935
-		return $this->query('CollaboratorSearch');
1936
-	}
1937
-
1938
-	/**
1939
-	 * @return \OCP\Collaboration\AutoComplete\IManager
1940
-	 */
1941
-	public function getAutoCompleteManager(){
1942
-		return $this->query(IManager::class);
1943
-	}
1944
-
1945
-	/**
1946
-	 * Returns the LDAP Provider
1947
-	 *
1948
-	 * @return \OCP\LDAP\ILDAPProvider
1949
-	 */
1950
-	public function getLDAPProvider() {
1951
-		return $this->query('LDAPProvider');
1952
-	}
1953
-
1954
-	/**
1955
-	 * @return \OCP\Settings\IManager
1956
-	 */
1957
-	public function getSettingsManager() {
1958
-		return $this->query('SettingsManager');
1959
-	}
1960
-
1961
-	/**
1962
-	 * @return \OCP\Files\IAppData
1963
-	 */
1964
-	public function getAppDataDir($app) {
1965
-		/** @var \OC\Files\AppData\Factory $factory */
1966
-		$factory = $this->query(\OC\Files\AppData\Factory::class);
1967
-		return $factory->get($app);
1968
-	}
1969
-
1970
-	/**
1971
-	 * @return \OCP\Lockdown\ILockdownManager
1972
-	 */
1973
-	public function getLockdownManager() {
1974
-		return $this->query('LockdownManager');
1975
-	}
1976
-
1977
-	/**
1978
-	 * @return \OCP\Federation\ICloudIdManager
1979
-	 */
1980
-	public function getCloudIdManager() {
1981
-		return $this->query(ICloudIdManager::class);
1982
-	}
1983
-
1984
-	/**
1985
-	 * @return \OCP\GlobalScale\IConfig
1986
-	 */
1987
-	public function getGlobalScaleConfig() {
1988
-		return $this->query(IConfig::class);
1989
-	}
1990
-
1991
-	/**
1992
-	 * @return \OCP\Federation\ICloudFederationProviderManager
1993
-	 */
1994
-	public function getCloudFederationProviderManager() {
1995
-		return $this->query(ICloudFederationProviderManager::class);
1996
-	}
1997
-
1998
-	/**
1999
-	 * @return \OCP\Remote\Api\IApiFactory
2000
-	 */
2001
-	public function getRemoteApiFactory() {
2002
-		return $this->query(IApiFactory::class);
2003
-	}
2004
-
2005
-	/**
2006
-	 * @return \OCP\Federation\ICloudFederationFactory
2007
-	 */
2008
-	public function getCloudFederationFactory() {
2009
-		return $this->query(ICloudFederationFactory::class);
2010
-	}
2011
-
2012
-	/**
2013
-	 * @return \OCP\Remote\IInstanceFactory
2014
-	 */
2015
-	public function getRemoteInstanceFactory() {
2016
-		return $this->query(IInstanceFactory::class);
2017
-	}
940
+            $prefixes = \OC::$composerAutoloader->getPrefixesPsr4();
941
+            if (isset($prefixes['OCA\\Theming\\'])) {
942
+                $classExists = true;
943
+            } else {
944
+                $classExists = false;
945
+            }
946
+
947
+            if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) {
948
+                return new ThemingDefaults(
949
+                    $c->getConfig(),
950
+                    $c->getL10N('theming'),
951
+                    $c->getURLGenerator(),
952
+                    $c->getMemCacheFactory(),
953
+                    new Util($c->getConfig(), $this->getAppManager(), $c->getAppDataDir('theming')),
954
+                    new ImageManager($c->getConfig(), $c->getAppDataDir('theming'), $c->getURLGenerator(), $this->getMemCacheFactory(), $this->getLogger()),
955
+                    $c->getAppManager()
956
+                );
957
+            }
958
+            return new \OC_Defaults();
959
+        });
960
+        $this->registerService(SCSSCacher::class, function (Server $c) {
961
+            /** @var Factory $cacheFactory */
962
+            $cacheFactory = $c->query(Factory::class);
963
+            return new SCSSCacher(
964
+                $c->getLogger(),
965
+                $c->query(\OC\Files\AppData\Factory::class),
966
+                $c->getURLGenerator(),
967
+                $c->getConfig(),
968
+                $c->getThemingDefaults(),
969
+                \OC::$SERVERROOT,
970
+                $this->getMemCacheFactory()
971
+            );
972
+        });
973
+        $this->registerService(JSCombiner::class, function (Server $c) {
974
+            /** @var Factory $cacheFactory */
975
+            $cacheFactory = $c->query(Factory::class);
976
+            return new JSCombiner(
977
+                $c->getAppDataDir('js'),
978
+                $c->getURLGenerator(),
979
+                $this->getMemCacheFactory(),
980
+                $c->getSystemConfig(),
981
+                $c->getLogger()
982
+            );
983
+        });
984
+        $this->registerService(EventDispatcher::class, function () {
985
+            return new EventDispatcher();
986
+        });
987
+        $this->registerAlias('EventDispatcher', EventDispatcher::class);
988
+        $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
989
+
990
+        $this->registerService('CryptoWrapper', function (Server $c) {
991
+            // FIXME: Instantiiated here due to cyclic dependency
992
+            $request = new Request(
993
+                [
994
+                    'get' => $_GET,
995
+                    'post' => $_POST,
996
+                    'files' => $_FILES,
997
+                    'server' => $_SERVER,
998
+                    'env' => $_ENV,
999
+                    'cookies' => $_COOKIE,
1000
+                    'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD']))
1001
+                        ? $_SERVER['REQUEST_METHOD']
1002
+                        : null,
1003
+                ],
1004
+                $c->getSecureRandom(),
1005
+                $c->getConfig()
1006
+            );
1007
+
1008
+            return new CryptoWrapper(
1009
+                $c->getConfig(),
1010
+                $c->getCrypto(),
1011
+                $c->getSecureRandom(),
1012
+                $request
1013
+            );
1014
+        });
1015
+        $this->registerService('CsrfTokenManager', function (Server $c) {
1016
+            $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1017
+
1018
+            return new CsrfTokenManager(
1019
+                $tokenGenerator,
1020
+                $c->query(SessionStorage::class)
1021
+            );
1022
+        });
1023
+        $this->registerService(SessionStorage::class, function (Server $c) {
1024
+            return new SessionStorage($c->getSession());
1025
+        });
1026
+        $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1027
+            return new ContentSecurityPolicyManager();
1028
+        });
1029
+        $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1030
+
1031
+        $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1032
+            return new ContentSecurityPolicyNonceManager(
1033
+                $c->getCsrfTokenManager(),
1034
+                $c->getRequest()
1035
+            );
1036
+        });
1037
+
1038
+        $this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1039
+            $config = $c->getConfig();
1040
+            $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1041
+            /** @var \OCP\Share\IProviderFactory $factory */
1042
+            $factory = new $factoryClass($this);
1043
+
1044
+            $manager = new \OC\Share20\Manager(
1045
+                $c->getLogger(),
1046
+                $c->getConfig(),
1047
+                $c->getSecureRandom(),
1048
+                $c->getHasher(),
1049
+                $c->getMountManager(),
1050
+                $c->getGroupManager(),
1051
+                $c->getL10N('lib'),
1052
+                $c->getL10NFactory(),
1053
+                $factory,
1054
+                $c->getUserManager(),
1055
+                $c->getLazyRootFolder(),
1056
+                $c->getEventDispatcher(),
1057
+                $c->getMailer(),
1058
+                $c->getURLGenerator(),
1059
+                $c->getThemingDefaults()
1060
+            );
1061
+
1062
+            return $manager;
1063
+        });
1064
+        $this->registerAlias('ShareManager', \OCP\Share\IManager::class);
1065
+
1066
+        $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) {
1067
+            $instance = new Collaboration\Collaborators\Search($c);
1068
+
1069
+            // register default plugins
1070
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]);
1071
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]);
1072
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]);
1073
+            $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]);
1074
+
1075
+            return $instance;
1076
+        });
1077
+        $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class);
1078
+
1079
+        $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1080
+
1081
+        $this->registerService('SettingsManager', function (Server $c) {
1082
+            $manager = new \OC\Settings\Manager(
1083
+                $c->getLogger(),
1084
+                $c->getDatabaseConnection(),
1085
+                $c->getL10N('lib'),
1086
+                $c->getConfig(),
1087
+                $c->getEncryptionManager(),
1088
+                $c->getUserManager(),
1089
+                $c->getLockingProvider(),
1090
+                $c->getRequest(),
1091
+                $c->getURLGenerator(),
1092
+                $c->query(AccountManager::class),
1093
+                $c->getGroupManager(),
1094
+                $c->getL10NFactory(),
1095
+                $c->getAppManager()
1096
+            );
1097
+            return $manager;
1098
+        });
1099
+        $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1100
+            return new \OC\Files\AppData\Factory(
1101
+                $c->getRootFolder(),
1102
+                $c->getSystemConfig()
1103
+            );
1104
+        });
1105
+
1106
+        $this->registerService('LockdownManager', function (Server $c) {
1107
+            return new LockdownManager(function () use ($c) {
1108
+                return $c->getSession();
1109
+            });
1110
+        });
1111
+
1112
+        $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1113
+            return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1114
+        });
1115
+
1116
+        $this->registerService(ICloudIdManager::class, function (Server $c) {
1117
+            return new CloudIdManager();
1118
+        });
1119
+
1120
+        $this->registerService(IConfig::class, function (Server $c) {
1121
+            return new GlobalScale\Config($c->getConfig());
1122
+        });
1123
+
1124
+        $this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1125
+            return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1126
+        });
1127
+
1128
+        $this->registerService(ICloudFederationFactory::class, function (Server $c) {
1129
+            return new CloudFederationFactory();
1130
+        });
1131
+
1132
+        $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class);
1133
+        $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class);
1134
+
1135
+        $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1136
+        $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1137
+
1138
+        $this->registerService(Defaults::class, function (Server $c) {
1139
+            return new Defaults(
1140
+                $c->getThemingDefaults()
1141
+            );
1142
+        });
1143
+        $this->registerAlias('Defaults', \OCP\Defaults::class);
1144
+
1145
+        $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1146
+            return $c->query(\OCP\IUserSession::class)->getSession();
1147
+        });
1148
+
1149
+        $this->registerService(IShareHelper::class, function (Server $c) {
1150
+            return new ShareHelper(
1151
+                $c->query(\OCP\Share\IManager::class)
1152
+            );
1153
+        });
1154
+
1155
+        $this->registerService(Installer::class, function(Server $c) {
1156
+            return new Installer(
1157
+                $c->getAppFetcher(),
1158
+                $c->getHTTPClientService(),
1159
+                $c->getTempManager(),
1160
+                $c->getLogger(),
1161
+                $c->getConfig()
1162
+            );
1163
+        });
1164
+
1165
+        $this->registerService(IApiFactory::class, function(Server $c) {
1166
+            return new ApiFactory($c->getHTTPClientService());
1167
+        });
1168
+
1169
+        $this->registerService(IInstanceFactory::class, function(Server $c) {
1170
+            $memcacheFactory = $c->getMemCacheFactory();
1171
+            return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService());
1172
+        });
1173
+
1174
+        $this->registerService(IContactsStore::class, function(Server $c) {
1175
+            return new ContactsStore(
1176
+                $c->getContactsManager(),
1177
+                $c->getConfig(),
1178
+                $c->getUserManager(),
1179
+                $c->getGroupManager()
1180
+            );
1181
+        });
1182
+        $this->registerAlias(IContactsStore::class, ContactsStore::class);
1183
+
1184
+        $this->connectDispatcher();
1185
+    }
1186
+
1187
+    /**
1188
+     * @return \OCP\Calendar\IManager
1189
+     */
1190
+    public function getCalendarManager() {
1191
+        return $this->query('CalendarManager');
1192
+    }
1193
+
1194
+    private function connectDispatcher() {
1195
+        $dispatcher = $this->getEventDispatcher();
1196
+
1197
+        // Delete avatar on user deletion
1198
+        $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) {
1199
+            $logger = $this->getLogger();
1200
+            $manager = $this->getAvatarManager();
1201
+            /** @var IUser $user */
1202
+            $user = $e->getSubject();
1203
+
1204
+            try {
1205
+                $avatar = $manager->getAvatar($user->getUID());
1206
+                $avatar->remove();
1207
+            } catch (NotFoundException $e) {
1208
+                // no avatar to remove
1209
+            } catch (\Exception $e) {
1210
+                // Ignore exceptions
1211
+                $logger->info('Could not cleanup avatar of ' . $user->getUID());
1212
+            }
1213
+        });
1214
+
1215
+        $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1216
+            $manager = $this->getAvatarManager();
1217
+            /** @var IUser $user */
1218
+            $user = $e->getSubject();
1219
+            $feature = $e->getArgument('feature');
1220
+            $oldValue = $e->getArgument('oldValue');
1221
+            $value = $e->getArgument('value');
1222
+
1223
+            try {
1224
+                $avatar = $manager->getAvatar($user->getUID());
1225
+                $avatar->userChanged($feature, $oldValue, $value);
1226
+            } catch (NotFoundException $e) {
1227
+                // no avatar to remove
1228
+            }
1229
+        });
1230
+    }
1231
+
1232
+    /**
1233
+     * @return \OCP\Contacts\IManager
1234
+     */
1235
+    public function getContactsManager() {
1236
+        return $this->query('ContactsManager');
1237
+    }
1238
+
1239
+    /**
1240
+     * @return \OC\Encryption\Manager
1241
+     */
1242
+    public function getEncryptionManager() {
1243
+        return $this->query('EncryptionManager');
1244
+    }
1245
+
1246
+    /**
1247
+     * @return \OC\Encryption\File
1248
+     */
1249
+    public function getEncryptionFilesHelper() {
1250
+        return $this->query('EncryptionFileHelper');
1251
+    }
1252
+
1253
+    /**
1254
+     * @return \OCP\Encryption\Keys\IStorage
1255
+     */
1256
+    public function getEncryptionKeyStorage() {
1257
+        return $this->query('EncryptionKeyStorage');
1258
+    }
1259
+
1260
+    /**
1261
+     * The current request object holding all information about the request
1262
+     * currently being processed is returned from this method.
1263
+     * In case the current execution was not initiated by a web request null is returned
1264
+     *
1265
+     * @return \OCP\IRequest
1266
+     */
1267
+    public function getRequest() {
1268
+        return $this->query('Request');
1269
+    }
1270
+
1271
+    /**
1272
+     * Returns the preview manager which can create preview images for a given file
1273
+     *
1274
+     * @return \OCP\IPreview
1275
+     */
1276
+    public function getPreviewManager() {
1277
+        return $this->query('PreviewManager');
1278
+    }
1279
+
1280
+    /**
1281
+     * Returns the tag manager which can get and set tags for different object types
1282
+     *
1283
+     * @see \OCP\ITagManager::load()
1284
+     * @return \OCP\ITagManager
1285
+     */
1286
+    public function getTagManager() {
1287
+        return $this->query('TagManager');
1288
+    }
1289
+
1290
+    /**
1291
+     * Returns the system-tag manager
1292
+     *
1293
+     * @return \OCP\SystemTag\ISystemTagManager
1294
+     *
1295
+     * @since 9.0.0
1296
+     */
1297
+    public function getSystemTagManager() {
1298
+        return $this->query('SystemTagManager');
1299
+    }
1300
+
1301
+    /**
1302
+     * Returns the system-tag object mapper
1303
+     *
1304
+     * @return \OCP\SystemTag\ISystemTagObjectMapper
1305
+     *
1306
+     * @since 9.0.0
1307
+     */
1308
+    public function getSystemTagObjectMapper() {
1309
+        return $this->query('SystemTagObjectMapper');
1310
+    }
1311
+
1312
+    /**
1313
+     * Returns the avatar manager, used for avatar functionality
1314
+     *
1315
+     * @return \OCP\IAvatarManager
1316
+     */
1317
+    public function getAvatarManager() {
1318
+        return $this->query('AvatarManager');
1319
+    }
1320
+
1321
+    /**
1322
+     * Returns the root folder of ownCloud's data directory
1323
+     *
1324
+     * @return \OCP\Files\IRootFolder
1325
+     */
1326
+    public function getRootFolder() {
1327
+        return $this->query('LazyRootFolder');
1328
+    }
1329
+
1330
+    /**
1331
+     * Returns the root folder of ownCloud's data directory
1332
+     * This is the lazy variant so this gets only initialized once it
1333
+     * is actually used.
1334
+     *
1335
+     * @return \OCP\Files\IRootFolder
1336
+     */
1337
+    public function getLazyRootFolder() {
1338
+        return $this->query('LazyRootFolder');
1339
+    }
1340
+
1341
+    /**
1342
+     * Returns a view to ownCloud's files folder
1343
+     *
1344
+     * @param string $userId user ID
1345
+     * @return \OCP\Files\Folder|null
1346
+     */
1347
+    public function getUserFolder($userId = null) {
1348
+        if ($userId === null) {
1349
+            $user = $this->getUserSession()->getUser();
1350
+            if (!$user) {
1351
+                return null;
1352
+            }
1353
+            $userId = $user->getUID();
1354
+        }
1355
+        $root = $this->getRootFolder();
1356
+        return $root->getUserFolder($userId);
1357
+    }
1358
+
1359
+    /**
1360
+     * Returns an app-specific view in ownClouds data directory
1361
+     *
1362
+     * @return \OCP\Files\Folder
1363
+     * @deprecated since 9.2.0 use IAppData
1364
+     */
1365
+    public function getAppFolder() {
1366
+        $dir = '/' . \OC_App::getCurrentApp();
1367
+        $root = $this->getRootFolder();
1368
+        if (!$root->nodeExists($dir)) {
1369
+            $folder = $root->newFolder($dir);
1370
+        } else {
1371
+            $folder = $root->get($dir);
1372
+        }
1373
+        return $folder;
1374
+    }
1375
+
1376
+    /**
1377
+     * @return \OC\User\Manager
1378
+     */
1379
+    public function getUserManager() {
1380
+        return $this->query('UserManager');
1381
+    }
1382
+
1383
+    /**
1384
+     * @return \OC\Group\Manager
1385
+     */
1386
+    public function getGroupManager() {
1387
+        return $this->query('GroupManager');
1388
+    }
1389
+
1390
+    /**
1391
+     * @return \OC\User\Session
1392
+     */
1393
+    public function getUserSession() {
1394
+        return $this->query('UserSession');
1395
+    }
1396
+
1397
+    /**
1398
+     * @return \OCP\ISession
1399
+     */
1400
+    public function getSession() {
1401
+        return $this->query('UserSession')->getSession();
1402
+    }
1403
+
1404
+    /**
1405
+     * @param \OCP\ISession $session
1406
+     */
1407
+    public function setSession(\OCP\ISession $session) {
1408
+        $this->query(SessionStorage::class)->setSession($session);
1409
+        $this->query('UserSession')->setSession($session);
1410
+        $this->query(Store::class)->setSession($session);
1411
+    }
1412
+
1413
+    /**
1414
+     * @return \OC\Authentication\TwoFactorAuth\Manager
1415
+     */
1416
+    public function getTwoFactorAuthManager() {
1417
+        return $this->query('\OC\Authentication\TwoFactorAuth\Manager');
1418
+    }
1419
+
1420
+    /**
1421
+     * @return \OC\NavigationManager
1422
+     */
1423
+    public function getNavigationManager() {
1424
+        return $this->query('NavigationManager');
1425
+    }
1426
+
1427
+    /**
1428
+     * @return \OCP\IConfig
1429
+     */
1430
+    public function getConfig() {
1431
+        return $this->query('AllConfig');
1432
+    }
1433
+
1434
+    /**
1435
+     * @return \OC\SystemConfig
1436
+     */
1437
+    public function getSystemConfig() {
1438
+        return $this->query('SystemConfig');
1439
+    }
1440
+
1441
+    /**
1442
+     * Returns the app config manager
1443
+     *
1444
+     * @return \OCP\IAppConfig
1445
+     */
1446
+    public function getAppConfig() {
1447
+        return $this->query('AppConfig');
1448
+    }
1449
+
1450
+    /**
1451
+     * @return \OCP\L10N\IFactory
1452
+     */
1453
+    public function getL10NFactory() {
1454
+        return $this->query('L10NFactory');
1455
+    }
1456
+
1457
+    /**
1458
+     * get an L10N instance
1459
+     *
1460
+     * @param string $app appid
1461
+     * @param string $lang
1462
+     * @return IL10N
1463
+     */
1464
+    public function getL10N($app, $lang = null) {
1465
+        return $this->getL10NFactory()->get($app, $lang);
1466
+    }
1467
+
1468
+    /**
1469
+     * @return \OCP\IURLGenerator
1470
+     */
1471
+    public function getURLGenerator() {
1472
+        return $this->query('URLGenerator');
1473
+    }
1474
+
1475
+    /**
1476
+     * @return AppFetcher
1477
+     */
1478
+    public function getAppFetcher() {
1479
+        return $this->query(AppFetcher::class);
1480
+    }
1481
+
1482
+    /**
1483
+     * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use
1484
+     * getMemCacheFactory() instead.
1485
+     *
1486
+     * @return \OCP\ICache
1487
+     * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache
1488
+     */
1489
+    public function getCache() {
1490
+        return $this->query('UserCache');
1491
+    }
1492
+
1493
+    /**
1494
+     * Returns an \OCP\CacheFactory instance
1495
+     *
1496
+     * @return \OCP\ICacheFactory
1497
+     */
1498
+    public function getMemCacheFactory() {
1499
+        return $this->query('MemCacheFactory');
1500
+    }
1501
+
1502
+    /**
1503
+     * Returns an \OC\RedisFactory instance
1504
+     *
1505
+     * @return \OC\RedisFactory
1506
+     */
1507
+    public function getGetRedisFactory() {
1508
+        return $this->query('RedisFactory');
1509
+    }
1510
+
1511
+
1512
+    /**
1513
+     * Returns the current session
1514
+     *
1515
+     * @return \OCP\IDBConnection
1516
+     */
1517
+    public function getDatabaseConnection() {
1518
+        return $this->query('DatabaseConnection');
1519
+    }
1520
+
1521
+    /**
1522
+     * Returns the activity manager
1523
+     *
1524
+     * @return \OCP\Activity\IManager
1525
+     */
1526
+    public function getActivityManager() {
1527
+        return $this->query('ActivityManager');
1528
+    }
1529
+
1530
+    /**
1531
+     * Returns an job list for controlling background jobs
1532
+     *
1533
+     * @return \OCP\BackgroundJob\IJobList
1534
+     */
1535
+    public function getJobList() {
1536
+        return $this->query('JobList');
1537
+    }
1538
+
1539
+    /**
1540
+     * Returns a logger instance
1541
+     *
1542
+     * @return \OCP\ILogger
1543
+     */
1544
+    public function getLogger() {
1545
+        return $this->query('Logger');
1546
+    }
1547
+
1548
+    /**
1549
+     * @return ILogFactory
1550
+     * @throws \OCP\AppFramework\QueryException
1551
+     */
1552
+    public function getLogFactory() {
1553
+        return $this->query(ILogFactory::class);
1554
+    }
1555
+
1556
+    /**
1557
+     * Returns a router for generating and matching urls
1558
+     *
1559
+     * @return \OCP\Route\IRouter
1560
+     */
1561
+    public function getRouter() {
1562
+        return $this->query('Router');
1563
+    }
1564
+
1565
+    /**
1566
+     * Returns a search instance
1567
+     *
1568
+     * @return \OCP\ISearch
1569
+     */
1570
+    public function getSearch() {
1571
+        return $this->query('Search');
1572
+    }
1573
+
1574
+    /**
1575
+     * Returns a SecureRandom instance
1576
+     *
1577
+     * @return \OCP\Security\ISecureRandom
1578
+     */
1579
+    public function getSecureRandom() {
1580
+        return $this->query('SecureRandom');
1581
+    }
1582
+
1583
+    /**
1584
+     * Returns a Crypto instance
1585
+     *
1586
+     * @return \OCP\Security\ICrypto
1587
+     */
1588
+    public function getCrypto() {
1589
+        return $this->query('Crypto');
1590
+    }
1591
+
1592
+    /**
1593
+     * Returns a Hasher instance
1594
+     *
1595
+     * @return \OCP\Security\IHasher
1596
+     */
1597
+    public function getHasher() {
1598
+        return $this->query('Hasher');
1599
+    }
1600
+
1601
+    /**
1602
+     * Returns a CredentialsManager instance
1603
+     *
1604
+     * @return \OCP\Security\ICredentialsManager
1605
+     */
1606
+    public function getCredentialsManager() {
1607
+        return $this->query('CredentialsManager');
1608
+    }
1609
+
1610
+    /**
1611
+     * Get the certificate manager for the user
1612
+     *
1613
+     * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager
1614
+     * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in
1615
+     */
1616
+    public function getCertificateManager($userId = '') {
1617
+        if ($userId === '') {
1618
+            $userSession = $this->getUserSession();
1619
+            $user = $userSession->getUser();
1620
+            if (is_null($user)) {
1621
+                return null;
1622
+            }
1623
+            $userId = $user->getUID();
1624
+        }
1625
+        return new CertificateManager(
1626
+            $userId,
1627
+            new View(),
1628
+            $this->getConfig(),
1629
+            $this->getLogger(),
1630
+            $this->getSecureRandom()
1631
+        );
1632
+    }
1633
+
1634
+    /**
1635
+     * Returns an instance of the HTTP client service
1636
+     *
1637
+     * @return \OCP\Http\Client\IClientService
1638
+     */
1639
+    public function getHTTPClientService() {
1640
+        return $this->query('HttpClientService');
1641
+    }
1642
+
1643
+    /**
1644
+     * Create a new event source
1645
+     *
1646
+     * @return \OCP\IEventSource
1647
+     */
1648
+    public function createEventSource() {
1649
+        return new \OC_EventSource();
1650
+    }
1651
+
1652
+    /**
1653
+     * Get the active event logger
1654
+     *
1655
+     * The returned logger only logs data when debug mode is enabled
1656
+     *
1657
+     * @return \OCP\Diagnostics\IEventLogger
1658
+     */
1659
+    public function getEventLogger() {
1660
+        return $this->query('EventLogger');
1661
+    }
1662
+
1663
+    /**
1664
+     * Get the active query logger
1665
+     *
1666
+     * The returned logger only logs data when debug mode is enabled
1667
+     *
1668
+     * @return \OCP\Diagnostics\IQueryLogger
1669
+     */
1670
+    public function getQueryLogger() {
1671
+        return $this->query('QueryLogger');
1672
+    }
1673
+
1674
+    /**
1675
+     * Get the manager for temporary files and folders
1676
+     *
1677
+     * @return \OCP\ITempManager
1678
+     */
1679
+    public function getTempManager() {
1680
+        return $this->query('TempManager');
1681
+    }
1682
+
1683
+    /**
1684
+     * Get the app manager
1685
+     *
1686
+     * @return \OCP\App\IAppManager
1687
+     */
1688
+    public function getAppManager() {
1689
+        return $this->query('AppManager');
1690
+    }
1691
+
1692
+    /**
1693
+     * Creates a new mailer
1694
+     *
1695
+     * @return \OCP\Mail\IMailer
1696
+     */
1697
+    public function getMailer() {
1698
+        return $this->query('Mailer');
1699
+    }
1700
+
1701
+    /**
1702
+     * Get the webroot
1703
+     *
1704
+     * @return string
1705
+     */
1706
+    public function getWebRoot() {
1707
+        return $this->webRoot;
1708
+    }
1709
+
1710
+    /**
1711
+     * @return \OC\OCSClient
1712
+     */
1713
+    public function getOcsClient() {
1714
+        return $this->query('OcsClient');
1715
+    }
1716
+
1717
+    /**
1718
+     * @return \OCP\IDateTimeZone
1719
+     */
1720
+    public function getDateTimeZone() {
1721
+        return $this->query('DateTimeZone');
1722
+    }
1723
+
1724
+    /**
1725
+     * @return \OCP\IDateTimeFormatter
1726
+     */
1727
+    public function getDateTimeFormatter() {
1728
+        return $this->query('DateTimeFormatter');
1729
+    }
1730
+
1731
+    /**
1732
+     * @return \OCP\Files\Config\IMountProviderCollection
1733
+     */
1734
+    public function getMountProviderCollection() {
1735
+        return $this->query('MountConfigManager');
1736
+    }
1737
+
1738
+    /**
1739
+     * Get the IniWrapper
1740
+     *
1741
+     * @return IniGetWrapper
1742
+     */
1743
+    public function getIniWrapper() {
1744
+        return $this->query('IniWrapper');
1745
+    }
1746
+
1747
+    /**
1748
+     * @return \OCP\Command\IBus
1749
+     */
1750
+    public function getCommandBus() {
1751
+        return $this->query('AsyncCommandBus');
1752
+    }
1753
+
1754
+    /**
1755
+     * Get the trusted domain helper
1756
+     *
1757
+     * @return TrustedDomainHelper
1758
+     */
1759
+    public function getTrustedDomainHelper() {
1760
+        return $this->query('TrustedDomainHelper');
1761
+    }
1762
+
1763
+    /**
1764
+     * Get the locking provider
1765
+     *
1766
+     * @return \OCP\Lock\ILockingProvider
1767
+     * @since 8.1.0
1768
+     */
1769
+    public function getLockingProvider() {
1770
+        return $this->query('LockingProvider');
1771
+    }
1772
+
1773
+    /**
1774
+     * @return \OCP\Files\Mount\IMountManager
1775
+     **/
1776
+    function getMountManager() {
1777
+        return $this->query('MountManager');
1778
+    }
1779
+
1780
+    /** @return \OCP\Files\Config\IUserMountCache */
1781
+    function getUserMountCache() {
1782
+        return $this->query('UserMountCache');
1783
+    }
1784
+
1785
+    /**
1786
+     * Get the MimeTypeDetector
1787
+     *
1788
+     * @return \OCP\Files\IMimeTypeDetector
1789
+     */
1790
+    public function getMimeTypeDetector() {
1791
+        return $this->query('MimeTypeDetector');
1792
+    }
1793
+
1794
+    /**
1795
+     * Get the MimeTypeLoader
1796
+     *
1797
+     * @return \OCP\Files\IMimeTypeLoader
1798
+     */
1799
+    public function getMimeTypeLoader() {
1800
+        return $this->query('MimeTypeLoader');
1801
+    }
1802
+
1803
+    /**
1804
+     * Get the manager of all the capabilities
1805
+     *
1806
+     * @return \OC\CapabilitiesManager
1807
+     */
1808
+    public function getCapabilitiesManager() {
1809
+        return $this->query('CapabilitiesManager');
1810
+    }
1811
+
1812
+    /**
1813
+     * Get the EventDispatcher
1814
+     *
1815
+     * @return EventDispatcherInterface
1816
+     * @since 8.2.0
1817
+     */
1818
+    public function getEventDispatcher() {
1819
+        return $this->query('EventDispatcher');
1820
+    }
1821
+
1822
+    /**
1823
+     * Get the Notification Manager
1824
+     *
1825
+     * @return \OCP\Notification\IManager
1826
+     * @since 8.2.0
1827
+     */
1828
+    public function getNotificationManager() {
1829
+        return $this->query('NotificationManager');
1830
+    }
1831
+
1832
+    /**
1833
+     * @return \OCP\Comments\ICommentsManager
1834
+     */
1835
+    public function getCommentsManager() {
1836
+        return $this->query('CommentsManager');
1837
+    }
1838
+
1839
+    /**
1840
+     * @return \OCA\Theming\ThemingDefaults
1841
+     */
1842
+    public function getThemingDefaults() {
1843
+        return $this->query('ThemingDefaults');
1844
+    }
1845
+
1846
+    /**
1847
+     * @return \OC\IntegrityCheck\Checker
1848
+     */
1849
+    public function getIntegrityCodeChecker() {
1850
+        return $this->query('IntegrityCodeChecker');
1851
+    }
1852
+
1853
+    /**
1854
+     * @return \OC\Session\CryptoWrapper
1855
+     */
1856
+    public function getSessionCryptoWrapper() {
1857
+        return $this->query('CryptoWrapper');
1858
+    }
1859
+
1860
+    /**
1861
+     * @return CsrfTokenManager
1862
+     */
1863
+    public function getCsrfTokenManager() {
1864
+        return $this->query('CsrfTokenManager');
1865
+    }
1866
+
1867
+    /**
1868
+     * @return Throttler
1869
+     */
1870
+    public function getBruteForceThrottler() {
1871
+        return $this->query('Throttler');
1872
+    }
1873
+
1874
+    /**
1875
+     * @return IContentSecurityPolicyManager
1876
+     */
1877
+    public function getContentSecurityPolicyManager() {
1878
+        return $this->query('ContentSecurityPolicyManager');
1879
+    }
1880
+
1881
+    /**
1882
+     * @return ContentSecurityPolicyNonceManager
1883
+     */
1884
+    public function getContentSecurityPolicyNonceManager() {
1885
+        return $this->query('ContentSecurityPolicyNonceManager');
1886
+    }
1887
+
1888
+    /**
1889
+     * Not a public API as of 8.2, wait for 9.0
1890
+     *
1891
+     * @return \OCA\Files_External\Service\BackendService
1892
+     */
1893
+    public function getStoragesBackendService() {
1894
+        return $this->query('OCA\\Files_External\\Service\\BackendService');
1895
+    }
1896
+
1897
+    /**
1898
+     * Not a public API as of 8.2, wait for 9.0
1899
+     *
1900
+     * @return \OCA\Files_External\Service\GlobalStoragesService
1901
+     */
1902
+    public function getGlobalStoragesService() {
1903
+        return $this->query('OCA\\Files_External\\Service\\GlobalStoragesService');
1904
+    }
1905
+
1906
+    /**
1907
+     * Not a public API as of 8.2, wait for 9.0
1908
+     *
1909
+     * @return \OCA\Files_External\Service\UserGlobalStoragesService
1910
+     */
1911
+    public function getUserGlobalStoragesService() {
1912
+        return $this->query('OCA\\Files_External\\Service\\UserGlobalStoragesService');
1913
+    }
1914
+
1915
+    /**
1916
+     * Not a public API as of 8.2, wait for 9.0
1917
+     *
1918
+     * @return \OCA\Files_External\Service\UserStoragesService
1919
+     */
1920
+    public function getUserStoragesService() {
1921
+        return $this->query('OCA\\Files_External\\Service\\UserStoragesService');
1922
+    }
1923
+
1924
+    /**
1925
+     * @return \OCP\Share\IManager
1926
+     */
1927
+    public function getShareManager() {
1928
+        return $this->query('ShareManager');
1929
+    }
1930
+
1931
+    /**
1932
+     * @return \OCP\Collaboration\Collaborators\ISearch
1933
+     */
1934
+    public function getCollaboratorSearch() {
1935
+        return $this->query('CollaboratorSearch');
1936
+    }
1937
+
1938
+    /**
1939
+     * @return \OCP\Collaboration\AutoComplete\IManager
1940
+     */
1941
+    public function getAutoCompleteManager(){
1942
+        return $this->query(IManager::class);
1943
+    }
1944
+
1945
+    /**
1946
+     * Returns the LDAP Provider
1947
+     *
1948
+     * @return \OCP\LDAP\ILDAPProvider
1949
+     */
1950
+    public function getLDAPProvider() {
1951
+        return $this->query('LDAPProvider');
1952
+    }
1953
+
1954
+    /**
1955
+     * @return \OCP\Settings\IManager
1956
+     */
1957
+    public function getSettingsManager() {
1958
+        return $this->query('SettingsManager');
1959
+    }
1960
+
1961
+    /**
1962
+     * @return \OCP\Files\IAppData
1963
+     */
1964
+    public function getAppDataDir($app) {
1965
+        /** @var \OC\Files\AppData\Factory $factory */
1966
+        $factory = $this->query(\OC\Files\AppData\Factory::class);
1967
+        return $factory->get($app);
1968
+    }
1969
+
1970
+    /**
1971
+     * @return \OCP\Lockdown\ILockdownManager
1972
+     */
1973
+    public function getLockdownManager() {
1974
+        return $this->query('LockdownManager');
1975
+    }
1976
+
1977
+    /**
1978
+     * @return \OCP\Federation\ICloudIdManager
1979
+     */
1980
+    public function getCloudIdManager() {
1981
+        return $this->query(ICloudIdManager::class);
1982
+    }
1983
+
1984
+    /**
1985
+     * @return \OCP\GlobalScale\IConfig
1986
+     */
1987
+    public function getGlobalScaleConfig() {
1988
+        return $this->query(IConfig::class);
1989
+    }
1990
+
1991
+    /**
1992
+     * @return \OCP\Federation\ICloudFederationProviderManager
1993
+     */
1994
+    public function getCloudFederationProviderManager() {
1995
+        return $this->query(ICloudFederationProviderManager::class);
1996
+    }
1997
+
1998
+    /**
1999
+     * @return \OCP\Remote\Api\IApiFactory
2000
+     */
2001
+    public function getRemoteApiFactory() {
2002
+        return $this->query(IApiFactory::class);
2003
+    }
2004
+
2005
+    /**
2006
+     * @return \OCP\Federation\ICloudFederationFactory
2007
+     */
2008
+    public function getCloudFederationFactory() {
2009
+        return $this->query(ICloudFederationFactory::class);
2010
+    }
2011
+
2012
+    /**
2013
+     * @return \OCP\Remote\IInstanceFactory
2014
+     */
2015
+    public function getRemoteInstanceFactory() {
2016
+        return $this->query(IInstanceFactory::class);
2017
+    }
2018 2018
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 		// To find out if we are running from CLI or not
173 173
 		$this->registerParameter('isCLI', \OC::$CLI);
174 174
 
175
-		$this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) {
175
+		$this->registerService(\OCP\IServerContainer::class, function(IServerContainer $c) {
176 176
 			return $c;
177 177
 		});
178 178
 
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		$this->registerAlias(IActionFactory::class, ActionFactory::class);
186 186
 
187 187
 
188
-		$this->registerService(\OCP\IPreview::class, function (Server $c) {
188
+		$this->registerService(\OCP\IPreview::class, function(Server $c) {
189 189
 			return new PreviewManager(
190 190
 				$c->getConfig(),
191 191
 				$c->getRootFolder(),
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
 		});
197 197
 		$this->registerAlias('PreviewManager', \OCP\IPreview::class);
198 198
 
199
-		$this->registerService(\OC\Preview\Watcher::class, function (Server $c) {
199
+		$this->registerService(\OC\Preview\Watcher::class, function(Server $c) {
200 200
 			return new \OC\Preview\Watcher(
201 201
 				$c->getAppDataDir('preview')
202 202
 			);
203 203
 		});
204 204
 
205
-		$this->registerService('EncryptionManager', function (Server $c) {
205
+		$this->registerService('EncryptionManager', function(Server $c) {
206 206
 			$view = new View();
207 207
 			$util = new Encryption\Util(
208 208
 				$view,
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
 			);
221 221
 		});
222 222
 
223
-		$this->registerService('EncryptionFileHelper', function (Server $c) {
223
+		$this->registerService('EncryptionFileHelper', function(Server $c) {
224 224
 			$util = new Encryption\Util(
225 225
 				new View(),
226 226
 				$c->getUserManager(),
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 			);
235 235
 		});
236 236
 
237
-		$this->registerService('EncryptionKeyStorage', function (Server $c) {
237
+		$this->registerService('EncryptionKeyStorage', function(Server $c) {
238 238
 			$view = new View();
239 239
 			$util = new Encryption\Util(
240 240
 				$view,
@@ -245,30 +245,30 @@  discard block
 block discarded – undo
245 245
 
246 246
 			return new Encryption\Keys\Storage($view, $util);
247 247
 		});
248
-		$this->registerService('TagMapper', function (Server $c) {
248
+		$this->registerService('TagMapper', function(Server $c) {
249 249
 			return new TagMapper($c->getDatabaseConnection());
250 250
 		});
251 251
 
252
-		$this->registerService(\OCP\ITagManager::class, function (Server $c) {
252
+		$this->registerService(\OCP\ITagManager::class, function(Server $c) {
253 253
 			$tagMapper = $c->query('TagMapper');
254 254
 			return new TagManager($tagMapper, $c->getUserSession());
255 255
 		});
256 256
 		$this->registerAlias('TagManager', \OCP\ITagManager::class);
257 257
 
258
-		$this->registerService('SystemTagManagerFactory', function (Server $c) {
258
+		$this->registerService('SystemTagManagerFactory', function(Server $c) {
259 259
 			$config = $c->getConfig();
260 260
 			$factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class);
261 261
 			return new $factoryClass($this);
262 262
 		});
263
-		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) {
263
+		$this->registerService(\OCP\SystemTag\ISystemTagManager::class, function(Server $c) {
264 264
 			return $c->query('SystemTagManagerFactory')->getManager();
265 265
 		});
266 266
 		$this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class);
267 267
 
268
-		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) {
268
+		$this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function(Server $c) {
269 269
 			return $c->query('SystemTagManagerFactory')->getObjectMapper();
270 270
 		});
271
-		$this->registerService('RootFolder', function (Server $c) {
271
+		$this->registerService('RootFolder', function(Server $c) {
272 272
 			$manager = \OC\Files\Filesystem::getMountManager(null);
273 273
 			$view = new View();
274 274
 			$root = new Root(
@@ -289,38 +289,38 @@  discard block
 block discarded – undo
289 289
 		});
290 290
 		$this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class);
291 291
 
292
-		$this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) {
293
-			return new LazyRoot(function () use ($c) {
292
+		$this->registerService(\OCP\Files\IRootFolder::class, function(Server $c) {
293
+			return new LazyRoot(function() use ($c) {
294 294
 				return $c->query('RootFolder');
295 295
 			});
296 296
 		});
297 297
 		$this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class);
298 298
 
299
-		$this->registerService(\OC\User\Manager::class, function (Server $c) {
299
+		$this->registerService(\OC\User\Manager::class, function(Server $c) {
300 300
 			$config = $c->getConfig();
301 301
 			return new \OC\User\Manager($config);
302 302
 		});
303 303
 		$this->registerAlias('UserManager', \OC\User\Manager::class);
304 304
 		$this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class);
305 305
 
306
-		$this->registerService(\OCP\IGroupManager::class, function (Server $c) {
306
+		$this->registerService(\OCP\IGroupManager::class, function(Server $c) {
307 307
 			$groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger());
308
-			$groupManager->listen('\OC\Group', 'preCreate', function ($gid) {
308
+			$groupManager->listen('\OC\Group', 'preCreate', function($gid) {
309 309
 				\OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid));
310 310
 			});
311
-			$groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) {
311
+			$groupManager->listen('\OC\Group', 'postCreate', function(\OC\Group\Group $gid) {
312 312
 				\OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID()));
313 313
 			});
314
-			$groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) {
314
+			$groupManager->listen('\OC\Group', 'preDelete', function(\OC\Group\Group $group) {
315 315
 				\OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID()));
316 316
 			});
317
-			$groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) {
317
+			$groupManager->listen('\OC\Group', 'postDelete', function(\OC\Group\Group $group) {
318 318
 				\OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID()));
319 319
 			});
320
-			$groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
320
+			$groupManager->listen('\OC\Group', 'preAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
321 321
 				\OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()));
322 322
 			});
323
-			$groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) {
323
+			$groupManager->listen('\OC\Group', 'postAddUser', function(\OC\Group\Group $group, \OC\User\User $user) {
324 324
 				\OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
325 325
 				//Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks
326 326
 				\OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID()));
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 		});
330 330
 		$this->registerAlias('GroupManager', \OCP\IGroupManager::class);
331 331
 
332
-		$this->registerService(Store::class, function (Server $c) {
332
+		$this->registerService(Store::class, function(Server $c) {
333 333
 			$session = $c->getSession();
334 334
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
335 335
 				$tokenProvider = $c->query(IProvider::class);
@@ -340,13 +340,13 @@  discard block
 block discarded – undo
340 340
 			return new Store($session, $logger, $tokenProvider);
341 341
 		});
342 342
 		$this->registerAlias(IStore::class, Store::class);
343
-		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) {
343
+		$this->registerService(Authentication\Token\DefaultTokenMapper::class, function(Server $c) {
344 344
 			$dbConnection = $c->getDatabaseConnection();
345 345
 			return new Authentication\Token\DefaultTokenMapper($dbConnection);
346 346
 		});
347 347
 		$this->registerAlias(IProvider::class, Authentication\Token\Manager::class);
348 348
 
349
-		$this->registerService(\OCP\IUserSession::class, function (Server $c) {
349
+		$this->registerService(\OCP\IUserSession::class, function(Server $c) {
350 350
 			$manager = $c->getUserManager();
351 351
 			$session = new \OC\Session\Memory('');
352 352
 			$timeFactory = new TimeFactory();
@@ -370,45 +370,45 @@  discard block
 block discarded – undo
370 370
 				$c->getLockdownManager(),
371 371
 				$c->getLogger()
372 372
 			);
373
-			$userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) {
373
+			$userSession->listen('\OC\User', 'preCreateUser', function($uid, $password) {
374 374
 				\OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password));
375 375
 			});
376
-			$userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) {
376
+			$userSession->listen('\OC\User', 'postCreateUser', function($user, $password) {
377 377
 				/** @var $user \OC\User\User */
378 378
 				\OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password));
379 379
 			});
380
-			$userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) {
380
+			$userSession->listen('\OC\User', 'preDelete', function($user) use ($dispatcher) {
381 381
 				/** @var $user \OC\User\User */
382 382
 				\OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID()));
383 383
 				$dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user));
384 384
 			});
385
-			$userSession->listen('\OC\User', 'postDelete', function ($user) {
385
+			$userSession->listen('\OC\User', 'postDelete', function($user) {
386 386
 				/** @var $user \OC\User\User */
387 387
 				\OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID()));
388 388
 			});
389
-			$userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) {
389
+			$userSession->listen('\OC\User', 'preSetPassword', function($user, $password, $recoveryPassword) {
390 390
 				/** @var $user \OC\User\User */
391 391
 				\OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
392 392
 			});
393
-			$userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) {
393
+			$userSession->listen('\OC\User', 'postSetPassword', function($user, $password, $recoveryPassword) {
394 394
 				/** @var $user \OC\User\User */
395 395
 				\OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword));
396 396
 			});
397
-			$userSession->listen('\OC\User', 'preLogin', function ($uid, $password) {
397
+			$userSession->listen('\OC\User', 'preLogin', function($uid, $password) {
398 398
 				\OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password));
399 399
 			});
400
-			$userSession->listen('\OC\User', 'postLogin', function ($user, $password) {
400
+			$userSession->listen('\OC\User', 'postLogin', function($user, $password) {
401 401
 				/** @var $user \OC\User\User */
402 402
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
403 403
 			});
404
-			$userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) {
404
+			$userSession->listen('\OC\User', 'postRememberedLogin', function($user, $password) {
405 405
 				/** @var $user \OC\User\User */
406 406
 				\OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password));
407 407
 			});
408
-			$userSession->listen('\OC\User', 'logout', function () {
408
+			$userSession->listen('\OC\User', 'logout', function() {
409 409
 				\OC_Hook::emit('OC_User', 'logout', array());
410 410
 			});
411
-			$userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) {
411
+			$userSession->listen('\OC\User', 'changeUser', function($user, $feature, $value, $oldValue) use ($dispatcher) {
412 412
 				/** @var $user \OC\User\User */
413 413
 				\OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue));
414 414
 				$dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value]));
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 		});
418 418
 		$this->registerAlias('UserSession', \OCP\IUserSession::class);
419 419
 
420
-		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) {
420
+		$this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function(Server $c) {
421 421
 			return new \OC\Authentication\TwoFactorAuth\Manager(
422 422
 				$c->getAppManager(),
423 423
 				$c->getSession(),
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
 		$this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class);
434 434
 		$this->registerAlias('NavigationManager', \OCP\INavigationManager::class);
435 435
 
436
-		$this->registerService(\OC\AllConfig::class, function (Server $c) {
436
+		$this->registerService(\OC\AllConfig::class, function(Server $c) {
437 437
 			return new \OC\AllConfig(
438 438
 				$c->getSystemConfig()
439 439
 			);
@@ -441,17 +441,17 @@  discard block
 block discarded – undo
441 441
 		$this->registerAlias('AllConfig', \OC\AllConfig::class);
442 442
 		$this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class);
443 443
 
444
-		$this->registerService('SystemConfig', function ($c) use ($config) {
444
+		$this->registerService('SystemConfig', function($c) use ($config) {
445 445
 			return new \OC\SystemConfig($config);
446 446
 		});
447 447
 
448
-		$this->registerService(\OC\AppConfig::class, function (Server $c) {
448
+		$this->registerService(\OC\AppConfig::class, function(Server $c) {
449 449
 			return new \OC\AppConfig($c->getDatabaseConnection());
450 450
 		});
451 451
 		$this->registerAlias('AppConfig', \OC\AppConfig::class);
452 452
 		$this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class);
453 453
 
454
-		$this->registerService(\OCP\L10N\IFactory::class, function (Server $c) {
454
+		$this->registerService(\OCP\L10N\IFactory::class, function(Server $c) {
455 455
 			return new \OC\L10N\Factory(
456 456
 				$c->getConfig(),
457 457
 				$c->getRequest(),
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 		});
462 462
 		$this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class);
463 463
 
464
-		$this->registerService(\OCP\IURLGenerator::class, function (Server $c) {
464
+		$this->registerService(\OCP\IURLGenerator::class, function(Server $c) {
465 465
 			$config = $c->getConfig();
466 466
 			$cacheFactory = $c->getMemCacheFactory();
467 467
 			$request = $c->getRequest();
@@ -476,12 +476,12 @@  discard block
 block discarded – undo
476 476
 		$this->registerAlias('AppFetcher', AppFetcher::class);
477 477
 		$this->registerAlias('CategoryFetcher', CategoryFetcher::class);
478 478
 
479
-		$this->registerService(\OCP\ICache::class, function ($c) {
479
+		$this->registerService(\OCP\ICache::class, function($c) {
480 480
 			return new Cache\File();
481 481
 		});
482 482
 		$this->registerAlias('UserCache', \OCP\ICache::class);
483 483
 
484
-		$this->registerService(Factory::class, function (Server $c) {
484
+		$this->registerService(Factory::class, function(Server $c) {
485 485
 
486 486
 			$arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(),
487 487
 				ArrayCache::class,
@@ -498,7 +498,7 @@  discard block
 block discarded – undo
498 498
 				$version = implode(',', $v);
499 499
 				$instanceId = \OC_Util::getInstanceId();
500 500
 				$path = \OC::$SERVERROOT;
501
-				$prefix = md5($instanceId . '-' . $version . '-' . $path);
501
+				$prefix = md5($instanceId.'-'.$version.'-'.$path);
502 502
 				return new \OC\Memcache\Factory($prefix, $c->getLogger(),
503 503
 					$config->getSystemValue('memcache.local', null),
504 504
 					$config->getSystemValue('memcache.distributed', null),
@@ -511,12 +511,12 @@  discard block
 block discarded – undo
511 511
 		$this->registerAlias('MemCacheFactory', Factory::class);
512 512
 		$this->registerAlias(ICacheFactory::class, Factory::class);
513 513
 
514
-		$this->registerService('RedisFactory', function (Server $c) {
514
+		$this->registerService('RedisFactory', function(Server $c) {
515 515
 			$systemConfig = $c->getSystemConfig();
516 516
 			return new RedisFactory($systemConfig);
517 517
 		});
518 518
 
519
-		$this->registerService(\OCP\Activity\IManager::class, function (Server $c) {
519
+		$this->registerService(\OCP\Activity\IManager::class, function(Server $c) {
520 520
 			return new \OC\Activity\Manager(
521 521
 				$c->getRequest(),
522 522
 				$c->getUserSession(),
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
 		});
527 527
 		$this->registerAlias('ActivityManager', \OCP\Activity\IManager::class);
528 528
 
529
-		$this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) {
529
+		$this->registerService(\OCP\Activity\IEventMerger::class, function(Server $c) {
530 530
 			return new \OC\Activity\EventMerger(
531 531
 				$c->getL10N('lib')
532 532
 			);
533 533
 		});
534 534
 		$this->registerAlias(IValidator::class, Validator::class);
535 535
 
536
-		$this->registerService(\OCP\IAvatarManager::class, function (Server $c) {
536
+		$this->registerService(\OCP\IAvatarManager::class, function(Server $c) {
537 537
 			return new AvatarManager(
538 538
 				$c->query(\OC\User\Manager::class),
539 539
 				$c->getAppDataDir('avatar'),
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
 
547 547
 		$this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class);
548 548
 
549
-		$this->registerService(\OCP\ILogger::class, function (Server $c) {
549
+		$this->registerService(\OCP\ILogger::class, function(Server $c) {
550 550
 			$logType = $c->query('AllConfig')->getSystemValue('log_type', 'file');
551 551
 			$factory = new LogFactory($c, $this->getSystemConfig());
552 552
 			$logger = $factory->get($logType);
@@ -556,11 +556,11 @@  discard block
 block discarded – undo
556 556
 		});
557 557
 		$this->registerAlias('Logger', \OCP\ILogger::class);
558 558
 
559
-		$this->registerService(ILogFactory::class, function (Server $c) {
559
+		$this->registerService(ILogFactory::class, function(Server $c) {
560 560
 			return new LogFactory($c, $this->getSystemConfig());
561 561
 		});
562 562
 
563
-		$this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) {
563
+		$this->registerService(\OCP\BackgroundJob\IJobList::class, function(Server $c) {
564 564
 			$config = $c->getConfig();
565 565
 			return new \OC\BackgroundJob\JobList(
566 566
 				$c->getDatabaseConnection(),
@@ -570,7 +570,7 @@  discard block
 block discarded – undo
570 570
 		});
571 571
 		$this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class);
572 572
 
573
-		$this->registerService(\OCP\Route\IRouter::class, function (Server $c) {
573
+		$this->registerService(\OCP\Route\IRouter::class, function(Server $c) {
574 574
 			$cacheFactory = $c->getMemCacheFactory();
575 575
 			$logger = $c->getLogger();
576 576
 			if ($cacheFactory->isLocalCacheAvailable()) {
@@ -582,12 +582,12 @@  discard block
 block discarded – undo
582 582
 		});
583 583
 		$this->registerAlias('Router', \OCP\Route\IRouter::class);
584 584
 
585
-		$this->registerService(\OCP\ISearch::class, function ($c) {
585
+		$this->registerService(\OCP\ISearch::class, function($c) {
586 586
 			return new Search();
587 587
 		});
588 588
 		$this->registerAlias('Search', \OCP\ISearch::class);
589 589
 
590
-		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function (Server $c) {
590
+		$this->registerService(\OC\Security\RateLimiting\Limiter::class, function(Server $c) {
591 591
 			return new \OC\Security\RateLimiting\Limiter(
592 592
 				$this->getUserSession(),
593 593
 				$this->getRequest(),
@@ -595,34 +595,34 @@  discard block
 block discarded – undo
595 595
 				$c->query(\OC\Security\RateLimiting\Backend\IBackend::class)
596 596
 			);
597 597
 		});
598
-		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) {
598
+		$this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function($c) {
599 599
 			return new \OC\Security\RateLimiting\Backend\MemoryCache(
600 600
 				$this->getMemCacheFactory(),
601 601
 				new \OC\AppFramework\Utility\TimeFactory()
602 602
 			);
603 603
 		});
604 604
 
605
-		$this->registerService(\OCP\Security\ISecureRandom::class, function ($c) {
605
+		$this->registerService(\OCP\Security\ISecureRandom::class, function($c) {
606 606
 			return new SecureRandom();
607 607
 		});
608 608
 		$this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class);
609 609
 
610
-		$this->registerService(\OCP\Security\ICrypto::class, function (Server $c) {
610
+		$this->registerService(\OCP\Security\ICrypto::class, function(Server $c) {
611 611
 			return new Crypto($c->getConfig(), $c->getSecureRandom());
612 612
 		});
613 613
 		$this->registerAlias('Crypto', \OCP\Security\ICrypto::class);
614 614
 
615
-		$this->registerService(\OCP\Security\IHasher::class, function (Server $c) {
615
+		$this->registerService(\OCP\Security\IHasher::class, function(Server $c) {
616 616
 			return new Hasher($c->getConfig());
617 617
 		});
618 618
 		$this->registerAlias('Hasher', \OCP\Security\IHasher::class);
619 619
 
620
-		$this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) {
620
+		$this->registerService(\OCP\Security\ICredentialsManager::class, function(Server $c) {
621 621
 			return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection());
622 622
 		});
623 623
 		$this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class);
624 624
 
625
-		$this->registerService(IDBConnection::class, function (Server $c) {
625
+		$this->registerService(IDBConnection::class, function(Server $c) {
626 626
 			$systemConfig = $c->getSystemConfig();
627 627
 			$factory = new \OC\DB\ConnectionFactory($systemConfig);
628 628
 			$type = $systemConfig->getValue('dbtype', 'sqlite');
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 		$this->registerAlias('DatabaseConnection', IDBConnection::class);
638 638
 
639 639
 
640
-		$this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) {
640
+		$this->registerService(\OCP\Http\Client\IClientService::class, function(Server $c) {
641 641
 			$user = \OC_User::getUser();
642 642
 			$uid = $user ? $user : null;
643 643
 			return new ClientService(
@@ -652,7 +652,7 @@  discard block
 block discarded – undo
652 652
 			);
653 653
 		});
654 654
 		$this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class);
655
-		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) {
655
+		$this->registerService(\OCP\Diagnostics\IEventLogger::class, function(Server $c) {
656 656
 			$eventLogger = new EventLogger();
657 657
 			if ($c->getSystemConfig()->getValue('debug', false)) {
658 658
 				// In debug mode, module is being activated by default
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 		});
663 663
 		$this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class);
664 664
 
665
-		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) {
665
+		$this->registerService(\OCP\Diagnostics\IQueryLogger::class, function(Server $c) {
666 666
 			$queryLogger = new QueryLogger();
667 667
 			if ($c->getSystemConfig()->getValue('debug', false)) {
668 668
 				// In debug mode, module is being activated by default
@@ -672,7 +672,7 @@  discard block
 block discarded – undo
672 672
 		});
673 673
 		$this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class);
674 674
 
675
-		$this->registerService(TempManager::class, function (Server $c) {
675
+		$this->registerService(TempManager::class, function(Server $c) {
676 676
 			return new TempManager(
677 677
 				$c->getLogger(),
678 678
 				$c->getConfig()
@@ -681,7 +681,7 @@  discard block
 block discarded – undo
681 681
 		$this->registerAlias('TempManager', TempManager::class);
682 682
 		$this->registerAlias(ITempManager::class, TempManager::class);
683 683
 
684
-		$this->registerService(AppManager::class, function (Server $c) {
684
+		$this->registerService(AppManager::class, function(Server $c) {
685 685
 			return new \OC\App\AppManager(
686 686
 				$c->getUserSession(),
687 687
 				$c->query(\OC\AppConfig::class),
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
 		$this->registerAlias('AppManager', AppManager::class);
694 694
 		$this->registerAlias(IAppManager::class, AppManager::class);
695 695
 
696
-		$this->registerService(\OCP\IDateTimeZone::class, function (Server $c) {
696
+		$this->registerService(\OCP\IDateTimeZone::class, function(Server $c) {
697 697
 			return new DateTimeZone(
698 698
 				$c->getConfig(),
699 699
 				$c->getSession()
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 		});
702 702
 		$this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class);
703 703
 
704
-		$this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) {
704
+		$this->registerService(\OCP\IDateTimeFormatter::class, function(Server $c) {
705 705
 			$language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null);
706 706
 
707 707
 			return new DateTimeFormatter(
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 		});
712 712
 		$this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class);
713 713
 
714
-		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) {
714
+		$this->registerService(\OCP\Files\Config\IUserMountCache::class, function(Server $c) {
715 715
 			$mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger());
716 716
 			$listener = new UserMountCacheListener($mountCache);
717 717
 			$listener->listen($c->getUserManager());
@@ -719,7 +719,7 @@  discard block
 block discarded – undo
719 719
 		});
720 720
 		$this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class);
721 721
 
722
-		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) {
722
+		$this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function(Server $c) {
723 723
 			$loader = \OC\Files\Filesystem::getLoader();
724 724
 			$mountCache = $c->query('UserMountCache');
725 725
 			$manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache);
@@ -735,10 +735,10 @@  discard block
 block discarded – undo
735 735
 		});
736 736
 		$this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class);
737 737
 
738
-		$this->registerService('IniWrapper', function ($c) {
738
+		$this->registerService('IniWrapper', function($c) {
739 739
 			return new IniGetWrapper();
740 740
 		});
741
-		$this->registerService('AsyncCommandBus', function (Server $c) {
741
+		$this->registerService('AsyncCommandBus', function(Server $c) {
742 742
 			$busClass = $c->getConfig()->getSystemValue('commandbus');
743 743
 			if ($busClass) {
744 744
 				list($app, $class) = explode('::', $busClass, 2);
@@ -753,10 +753,10 @@  discard block
 block discarded – undo
753 753
 				return new CronBus($jobList);
754 754
 			}
755 755
 		});
756
-		$this->registerService('TrustedDomainHelper', function ($c) {
756
+		$this->registerService('TrustedDomainHelper', function($c) {
757 757
 			return new TrustedDomainHelper($this->getConfig());
758 758
 		});
759
-		$this->registerService('Throttler', function (Server $c) {
759
+		$this->registerService('Throttler', function(Server $c) {
760 760
 			return new Throttler(
761 761
 				$c->getDatabaseConnection(),
762 762
 				new TimeFactory(),
@@ -764,7 +764,7 @@  discard block
 block discarded – undo
764 764
 				$c->getConfig()
765 765
 			);
766 766
 		});
767
-		$this->registerService('IntegrityCodeChecker', function (Server $c) {
767
+		$this->registerService('IntegrityCodeChecker', function(Server $c) {
768 768
 			// IConfig and IAppManager requires a working database. This code
769 769
 			// might however be called when ownCloud is not yet setup.
770 770
 			if (\OC::$server->getSystemConfig()->getValue('installed', false)) {
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 				$c->getTempManager()
786 786
 			);
787 787
 		});
788
-		$this->registerService(\OCP\IRequest::class, function ($c) {
788
+		$this->registerService(\OCP\IRequest::class, function($c) {
789 789
 			if (isset($this['urlParams'])) {
790 790
 				$urlParams = $this['urlParams'];
791 791
 			} else {
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 		});
822 822
 		$this->registerAlias('Request', \OCP\IRequest::class);
823 823
 
824
-		$this->registerService(\OCP\Mail\IMailer::class, function (Server $c) {
824
+		$this->registerService(\OCP\Mail\IMailer::class, function(Server $c) {
825 825
 			return new Mailer(
826 826
 				$c->getConfig(),
827 827
 				$c->getLogger(),
@@ -832,7 +832,7 @@  discard block
 block discarded – undo
832 832
 		});
833 833
 		$this->registerAlias('Mailer', \OCP\Mail\IMailer::class);
834 834
 
835
-		$this->registerService('LDAPProvider', function (Server $c) {
835
+		$this->registerService('LDAPProvider', function(Server $c) {
836 836
 			$config = $c->getConfig();
837 837
 			$factoryClass = $config->getSystemValue('ldapProviderFactory', null);
838 838
 			if (is_null($factoryClass)) {
@@ -842,7 +842,7 @@  discard block
 block discarded – undo
842 842
 			$factory = new $factoryClass($this);
843 843
 			return $factory->getLDAPProvider();
844 844
 		});
845
-		$this->registerService(ILockingProvider::class, function (Server $c) {
845
+		$this->registerService(ILockingProvider::class, function(Server $c) {
846 846
 			$ini = $c->getIniWrapper();
847 847
 			$config = $c->getConfig();
848 848
 			$ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time')));
@@ -865,49 +865,49 @@  discard block
 block discarded – undo
865 865
 		});
866 866
 		$this->registerAlias('LockingProvider', ILockingProvider::class);
867 867
 
868
-		$this->registerService(\OCP\Files\Mount\IMountManager::class, function () {
868
+		$this->registerService(\OCP\Files\Mount\IMountManager::class, function() {
869 869
 			return new \OC\Files\Mount\Manager();
870 870
 		});
871 871
 		$this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class);
872 872
 
873
-		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) {
873
+		$this->registerService(\OCP\Files\IMimeTypeDetector::class, function(Server $c) {
874 874
 			return new \OC\Files\Type\Detection(
875 875
 				$c->getURLGenerator(),
876 876
 				\OC::$configDir,
877
-				\OC::$SERVERROOT . '/resources/config/'
877
+				\OC::$SERVERROOT.'/resources/config/'
878 878
 			);
879 879
 		});
880 880
 		$this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class);
881 881
 
882
-		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) {
882
+		$this->registerService(\OCP\Files\IMimeTypeLoader::class, function(Server $c) {
883 883
 			return new \OC\Files\Type\Loader(
884 884
 				$c->getDatabaseConnection()
885 885
 			);
886 886
 		});
887 887
 		$this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class);
888
-		$this->registerService(BundleFetcher::class, function () {
888
+		$this->registerService(BundleFetcher::class, function() {
889 889
 			return new BundleFetcher($this->getL10N('lib'));
890 890
 		});
891
-		$this->registerService(\OCP\Notification\IManager::class, function (Server $c) {
891
+		$this->registerService(\OCP\Notification\IManager::class, function(Server $c) {
892 892
 			return new Manager(
893 893
 				$c->query(IValidator::class)
894 894
 			);
895 895
 		});
896 896
 		$this->registerAlias('NotificationManager', \OCP\Notification\IManager::class);
897 897
 
898
-		$this->registerService(\OC\CapabilitiesManager::class, function (Server $c) {
898
+		$this->registerService(\OC\CapabilitiesManager::class, function(Server $c) {
899 899
 			$manager = new \OC\CapabilitiesManager($c->getLogger());
900
-			$manager->registerCapability(function () use ($c) {
900
+			$manager->registerCapability(function() use ($c) {
901 901
 				return new \OC\OCS\CoreCapabilities($c->getConfig());
902 902
 			});
903
-			$manager->registerCapability(function () use ($c) {
903
+			$manager->registerCapability(function() use ($c) {
904 904
 				return $c->query(\OC\Security\Bruteforce\Capabilities::class);
905 905
 			});
906 906
 			return $manager;
907 907
 		});
908 908
 		$this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class);
909 909
 
910
-		$this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) {
910
+		$this->registerService(\OCP\Comments\ICommentsManager::class, function(Server $c) {
911 911
 			$config = $c->getConfig();
912 912
 			$factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class);
913 913
 			/** @var \OCP\Comments\ICommentsManagerFactory $factory */
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
 			$manager->registerDisplayNameResolver('user', function($id) use ($c) {
918 918
 				$manager = $c->getUserManager();
919 919
 				$user = $manager->get($id);
920
-				if(is_null($user)) {
920
+				if (is_null($user)) {
921 921
 					$l = $c->getL10N('core');
922 922
 					$displayName = $l->t('Unknown user');
923 923
 				} else {
@@ -930,7 +930,7 @@  discard block
 block discarded – undo
930 930
 		});
931 931
 		$this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class);
932 932
 
933
-		$this->registerService('ThemingDefaults', function (Server $c) {
933
+		$this->registerService('ThemingDefaults', function(Server $c) {
934 934
 			/*
935 935
 			 * Dark magic for autoloader.
936 936
 			 * If we do a class_exists it will try to load the class which will
@@ -957,7 +957,7 @@  discard block
 block discarded – undo
957 957
 			}
958 958
 			return new \OC_Defaults();
959 959
 		});
960
-		$this->registerService(SCSSCacher::class, function (Server $c) {
960
+		$this->registerService(SCSSCacher::class, function(Server $c) {
961 961
 			/** @var Factory $cacheFactory */
962 962
 			$cacheFactory = $c->query(Factory::class);
963 963
 			return new SCSSCacher(
@@ -970,7 +970,7 @@  discard block
 block discarded – undo
970 970
 				$this->getMemCacheFactory()
971 971
 			);
972 972
 		});
973
-		$this->registerService(JSCombiner::class, function (Server $c) {
973
+		$this->registerService(JSCombiner::class, function(Server $c) {
974 974
 			/** @var Factory $cacheFactory */
975 975
 			$cacheFactory = $c->query(Factory::class);
976 976
 			return new JSCombiner(
@@ -981,13 +981,13 @@  discard block
 block discarded – undo
981 981
 				$c->getLogger()
982 982
 			);
983 983
 		});
984
-		$this->registerService(EventDispatcher::class, function () {
984
+		$this->registerService(EventDispatcher::class, function() {
985 985
 			return new EventDispatcher();
986 986
 		});
987 987
 		$this->registerAlias('EventDispatcher', EventDispatcher::class);
988 988
 		$this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class);
989 989
 
990
-		$this->registerService('CryptoWrapper', function (Server $c) {
990
+		$this->registerService('CryptoWrapper', function(Server $c) {
991 991
 			// FIXME: Instantiiated here due to cyclic dependency
992 992
 			$request = new Request(
993 993
 				[
@@ -1012,7 +1012,7 @@  discard block
 block discarded – undo
1012 1012
 				$request
1013 1013
 			);
1014 1014
 		});
1015
-		$this->registerService('CsrfTokenManager', function (Server $c) {
1015
+		$this->registerService('CsrfTokenManager', function(Server $c) {
1016 1016
 			$tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom());
1017 1017
 
1018 1018
 			return new CsrfTokenManager(
@@ -1020,22 +1020,22 @@  discard block
 block discarded – undo
1020 1020
 				$c->query(SessionStorage::class)
1021 1021
 			);
1022 1022
 		});
1023
-		$this->registerService(SessionStorage::class, function (Server $c) {
1023
+		$this->registerService(SessionStorage::class, function(Server $c) {
1024 1024
 			return new SessionStorage($c->getSession());
1025 1025
 		});
1026
-		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) {
1026
+		$this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function(Server $c) {
1027 1027
 			return new ContentSecurityPolicyManager();
1028 1028
 		});
1029 1029
 		$this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class);
1030 1030
 
1031
-		$this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) {
1031
+		$this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) {
1032 1032
 			return new ContentSecurityPolicyNonceManager(
1033 1033
 				$c->getCsrfTokenManager(),
1034 1034
 				$c->getRequest()
1035 1035
 			);
1036 1036
 		});
1037 1037
 
1038
-		$this->registerService(\OCP\Share\IManager::class, function (Server $c) {
1038
+		$this->registerService(\OCP\Share\IManager::class, function(Server $c) {
1039 1039
 			$config = $c->getConfig();
1040 1040
 			$factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class);
1041 1041
 			/** @var \OCP\Share\IProviderFactory $factory */
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
 
1079 1079
 		$this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class);
1080 1080
 
1081
-		$this->registerService('SettingsManager', function (Server $c) {
1081
+		$this->registerService('SettingsManager', function(Server $c) {
1082 1082
 			$manager = new \OC\Settings\Manager(
1083 1083
 				$c->getLogger(),
1084 1084
 				$c->getDatabaseConnection(),
@@ -1096,36 +1096,36 @@  discard block
 block discarded – undo
1096 1096
 			);
1097 1097
 			return $manager;
1098 1098
 		});
1099
-		$this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) {
1099
+		$this->registerService(\OC\Files\AppData\Factory::class, function(Server $c) {
1100 1100
 			return new \OC\Files\AppData\Factory(
1101 1101
 				$c->getRootFolder(),
1102 1102
 				$c->getSystemConfig()
1103 1103
 			);
1104 1104
 		});
1105 1105
 
1106
-		$this->registerService('LockdownManager', function (Server $c) {
1107
-			return new LockdownManager(function () use ($c) {
1106
+		$this->registerService('LockdownManager', function(Server $c) {
1107
+			return new LockdownManager(function() use ($c) {
1108 1108
 				return $c->getSession();
1109 1109
 			});
1110 1110
 		});
1111 1111
 
1112
-		$this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) {
1112
+		$this->registerService(\OCP\OCS\IDiscoveryService::class, function(Server $c) {
1113 1113
 			return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService());
1114 1114
 		});
1115 1115
 
1116
-		$this->registerService(ICloudIdManager::class, function (Server $c) {
1116
+		$this->registerService(ICloudIdManager::class, function(Server $c) {
1117 1117
 			return new CloudIdManager();
1118 1118
 		});
1119 1119
 
1120
-		$this->registerService(IConfig::class, function (Server $c) {
1120
+		$this->registerService(IConfig::class, function(Server $c) {
1121 1121
 			return new GlobalScale\Config($c->getConfig());
1122 1122
 		});
1123 1123
 
1124
-		$this->registerService(ICloudFederationProviderManager::class, function (Server $c) {
1124
+		$this->registerService(ICloudFederationProviderManager::class, function(Server $c) {
1125 1125
 			return new CloudFederationProviderManager($c->getAppManager(), $c->getHTTPClientService(), $c->getCloudIdManager(), $c->getLogger());
1126 1126
 		});
1127 1127
 
1128
-		$this->registerService(ICloudFederationFactory::class, function (Server $c) {
1128
+		$this->registerService(ICloudFederationFactory::class, function(Server $c) {
1129 1129
 			return new CloudFederationFactory();
1130 1130
 		});
1131 1131
 
@@ -1135,18 +1135,18 @@  discard block
 block discarded – undo
1135 1135
 		$this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class);
1136 1136
 		$this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class);
1137 1137
 
1138
-		$this->registerService(Defaults::class, function (Server $c) {
1138
+		$this->registerService(Defaults::class, function(Server $c) {
1139 1139
 			return new Defaults(
1140 1140
 				$c->getThemingDefaults()
1141 1141
 			);
1142 1142
 		});
1143 1143
 		$this->registerAlias('Defaults', \OCP\Defaults::class);
1144 1144
 
1145
-		$this->registerService(\OCP\ISession::class, function (SimpleContainer $c) {
1145
+		$this->registerService(\OCP\ISession::class, function(SimpleContainer $c) {
1146 1146
 			return $c->query(\OCP\IUserSession::class)->getSession();
1147 1147
 		});
1148 1148
 
1149
-		$this->registerService(IShareHelper::class, function (Server $c) {
1149
+		$this->registerService(IShareHelper::class, function(Server $c) {
1150 1150
 			return new ShareHelper(
1151 1151
 				$c->query(\OCP\Share\IManager::class)
1152 1152
 			);
@@ -1208,11 +1208,11 @@  discard block
 block discarded – undo
1208 1208
 				// no avatar to remove
1209 1209
 			} catch (\Exception $e) {
1210 1210
 				// Ignore exceptions
1211
-				$logger->info('Could not cleanup avatar of ' . $user->getUID());
1211
+				$logger->info('Could not cleanup avatar of '.$user->getUID());
1212 1212
 			}
1213 1213
 		});
1214 1214
 
1215
-		$dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) {
1215
+		$dispatcher->addListener('OCP\IUser::changeUser', function(GenericEvent $e) {
1216 1216
 			$manager = $this->getAvatarManager();
1217 1217
 			/** @var IUser $user */
1218 1218
 			$user = $e->getSubject();
@@ -1363,7 +1363,7 @@  discard block
 block discarded – undo
1363 1363
 	 * @deprecated since 9.2.0 use IAppData
1364 1364
 	 */
1365 1365
 	public function getAppFolder() {
1366
-		$dir = '/' . \OC_App::getCurrentApp();
1366
+		$dir = '/'.\OC_App::getCurrentApp();
1367 1367
 		$root = $this->getRootFolder();
1368 1368
 		if (!$root->nodeExists($dir)) {
1369 1369
 			$folder = $root->newFolder($dir);
@@ -1938,7 +1938,7 @@  discard block
 block discarded – undo
1938 1938
 	/**
1939 1939
 	 * @return \OCP\Collaboration\AutoComplete\IManager
1940 1940
 	 */
1941
-	public function getAutoCompleteManager(){
1941
+	public function getAutoCompleteManager() {
1942 1942
 		return $this->query(IManager::class);
1943 1943
 	}
1944 1944
 
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/ocm/CloudFederationProviderFiles.php 3 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
 		// for backward compatibility make sure that the remote url stored in the
165 165
 		// database ends with a trailing slash
166 166
 		if (substr($remote, -1) !== '/') {
167
-			$remote = $remote . '/';
167
+			$remote = $remote.'/';
168 168
 		}
169 169
 
170 170
 		$token = $share->getShareSecret();
@@ -190,16 +190,16 @@  discard block
 block discarded – undo
190 190
 			}
191 191
 
192 192
 			// FIXME this should be a method in the user management instead
193
-			$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
193
+			$this->logger->debug('shareWith before, '.$shareWith, ['app' => 'files_sharing']);
194 194
 			Util::emitHook(
195 195
 				'\OCA\Files_Sharing\API\Server2Server',
196 196
 				'preLoginNameUsedAsUserName',
197 197
 				array('uid' => &$shareWith)
198 198
 			);
199
-			$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
199
+			$this->logger->debug('shareWith after, '.$shareWith, ['app' => 'files_sharing']);
200 200
 
201 201
 			if (!$this->userManager->userExists($shareWith)) {
202
-				throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
202
+				throw new ProviderCouldNotAddShareException('User does not exists', '', Http::STATUS_BAD_REQUEST);
203 203
 			}
204 204
 
205 205
 			\OC_Util::setupFS($shareWith);
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 					->setType('remote_share')
226 226
 					->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
227 227
 					->setAffectedUser($shareWith)
228
-					->setObject('remote_share', (int)$shareId, $name);
228
+					->setObject('remote_share', (int) $shareId, $name);
229 229
 				\OC::$server->getActivityManager()->publish($event);
230 230
 
231 231
 				$notification = $this->notificationManager->createNotification();
@@ -237,12 +237,12 @@  discard block
 block discarded – undo
237 237
 
238 238
 				$declineAction = $notification->createAction();
239 239
 				$declineAction->setLabel('decline')
240
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
240
+					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'DELETE');
241 241
 				$notification->addAction($declineAction);
242 242
 
243 243
 				$acceptAction = $notification->createAction();
244 244
 				$acceptAction->setLabel('accept')
245
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
245
+					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/'.$shareId)), 'POST');
246 246
 				$notification->addAction($acceptAction);
247 247
 
248 248
 				$this->notificationManager->notify($notification);
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 					'level' => ILogger::ERROR,
255 255
 					'app' => 'files_sharing'
256 256
 				]);
257
-				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
257
+				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from '.$remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
258 258
 			}
259 259
 		}
260 260
 
@@ -351,7 +351,7 @@  discard block
 block discarded – undo
351 351
 	 */
352 352
 	protected function executeAcceptShare(IShare $share) {
353 353
 		try {
354
-			$fileId = (int)$share->getNode()->getId();
354
+			$fileId = (int) $share->getNode()->getId();
355 355
 			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
356 356
 		} catch (\Exception $e) {
357 357
 			throw new ShareNotFound();
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
 		$this->federatedShareProvider->removeShareFromTable($share);
430 430
 
431 431
 		try {
432
-			$fileId = (int)$share->getNode()->getId();
432
+			$fileId = (int) $share->getNode()->getId();
433 433
 			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
434 434
 		} catch (\Exception $e) {
435 435
 			throw new ShareNotFound();
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
 			$notification = $this->notificationManager->createNotification();
531 531
 			$notification->setApp('files_sharing')
532 532
 				->setUser($share['user'])
533
-				->setObject('remote_share', (int)$share['id']);
533
+				->setObject('remote_share', (int) $share['id']);
534 534
 			$this->notificationManager->markProcessed($notification);
535 535
 
536 536
 			$event = $this->activityManager->generateEvent();
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				->setType('remote_share')
539 539
 				->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
540 540
 				->setAffectedUser($user)
541
-				->setObject('remote_share', (int)$share['id'], $path);
541
+				->setObject('remote_share', (int) $share['id'], $path);
542 542
 			\OC::$server->getActivityManager()->publish($event);
543 543
 		}
544 544
 
@@ -586,7 +586,7 @@  discard block
 block discarded – undo
586 586
 			$owner = $share->getShareOwner();
587 587
 			$currentServer = $this->addressHandler->generateRemoteURL();
588 588
 			if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
589
-				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id);
589
+				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: '.$id);
590 590
 			}
591 591
 		} catch (\Exception $e) {
592 592
 			throw new ProviderCouldNotAddShareException($e->getMessage());
@@ -600,10 +600,10 @@  discard block
 block discarded – undo
600 600
 			$share->setSharedBy($share->getSharedWith());
601 601
 			$share->setSharedWith($shareWith);
602 602
 			$result = $this->federatedShareProvider->create($share);
603
-			$this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);
603
+			$this->federatedShareProvider->storeRemoteId((int) $result->getId(), $senderId);
604 604
 			return ['token' => $result->getToken(), 'providerId' => $result->getId()];
605 605
 		} else {
606
-			throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
606
+			throw new ProviderCouldNotAddShareException('resharing not allowed for share: '.$id);
607 607
 		}
608 608
 
609 609
 	}
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
 	 */
650 650
 	protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
651 651
 		$ncPermissions = 0;
652
-		foreach($ocmPermissions as $permission) {
652
+		foreach ($ocmPermissions as $permission) {
653 653
 			switch (strtolower($permission)) {
654 654
 				case 'read':
655 655
 					$ncPermissions += Constants::PERMISSION_READ;
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * share received from another server
143 143
 	 *
144 144
 	 * @param ICloudFederationShare $share
145
-	 * @return string provider specific unique ID of the share
145
+	 * @return integer provider specific unique ID of the share
146 146
 	 *
147 147
 	 * @throws ProviderCouldNotAddShareException
148 148
 	 * @throws \OCP\AppFramework\QueryException
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 	/**
767 767
 	 * get the supported share types, e.g. "user", "group", etc.
768 768
 	 *
769
-	 * @return array
769
+	 * @return string[]
770 770
 	 *
771 771
 	 * @since 14.0.0
772 772
 	 */
Please login to merge, or discard this patch.
Indentation   +723 added lines, -723 removed lines patch added patch discarded remove patch
@@ -50,727 +50,727 @@
 block discarded – undo
50 50
 
51 51
 class CloudFederationProviderFiles implements ICloudFederationProvider {
52 52
 
53
-	/** @var IAppManager */
54
-	private $appManager;
55
-
56
-	/** @var FederatedShareProvider */
57
-	private $federatedShareProvider;
58
-
59
-	/** @var AddressHandler */
60
-	private $addressHandler;
61
-
62
-	/** @var ILogger */
63
-	private $logger;
64
-
65
-	/** @var IUserManager */
66
-	private $userManager;
67
-
68
-	/** @var ICloudIdManager */
69
-	private $cloudIdManager;
70
-
71
-	/** @var IActivityManager */
72
-	private $activityManager;
73
-
74
-	/** @var INotificationManager */
75
-	private $notificationManager;
76
-
77
-	/** @var IURLGenerator */
78
-	private $urlGenerator;
79
-
80
-	/** @var ICloudFederationFactory */
81
-	private $cloudFederationFactory;
82
-
83
-	/** @var ICloudFederationProviderManager */
84
-	private $cloudFederationProviderManager;
85
-
86
-	/** @var IDBConnection */
87
-	private $connection;
88
-
89
-	/**
90
-	 * CloudFederationProvider constructor.
91
-	 *
92
-	 * @param IAppManager $appManager
93
-	 * @param FederatedShareProvider $federatedShareProvider
94
-	 * @param AddressHandler $addressHandler
95
-	 * @param ILogger $logger
96
-	 * @param IUserManager $userManager
97
-	 * @param ICloudIdManager $cloudIdManager
98
-	 * @param IActivityManager $activityManager
99
-	 * @param INotificationManager $notificationManager
100
-	 * @param IURLGenerator $urlGenerator
101
-	 * @param ICloudFederationFactory $cloudFederationFactory
102
-	 * @param ICloudFederationProviderManager $cloudFederationProviderManager
103
-	 * @param IDBConnection $connection
104
-	 */
105
-	public function __construct(IAppManager $appManager,
106
-								FederatedShareProvider $federatedShareProvider,
107
-								AddressHandler $addressHandler,
108
-								ILogger $logger,
109
-								IUserManager $userManager,
110
-								ICloudIdManager $cloudIdManager,
111
-								IActivityManager $activityManager,
112
-								INotificationManager $notificationManager,
113
-								IURLGenerator $urlGenerator,
114
-								ICloudFederationFactory $cloudFederationFactory,
115
-								ICloudFederationProviderManager $cloudFederationProviderManager,
116
-								IDBConnection $connection
117
-	) {
118
-		$this->appManager = $appManager;
119
-		$this->federatedShareProvider = $federatedShareProvider;
120
-		$this->addressHandler = $addressHandler;
121
-		$this->logger = $logger;
122
-		$this->userManager = $userManager;
123
-		$this->cloudIdManager = $cloudIdManager;
124
-		$this->activityManager = $activityManager;
125
-		$this->notificationManager = $notificationManager;
126
-		$this->urlGenerator = $urlGenerator;
127
-		$this->cloudFederationFactory = $cloudFederationFactory;
128
-		$this->cloudFederationProviderManager = $cloudFederationProviderManager;
129
-		$this->connection = $connection;
130
-	}
131
-
132
-
133
-
134
-	/**
135
-	 * @return string
136
-	 */
137
-	public function getShareType() {
138
-		return 'file';
139
-	}
140
-
141
-	/**
142
-	 * share received from another server
143
-	 *
144
-	 * @param ICloudFederationShare $share
145
-	 * @return string provider specific unique ID of the share
146
-	 *
147
-	 * @throws ProviderCouldNotAddShareException
148
-	 * @throws \OCP\AppFramework\QueryException
149
-	 * @throws \OC\HintException
150
-	 * @since 14.0.0
151
-	 */
152
-	public function shareReceived(ICloudFederationShare $share) {
153
-
154
-		if (!$this->isS2SEnabled(true)) {
155
-			throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE);
156
-		}
157
-
158
-		$protocol = $share->getProtocol();
159
-		if ($protocol['name'] !== 'webdav') {
160
-			throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED);
161
-		}
162
-
163
-		list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());
164
-		// for backward compatibility make sure that the remote url stored in the
165
-		// database ends with a trailing slash
166
-		if (substr($remote, -1) !== '/') {
167
-			$remote = $remote . '/';
168
-		}
169
-
170
-		$token = $share->getShareSecret();
171
-		$name = $share->getResourceName();
172
-		$owner = $share->getOwnerDisplayName();
173
-		$sharedBy = $share->getSharedByDisplayName();
174
-		$shareWith = $share->getShareWith();
175
-		$remoteId = $share->getProviderId();
176
-		$sharedByFederatedId = $share->getSharedBy();
177
-		$ownerFederatedId = $share->getOwner();
178
-
179
-		// if no explicit information about the person who created the share was send
180
-		// we assume that the share comes from the owner
181
-		if ($sharedByFederatedId === null) {
182
-			$sharedBy = $owner;
183
-			$sharedByFederatedId = $ownerFederatedId;
184
-		}
185
-
186
-		if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
187
-
188
-			if (!Util::isValidFileName($name)) {
189
-				throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST);
190
-			}
191
-
192
-			// FIXME this should be a method in the user management instead
193
-			$this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
194
-			Util::emitHook(
195
-				'\OCA\Files_Sharing\API\Server2Server',
196
-				'preLoginNameUsedAsUserName',
197
-				array('uid' => &$shareWith)
198
-			);
199
-			$this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
200
-
201
-			if (!$this->userManager->userExists($shareWith)) {
202
-				throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
203
-			}
204
-
205
-			\OC_Util::setupFS($shareWith);
206
-
207
-			$externalManager = new \OCA\Files_Sharing\External\Manager(
208
-				\OC::$server->getDatabaseConnection(),
209
-				Filesystem::getMountManager(),
210
-				Filesystem::getLoader(),
211
-				\OC::$server->getHTTPClientService(),
212
-				\OC::$server->getNotificationManager(),
213
-				\OC::$server->query(\OCP\OCS\IDiscoveryService::class),
214
-				\OC::$server->getCloudFederationProviderManager(),
215
-				\OC::$server->getCloudFederationFactory(),
216
-				$shareWith
217
-			);
218
-
219
-			try {
220
-				$externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
221
-				$shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
222
-
223
-				$event = $this->activityManager->generateEvent();
224
-				$event->setApp('files_sharing')
225
-					->setType('remote_share')
226
-					->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
227
-					->setAffectedUser($shareWith)
228
-					->setObject('remote_share', (int)$shareId, $name);
229
-				\OC::$server->getActivityManager()->publish($event);
230
-
231
-				$notification = $this->notificationManager->createNotification();
232
-				$notification->setApp('files_sharing')
233
-					->setUser($shareWith)
234
-					->setDateTime(new \DateTime())
235
-					->setObject('remote_share', $shareId)
236
-					->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
237
-
238
-				$declineAction = $notification->createAction();
239
-				$declineAction->setLabel('decline')
240
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
241
-				$notification->addAction($declineAction);
242
-
243
-				$acceptAction = $notification->createAction();
244
-				$acceptAction->setLabel('accept')
245
-					->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
246
-				$notification->addAction($acceptAction);
247
-
248
-				$this->notificationManager->notify($notification);
249
-
250
-				return $shareId;
251
-			} catch (\Exception $e) {
252
-				$this->logger->logException($e, [
253
-					'message' => 'Server can not add remote share.',
254
-					'level' => ILogger::ERROR,
255
-					'app' => 'files_sharing'
256
-				]);
257
-				throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
258
-			}
259
-		}
260
-
261
-		throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST);
262
-
263
-	}
264
-
265
-	/**
266
-	 * notification received from another server
267
-	 *
268
-	 * @param string $notificationType (e.g. SHARE_ACCEPTED)
269
-	 * @param string $providerId id of the share
270
-	 * @param array $notification payload of the notification
271
-	 * @return array data send back to the sender
272
-	 *
273
-	 * @throws ActionNotSupportedException
274
-	 * @throws AuthenticationFailedException
275
-	 * @throws BadRequestException
276
-	 * @throws \OC\HintException
277
-	 * @since 14.0.0
278
-	 */
279
-	public function notificationReceived($notificationType, $providerId, array $notification) {
280
-
281
-		switch ($notificationType) {
282
-			case 'SHARE_ACCEPTED':
283
-				return $this->shareAccepted($providerId, $notification);
284
-			case 'SHARE_DECLINED':
285
-				return $this->shareDeclined($providerId, $notification);
286
-			case 'SHARE_UNSHARED':
287
-				return $this->unshare($providerId, $notification);
288
-			case 'REQUEST_RESHARE':
289
-				return $this->reshareRequested($providerId, $notification);
290
-			case 'RESHARE_UNDO':
291
-				return $this->undoReshare($providerId, $notification);
292
-			case 'RESHARE_CHANGE_PERMISSION':
293
-				return $this->updateResharePermissions($providerId, $notification);
294
-		}
295
-
296
-
297
-		throw new BadRequestException([$notificationType]);
298
-	}
299
-
300
-	/**
301
-	 * process notification that the recipient accepted a share
302
-	 *
303
-	 * @param string $id
304
-	 * @param array $notification
305
-	 * @return array
306
-	 * @throws ActionNotSupportedException
307
-	 * @throws AuthenticationFailedException
308
-	 * @throws BadRequestException
309
-	 * @throws \OC\HintException
310
-	 */
311
-	private function shareAccepted($id, array $notification) {
312
-
313
-		if (!$this->isS2SEnabled()) {
314
-			throw new ActionNotSupportedException('Server does not support federated cloud sharing');
315
-		}
316
-
317
-		if (!isset($notification['sharedSecret'])) {
318
-			throw new BadRequestException(['sharedSecret']);
319
-		}
320
-
321
-		$token = $notification['sharedSecret'];
322
-
323
-		$share = $this->federatedShareProvider->getShareById($id);
324
-
325
-		$this->verifyShare($share, $token);
326
-		$this->executeAcceptShare($share);
327
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
328
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
329
-			$remoteId = $this->federatedShareProvider->getRemoteId($share);
330
-			$notification = $this->cloudFederationFactory->getCloudFederationNotification();
331
-			$notification->setMessage(
332
-				'SHARE_ACCEPTED',
333
-				'file',
334
-				$remoteId,
335
-				[
336
-					'sharedSecret' => $token,
337
-					'message' => 'Recipient accepted the re-share'
338
-				]
339
-
340
-			);
341
-			$this->cloudFederationProviderManager->sendNotification($remote, $notification);
342
-
343
-		}
344
-
345
-		return [];
346
-	}
347
-
348
-	/**
349
-	 * @param IShare $share
350
-	 * @throws ShareNotFound
351
-	 */
352
-	protected function executeAcceptShare(IShare $share) {
353
-		try {
354
-			$fileId = (int)$share->getNode()->getId();
355
-			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
356
-		} catch (\Exception $e) {
357
-			throw new ShareNotFound();
358
-		}
359
-
360
-		$event = $this->activityManager->generateEvent();
361
-		$event->setApp('files_sharing')
362
-			->setType('remote_share')
363
-			->setAffectedUser($this->getCorrectUid($share))
364
-			->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])
365
-			->setObject('files', $fileId, $file)
366
-			->setLink($link);
367
-		$this->activityManager->publish($event);
368
-	}
369
-
370
-	/**
371
-	 * process notification that the recipient declined a share
372
-	 *
373
-	 * @param string $id
374
-	 * @param array $notification
375
-	 * @return array
376
-	 * @throws ActionNotSupportedException
377
-	 * @throws AuthenticationFailedException
378
-	 * @throws BadRequestException
379
-	 * @throws ShareNotFound
380
-	 * @throws \OC\HintException
381
-	 *
382
-	 */
383
-	protected function shareDeclined($id, array $notification) {
384
-
385
-		if (!$this->isS2SEnabled()) {
386
-			throw new ActionNotSupportedException('Server does not support federated cloud sharing');
387
-		}
388
-
389
-		if (!isset($notification['sharedSecret'])) {
390
-			throw new BadRequestException(['sharedSecret']);
391
-		}
392
-
393
-		$token = $notification['sharedSecret'];
394
-
395
-		$share = $this->federatedShareProvider->getShareById($id);
396
-
397
-		$this->verifyShare($share, $token);
398
-
399
-		if ($share->getShareOwner() !== $share->getSharedBy()) {
400
-			list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
401
-			$remoteId = $this->federatedShareProvider->getRemoteId($share);
402
-			$notification = $this->cloudFederationFactory->getCloudFederationNotification();
403
-			$notification->setMessage(
404
-				'SHARE_DECLINED',
405
-				'file',
406
-				$remoteId,
407
-				[
408
-					'sharedSecret' => $token,
409
-					'message' => 'Recipient declined the re-share'
410
-				]
411
-
412
-			);
413
-			$this->cloudFederationProviderManager->sendNotification($remote, $notification);
414
-		}
415
-
416
-		$this->executeDeclineShare($share);
417
-
418
-		return [];
419
-
420
-	}
421
-
422
-	/**
423
-	 * delete declined share and create a activity
424
-	 *
425
-	 * @param IShare $share
426
-	 * @throws ShareNotFound
427
-	 */
428
-	protected function executeDeclineShare(IShare $share) {
429
-		$this->federatedShareProvider->removeShareFromTable($share);
430
-
431
-		try {
432
-			$fileId = (int)$share->getNode()->getId();
433
-			list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
434
-		} catch (\Exception $e) {
435
-			throw new ShareNotFound();
436
-		}
437
-
438
-		$event = $this->activityManager->generateEvent();
439
-		$event->setApp('files_sharing')
440
-			->setType('remote_share')
441
-			->setAffectedUser($this->getCorrectUid($share))
442
-			->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])
443
-			->setObject('files', $fileId, $file)
444
-			->setLink($link);
445
-		$this->activityManager->publish($event);
446
-
447
-	}
448
-
449
-	/**
450
-	 * received the notification that the owner unshared a file from you
451
-	 *
452
-	 * @param string $id
453
-	 * @param array $notification
454
-	 * @return array
455
-	 * @throws AuthenticationFailedException
456
-	 * @throws BadRequestException
457
-	 */
458
-	private function undoReshare($id, array $notification) {
459
-		if (!isset($notification['sharedSecret'])) {
460
-			throw new BadRequestException(['sharedSecret']);
461
-		}
462
-		$token = $notification['sharedSecret'];
463
-
464
-		$share = $this->federatedShareProvider->getShareById($id);
465
-
466
-		$this->verifyShare($share, $token);
467
-		$this->federatedShareProvider->removeShareFromTable($share);
468
-		return [];
469
-	}
470
-
471
-	/**
472
-	 * unshare file from self
473
-	 *
474
-	 * @param string $id
475
-	 * @param array $notification
476
-	 * @return array
477
-	 * @throws ActionNotSupportedException
478
-	 * @throws BadRequestException
479
-	 */
480
-	private function unshare($id, array $notification) {
481
-
482
-		if (!$this->isS2SEnabled(true)) {
483
-			throw new ActionNotSupportedException("incoming shares disabled!");
484
-		}
485
-
486
-		if (!isset($notification['sharedSecret'])) {
487
-			throw new BadRequestException(['sharedSecret']);
488
-		}
489
-		$token = $notification['sharedSecret'];
490
-
491
-		$qb = $this->connection->getQueryBuilder();
492
-		$qb->select('*')
493
-			->from('share_external')
494
-			->where(
495
-				$qb->expr()->andX(
496
-					$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
497
-					$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
498
-				)
499
-			);
500
-
501
-		$result = $qb->execute();
502
-		$share = $result->fetch();
503
-		$result->closeCursor();
504
-
505
-		if ($token && $id && !empty($share)) {
506
-
507
-			$remote = $this->cleanupRemote($share['remote']);
508
-
509
-			$owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);
510
-			$mountpoint = $share['mountpoint'];
511
-			$user = $share['user'];
512
-
513
-			$qb = $this->connection->getQueryBuilder();
514
-			$qb->delete('share_external')
515
-				->where(
516
-					$qb->expr()->andX(
517
-						$qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
518
-						$qb->expr()->eq('share_token', $qb->createNamedParameter($token))
519
-					)
520
-				);
521
-
522
-			$qb->execute();
523
-
524
-			if ($share['accepted']) {
525
-				$path = trim($mountpoint, '/');
526
-			} else {
527
-				$path = trim($share['name'], '/');
528
-			}
529
-
530
-			$notification = $this->notificationManager->createNotification();
531
-			$notification->setApp('files_sharing')
532
-				->setUser($share['user'])
533
-				->setObject('remote_share', (int)$share['id']);
534
-			$this->notificationManager->markProcessed($notification);
535
-
536
-			$event = $this->activityManager->generateEvent();
537
-			$event->setApp('files_sharing')
538
-				->setType('remote_share')
539
-				->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
540
-				->setAffectedUser($user)
541
-				->setObject('remote_share', (int)$share['id'], $path);
542
-			\OC::$server->getActivityManager()->publish($event);
543
-		}
544
-
545
-		return [];
546
-	}
547
-
548
-	private function cleanupRemote($remote) {
549
-		$remote = substr($remote, strpos($remote, '://') + 3);
550
-
551
-		return rtrim($remote, '/');
552
-	}
553
-
554
-	/**
555
-	 * recipient of a share request to re-share the file with another user
556
-	 *
557
-	 * @param string $id
558
-	 * @param array $notification
559
-	 * @return array
560
-	 * @throws AuthenticationFailedException
561
-	 * @throws BadRequestException
562
-	 * @throws ProviderCouldNotAddShareException
563
-	 * @throws ShareNotFound
564
-	 */
565
-	protected function reshareRequested($id, array $notification) {
566
-
567
-		if (!isset($notification['sharedSecret'])) {
568
-			throw new BadRequestException(['sharedSecret']);
569
-		}
570
-		$token = $notification['sharedSecret'];
571
-
572
-		if (!isset($notification['shareWith'])) {
573
-			throw new BadRequestException(['shareWith']);
574
-		}
575
-		$shareWith = $notification['shareWith'];
576
-
577
-		if (!isset($notification['senderId'])) {
578
-			throw new BadRequestException(['senderId']);
579
-		}
580
-		$senderId = $notification['senderId'];
581
-
582
-		$share = $this->federatedShareProvider->getShareById($id);
583
-		// don't allow to share a file back to the owner
584
-		try {
585
-			list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
586
-			$owner = $share->getShareOwner();
587
-			$currentServer = $this->addressHandler->generateRemoteURL();
588
-			if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
589
-				throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id);
590
-			}
591
-		} catch (\Exception $e) {
592
-			throw new ProviderCouldNotAddShareException($e->getMessage());
593
-		}
594
-
595
-		$this->verifyShare($share, $token);
596
-
597
-		// check if re-sharing is allowed
598
-		if ($share->getPermissions() & Constants::PERMISSION_SHARE) {
599
-			// the recipient of the initial share is now the initiator for the re-share
600
-			$share->setSharedBy($share->getSharedWith());
601
-			$share->setSharedWith($shareWith);
602
-			$result = $this->federatedShareProvider->create($share);
603
-			$this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);
604
-			return ['token' => $result->getToken(), 'providerId' => $result->getId()];
605
-		} else {
606
-			throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
607
-		}
608
-
609
-	}
610
-
611
-	/**
612
-	 * update permission of a re-share so that the share dialog shows the right
613
-	 * permission if the owner or the sender changes the permission
614
-	 *
615
-	 * @param string $id
616
-	 * @param array $notification
617
-	 * @return array
618
-	 * @throws AuthenticationFailedException
619
-	 * @throws BadRequestException
620
-	 */
621
-	protected function updateResharePermissions($id, array $notification) {
622
-
623
-		if (!isset($notification['sharedSecret'])) {
624
-			throw new BadRequestException(['sharedSecret']);
625
-		}
626
-		$token = $notification['sharedSecret'];
627
-
628
-		if (!isset($notification['permission'])) {
629
-			throw new BadRequestException(['permission']);
630
-		}
631
-		$ocmPermissions = $notification['permission'];
632
-
633
-		$share = $this->federatedShareProvider->getShareById($id);
634
-
635
-		$ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);
636
-
637
-		$this->verifyShare($share, $token);
638
-		$this->updatePermissionsInDatabase($share, $ncPermission);
639
-
640
-		return [];
641
-	}
642
-
643
-	/**
644
-	 * translate OCM Permissions to Nextcloud permissions
645
-	 *
646
-	 * @param array $ocmPermissions
647
-	 * @return int
648
-	 * @throws BadRequestException
649
-	 */
650
-	protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
651
-		$ncPermissions = 0;
652
-		foreach($ocmPermissions as $permission) {
653
-			switch (strtolower($permission)) {
654
-				case 'read':
655
-					$ncPermissions += Constants::PERMISSION_READ;
656
-					break;
657
-				case 'write':
658
-					$ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
659
-					break;
660
-				case 'share':
661
-					$ncPermissions += Constants::PERMISSION_SHARE;
662
-					break;
663
-				default:
664
-					throw new BadRequestException(['permission']);
665
-			}
666
-
667
-		}
668
-
669
-		return $ncPermissions;
670
-	}
671
-
672
-	/**
673
-	 * update permissions in database
674
-	 *
675
-	 * @param IShare $share
676
-	 * @param int $permissions
677
-	 */
678
-	protected function updatePermissionsInDatabase(IShare $share, $permissions) {
679
-		$query = $this->connection->getQueryBuilder();
680
-		$query->update('share')
681
-			->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
682
-			->set('permissions', $query->createNamedParameter($permissions))
683
-			->execute();
684
-	}
685
-
686
-
687
-	/**
688
-	 * get file
689
-	 *
690
-	 * @param string $user
691
-	 * @param int $fileSource
692
-	 * @return array with internal path of the file and a absolute link to it
693
-	 */
694
-	private function getFile($user, $fileSource) {
695
-		\OC_Util::setupFS($user);
696
-
697
-		try {
698
-			$file = Filesystem::getPath($fileSource);
699
-		} catch (NotFoundException $e) {
700
-			$file = null;
701
-		}
702
-		$args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
703
-		$link = Util::linkToAbsolute('files', 'index.php', $args);
704
-
705
-		return [$file, $link];
706
-
707
-	}
708
-
709
-	/**
710
-	 * check if we are the initiator or the owner of a re-share and return the correct UID
711
-	 *
712
-	 * @param IShare $share
713
-	 * @return string
714
-	 */
715
-	protected function getCorrectUid(IShare $share) {
716
-		if ($this->userManager->userExists($share->getShareOwner())) {
717
-			return $share->getShareOwner();
718
-		}
719
-
720
-		return $share->getSharedBy();
721
-	}
722
-
723
-
724
-
725
-	/**
726
-	 * check if we got the right share
727
-	 *
728
-	 * @param IShare $share
729
-	 * @param string $token
730
-	 * @return bool
731
-	 * @throws AuthenticationFailedException
732
-	 */
733
-	protected function verifyShare(IShare $share, $token) {
734
-		if (
735
-			$share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&
736
-			$share->getToken() === $token
737
-		) {
738
-			return true;
739
-		}
740
-
741
-		throw new AuthenticationFailedException();
742
-	}
743
-
744
-
745
-
746
-	/**
747
-	 * check if server-to-server sharing is enabled
748
-	 *
749
-	 * @param bool $incoming
750
-	 * @return bool
751
-	 */
752
-	private function isS2SEnabled($incoming = false) {
753
-
754
-		$result = $this->appManager->isEnabledForUser('files_sharing');
755
-
756
-		if ($incoming) {
757
-			$result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
758
-		} else {
759
-			$result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
760
-		}
761
-
762
-		return $result;
763
-	}
764
-
765
-
766
-	/**
767
-	 * get the supported share types, e.g. "user", "group", etc.
768
-	 *
769
-	 * @return array
770
-	 *
771
-	 * @since 14.0.0
772
-	 */
773
-	public function getSupportedShareTypes() {
774
-		return ['user'];
775
-	}
53
+    /** @var IAppManager */
54
+    private $appManager;
55
+
56
+    /** @var FederatedShareProvider */
57
+    private $federatedShareProvider;
58
+
59
+    /** @var AddressHandler */
60
+    private $addressHandler;
61
+
62
+    /** @var ILogger */
63
+    private $logger;
64
+
65
+    /** @var IUserManager */
66
+    private $userManager;
67
+
68
+    /** @var ICloudIdManager */
69
+    private $cloudIdManager;
70
+
71
+    /** @var IActivityManager */
72
+    private $activityManager;
73
+
74
+    /** @var INotificationManager */
75
+    private $notificationManager;
76
+
77
+    /** @var IURLGenerator */
78
+    private $urlGenerator;
79
+
80
+    /** @var ICloudFederationFactory */
81
+    private $cloudFederationFactory;
82
+
83
+    /** @var ICloudFederationProviderManager */
84
+    private $cloudFederationProviderManager;
85
+
86
+    /** @var IDBConnection */
87
+    private $connection;
88
+
89
+    /**
90
+     * CloudFederationProvider constructor.
91
+     *
92
+     * @param IAppManager $appManager
93
+     * @param FederatedShareProvider $federatedShareProvider
94
+     * @param AddressHandler $addressHandler
95
+     * @param ILogger $logger
96
+     * @param IUserManager $userManager
97
+     * @param ICloudIdManager $cloudIdManager
98
+     * @param IActivityManager $activityManager
99
+     * @param INotificationManager $notificationManager
100
+     * @param IURLGenerator $urlGenerator
101
+     * @param ICloudFederationFactory $cloudFederationFactory
102
+     * @param ICloudFederationProviderManager $cloudFederationProviderManager
103
+     * @param IDBConnection $connection
104
+     */
105
+    public function __construct(IAppManager $appManager,
106
+                                FederatedShareProvider $federatedShareProvider,
107
+                                AddressHandler $addressHandler,
108
+                                ILogger $logger,
109
+                                IUserManager $userManager,
110
+                                ICloudIdManager $cloudIdManager,
111
+                                IActivityManager $activityManager,
112
+                                INotificationManager $notificationManager,
113
+                                IURLGenerator $urlGenerator,
114
+                                ICloudFederationFactory $cloudFederationFactory,
115
+                                ICloudFederationProviderManager $cloudFederationProviderManager,
116
+                                IDBConnection $connection
117
+    ) {
118
+        $this->appManager = $appManager;
119
+        $this->federatedShareProvider = $federatedShareProvider;
120
+        $this->addressHandler = $addressHandler;
121
+        $this->logger = $logger;
122
+        $this->userManager = $userManager;
123
+        $this->cloudIdManager = $cloudIdManager;
124
+        $this->activityManager = $activityManager;
125
+        $this->notificationManager = $notificationManager;
126
+        $this->urlGenerator = $urlGenerator;
127
+        $this->cloudFederationFactory = $cloudFederationFactory;
128
+        $this->cloudFederationProviderManager = $cloudFederationProviderManager;
129
+        $this->connection = $connection;
130
+    }
131
+
132
+
133
+
134
+    /**
135
+     * @return string
136
+     */
137
+    public function getShareType() {
138
+        return 'file';
139
+    }
140
+
141
+    /**
142
+     * share received from another server
143
+     *
144
+     * @param ICloudFederationShare $share
145
+     * @return string provider specific unique ID of the share
146
+     *
147
+     * @throws ProviderCouldNotAddShareException
148
+     * @throws \OCP\AppFramework\QueryException
149
+     * @throws \OC\HintException
150
+     * @since 14.0.0
151
+     */
152
+    public function shareReceived(ICloudFederationShare $share) {
153
+
154
+        if (!$this->isS2SEnabled(true)) {
155
+            throw new ProviderCouldNotAddShareException('Server does not support federated cloud sharing', '', Http::STATUS_SERVICE_UNAVAILABLE);
156
+        }
157
+
158
+        $protocol = $share->getProtocol();
159
+        if ($protocol['name'] !== 'webdav') {
160
+            throw new ProviderCouldNotAddShareException('Unsupported protocol for data exchange.', '', Http::STATUS_NOT_IMPLEMENTED);
161
+        }
162
+
163
+        list($ownerUid, $remote) = $this->addressHandler->splitUserRemote($share->getOwner());
164
+        // for backward compatibility make sure that the remote url stored in the
165
+        // database ends with a trailing slash
166
+        if (substr($remote, -1) !== '/') {
167
+            $remote = $remote . '/';
168
+        }
169
+
170
+        $token = $share->getShareSecret();
171
+        $name = $share->getResourceName();
172
+        $owner = $share->getOwnerDisplayName();
173
+        $sharedBy = $share->getSharedByDisplayName();
174
+        $shareWith = $share->getShareWith();
175
+        $remoteId = $share->getProviderId();
176
+        $sharedByFederatedId = $share->getSharedBy();
177
+        $ownerFederatedId = $share->getOwner();
178
+
179
+        // if no explicit information about the person who created the share was send
180
+        // we assume that the share comes from the owner
181
+        if ($sharedByFederatedId === null) {
182
+            $sharedBy = $owner;
183
+            $sharedByFederatedId = $ownerFederatedId;
184
+        }
185
+
186
+        if ($remote && $token && $name && $owner && $remoteId && $shareWith) {
187
+
188
+            if (!Util::isValidFileName($name)) {
189
+                throw new ProviderCouldNotAddShareException('The mountpoint name contains invalid characters.', '', Http::STATUS_BAD_REQUEST);
190
+            }
191
+
192
+            // FIXME this should be a method in the user management instead
193
+            $this->logger->debug('shareWith before, ' . $shareWith, ['app' => 'files_sharing']);
194
+            Util::emitHook(
195
+                '\OCA\Files_Sharing\API\Server2Server',
196
+                'preLoginNameUsedAsUserName',
197
+                array('uid' => &$shareWith)
198
+            );
199
+            $this->logger->debug('shareWith after, ' . $shareWith, ['app' => 'files_sharing']);
200
+
201
+            if (!$this->userManager->userExists($shareWith)) {
202
+                throw new ProviderCouldNotAddShareException('User does not exists', '',Http::STATUS_BAD_REQUEST);
203
+            }
204
+
205
+            \OC_Util::setupFS($shareWith);
206
+
207
+            $externalManager = new \OCA\Files_Sharing\External\Manager(
208
+                \OC::$server->getDatabaseConnection(),
209
+                Filesystem::getMountManager(),
210
+                Filesystem::getLoader(),
211
+                \OC::$server->getHTTPClientService(),
212
+                \OC::$server->getNotificationManager(),
213
+                \OC::$server->query(\OCP\OCS\IDiscoveryService::class),
214
+                \OC::$server->getCloudFederationProviderManager(),
215
+                \OC::$server->getCloudFederationFactory(),
216
+                $shareWith
217
+            );
218
+
219
+            try {
220
+                $externalManager->addShare($remote, $token, '', $name, $owner, false, $shareWith, $remoteId);
221
+                $shareId = \OC::$server->getDatabaseConnection()->lastInsertId('*PREFIX*share_external');
222
+
223
+                $event = $this->activityManager->generateEvent();
224
+                $event->setApp('files_sharing')
225
+                    ->setType('remote_share')
226
+                    ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_RECEIVED, [$ownerFederatedId, trim($name, '/')])
227
+                    ->setAffectedUser($shareWith)
228
+                    ->setObject('remote_share', (int)$shareId, $name);
229
+                \OC::$server->getActivityManager()->publish($event);
230
+
231
+                $notification = $this->notificationManager->createNotification();
232
+                $notification->setApp('files_sharing')
233
+                    ->setUser($shareWith)
234
+                    ->setDateTime(new \DateTime())
235
+                    ->setObject('remote_share', $shareId)
236
+                    ->setSubject('remote_share', [$ownerFederatedId, $sharedByFederatedId, trim($name, '/')]);
237
+
238
+                $declineAction = $notification->createAction();
239
+                $declineAction->setLabel('decline')
240
+                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'DELETE');
241
+                $notification->addAction($declineAction);
242
+
243
+                $acceptAction = $notification->createAction();
244
+                $acceptAction->setLabel('accept')
245
+                    ->setLink($this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkTo('', 'ocs/v2.php/apps/files_sharing/api/v1/remote_shares/pending/' . $shareId)), 'POST');
246
+                $notification->addAction($acceptAction);
247
+
248
+                $this->notificationManager->notify($notification);
249
+
250
+                return $shareId;
251
+            } catch (\Exception $e) {
252
+                $this->logger->logException($e, [
253
+                    'message' => 'Server can not add remote share.',
254
+                    'level' => ILogger::ERROR,
255
+                    'app' => 'files_sharing'
256
+                ]);
257
+                throw new ProviderCouldNotAddShareException('internal server error, was not able to add share from ' . $remote, '', HTTP::STATUS_INTERNAL_SERVER_ERROR);
258
+            }
259
+        }
260
+
261
+        throw new ProviderCouldNotAddShareException('server can not add remote share, missing parameter', '', HTTP::STATUS_BAD_REQUEST);
262
+
263
+    }
264
+
265
+    /**
266
+     * notification received from another server
267
+     *
268
+     * @param string $notificationType (e.g. SHARE_ACCEPTED)
269
+     * @param string $providerId id of the share
270
+     * @param array $notification payload of the notification
271
+     * @return array data send back to the sender
272
+     *
273
+     * @throws ActionNotSupportedException
274
+     * @throws AuthenticationFailedException
275
+     * @throws BadRequestException
276
+     * @throws \OC\HintException
277
+     * @since 14.0.0
278
+     */
279
+    public function notificationReceived($notificationType, $providerId, array $notification) {
280
+
281
+        switch ($notificationType) {
282
+            case 'SHARE_ACCEPTED':
283
+                return $this->shareAccepted($providerId, $notification);
284
+            case 'SHARE_DECLINED':
285
+                return $this->shareDeclined($providerId, $notification);
286
+            case 'SHARE_UNSHARED':
287
+                return $this->unshare($providerId, $notification);
288
+            case 'REQUEST_RESHARE':
289
+                return $this->reshareRequested($providerId, $notification);
290
+            case 'RESHARE_UNDO':
291
+                return $this->undoReshare($providerId, $notification);
292
+            case 'RESHARE_CHANGE_PERMISSION':
293
+                return $this->updateResharePermissions($providerId, $notification);
294
+        }
295
+
296
+
297
+        throw new BadRequestException([$notificationType]);
298
+    }
299
+
300
+    /**
301
+     * process notification that the recipient accepted a share
302
+     *
303
+     * @param string $id
304
+     * @param array $notification
305
+     * @return array
306
+     * @throws ActionNotSupportedException
307
+     * @throws AuthenticationFailedException
308
+     * @throws BadRequestException
309
+     * @throws \OC\HintException
310
+     */
311
+    private function shareAccepted($id, array $notification) {
312
+
313
+        if (!$this->isS2SEnabled()) {
314
+            throw new ActionNotSupportedException('Server does not support federated cloud sharing');
315
+        }
316
+
317
+        if (!isset($notification['sharedSecret'])) {
318
+            throw new BadRequestException(['sharedSecret']);
319
+        }
320
+
321
+        $token = $notification['sharedSecret'];
322
+
323
+        $share = $this->federatedShareProvider->getShareById($id);
324
+
325
+        $this->verifyShare($share, $token);
326
+        $this->executeAcceptShare($share);
327
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
328
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
329
+            $remoteId = $this->federatedShareProvider->getRemoteId($share);
330
+            $notification = $this->cloudFederationFactory->getCloudFederationNotification();
331
+            $notification->setMessage(
332
+                'SHARE_ACCEPTED',
333
+                'file',
334
+                $remoteId,
335
+                [
336
+                    'sharedSecret' => $token,
337
+                    'message' => 'Recipient accepted the re-share'
338
+                ]
339
+
340
+            );
341
+            $this->cloudFederationProviderManager->sendNotification($remote, $notification);
342
+
343
+        }
344
+
345
+        return [];
346
+    }
347
+
348
+    /**
349
+     * @param IShare $share
350
+     * @throws ShareNotFound
351
+     */
352
+    protected function executeAcceptShare(IShare $share) {
353
+        try {
354
+            $fileId = (int)$share->getNode()->getId();
355
+            list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
356
+        } catch (\Exception $e) {
357
+            throw new ShareNotFound();
358
+        }
359
+
360
+        $event = $this->activityManager->generateEvent();
361
+        $event->setApp('files_sharing')
362
+            ->setType('remote_share')
363
+            ->setAffectedUser($this->getCorrectUid($share))
364
+            ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_ACCEPTED, [$share->getSharedWith(), [$fileId => $file]])
365
+            ->setObject('files', $fileId, $file)
366
+            ->setLink($link);
367
+        $this->activityManager->publish($event);
368
+    }
369
+
370
+    /**
371
+     * process notification that the recipient declined a share
372
+     *
373
+     * @param string $id
374
+     * @param array $notification
375
+     * @return array
376
+     * @throws ActionNotSupportedException
377
+     * @throws AuthenticationFailedException
378
+     * @throws BadRequestException
379
+     * @throws ShareNotFound
380
+     * @throws \OC\HintException
381
+     *
382
+     */
383
+    protected function shareDeclined($id, array $notification) {
384
+
385
+        if (!$this->isS2SEnabled()) {
386
+            throw new ActionNotSupportedException('Server does not support federated cloud sharing');
387
+        }
388
+
389
+        if (!isset($notification['sharedSecret'])) {
390
+            throw new BadRequestException(['sharedSecret']);
391
+        }
392
+
393
+        $token = $notification['sharedSecret'];
394
+
395
+        $share = $this->federatedShareProvider->getShareById($id);
396
+
397
+        $this->verifyShare($share, $token);
398
+
399
+        if ($share->getShareOwner() !== $share->getSharedBy()) {
400
+            list(, $remote) = $this->addressHandler->splitUserRemote($share->getSharedBy());
401
+            $remoteId = $this->federatedShareProvider->getRemoteId($share);
402
+            $notification = $this->cloudFederationFactory->getCloudFederationNotification();
403
+            $notification->setMessage(
404
+                'SHARE_DECLINED',
405
+                'file',
406
+                $remoteId,
407
+                [
408
+                    'sharedSecret' => $token,
409
+                    'message' => 'Recipient declined the re-share'
410
+                ]
411
+
412
+            );
413
+            $this->cloudFederationProviderManager->sendNotification($remote, $notification);
414
+        }
415
+
416
+        $this->executeDeclineShare($share);
417
+
418
+        return [];
419
+
420
+    }
421
+
422
+    /**
423
+     * delete declined share and create a activity
424
+     *
425
+     * @param IShare $share
426
+     * @throws ShareNotFound
427
+     */
428
+    protected function executeDeclineShare(IShare $share) {
429
+        $this->federatedShareProvider->removeShareFromTable($share);
430
+
431
+        try {
432
+            $fileId = (int)$share->getNode()->getId();
433
+            list($file, $link) = $this->getFile($this->getCorrectUid($share), $fileId);
434
+        } catch (\Exception $e) {
435
+            throw new ShareNotFound();
436
+        }
437
+
438
+        $event = $this->activityManager->generateEvent();
439
+        $event->setApp('files_sharing')
440
+            ->setType('remote_share')
441
+            ->setAffectedUser($this->getCorrectUid($share))
442
+            ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_DECLINED, [$share->getSharedWith(), [$fileId => $file]])
443
+            ->setObject('files', $fileId, $file)
444
+            ->setLink($link);
445
+        $this->activityManager->publish($event);
446
+
447
+    }
448
+
449
+    /**
450
+     * received the notification that the owner unshared a file from you
451
+     *
452
+     * @param string $id
453
+     * @param array $notification
454
+     * @return array
455
+     * @throws AuthenticationFailedException
456
+     * @throws BadRequestException
457
+     */
458
+    private function undoReshare($id, array $notification) {
459
+        if (!isset($notification['sharedSecret'])) {
460
+            throw new BadRequestException(['sharedSecret']);
461
+        }
462
+        $token = $notification['sharedSecret'];
463
+
464
+        $share = $this->federatedShareProvider->getShareById($id);
465
+
466
+        $this->verifyShare($share, $token);
467
+        $this->federatedShareProvider->removeShareFromTable($share);
468
+        return [];
469
+    }
470
+
471
+    /**
472
+     * unshare file from self
473
+     *
474
+     * @param string $id
475
+     * @param array $notification
476
+     * @return array
477
+     * @throws ActionNotSupportedException
478
+     * @throws BadRequestException
479
+     */
480
+    private function unshare($id, array $notification) {
481
+
482
+        if (!$this->isS2SEnabled(true)) {
483
+            throw new ActionNotSupportedException("incoming shares disabled!");
484
+        }
485
+
486
+        if (!isset($notification['sharedSecret'])) {
487
+            throw new BadRequestException(['sharedSecret']);
488
+        }
489
+        $token = $notification['sharedSecret'];
490
+
491
+        $qb = $this->connection->getQueryBuilder();
492
+        $qb->select('*')
493
+            ->from('share_external')
494
+            ->where(
495
+                $qb->expr()->andX(
496
+                    $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
497
+                    $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
498
+                )
499
+            );
500
+
501
+        $result = $qb->execute();
502
+        $share = $result->fetch();
503
+        $result->closeCursor();
504
+
505
+        if ($token && $id && !empty($share)) {
506
+
507
+            $remote = $this->cleanupRemote($share['remote']);
508
+
509
+            $owner = $this->cloudIdManager->getCloudId($share['owner'], $remote);
510
+            $mountpoint = $share['mountpoint'];
511
+            $user = $share['user'];
512
+
513
+            $qb = $this->connection->getQueryBuilder();
514
+            $qb->delete('share_external')
515
+                ->where(
516
+                    $qb->expr()->andX(
517
+                        $qb->expr()->eq('remote_id', $qb->createNamedParameter($id)),
518
+                        $qb->expr()->eq('share_token', $qb->createNamedParameter($token))
519
+                    )
520
+                );
521
+
522
+            $qb->execute();
523
+
524
+            if ($share['accepted']) {
525
+                $path = trim($mountpoint, '/');
526
+            } else {
527
+                $path = trim($share['name'], '/');
528
+            }
529
+
530
+            $notification = $this->notificationManager->createNotification();
531
+            $notification->setApp('files_sharing')
532
+                ->setUser($share['user'])
533
+                ->setObject('remote_share', (int)$share['id']);
534
+            $this->notificationManager->markProcessed($notification);
535
+
536
+            $event = $this->activityManager->generateEvent();
537
+            $event->setApp('files_sharing')
538
+                ->setType('remote_share')
539
+                ->setSubject(RemoteShares::SUBJECT_REMOTE_SHARE_UNSHARED, [$owner->getId(), $path])
540
+                ->setAffectedUser($user)
541
+                ->setObject('remote_share', (int)$share['id'], $path);
542
+            \OC::$server->getActivityManager()->publish($event);
543
+        }
544
+
545
+        return [];
546
+    }
547
+
548
+    private function cleanupRemote($remote) {
549
+        $remote = substr($remote, strpos($remote, '://') + 3);
550
+
551
+        return rtrim($remote, '/');
552
+    }
553
+
554
+    /**
555
+     * recipient of a share request to re-share the file with another user
556
+     *
557
+     * @param string $id
558
+     * @param array $notification
559
+     * @return array
560
+     * @throws AuthenticationFailedException
561
+     * @throws BadRequestException
562
+     * @throws ProviderCouldNotAddShareException
563
+     * @throws ShareNotFound
564
+     */
565
+    protected function reshareRequested($id, array $notification) {
566
+
567
+        if (!isset($notification['sharedSecret'])) {
568
+            throw new BadRequestException(['sharedSecret']);
569
+        }
570
+        $token = $notification['sharedSecret'];
571
+
572
+        if (!isset($notification['shareWith'])) {
573
+            throw new BadRequestException(['shareWith']);
574
+        }
575
+        $shareWith = $notification['shareWith'];
576
+
577
+        if (!isset($notification['senderId'])) {
578
+            throw new BadRequestException(['senderId']);
579
+        }
580
+        $senderId = $notification['senderId'];
581
+
582
+        $share = $this->federatedShareProvider->getShareById($id);
583
+        // don't allow to share a file back to the owner
584
+        try {
585
+            list($user, $remote) = $this->addressHandler->splitUserRemote($shareWith);
586
+            $owner = $share->getShareOwner();
587
+            $currentServer = $this->addressHandler->generateRemoteURL();
588
+            if ($this->addressHandler->compareAddresses($user, $remote, $owner, $currentServer)) {
589
+                throw new ProviderCouldNotAddShareException('Resharing back to the owner is not allowed: ' . $id);
590
+            }
591
+        } catch (\Exception $e) {
592
+            throw new ProviderCouldNotAddShareException($e->getMessage());
593
+        }
594
+
595
+        $this->verifyShare($share, $token);
596
+
597
+        // check if re-sharing is allowed
598
+        if ($share->getPermissions() & Constants::PERMISSION_SHARE) {
599
+            // the recipient of the initial share is now the initiator for the re-share
600
+            $share->setSharedBy($share->getSharedWith());
601
+            $share->setSharedWith($shareWith);
602
+            $result = $this->federatedShareProvider->create($share);
603
+            $this->federatedShareProvider->storeRemoteId((int)$result->getId(), $senderId);
604
+            return ['token' => $result->getToken(), 'providerId' => $result->getId()];
605
+        } else {
606
+            throw new ProviderCouldNotAddShareException('resharing not allowed for share: ' . $id);
607
+        }
608
+
609
+    }
610
+
611
+    /**
612
+     * update permission of a re-share so that the share dialog shows the right
613
+     * permission if the owner or the sender changes the permission
614
+     *
615
+     * @param string $id
616
+     * @param array $notification
617
+     * @return array
618
+     * @throws AuthenticationFailedException
619
+     * @throws BadRequestException
620
+     */
621
+    protected function updateResharePermissions($id, array $notification) {
622
+
623
+        if (!isset($notification['sharedSecret'])) {
624
+            throw new BadRequestException(['sharedSecret']);
625
+        }
626
+        $token = $notification['sharedSecret'];
627
+
628
+        if (!isset($notification['permission'])) {
629
+            throw new BadRequestException(['permission']);
630
+        }
631
+        $ocmPermissions = $notification['permission'];
632
+
633
+        $share = $this->federatedShareProvider->getShareById($id);
634
+
635
+        $ncPermission = $this->ocmPermissions2ncPermissions($ocmPermissions);
636
+
637
+        $this->verifyShare($share, $token);
638
+        $this->updatePermissionsInDatabase($share, $ncPermission);
639
+
640
+        return [];
641
+    }
642
+
643
+    /**
644
+     * translate OCM Permissions to Nextcloud permissions
645
+     *
646
+     * @param array $ocmPermissions
647
+     * @return int
648
+     * @throws BadRequestException
649
+     */
650
+    protected function ocmPermissions2ncPermissions(array $ocmPermissions) {
651
+        $ncPermissions = 0;
652
+        foreach($ocmPermissions as $permission) {
653
+            switch (strtolower($permission)) {
654
+                case 'read':
655
+                    $ncPermissions += Constants::PERMISSION_READ;
656
+                    break;
657
+                case 'write':
658
+                    $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
659
+                    break;
660
+                case 'share':
661
+                    $ncPermissions += Constants::PERMISSION_SHARE;
662
+                    break;
663
+                default:
664
+                    throw new BadRequestException(['permission']);
665
+            }
666
+
667
+        }
668
+
669
+        return $ncPermissions;
670
+    }
671
+
672
+    /**
673
+     * update permissions in database
674
+     *
675
+     * @param IShare $share
676
+     * @param int $permissions
677
+     */
678
+    protected function updatePermissionsInDatabase(IShare $share, $permissions) {
679
+        $query = $this->connection->getQueryBuilder();
680
+        $query->update('share')
681
+            ->where($query->expr()->eq('id', $query->createNamedParameter($share->getId())))
682
+            ->set('permissions', $query->createNamedParameter($permissions))
683
+            ->execute();
684
+    }
685
+
686
+
687
+    /**
688
+     * get file
689
+     *
690
+     * @param string $user
691
+     * @param int $fileSource
692
+     * @return array with internal path of the file and a absolute link to it
693
+     */
694
+    private function getFile($user, $fileSource) {
695
+        \OC_Util::setupFS($user);
696
+
697
+        try {
698
+            $file = Filesystem::getPath($fileSource);
699
+        } catch (NotFoundException $e) {
700
+            $file = null;
701
+        }
702
+        $args = Filesystem::is_dir($file) ? array('dir' => $file) : array('dir' => dirname($file), 'scrollto' => $file);
703
+        $link = Util::linkToAbsolute('files', 'index.php', $args);
704
+
705
+        return [$file, $link];
706
+
707
+    }
708
+
709
+    /**
710
+     * check if we are the initiator or the owner of a re-share and return the correct UID
711
+     *
712
+     * @param IShare $share
713
+     * @return string
714
+     */
715
+    protected function getCorrectUid(IShare $share) {
716
+        if ($this->userManager->userExists($share->getShareOwner())) {
717
+            return $share->getShareOwner();
718
+        }
719
+
720
+        return $share->getSharedBy();
721
+    }
722
+
723
+
724
+
725
+    /**
726
+     * check if we got the right share
727
+     *
728
+     * @param IShare $share
729
+     * @param string $token
730
+     * @return bool
731
+     * @throws AuthenticationFailedException
732
+     */
733
+    protected function verifyShare(IShare $share, $token) {
734
+        if (
735
+            $share->getShareType() === FederatedShareProvider::SHARE_TYPE_REMOTE &&
736
+            $share->getToken() === $token
737
+        ) {
738
+            return true;
739
+        }
740
+
741
+        throw new AuthenticationFailedException();
742
+    }
743
+
744
+
745
+
746
+    /**
747
+     * check if server-to-server sharing is enabled
748
+     *
749
+     * @param bool $incoming
750
+     * @return bool
751
+     */
752
+    private function isS2SEnabled($incoming = false) {
753
+
754
+        $result = $this->appManager->isEnabledForUser('files_sharing');
755
+
756
+        if ($incoming) {
757
+            $result = $result && $this->federatedShareProvider->isIncomingServer2serverShareEnabled();
758
+        } else {
759
+            $result = $result && $this->federatedShareProvider->isOutgoingServer2serverShareEnabled();
760
+        }
761
+
762
+        return $result;
763
+    }
764
+
765
+
766
+    /**
767
+     * get the supported share types, e.g. "user", "group", etc.
768
+     *
769
+     * @return array
770
+     *
771
+     * @since 14.0.0
772
+     */
773
+    public function getSupportedShareTypes() {
774
+        return ['user'];
775
+    }
776 776
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/External/Storage.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -407,7 +407,7 @@
 block discarded – undo
407 407
 	/**
408 408
 	 * calculate default permissions in case no permissions are provided
409 409
 	 *
410
-	 * @param $path
410
+	 * @param string $path
411 411
 	 * @return int
412 412
 	 */
413 413
 	protected function getDefaultPermissions($path) {
Please login to merge, or discard this patch.
Indentation   +376 added lines, -376 removed lines patch added patch discarded remove patch
@@ -43,380 +43,380 @@
 block discarded – undo
43 43
 use OCP\Files\StorageNotAvailableException;
44 44
 
45 45
 class Storage extends DAV implements ISharedStorage {
46
-	/** @var ICloudId */
47
-	private $cloudId;
48
-	/** @var string */
49
-	private $mountPoint;
50
-	/** @var string */
51
-	private $token;
52
-	/** @var \OCP\ICacheFactory */
53
-	private $memcacheFactory;
54
-	/** @var \OCP\Http\Client\IClientService */
55
-	private $httpClient;
56
-	/** @var bool */
57
-	private $updateChecked = false;
58
-
59
-	/**
60
-	 * @var \OCA\Files_Sharing\External\Manager
61
-	 */
62
-	private $manager;
63
-
64
-	public function __construct($options) {
65
-		$this->memcacheFactory = \OC::$server->getMemCacheFactory();
66
-		$this->httpClient = $options['HttpClientService'];
67
-
68
-		$this->manager = $options['manager'];
69
-		$this->cloudId = $options['cloudId'];
70
-		$discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
71
-
72
-		list($protocol, $remote) = explode('://', $this->cloudId->getRemote());
73
-		if (strpos($remote, '/')) {
74
-			list($host, $root) = explode('/', $remote, 2);
75
-		} else {
76
-			$host = $remote;
77
-			$root = '';
78
-		}
79
-		$secure = $protocol === 'https';
80
-		$federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81
-		$webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
-		$root = rtrim($root, '/') . $webDavEndpoint;
83
-		$this->mountPoint = $options['mountpoint'];
84
-		$this->token = $options['token'];
85
-
86
-		parent::__construct(array(
87
-			'secure' => $secure,
88
-			'host' => $host,
89
-			'root' => $root,
90
-			'user' => $options['token'],
91
-			'password' => (string)$options['password']
92
-		));
93
-	}
94
-
95
-	public function getWatcher($path = '', $storage = null) {
96
-		if (!$storage) {
97
-			$storage = $this;
98
-		}
99
-		if (!isset($this->watcher)) {
100
-			$this->watcher = new Watcher($storage);
101
-			$this->watcher->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
102
-		}
103
-		return $this->watcher;
104
-	}
105
-
106
-	public function getRemoteUser() {
107
-		return $this->cloudId->getUser();
108
-	}
109
-
110
-	public function getRemote() {
111
-		return $this->cloudId->getRemote();
112
-	}
113
-
114
-	public function getMountPoint() {
115
-		return $this->mountPoint;
116
-	}
117
-
118
-	public function getToken() {
119
-		return $this->token;
120
-	}
121
-
122
-	public function getPassword() {
123
-		return $this->password;
124
-	}
125
-
126
-	/**
127
-	 * @brief get id of the mount point
128
-	 * @return string
129
-	 */
130
-	public function getId() {
131
-		return 'shared::' . md5($this->token . '@' . $this->getRemote());
132
-	}
133
-
134
-	public function getCache($path = '', $storage = null) {
135
-		if (is_null($this->cache)) {
136
-			$this->cache = new Cache($this, $this->cloudId);
137
-		}
138
-		return $this->cache;
139
-	}
140
-
141
-	/**
142
-	 * @param string $path
143
-	 * @param \OC\Files\Storage\Storage $storage
144
-	 * @return \OCA\Files_Sharing\External\Scanner
145
-	 */
146
-	public function getScanner($path = '', $storage = null) {
147
-		if (!$storage) {
148
-			$storage = $this;
149
-		}
150
-		if (!isset($this->scanner)) {
151
-			$this->scanner = new Scanner($storage);
152
-		}
153
-		return $this->scanner;
154
-	}
155
-
156
-	/**
157
-	 * check if a file or folder has been updated since $time
158
-	 *
159
-	 * @param string $path
160
-	 * @param int $time
161
-	 * @throws \OCP\Files\StorageNotAvailableException
162
-	 * @throws \OCP\Files\StorageInvalidException
163
-	 * @return bool
164
-	 */
165
-	public function hasUpdated($path, $time) {
166
-		// since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage
167
-		// because of that we only do one check for the entire storage per request
168
-		if ($this->updateChecked) {
169
-			return false;
170
-		}
171
-		$this->updateChecked = true;
172
-		try {
173
-			return parent::hasUpdated('', $time);
174
-		} catch (StorageInvalidException $e) {
175
-			// check if it needs to be removed
176
-			$this->checkStorageAvailability();
177
-			throw $e;
178
-		} catch (StorageNotAvailableException $e) {
179
-			// check if it needs to be removed or just temp unavailable
180
-			$this->checkStorageAvailability();
181
-			throw $e;
182
-		}
183
-	}
184
-
185
-	public function test() {
186
-		try {
187
-			return parent::test();
188
-		} catch (StorageInvalidException $e) {
189
-			// check if it needs to be removed
190
-			$this->checkStorageAvailability();
191
-			throw $e;
192
-		} catch (StorageNotAvailableException $e) {
193
-			// check if it needs to be removed or just temp unavailable
194
-			$this->checkStorageAvailability();
195
-			throw $e;
196
-		}
197
-	}
198
-
199
-	/**
200
-	 * Check whether this storage is permanently or temporarily
201
-	 * unavailable
202
-	 *
203
-	 * @throws \OCP\Files\StorageNotAvailableException
204
-	 * @throws \OCP\Files\StorageInvalidException
205
-	 */
206
-	public function checkStorageAvailability() {
207
-		// see if we can find out why the share is unavailable
208
-		try {
209
-			$this->getShareInfo();
210
-		} catch (NotFoundException $e) {
211
-			// a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
212
-			if ($this->testRemote()) {
213
-				// valid Nextcloud instance means that the public share no longer exists
214
-				// since this is permanent (re-sharing the file will create a new token)
215
-				// we remove the invalid storage
216
-				$this->manager->removeShare($this->mountPoint);
217
-				$this->manager->getMountManager()->removeMount($this->mountPoint);
218
-				throw new StorageInvalidException();
219
-			} else {
220
-				// Nextcloud instance is gone, likely to be a temporary server configuration error
221
-				throw new StorageNotAvailableException();
222
-			}
223
-		} catch (ForbiddenException $e) {
224
-			// auth error, remove share for now (provide a dialog in the future)
225
-			$this->manager->removeShare($this->mountPoint);
226
-			$this->manager->getMountManager()->removeMount($this->mountPoint);
227
-			throw new StorageInvalidException();
228
-		} catch (\GuzzleHttp\Exception\ConnectException $e) {
229
-			throw new StorageNotAvailableException();
230
-		} catch (\GuzzleHttp\Exception\RequestException $e) {
231
-			throw new StorageNotAvailableException();
232
-		} catch (\Exception $e) {
233
-			throw $e;
234
-		}
235
-	}
236
-
237
-	public function file_exists($path) {
238
-		if ($path === '') {
239
-			return true;
240
-		} else {
241
-			return parent::file_exists($path);
242
-		}
243
-	}
244
-
245
-	/**
246
-	 * check if the configured remote is a valid federated share provider
247
-	 *
248
-	 * @return bool
249
-	 */
250
-	protected function testRemote() {
251
-		try {
252
-			return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
-				|| $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
-				|| $this->testRemoteUrl($this->getRemote() . '/status.php');
255
-		} catch (\Exception $e) {
256
-			return false;
257
-		}
258
-	}
259
-
260
-	/**
261
-	 * @param string $url
262
-	 * @return bool
263
-	 */
264
-	private function testRemoteUrl($url) {
265
-		$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
-		if($cache->hasKey($url)) {
267
-			return (bool)$cache->get($url);
268
-		}
269
-
270
-		$client = $this->httpClient->newClient();
271
-		try {
272
-			$result = $client->get($url, [
273
-				'timeout' => 10,
274
-				'connect_timeout' => 10,
275
-			])->getBody();
276
-			$data = json_decode($result);
277
-			$returnValue = (is_object($data) && !empty($data->version));
278
-		} catch (ConnectException $e) {
279
-			$returnValue = false;
280
-		} catch (ClientException $e) {
281
-			$returnValue = false;
282
-		}
283
-
284
-		$cache->set($url, $returnValue, 60*60*24);
285
-		return $returnValue;
286
-	}
287
-
288
-	/**
289
-	 * Whether the remote is an ownCloud/Nextcloud, used since some sharing features are not
290
-	 * standardized. Let's use this to detect whether to use it.
291
-	 *
292
-	 * @return bool
293
-	 */
294
-	public function remoteIsOwnCloud() {
295
-		if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
296
-			return false;
297
-		}
298
-		return true;
299
-	}
300
-
301
-	/**
302
-	 * @return mixed
303
-	 * @throws ForbiddenException
304
-	 * @throws NotFoundException
305
-	 * @throws \Exception
306
-	 */
307
-	public function getShareInfo() {
308
-		$remote = $this->getRemote();
309
-		$token = $this->getToken();
310
-		$password = $this->getPassword();
311
-
312
-		// If remote is not an ownCloud do not try to get any share info
313
-		if(!$this->remoteIsOwnCloud()) {
314
-			return ['status' => 'unsupported'];
315
-		}
316
-
317
-		$url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
318
-
319
-		// TODO: DI
320
-		$client = \OC::$server->getHTTPClientService()->newClient();
321
-		try {
322
-			$response = $client->post($url, [
323
-				'body' => ['password' => $password],
324
-				'timeout' => 10,
325
-				'connect_timeout' => 10,
326
-			]);
327
-		} catch (\GuzzleHttp\Exception\RequestException $e) {
328
-			if ($e->getCode() === Http::STATUS_UNAUTHORIZED || $e->getCode() === Http::STATUS_FORBIDDEN) {
329
-				throw new ForbiddenException();
330
-			}
331
-			if ($e->getCode() === Http::STATUS_NOT_FOUND) {
332
-				throw new NotFoundException();
333
-			}
334
-			// throw this to be on the safe side: the share will still be visible
335
-			// in the UI in case the failure is intermittent, and the user will
336
-			// be able to decide whether to remove it if it's really gone
337
-			throw new StorageNotAvailableException();
338
-		}
339
-
340
-		return json_decode($response->getBody(), true);
341
-	}
342
-
343
-	public function getOwner($path) {
344
-		return $this->cloudId->getDisplayId();
345
-	}
346
-
347
-	public function isSharable($path) {
348
-		if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
349
-			return false;
350
-		}
351
-		return ($this->getPermissions($path) & Constants::PERMISSION_SHARE);
352
-	}
353
-
354
-	public function getPermissions($path) {
355
-		$response = $this->propfind($path);
356
-		// old federated sharing permissions
357
-		if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) {
358
-			$permissions = $response['{http://open-collaboration-services.org/ns}share-permissions'];
359
-		} else if (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) {
360
-			// permissions provided by the OCM API
361
-			$permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions']);
362
-		} else {
363
-			// use default permission if remote server doesn't provide the share permissions
364
-			$permissions = $this->getDefaultPermissions($path);
365
-		}
366
-
367
-		return $permissions;
368
-	}
369
-
370
-	public function needsPartFile() {
371
-		return false;
372
-	}
373
-
374
-	/**
375
-	 * translate OCM Permissions to Nextcloud permissions
376
-	 *
377
-	 * @param string $ocmPermissions json encoded OCM permissions
378
-	 * @param string $path path to file
379
-	 * @return int
380
-	 */
381
-	protected function ocmPermissions2ncPermissions($ocmPermissions, $path) {
382
-		try {
383
-			$ocmPermissions = json_decode($ocmPermissions);
384
-			$ncPermissions = 0;
385
-			foreach($ocmPermissions as $permission) {
386
-				switch (strtolower($permission)) {
387
-					case 'read':
388
-						$ncPermissions += Constants::PERMISSION_READ;
389
-						break;
390
-					case 'write':
391
-						$ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
392
-						break;
393
-					case 'share':
394
-						$ncPermissions += Constants::PERMISSION_SHARE;
395
-						break;
396
-					default:
397
-						throw new \Exception();
398
-				}
399
-			}
400
-		} catch (\Exception $e) {
401
-			$ncPermissions = $this->getDefaultPermissions($path);
402
-		}
403
-
404
-		return $ncPermissions;
405
-	}
406
-
407
-	/**
408
-	 * calculate default permissions in case no permissions are provided
409
-	 *
410
-	 * @param $path
411
-	 * @return int
412
-	 */
413
-	protected function getDefaultPermissions($path) {
414
-		if ($this->is_dir($path)) {
415
-			$permissions = Constants::PERMISSION_ALL;
416
-		} else {
417
-			$permissions = Constants::PERMISSION_ALL & ~Constants::PERMISSION_CREATE;
418
-		}
419
-
420
-		return $permissions;
421
-	}
46
+    /** @var ICloudId */
47
+    private $cloudId;
48
+    /** @var string */
49
+    private $mountPoint;
50
+    /** @var string */
51
+    private $token;
52
+    /** @var \OCP\ICacheFactory */
53
+    private $memcacheFactory;
54
+    /** @var \OCP\Http\Client\IClientService */
55
+    private $httpClient;
56
+    /** @var bool */
57
+    private $updateChecked = false;
58
+
59
+    /**
60
+     * @var \OCA\Files_Sharing\External\Manager
61
+     */
62
+    private $manager;
63
+
64
+    public function __construct($options) {
65
+        $this->memcacheFactory = \OC::$server->getMemCacheFactory();
66
+        $this->httpClient = $options['HttpClientService'];
67
+
68
+        $this->manager = $options['manager'];
69
+        $this->cloudId = $options['cloudId'];
70
+        $discoveryService = \OC::$server->query(\OCP\OCS\IDiscoveryService::class);
71
+
72
+        list($protocol, $remote) = explode('://', $this->cloudId->getRemote());
73
+        if (strpos($remote, '/')) {
74
+            list($host, $root) = explode('/', $remote, 2);
75
+        } else {
76
+            $host = $remote;
77
+            $root = '';
78
+        }
79
+        $secure = $protocol === 'https';
80
+        $federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81
+        $webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
+        $root = rtrim($root, '/') . $webDavEndpoint;
83
+        $this->mountPoint = $options['mountpoint'];
84
+        $this->token = $options['token'];
85
+
86
+        parent::__construct(array(
87
+            'secure' => $secure,
88
+            'host' => $host,
89
+            'root' => $root,
90
+            'user' => $options['token'],
91
+            'password' => (string)$options['password']
92
+        ));
93
+    }
94
+
95
+    public function getWatcher($path = '', $storage = null) {
96
+        if (!$storage) {
97
+            $storage = $this;
98
+        }
99
+        if (!isset($this->watcher)) {
100
+            $this->watcher = new Watcher($storage);
101
+            $this->watcher->setPolicy(\OC\Files\Cache\Watcher::CHECK_ONCE);
102
+        }
103
+        return $this->watcher;
104
+    }
105
+
106
+    public function getRemoteUser() {
107
+        return $this->cloudId->getUser();
108
+    }
109
+
110
+    public function getRemote() {
111
+        return $this->cloudId->getRemote();
112
+    }
113
+
114
+    public function getMountPoint() {
115
+        return $this->mountPoint;
116
+    }
117
+
118
+    public function getToken() {
119
+        return $this->token;
120
+    }
121
+
122
+    public function getPassword() {
123
+        return $this->password;
124
+    }
125
+
126
+    /**
127
+     * @brief get id of the mount point
128
+     * @return string
129
+     */
130
+    public function getId() {
131
+        return 'shared::' . md5($this->token . '@' . $this->getRemote());
132
+    }
133
+
134
+    public function getCache($path = '', $storage = null) {
135
+        if (is_null($this->cache)) {
136
+            $this->cache = new Cache($this, $this->cloudId);
137
+        }
138
+        return $this->cache;
139
+    }
140
+
141
+    /**
142
+     * @param string $path
143
+     * @param \OC\Files\Storage\Storage $storage
144
+     * @return \OCA\Files_Sharing\External\Scanner
145
+     */
146
+    public function getScanner($path = '', $storage = null) {
147
+        if (!$storage) {
148
+            $storage = $this;
149
+        }
150
+        if (!isset($this->scanner)) {
151
+            $this->scanner = new Scanner($storage);
152
+        }
153
+        return $this->scanner;
154
+    }
155
+
156
+    /**
157
+     * check if a file or folder has been updated since $time
158
+     *
159
+     * @param string $path
160
+     * @param int $time
161
+     * @throws \OCP\Files\StorageNotAvailableException
162
+     * @throws \OCP\Files\StorageInvalidException
163
+     * @return bool
164
+     */
165
+    public function hasUpdated($path, $time) {
166
+        // since for owncloud webdav servers we can rely on etag propagation we only need to check the root of the storage
167
+        // because of that we only do one check for the entire storage per request
168
+        if ($this->updateChecked) {
169
+            return false;
170
+        }
171
+        $this->updateChecked = true;
172
+        try {
173
+            return parent::hasUpdated('', $time);
174
+        } catch (StorageInvalidException $e) {
175
+            // check if it needs to be removed
176
+            $this->checkStorageAvailability();
177
+            throw $e;
178
+        } catch (StorageNotAvailableException $e) {
179
+            // check if it needs to be removed or just temp unavailable
180
+            $this->checkStorageAvailability();
181
+            throw $e;
182
+        }
183
+    }
184
+
185
+    public function test() {
186
+        try {
187
+            return parent::test();
188
+        } catch (StorageInvalidException $e) {
189
+            // check if it needs to be removed
190
+            $this->checkStorageAvailability();
191
+            throw $e;
192
+        } catch (StorageNotAvailableException $e) {
193
+            // check if it needs to be removed or just temp unavailable
194
+            $this->checkStorageAvailability();
195
+            throw $e;
196
+        }
197
+    }
198
+
199
+    /**
200
+     * Check whether this storage is permanently or temporarily
201
+     * unavailable
202
+     *
203
+     * @throws \OCP\Files\StorageNotAvailableException
204
+     * @throws \OCP\Files\StorageInvalidException
205
+     */
206
+    public function checkStorageAvailability() {
207
+        // see if we can find out why the share is unavailable
208
+        try {
209
+            $this->getShareInfo();
210
+        } catch (NotFoundException $e) {
211
+            // a 404 can either mean that the share no longer exists or there is no Nextcloud on the remote
212
+            if ($this->testRemote()) {
213
+                // valid Nextcloud instance means that the public share no longer exists
214
+                // since this is permanent (re-sharing the file will create a new token)
215
+                // we remove the invalid storage
216
+                $this->manager->removeShare($this->mountPoint);
217
+                $this->manager->getMountManager()->removeMount($this->mountPoint);
218
+                throw new StorageInvalidException();
219
+            } else {
220
+                // Nextcloud instance is gone, likely to be a temporary server configuration error
221
+                throw new StorageNotAvailableException();
222
+            }
223
+        } catch (ForbiddenException $e) {
224
+            // auth error, remove share for now (provide a dialog in the future)
225
+            $this->manager->removeShare($this->mountPoint);
226
+            $this->manager->getMountManager()->removeMount($this->mountPoint);
227
+            throw new StorageInvalidException();
228
+        } catch (\GuzzleHttp\Exception\ConnectException $e) {
229
+            throw new StorageNotAvailableException();
230
+        } catch (\GuzzleHttp\Exception\RequestException $e) {
231
+            throw new StorageNotAvailableException();
232
+        } catch (\Exception $e) {
233
+            throw $e;
234
+        }
235
+    }
236
+
237
+    public function file_exists($path) {
238
+        if ($path === '') {
239
+            return true;
240
+        } else {
241
+            return parent::file_exists($path);
242
+        }
243
+    }
244
+
245
+    /**
246
+     * check if the configured remote is a valid federated share provider
247
+     *
248
+     * @return bool
249
+     */
250
+    protected function testRemote() {
251
+        try {
252
+            return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
+                || $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
+                || $this->testRemoteUrl($this->getRemote() . '/status.php');
255
+        } catch (\Exception $e) {
256
+            return false;
257
+        }
258
+    }
259
+
260
+    /**
261
+     * @param string $url
262
+     * @return bool
263
+     */
264
+    private function testRemoteUrl($url) {
265
+        $cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
+        if($cache->hasKey($url)) {
267
+            return (bool)$cache->get($url);
268
+        }
269
+
270
+        $client = $this->httpClient->newClient();
271
+        try {
272
+            $result = $client->get($url, [
273
+                'timeout' => 10,
274
+                'connect_timeout' => 10,
275
+            ])->getBody();
276
+            $data = json_decode($result);
277
+            $returnValue = (is_object($data) && !empty($data->version));
278
+        } catch (ConnectException $e) {
279
+            $returnValue = false;
280
+        } catch (ClientException $e) {
281
+            $returnValue = false;
282
+        }
283
+
284
+        $cache->set($url, $returnValue, 60*60*24);
285
+        return $returnValue;
286
+    }
287
+
288
+    /**
289
+     * Whether the remote is an ownCloud/Nextcloud, used since some sharing features are not
290
+     * standardized. Let's use this to detect whether to use it.
291
+     *
292
+     * @return bool
293
+     */
294
+    public function remoteIsOwnCloud() {
295
+        if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
296
+            return false;
297
+        }
298
+        return true;
299
+    }
300
+
301
+    /**
302
+     * @return mixed
303
+     * @throws ForbiddenException
304
+     * @throws NotFoundException
305
+     * @throws \Exception
306
+     */
307
+    public function getShareInfo() {
308
+        $remote = $this->getRemote();
309
+        $token = $this->getToken();
310
+        $password = $this->getPassword();
311
+
312
+        // If remote is not an ownCloud do not try to get any share info
313
+        if(!$this->remoteIsOwnCloud()) {
314
+            return ['status' => 'unsupported'];
315
+        }
316
+
317
+        $url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
318
+
319
+        // TODO: DI
320
+        $client = \OC::$server->getHTTPClientService()->newClient();
321
+        try {
322
+            $response = $client->post($url, [
323
+                'body' => ['password' => $password],
324
+                'timeout' => 10,
325
+                'connect_timeout' => 10,
326
+            ]);
327
+        } catch (\GuzzleHttp\Exception\RequestException $e) {
328
+            if ($e->getCode() === Http::STATUS_UNAUTHORIZED || $e->getCode() === Http::STATUS_FORBIDDEN) {
329
+                throw new ForbiddenException();
330
+            }
331
+            if ($e->getCode() === Http::STATUS_NOT_FOUND) {
332
+                throw new NotFoundException();
333
+            }
334
+            // throw this to be on the safe side: the share will still be visible
335
+            // in the UI in case the failure is intermittent, and the user will
336
+            // be able to decide whether to remove it if it's really gone
337
+            throw new StorageNotAvailableException();
338
+        }
339
+
340
+        return json_decode($response->getBody(), true);
341
+    }
342
+
343
+    public function getOwner($path) {
344
+        return $this->cloudId->getDisplayId();
345
+    }
346
+
347
+    public function isSharable($path) {
348
+        if (\OCP\Util::isSharingDisabledForUser() || !\OC\Share\Share::isResharingAllowed()) {
349
+            return false;
350
+        }
351
+        return ($this->getPermissions($path) & Constants::PERMISSION_SHARE);
352
+    }
353
+
354
+    public function getPermissions($path) {
355
+        $response = $this->propfind($path);
356
+        // old federated sharing permissions
357
+        if (isset($response['{http://open-collaboration-services.org/ns}share-permissions'])) {
358
+            $permissions = $response['{http://open-collaboration-services.org/ns}share-permissions'];
359
+        } else if (isset($response['{http://open-cloud-mesh.org/ns}share-permissions'])) {
360
+            // permissions provided by the OCM API
361
+            $permissions = $this->ocmPermissions2ncPermissions($response['{http://open-collaboration-services.org/ns}share-permissions']);
362
+        } else {
363
+            // use default permission if remote server doesn't provide the share permissions
364
+            $permissions = $this->getDefaultPermissions($path);
365
+        }
366
+
367
+        return $permissions;
368
+    }
369
+
370
+    public function needsPartFile() {
371
+        return false;
372
+    }
373
+
374
+    /**
375
+     * translate OCM Permissions to Nextcloud permissions
376
+     *
377
+     * @param string $ocmPermissions json encoded OCM permissions
378
+     * @param string $path path to file
379
+     * @return int
380
+     */
381
+    protected function ocmPermissions2ncPermissions($ocmPermissions, $path) {
382
+        try {
383
+            $ocmPermissions = json_decode($ocmPermissions);
384
+            $ncPermissions = 0;
385
+            foreach($ocmPermissions as $permission) {
386
+                switch (strtolower($permission)) {
387
+                    case 'read':
388
+                        $ncPermissions += Constants::PERMISSION_READ;
389
+                        break;
390
+                    case 'write':
391
+                        $ncPermissions += Constants::PERMISSION_CREATE + Constants::PERMISSION_UPDATE;
392
+                        break;
393
+                    case 'share':
394
+                        $ncPermissions += Constants::PERMISSION_SHARE;
395
+                        break;
396
+                    default:
397
+                        throw new \Exception();
398
+                }
399
+            }
400
+        } catch (\Exception $e) {
401
+            $ncPermissions = $this->getDefaultPermissions($path);
402
+        }
403
+
404
+        return $ncPermissions;
405
+    }
406
+
407
+    /**
408
+     * calculate default permissions in case no permissions are provided
409
+     *
410
+     * @param $path
411
+     * @return int
412
+     */
413
+    protected function getDefaultPermissions($path) {
414
+        if ($this->is_dir($path)) {
415
+            $permissions = Constants::PERMISSION_ALL;
416
+        } else {
417
+            $permissions = Constants::PERMISSION_ALL & ~Constants::PERMISSION_CREATE;
418
+        }
419
+
420
+        return $permissions;
421
+    }
422 422
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		$secure = $protocol === 'https';
80 80
 		$federatedSharingEndpoints = $discoveryService->discover($this->cloudId->getRemote(), 'FEDERATED_SHARING');
81 81
 		$webDavEndpoint = isset($federatedSharingEndpoints['webdav']) ? $federatedSharingEndpoints['webdav'] : '/public.php/webdav';
82
-		$root = rtrim($root, '/') . $webDavEndpoint;
82
+		$root = rtrim($root, '/').$webDavEndpoint;
83 83
 		$this->mountPoint = $options['mountpoint'];
84 84
 		$this->token = $options['token'];
85 85
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 			'host' => $host,
89 89
 			'root' => $root,
90 90
 			'user' => $options['token'],
91
-			'password' => (string)$options['password']
91
+			'password' => (string) $options['password']
92 92
 		));
93 93
 	}
94 94
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return string
129 129
 	 */
130 130
 	public function getId() {
131
-		return 'shared::' . md5($this->token . '@' . $this->getRemote());
131
+		return 'shared::'.md5($this->token.'@'.$this->getRemote());
132 132
 	}
133 133
 
134 134
 	public function getCache($path = '', $storage = null) {
@@ -249,9 +249,9 @@  discard block
 block discarded – undo
249 249
 	 */
250 250
 	protected function testRemote() {
251 251
 		try {
252
-			return $this->testRemoteUrl($this->getRemote() . '/ocs-provider/index.php')
253
-				|| $this->testRemoteUrl($this->getRemote() . '/ocs-provider/')
254
-				|| $this->testRemoteUrl($this->getRemote() . '/status.php');
252
+			return $this->testRemoteUrl($this->getRemote().'/ocs-provider/index.php')
253
+				|| $this->testRemoteUrl($this->getRemote().'/ocs-provider/')
254
+				|| $this->testRemoteUrl($this->getRemote().'/status.php');
255 255
 		} catch (\Exception $e) {
256 256
 			return false;
257 257
 		}
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 */
264 264
 	private function testRemoteUrl($url) {
265 265
 		$cache = $this->memcacheFactory->createDistributed('files_sharing_remote_url');
266
-		if($cache->hasKey($url)) {
267
-			return (bool)$cache->get($url);
266
+		if ($cache->hasKey($url)) {
267
+			return (bool) $cache->get($url);
268 268
 		}
269 269
 
270 270
 		$client = $this->httpClient->newClient();
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 			$returnValue = false;
282 282
 		}
283 283
 
284
-		$cache->set($url, $returnValue, 60*60*24);
284
+		$cache->set($url, $returnValue, 60 * 60 * 24);
285 285
 		return $returnValue;
286 286
 	}
287 287
 
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return bool
293 293
 	 */
294 294
 	public function remoteIsOwnCloud() {
295
-		if(defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote() . '/status.php')) {
295
+		if (defined('PHPUNIT_RUN') || !$this->testRemoteUrl($this->getRemote().'/status.php')) {
296 296
 			return false;
297 297
 		}
298 298
 		return true;
@@ -310,11 +310,11 @@  discard block
 block discarded – undo
310 310
 		$password = $this->getPassword();
311 311
 
312 312
 		// If remote is not an ownCloud do not try to get any share info
313
-		if(!$this->remoteIsOwnCloud()) {
313
+		if (!$this->remoteIsOwnCloud()) {
314 314
 			return ['status' => 'unsupported'];
315 315
 		}
316 316
 
317
-		$url = rtrim($remote, '/') . '/index.php/apps/files_sharing/shareinfo?t=' . $token;
317
+		$url = rtrim($remote, '/').'/index.php/apps/files_sharing/shareinfo?t='.$token;
318 318
 
319 319
 		// TODO: DI
320 320
 		$client = \OC::$server->getHTTPClientService()->newClient();
@@ -382,7 +382,7 @@  discard block
 block discarded – undo
382 382
 		try {
383 383
 			$ocmPermissions = json_decode($ocmPermissions);
384 384
 			$ncPermissions = 0;
385
-			foreach($ocmPermissions as $permission) {
385
+			foreach ($ocmPermissions as $permission) {
386 386
 				switch (strtolower($permission)) {
387 387
 					case 'read':
388 388
 						$ncPermissions += Constants::PERMISSION_READ;
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/FilesPlugin.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 	/**
451 451
 	 * translate Nextcloud permissions to OCM Permissions
452 452
 	 *
453
-	 * @param $ncPermissions
453
+	 * @param integer $ncPermissions
454 454
 	 * @return array
455 455
 	 */
456 456
 	protected function ncPermissions2ocmPermissions($ncPermissions) {
Please login to merge, or discard this patch.
Indentation   +436 added lines, -436 removed lines patch added patch discarded remove patch
@@ -50,444 +50,444 @@
 block discarded – undo
50 50
 
51 51
 class FilesPlugin extends ServerPlugin {
52 52
 
53
-	// namespace
54
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
55
-	const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
56
-	const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
57
-	const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
58
-	const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
59
-	const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
60
-	const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
61
-	const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
62
-	const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
63
-	const GETETAG_PROPERTYNAME = '{DAV:}getetag';
64
-	const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
65
-	const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
66
-	const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
67
-	const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
68
-	const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
69
-	const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
70
-	const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
71
-	const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
72
-
73
-	/**
74
-	 * Reference to main server object
75
-	 *
76
-	 * @var \Sabre\DAV\Server
77
-	 */
78
-	private $server;
79
-
80
-	/**
81
-	 * @var Tree
82
-	 */
83
-	private $tree;
84
-
85
-	/**
86
-	 * Whether this is public webdav.
87
-	 * If true, some returned information will be stripped off.
88
-	 *
89
-	 * @var bool
90
-	 */
91
-	private $isPublic;
92
-
93
-	/**
94
-	 * @var bool
95
-	 */
96
-	private $downloadAttachment;
97
-
98
-	/**
99
-	 * @var IConfig
100
-	 */
101
-	private $config;
102
-
103
-	/**
104
-	 * @var IRequest
105
-	 */
106
-	private $request;
107
-
108
-	/**
109
-	 * @var IPreview
110
-	 */
111
-	private $previewManager;
112
-
113
-	/**
114
-	 * @param Tree $tree
115
-	 * @param IConfig $config
116
-	 * @param IRequest $request
117
-	 * @param IPreview $previewManager
118
-	 * @param bool $isPublic
119
-	 * @param bool $downloadAttachment
120
-	 */
121
-	public function __construct(Tree $tree,
122
-								IConfig $config,
123
-								IRequest $request,
124
-								IPreview $previewManager,
125
-								$isPublic = false,
126
-								$downloadAttachment = true) {
127
-		$this->tree = $tree;
128
-		$this->config = $config;
129
-		$this->request = $request;
130
-		$this->isPublic = $isPublic;
131
-		$this->downloadAttachment = $downloadAttachment;
132
-		$this->previewManager = $previewManager;
133
-	}
134
-
135
-	/**
136
-	 * This initializes the plugin.
137
-	 *
138
-	 * This function is called by \Sabre\DAV\Server, after
139
-	 * addPlugin is called.
140
-	 *
141
-	 * This method should set up the required event subscriptions.
142
-	 *
143
-	 * @param \Sabre\DAV\Server $server
144
-	 * @return void
145
-	 */
146
-	public function initialize(\Sabre\DAV\Server $server) {
147
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
148
-		$server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
149
-		$server->protectedProperties[] = self::FILEID_PROPERTYNAME;
150
-		$server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
151
-		$server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
152
-		$server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
153
-		$server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
154
-		$server->protectedProperties[] = self::SIZE_PROPERTYNAME;
155
-		$server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
156
-		$server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
157
-		$server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
158
-		$server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
159
-		$server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
160
-		$server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
161
-		$server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
162
-		$server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
163
-
164
-		// normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
165
-		$allowedProperties = ['{DAV:}getetag'];
166
-		$server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
167
-
168
-		$this->server = $server;
169
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
170
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
171
-		$this->server->on('afterBind', array($this, 'sendFileIdHeader'));
172
-		$this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
173
-		$this->server->on('afterMethod:GET', [$this,'httpGet']);
174
-		$this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
175
-		$this->server->on('afterResponse', function($request, ResponseInterface $response) {
176
-			$body = $response->getBody();
177
-			if (is_resource($body)) {
178
-				fclose($body);
179
-			}
180
-		});
181
-		$this->server->on('beforeMove', [$this, 'checkMove']);
182
-	}
183
-
184
-	/**
185
-	 * Plugin that checks if a move can actually be performed.
186
-	 *
187
-	 * @param string $source source path
188
-	 * @param string $destination destination path
189
-	 * @throws Forbidden
190
-	 * @throws NotFound
191
-	 */
192
-	function checkMove($source, $destination) {
193
-		$sourceNode = $this->tree->getNodeForPath($source);
194
-		if (!$sourceNode instanceof Node) {
195
-			return;
196
-		}
197
-		list($sourceDir,) = \Sabre\Uri\split($source);
198
-		list($destinationDir,) = \Sabre\Uri\split($destination);
199
-
200
-		if ($sourceDir !== $destinationDir) {
201
-			$sourceNodeFileInfo = $sourceNode->getFileInfo();
202
-			if ($sourceNodeFileInfo === null) {
203
-				throw new NotFound($source . ' does not exist');
204
- 			}
205
-
206
-			if (!$sourceNodeFileInfo->isDeletable()) {
207
-				throw new Forbidden($source . " cannot be deleted");
208
-			}
209
-		}
210
-	}
211
-
212
-	/**
213
-	 * This sets a cookie to be able to recognize the start of the download
214
-	 * the content must not be longer than 32 characters and must only contain
215
-	 * alphanumeric characters
216
-	 *
217
-	 * @param RequestInterface $request
218
-	 * @param ResponseInterface $response
219
-	 */
220
-	function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
221
-		$queryParams = $request->getQueryParameters();
222
-
223
-		/**
224
-		 * this sets a cookie to be able to recognize the start of the download
225
-		 * the content must not be longer than 32 characters and must only contain
226
-		 * alphanumeric characters
227
-		 */
228
-		if (isset($queryParams['downloadStartSecret'])) {
229
-			$token = $queryParams['downloadStartSecret'];
230
-			if (!isset($token[32])
231
-				&& preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
232
-				// FIXME: use $response->setHeader() instead
233
-				setcookie('ocDownloadStarted', $token, time() + 20, '/');
234
-			}
235
-		}
236
-	}
237
-
238
-	/**
239
-	 * Add headers to file download
240
-	 *
241
-	 * @param RequestInterface $request
242
-	 * @param ResponseInterface $response
243
-	 */
244
-	function httpGet(RequestInterface $request, ResponseInterface $response) {
245
-		// Only handle valid files
246
-		$node = $this->tree->getNodeForPath($request->getPath());
247
-		if (!($node instanceof IFile)) return;
248
-
249
-		// adds a 'Content-Disposition: attachment' header in case no disposition
250
-		// header has been set before
251
-		if ($this->downloadAttachment &&
252
-			$response->getHeader('Content-Disposition') === null) {
253
-			$filename = $node->getName();
254
-			if ($this->request->isUserAgent(
255
-				[
256
-					Request::USER_AGENT_IE,
257
-					Request::USER_AGENT_ANDROID_MOBILE_CHROME,
258
-					Request::USER_AGENT_FREEBOX,
259
-				])) {
260
-				$response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
261
-			} else {
262
-				$response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
263
-													 . '; filename="' . rawurlencode($filename) . '"');
264
-			}
265
-		}
266
-
267
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
268
-			//Add OC-Checksum header
269
-			/** @var $node File */
270
-			$checksum = $node->getChecksum();
271
-			if ($checksum !== null && $checksum !== '') {
272
-				$response->addHeader('OC-Checksum', $checksum);
273
-			}
274
-		}
275
-	}
276
-
277
-	/**
278
-	 * Adds all ownCloud-specific properties
279
-	 *
280
-	 * @param PropFind $propFind
281
-	 * @param \Sabre\DAV\INode $node
282
-	 * @return void
283
-	 */
284
-	public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
285
-
286
-		$httpRequest = $this->server->httpRequest;
287
-
288
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
289
-			/**
290
-			 * This was disabled, because it made dir listing throw an exception,
291
-			 * so users were unable to navigate into folders where one subitem
292
-			 * is blocked by the files_accesscontrol app, see:
293
-			 * https://github.com/nextcloud/files_accesscontrol/issues/65
53
+    // namespace
54
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
55
+    const NS_NEXTCLOUD = 'http://nextcloud.org/ns';
56
+    const FILEID_PROPERTYNAME = '{http://owncloud.org/ns}id';
57
+    const INTERNAL_FILEID_PROPERTYNAME = '{http://owncloud.org/ns}fileid';
58
+    const PERMISSIONS_PROPERTYNAME = '{http://owncloud.org/ns}permissions';
59
+    const SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-collaboration-services.org/ns}share-permissions';
60
+    const OCM_SHARE_PERMISSIONS_PROPERTYNAME = '{http://open-cloud-mesh.org/ns}share-permissions';
61
+    const DOWNLOADURL_PROPERTYNAME = '{http://owncloud.org/ns}downloadURL';
62
+    const SIZE_PROPERTYNAME = '{http://owncloud.org/ns}size';
63
+    const GETETAG_PROPERTYNAME = '{DAV:}getetag';
64
+    const LASTMODIFIED_PROPERTYNAME = '{DAV:}lastmodified';
65
+    const OWNER_ID_PROPERTYNAME = '{http://owncloud.org/ns}owner-id';
66
+    const OWNER_DISPLAY_NAME_PROPERTYNAME = '{http://owncloud.org/ns}owner-display-name';
67
+    const CHECKSUMS_PROPERTYNAME = '{http://owncloud.org/ns}checksums';
68
+    const DATA_FINGERPRINT_PROPERTYNAME = '{http://owncloud.org/ns}data-fingerprint';
69
+    const HAS_PREVIEW_PROPERTYNAME = '{http://nextcloud.org/ns}has-preview';
70
+    const MOUNT_TYPE_PROPERTYNAME = '{http://nextcloud.org/ns}mount-type';
71
+    const IS_ENCRYPTED_PROPERTYNAME = '{http://nextcloud.org/ns}is-encrypted';
72
+
73
+    /**
74
+     * Reference to main server object
75
+     *
76
+     * @var \Sabre\DAV\Server
77
+     */
78
+    private $server;
79
+
80
+    /**
81
+     * @var Tree
82
+     */
83
+    private $tree;
84
+
85
+    /**
86
+     * Whether this is public webdav.
87
+     * If true, some returned information will be stripped off.
88
+     *
89
+     * @var bool
90
+     */
91
+    private $isPublic;
92
+
93
+    /**
94
+     * @var bool
95
+     */
96
+    private $downloadAttachment;
97
+
98
+    /**
99
+     * @var IConfig
100
+     */
101
+    private $config;
102
+
103
+    /**
104
+     * @var IRequest
105
+     */
106
+    private $request;
107
+
108
+    /**
109
+     * @var IPreview
110
+     */
111
+    private $previewManager;
112
+
113
+    /**
114
+     * @param Tree $tree
115
+     * @param IConfig $config
116
+     * @param IRequest $request
117
+     * @param IPreview $previewManager
118
+     * @param bool $isPublic
119
+     * @param bool $downloadAttachment
120
+     */
121
+    public function __construct(Tree $tree,
122
+                                IConfig $config,
123
+                                IRequest $request,
124
+                                IPreview $previewManager,
125
+                                $isPublic = false,
126
+                                $downloadAttachment = true) {
127
+        $this->tree = $tree;
128
+        $this->config = $config;
129
+        $this->request = $request;
130
+        $this->isPublic = $isPublic;
131
+        $this->downloadAttachment = $downloadAttachment;
132
+        $this->previewManager = $previewManager;
133
+    }
134
+
135
+    /**
136
+     * This initializes the plugin.
137
+     *
138
+     * This function is called by \Sabre\DAV\Server, after
139
+     * addPlugin is called.
140
+     *
141
+     * This method should set up the required event subscriptions.
142
+     *
143
+     * @param \Sabre\DAV\Server $server
144
+     * @return void
145
+     */
146
+    public function initialize(\Sabre\DAV\Server $server) {
147
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
148
+        $server->xml->namespaceMap[self::NS_NEXTCLOUD] = 'nc';
149
+        $server->protectedProperties[] = self::FILEID_PROPERTYNAME;
150
+        $server->protectedProperties[] = self::INTERNAL_FILEID_PROPERTYNAME;
151
+        $server->protectedProperties[] = self::PERMISSIONS_PROPERTYNAME;
152
+        $server->protectedProperties[] = self::SHARE_PERMISSIONS_PROPERTYNAME;
153
+        $server->protectedProperties[] = self::OCM_SHARE_PERMISSIONS_PROPERTYNAME;
154
+        $server->protectedProperties[] = self::SIZE_PROPERTYNAME;
155
+        $server->protectedProperties[] = self::DOWNLOADURL_PROPERTYNAME;
156
+        $server->protectedProperties[] = self::OWNER_ID_PROPERTYNAME;
157
+        $server->protectedProperties[] = self::OWNER_DISPLAY_NAME_PROPERTYNAME;
158
+        $server->protectedProperties[] = self::CHECKSUMS_PROPERTYNAME;
159
+        $server->protectedProperties[] = self::DATA_FINGERPRINT_PROPERTYNAME;
160
+        $server->protectedProperties[] = self::HAS_PREVIEW_PROPERTYNAME;
161
+        $server->protectedProperties[] = self::MOUNT_TYPE_PROPERTYNAME;
162
+        $server->protectedProperties[] = self::IS_ENCRYPTED_PROPERTYNAME;
163
+
164
+        // normally these cannot be changed (RFC4918), but we want them modifiable through PROPPATCH
165
+        $allowedProperties = ['{DAV:}getetag'];
166
+        $server->protectedProperties = array_diff($server->protectedProperties, $allowedProperties);
167
+
168
+        $this->server = $server;
169
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
170
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
171
+        $this->server->on('afterBind', array($this, 'sendFileIdHeader'));
172
+        $this->server->on('afterWriteContent', array($this, 'sendFileIdHeader'));
173
+        $this->server->on('afterMethod:GET', [$this,'httpGet']);
174
+        $this->server->on('afterMethod:GET', array($this, 'handleDownloadToken'));
175
+        $this->server->on('afterResponse', function($request, ResponseInterface $response) {
176
+            $body = $response->getBody();
177
+            if (is_resource($body)) {
178
+                fclose($body);
179
+            }
180
+        });
181
+        $this->server->on('beforeMove', [$this, 'checkMove']);
182
+    }
183
+
184
+    /**
185
+     * Plugin that checks if a move can actually be performed.
186
+     *
187
+     * @param string $source source path
188
+     * @param string $destination destination path
189
+     * @throws Forbidden
190
+     * @throws NotFound
191
+     */
192
+    function checkMove($source, $destination) {
193
+        $sourceNode = $this->tree->getNodeForPath($source);
194
+        if (!$sourceNode instanceof Node) {
195
+            return;
196
+        }
197
+        list($sourceDir,) = \Sabre\Uri\split($source);
198
+        list($destinationDir,) = \Sabre\Uri\split($destination);
199
+
200
+        if ($sourceDir !== $destinationDir) {
201
+            $sourceNodeFileInfo = $sourceNode->getFileInfo();
202
+            if ($sourceNodeFileInfo === null) {
203
+                throw new NotFound($source . ' does not exist');
204
+                }
205
+
206
+            if (!$sourceNodeFileInfo->isDeletable()) {
207
+                throw new Forbidden($source . " cannot be deleted");
208
+            }
209
+        }
210
+    }
211
+
212
+    /**
213
+     * This sets a cookie to be able to recognize the start of the download
214
+     * the content must not be longer than 32 characters and must only contain
215
+     * alphanumeric characters
216
+     *
217
+     * @param RequestInterface $request
218
+     * @param ResponseInterface $response
219
+     */
220
+    function handleDownloadToken(RequestInterface $request, ResponseInterface $response) {
221
+        $queryParams = $request->getQueryParameters();
222
+
223
+        /**
224
+         * this sets a cookie to be able to recognize the start of the download
225
+         * the content must not be longer than 32 characters and must only contain
226
+         * alphanumeric characters
227
+         */
228
+        if (isset($queryParams['downloadStartSecret'])) {
229
+            $token = $queryParams['downloadStartSecret'];
230
+            if (!isset($token[32])
231
+                && preg_match('!^[a-zA-Z0-9]+$!', $token) === 1) {
232
+                // FIXME: use $response->setHeader() instead
233
+                setcookie('ocDownloadStarted', $token, time() + 20, '/');
234
+            }
235
+        }
236
+    }
237
+
238
+    /**
239
+     * Add headers to file download
240
+     *
241
+     * @param RequestInterface $request
242
+     * @param ResponseInterface $response
243
+     */
244
+    function httpGet(RequestInterface $request, ResponseInterface $response) {
245
+        // Only handle valid files
246
+        $node = $this->tree->getNodeForPath($request->getPath());
247
+        if (!($node instanceof IFile)) return;
248
+
249
+        // adds a 'Content-Disposition: attachment' header in case no disposition
250
+        // header has been set before
251
+        if ($this->downloadAttachment &&
252
+            $response->getHeader('Content-Disposition') === null) {
253
+            $filename = $node->getName();
254
+            if ($this->request->isUserAgent(
255
+                [
256
+                    Request::USER_AGENT_IE,
257
+                    Request::USER_AGENT_ANDROID_MOBILE_CHROME,
258
+                    Request::USER_AGENT_FREEBOX,
259
+                ])) {
260
+                $response->addHeader('Content-Disposition', 'attachment; filename="' . rawurlencode($filename) . '"');
261
+            } else {
262
+                $response->addHeader('Content-Disposition', 'attachment; filename*=UTF-8\'\'' . rawurlencode($filename)
263
+                                                        . '; filename="' . rawurlencode($filename) . '"');
264
+            }
265
+        }
266
+
267
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
268
+            //Add OC-Checksum header
269
+            /** @var $node File */
270
+            $checksum = $node->getChecksum();
271
+            if ($checksum !== null && $checksum !== '') {
272
+                $response->addHeader('OC-Checksum', $checksum);
273
+            }
274
+        }
275
+    }
276
+
277
+    /**
278
+     * Adds all ownCloud-specific properties
279
+     *
280
+     * @param PropFind $propFind
281
+     * @param \Sabre\DAV\INode $node
282
+     * @return void
283
+     */
284
+    public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node) {
285
+
286
+        $httpRequest = $this->server->httpRequest;
287
+
288
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
289
+            /**
290
+             * This was disabled, because it made dir listing throw an exception,
291
+             * so users were unable to navigate into folders where one subitem
292
+             * is blocked by the files_accesscontrol app, see:
293
+             * https://github.com/nextcloud/files_accesscontrol/issues/65
294 294
 			if (!$node->getFileInfo()->isReadable()) {
295 295
 				// avoid detecting files through this means
296 296
 				throw new NotFound();
297 297
 			}
298
-			 */
299
-
300
-			$propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
301
-				return $node->getFileId();
302
-			});
303
-
304
-			$propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
305
-				return $node->getInternalFileId();
306
-			});
307
-
308
-			$propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
309
-				$perms = $node->getDavPermissions();
310
-				if ($this->isPublic) {
311
-					// remove mount information
312
-					$perms = str_replace(['S', 'M'], '', $perms);
313
-				}
314
-				return $perms;
315
-			});
316
-
317
-			$propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
318
-				return $node->getSharePermissions(
319
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
320
-				);
321
-			});
322
-
323
-			$propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
-				$ncPermissions = $node->getSharePermissions(
325
-					$httpRequest->getRawServerValue('PHP_AUTH_USER')
326
-				);
327
-				$ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
328
-				return json_encode($ocmPermissions);
329
-			});
330
-
331
-			$propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
332
-				return $node->getETag();
333
-			});
334
-
335
-			$propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
336
-				$owner = $node->getOwner();
337
-				if (!$owner) {
338
-					return null;
339
-				} else {
340
-					return $owner->getUID();
341
-				}
342
-			});
343
-			$propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
344
-				$owner = $node->getOwner();
345
-				if (!$owner) {
346
-					return null;
347
-				} else {
348
-					return $owner->getDisplayName();
349
-				}
350
-			});
351
-
352
-			$propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
353
-				return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
354
-			});
355
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
356
-				return $node->getSize();
357
-			});
358
-			$propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
359
-				return $node->getFileInfo()->getMountPoint()->getMountType();
360
-			});
361
-		}
362
-
363
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
364
-			$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
365
-				return $this->config->getSystemValue('data-fingerprint', '');
366
-			});
367
-		}
368
-
369
-		if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
370
-			$propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
371
-				/** @var $node \OCA\DAV\Connector\Sabre\File */
372
-				try {
373
-					$directDownloadUrl = $node->getDirectDownload();
374
-					if (isset($directDownloadUrl['url'])) {
375
-						return $directDownloadUrl['url'];
376
-					}
377
-				} catch (StorageNotAvailableException $e) {
378
-					return false;
379
-				} catch (ForbiddenException $e) {
380
-					return false;
381
-				}
382
-				return false;
383
-			});
384
-
385
-			$propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
386
-				$checksum = $node->getChecksum();
387
-				if ($checksum === NULL || $checksum === '') {
388
-					return null;
389
-				}
390
-
391
-				return new ChecksumList($checksum);
392
-			});
393
-
394
-		}
395
-
396
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
397
-			$propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
398
-				return $node->getSize();
399
-			});
400
-
401
-			$propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
402
-				return $node->getFileInfo()->isEncrypted() ? '1' : '0';
403
-			});
404
-		}
405
-	}
406
-
407
-	/**
408
-	 * translate Nextcloud permissions to OCM Permissions
409
-	 *
410
-	 * @param $ncPermissions
411
-	 * @return array
412
-	 */
413
-	protected function ncPermissions2ocmPermissions($ncPermissions) {
414
-
415
-		$ocmPermissions = [];
416
-
417
-		if ($ncPermissions & Constants::PERMISSION_SHARE) {
418
-			$ocmPermissions[] = 'share';
419
-		}
420
-
421
-		if ($ncPermissions & Constants::PERMISSION_READ) {
422
-			$ocmPermissions[] = 'read';
423
-		}
424
-
425
-		if (($ncPermissions & Constants::PERMISSION_CREATE) ||
426
-			($ncPermissions & Constants::PERMISSION_UPDATE)) {
427
-			$ocmPermissions[] = 'write';
428
-		}
429
-
430
-		return $ocmPermissions;
431
-
432
-	}
433
-
434
-	/**
435
-	 * Update ownCloud-specific properties
436
-	 *
437
-	 * @param string $path
438
-	 * @param PropPatch $propPatch
439
-	 *
440
-	 * @return void
441
-	 */
442
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
443
-		$node = $this->tree->getNodeForPath($path);
444
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
445
-			return;
446
-		}
447
-
448
-		$propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
449
-			if (empty($time)) {
450
-				return false;
451
-			}
452
-			$node->touch($time);
453
-			return true;
454
-		});
455
-		$propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
456
-			if (empty($etag)) {
457
-				return false;
458
-			}
459
-			if ($node->setEtag($etag) !== -1) {
460
-				return true;
461
-			}
462
-			return false;
463
-		});
464
-	}
465
-
466
-	/**
467
-	 * @param string $filePath
468
-	 * @param \Sabre\DAV\INode $node
469
-	 * @throws \Sabre\DAV\Exception\BadRequest
470
-	 */
471
-	public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
472
-		// chunked upload handling
473
-		if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
474
-			list($path, $name) = \Sabre\Uri\split($filePath);
475
-			$info = \OC_FileChunking::decodeName($name);
476
-			if (!empty($info)) {
477
-				$filePath = $path . '/' . $info['name'];
478
-			}
479
-		}
480
-
481
-		// we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
482
-		if (!$this->server->tree->nodeExists($filePath)) {
483
-			return;
484
-		}
485
-		$node = $this->server->tree->getNodeForPath($filePath);
486
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
487
-			$fileId = $node->getFileId();
488
-			if (!is_null($fileId)) {
489
-				$this->server->httpResponse->setHeader('OC-FileId', $fileId);
490
-			}
491
-		}
492
-	}
298
+             */
299
+
300
+            $propFind->handle(self::FILEID_PROPERTYNAME, function() use ($node) {
301
+                return $node->getFileId();
302
+            });
303
+
304
+            $propFind->handle(self::INTERNAL_FILEID_PROPERTYNAME, function() use ($node) {
305
+                return $node->getInternalFileId();
306
+            });
307
+
308
+            $propFind->handle(self::PERMISSIONS_PROPERTYNAME, function() use ($node) {
309
+                $perms = $node->getDavPermissions();
310
+                if ($this->isPublic) {
311
+                    // remove mount information
312
+                    $perms = str_replace(['S', 'M'], '', $perms);
313
+                }
314
+                return $perms;
315
+            });
316
+
317
+            $propFind->handle(self::SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
318
+                return $node->getSharePermissions(
319
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
320
+                );
321
+            });
322
+
323
+            $propFind->handle(self::OCM_SHARE_PERMISSIONS_PROPERTYNAME, function() use ($node, $httpRequest) {
324
+                $ncPermissions = $node->getSharePermissions(
325
+                    $httpRequest->getRawServerValue('PHP_AUTH_USER')
326
+                );
327
+                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
328
+                return json_encode($ocmPermissions);
329
+            });
330
+
331
+            $propFind->handle(self::GETETAG_PROPERTYNAME, function() use ($node) {
332
+                return $node->getETag();
333
+            });
334
+
335
+            $propFind->handle(self::OWNER_ID_PROPERTYNAME, function() use ($node) {
336
+                $owner = $node->getOwner();
337
+                if (!$owner) {
338
+                    return null;
339
+                } else {
340
+                    return $owner->getUID();
341
+                }
342
+            });
343
+            $propFind->handle(self::OWNER_DISPLAY_NAME_PROPERTYNAME, function() use ($node) {
344
+                $owner = $node->getOwner();
345
+                if (!$owner) {
346
+                    return null;
347
+                } else {
348
+                    return $owner->getDisplayName();
349
+                }
350
+            });
351
+
352
+            $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
353
+                return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
354
+            });
355
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
356
+                return $node->getSize();
357
+            });
358
+            $propFind->handle(self::MOUNT_TYPE_PROPERTYNAME, function () use ($node) {
359
+                return $node->getFileInfo()->getMountPoint()->getMountType();
360
+            });
361
+        }
362
+
363
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
364
+            $propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function() use ($node) {
365
+                return $this->config->getSystemValue('data-fingerprint', '');
366
+            });
367
+        }
368
+
369
+        if ($node instanceof \OCA\DAV\Connector\Sabre\File) {
370
+            $propFind->handle(self::DOWNLOADURL_PROPERTYNAME, function() use ($node) {
371
+                /** @var $node \OCA\DAV\Connector\Sabre\File */
372
+                try {
373
+                    $directDownloadUrl = $node->getDirectDownload();
374
+                    if (isset($directDownloadUrl['url'])) {
375
+                        return $directDownloadUrl['url'];
376
+                    }
377
+                } catch (StorageNotAvailableException $e) {
378
+                    return false;
379
+                } catch (ForbiddenException $e) {
380
+                    return false;
381
+                }
382
+                return false;
383
+            });
384
+
385
+            $propFind->handle(self::CHECKSUMS_PROPERTYNAME, function() use ($node) {
386
+                $checksum = $node->getChecksum();
387
+                if ($checksum === NULL || $checksum === '') {
388
+                    return null;
389
+                }
390
+
391
+                return new ChecksumList($checksum);
392
+            });
393
+
394
+        }
395
+
396
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory) {
397
+            $propFind->handle(self::SIZE_PROPERTYNAME, function() use ($node) {
398
+                return $node->getSize();
399
+            });
400
+
401
+            $propFind->handle(self::IS_ENCRYPTED_PROPERTYNAME, function() use ($node) {
402
+                return $node->getFileInfo()->isEncrypted() ? '1' : '0';
403
+            });
404
+        }
405
+    }
406
+
407
+    /**
408
+     * translate Nextcloud permissions to OCM Permissions
409
+     *
410
+     * @param $ncPermissions
411
+     * @return array
412
+     */
413
+    protected function ncPermissions2ocmPermissions($ncPermissions) {
414
+
415
+        $ocmPermissions = [];
416
+
417
+        if ($ncPermissions & Constants::PERMISSION_SHARE) {
418
+            $ocmPermissions[] = 'share';
419
+        }
420
+
421
+        if ($ncPermissions & Constants::PERMISSION_READ) {
422
+            $ocmPermissions[] = 'read';
423
+        }
424
+
425
+        if (($ncPermissions & Constants::PERMISSION_CREATE) ||
426
+            ($ncPermissions & Constants::PERMISSION_UPDATE)) {
427
+            $ocmPermissions[] = 'write';
428
+        }
429
+
430
+        return $ocmPermissions;
431
+
432
+    }
433
+
434
+    /**
435
+     * Update ownCloud-specific properties
436
+     *
437
+     * @param string $path
438
+     * @param PropPatch $propPatch
439
+     *
440
+     * @return void
441
+     */
442
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
443
+        $node = $this->tree->getNodeForPath($path);
444
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
445
+            return;
446
+        }
447
+
448
+        $propPatch->handle(self::LASTMODIFIED_PROPERTYNAME, function($time) use ($node) {
449
+            if (empty($time)) {
450
+                return false;
451
+            }
452
+            $node->touch($time);
453
+            return true;
454
+        });
455
+        $propPatch->handle(self::GETETAG_PROPERTYNAME, function($etag) use ($node) {
456
+            if (empty($etag)) {
457
+                return false;
458
+            }
459
+            if ($node->setEtag($etag) !== -1) {
460
+                return true;
461
+            }
462
+            return false;
463
+        });
464
+    }
465
+
466
+    /**
467
+     * @param string $filePath
468
+     * @param \Sabre\DAV\INode $node
469
+     * @throws \Sabre\DAV\Exception\BadRequest
470
+     */
471
+    public function sendFileIdHeader($filePath, \Sabre\DAV\INode $node = null) {
472
+        // chunked upload handling
473
+        if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
474
+            list($path, $name) = \Sabre\Uri\split($filePath);
475
+            $info = \OC_FileChunking::decodeName($name);
476
+            if (!empty($info)) {
477
+                $filePath = $path . '/' . $info['name'];
478
+            }
479
+        }
480
+
481
+        // we get the node for the given $filePath here because in case of afterCreateFile $node is the parent folder
482
+        if (!$this->server->tree->nodeExists($filePath)) {
483
+            return;
484
+        }
485
+        $node = $this->server->tree->getNodeForPath($filePath);
486
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
487
+            $fileId = $node->getFileId();
488
+            if (!is_null($fileId)) {
489
+                $this->server->httpResponse->setHeader('OC-FileId', $fileId);
490
+            }
491
+        }
492
+    }
493 493
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationShare.php 1 patch
Indentation   +298 added lines, -298 removed lines patch added patch discarded remove patch
@@ -25,328 +25,328 @@
 block discarded – undo
25 25
 
26 26
 class CloudFederationShare implements ICloudFederationShare {
27 27
 
28
-	private $share = [
29
-		'shareWith' => '',
30
-		'shareType' => '',
31
-		'name' => '',
32
-		'resourceType' => '',
33
-		'description' => '',
34
-		'providerId' => '',
35
-		'owner' => '',
36
-		'ownerDisplayName' => '',
37
-		'sharedBy' => '',
38
-		'sharedByDisplayName' => '',
39
-		'protocol' => []
40
-	];
28
+    private $share = [
29
+        'shareWith' => '',
30
+        'shareType' => '',
31
+        'name' => '',
32
+        'resourceType' => '',
33
+        'description' => '',
34
+        'providerId' => '',
35
+        'owner' => '',
36
+        'ownerDisplayName' => '',
37
+        'sharedBy' => '',
38
+        'sharedByDisplayName' => '',
39
+        'protocol' => []
40
+    ];
41 41
 
42
-	/**
43
-	 * get a CloudFederationShare Object to prepare a share you want to send
44
-	 *
45
-	 * @param string $shareWith
46
-	 * @param string $name resource name (e.g. document.odt)
47
-	 * @param string $description share description (optional)
48
-	 * @param string $providerId resource UID on the provider side
49
-	 * @param string $owner provider specific UID of the user who owns the resource
50
-	 * @param string $ownerDisplayName display name of the user who shared the item
51
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
52
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
53
-	 * @param string $shareType ('group' or 'user' share)
54
-	 * @param string $resourceType ('file', 'calendar',...)
55
-	 * @param string $sharedSecret
56
-	 */
57
-	public function __construct($shareWith = '',
58
-								$name = '',
59
-								$description = '',
60
-								$providerId = '',
61
-								$owner = '',
62
-								$ownerDisplayName = '',
63
-								$sharedBy = '',
64
-								$sharedByDisplayName = '',
65
-								$shareType = '',
66
-								$resourceType = '',
67
-								$sharedSecret = ''
68
-	) {
69
-		$this->setShareWith($shareWith);
70
-		$this->setResourceName($name);
71
-		$this->setDescription($description);
72
-		$this->setProviderId($providerId);
73
-		$this->setOwner($owner);
74
-		$this->setOwnerDisplayName($ownerDisplayName);
75
-		$this->setSharedBy($sharedBy);
76
-		$this->setSharedByDisplayName($sharedByDisplayName);
77
-		$this->setProtocol([
78
-			'name' => 'webdav',
79
-			'options' => [
80
-				'sharedSecret' => $sharedSecret,
81
-				'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
82
-			]
83
-		]);
84
-		$this->setShareType($shareType);
85
-		$this->setResourceType($resourceType);
42
+    /**
43
+     * get a CloudFederationShare Object to prepare a share you want to send
44
+     *
45
+     * @param string $shareWith
46
+     * @param string $name resource name (e.g. document.odt)
47
+     * @param string $description share description (optional)
48
+     * @param string $providerId resource UID on the provider side
49
+     * @param string $owner provider specific UID of the user who owns the resource
50
+     * @param string $ownerDisplayName display name of the user who shared the item
51
+     * @param string $sharedBy provider specific UID of the user who shared the resource
52
+     * @param string $sharedByDisplayName display name of the user who shared the resource
53
+     * @param string $shareType ('group' or 'user' share)
54
+     * @param string $resourceType ('file', 'calendar',...)
55
+     * @param string $sharedSecret
56
+     */
57
+    public function __construct($shareWith = '',
58
+                                $name = '',
59
+                                $description = '',
60
+                                $providerId = '',
61
+                                $owner = '',
62
+                                $ownerDisplayName = '',
63
+                                $sharedBy = '',
64
+                                $sharedByDisplayName = '',
65
+                                $shareType = '',
66
+                                $resourceType = '',
67
+                                $sharedSecret = ''
68
+    ) {
69
+        $this->setShareWith($shareWith);
70
+        $this->setResourceName($name);
71
+        $this->setDescription($description);
72
+        $this->setProviderId($providerId);
73
+        $this->setOwner($owner);
74
+        $this->setOwnerDisplayName($ownerDisplayName);
75
+        $this->setSharedBy($sharedBy);
76
+        $this->setSharedByDisplayName($sharedByDisplayName);
77
+        $this->setProtocol([
78
+            'name' => 'webdav',
79
+            'options' => [
80
+                'sharedSecret' => $sharedSecret,
81
+                'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
82
+            ]
83
+        ]);
84
+        $this->setShareType($shareType);
85
+        $this->setResourceType($resourceType);
86 86
 
87
-	}
87
+    }
88 88
 
89
-	/**
90
-	 * set uid of the recipient
91
-	 *
92
-	 * @param string $user
93
-	 *
94
-	 * @since 14.0.0
95
-	 */
96
-	public function setShareWith($user) {
97
-		$this->share['shareWith'] = $user;
98
-	}
89
+    /**
90
+     * set uid of the recipient
91
+     *
92
+     * @param string $user
93
+     *
94
+     * @since 14.0.0
95
+     */
96
+    public function setShareWith($user) {
97
+        $this->share['shareWith'] = $user;
98
+    }
99 99
 
100
-	/**
101
-	 * set resource name (e.g. document.odt)
102
-	 *
103
-	 * @param string $name
104
-	 *
105
-	 * @since 14.0.0
106
-	 */
107
-	public function setResourceName($name) {
108
-		$this->share['name'] = $name;
109
-	}
100
+    /**
101
+     * set resource name (e.g. document.odt)
102
+     *
103
+     * @param string $name
104
+     *
105
+     * @since 14.0.0
106
+     */
107
+    public function setResourceName($name) {
108
+        $this->share['name'] = $name;
109
+    }
110 110
 
111
-	/**
112
-	 * set resource type (e.g. file, calendar, contact,...)
113
-	 *
114
-	 * @param string $resourceType
115
-	 *
116
-	 * @since 14.0.0
117
-	 */
118
-	public function setResourceType($resourceType) {
119
-		$this->share['resourceType'] = $resourceType;
120
-	}
111
+    /**
112
+     * set resource type (e.g. file, calendar, contact,...)
113
+     *
114
+     * @param string $resourceType
115
+     *
116
+     * @since 14.0.0
117
+     */
118
+    public function setResourceType($resourceType) {
119
+        $this->share['resourceType'] = $resourceType;
120
+    }
121 121
 
122
-	/**
123
-	 * set resource description (optional)
124
-	 *
125
-	 * @param string $description
126
-	 *
127
-	 * @since 14.0.0
128
-	 */
129
-	public function setDescription($description) {
130
-		$this->share['description'] = $description;
131
-	}
122
+    /**
123
+     * set resource description (optional)
124
+     *
125
+     * @param string $description
126
+     *
127
+     * @since 14.0.0
128
+     */
129
+    public function setDescription($description) {
130
+        $this->share['description'] = $description;
131
+    }
132 132
 
133
-	/**
134
-	 * set provider ID (e.g. file ID)
135
-	 *
136
-	 * @param string $providerId
137
-	 *
138
-	 * @since 14.0.0
139
-	 */
140
-	public function setProviderId($providerId) {
141
-		$this->share['providerId'] = $providerId;
142
-	}
133
+    /**
134
+     * set provider ID (e.g. file ID)
135
+     *
136
+     * @param string $providerId
137
+     *
138
+     * @since 14.0.0
139
+     */
140
+    public function setProviderId($providerId) {
141
+        $this->share['providerId'] = $providerId;
142
+    }
143 143
 
144
-	/**
145
-	 * set owner UID
146
-	 *
147
-	 * @param string $owner
148
-	 *
149
-	 * @since 14.0.0
150
-	 */
151
-	public function setOwner($owner) {
152
-		$this->share['owner'] = $owner;
153
-	}
144
+    /**
145
+     * set owner UID
146
+     *
147
+     * @param string $owner
148
+     *
149
+     * @since 14.0.0
150
+     */
151
+    public function setOwner($owner) {
152
+        $this->share['owner'] = $owner;
153
+    }
154 154
 
155
-	/**
156
-	 * set owner display name
157
-	 *
158
-	 * @param string $ownerDisplayName
159
-	 *
160
-	 * @since 14.0.0
161
-	 */
162
-	public function setOwnerDisplayName($ownerDisplayName) {
163
-		$this->share['ownerDisplayName'] = $ownerDisplayName;
164
-	}
155
+    /**
156
+     * set owner display name
157
+     *
158
+     * @param string $ownerDisplayName
159
+     *
160
+     * @since 14.0.0
161
+     */
162
+    public function setOwnerDisplayName($ownerDisplayName) {
163
+        $this->share['ownerDisplayName'] = $ownerDisplayName;
164
+    }
165 165
 
166
-	/**
167
-	 * set UID of the user who sends the share
168
-	 *
169
-	 * @param string $sharedBy
170
-	 *
171
-	 * @since 14.0.0
172
-	 */
173
-	public function setSharedBy($sharedBy) {
174
-		$this->share['sharedBy'] = $sharedBy;
175
-	}
166
+    /**
167
+     * set UID of the user who sends the share
168
+     *
169
+     * @param string $sharedBy
170
+     *
171
+     * @since 14.0.0
172
+     */
173
+    public function setSharedBy($sharedBy) {
174
+        $this->share['sharedBy'] = $sharedBy;
175
+    }
176 176
 
177
-	/**
178
-	 * set display name of the user who sends the share
179
-	 *
180
-	 * @param $sharedByDisplayName
181
-	 *
182
-	 * @since 14.0.0
183
-	 */
184
-	public function setSharedByDisplayName($sharedByDisplayName) {
185
-		$this->share['sharedByDisplayName'] = $sharedByDisplayName;
186
-	}
177
+    /**
178
+     * set display name of the user who sends the share
179
+     *
180
+     * @param $sharedByDisplayName
181
+     *
182
+     * @since 14.0.0
183
+     */
184
+    public function setSharedByDisplayName($sharedByDisplayName) {
185
+        $this->share['sharedByDisplayName'] = $sharedByDisplayName;
186
+    }
187 187
 
188
-	/**
189
-	 * set protocol specification
190
-	 *
191
-	 * @param array $protocol
192
-	 *
193
-	 * @since 14.0.0
194
-	 */
195
-	public function setProtocol(array $protocol) {
196
-		$this->share['protocol'] = $protocol;
197
-	}
188
+    /**
189
+     * set protocol specification
190
+     *
191
+     * @param array $protocol
192
+     *
193
+     * @since 14.0.0
194
+     */
195
+    public function setProtocol(array $protocol) {
196
+        $this->share['protocol'] = $protocol;
197
+    }
198 198
 
199
-	/**
200
-	 * share type (group or user)
201
-	 *
202
-	 * @param string $shareType
203
-	 *
204
-	 * @since 14.0.0
205
-	 */
206
-	public function setShareType($shareType) {
207
-		$this->share['shareType'] = $shareType;
208
-	}
199
+    /**
200
+     * share type (group or user)
201
+     *
202
+     * @param string $shareType
203
+     *
204
+     * @since 14.0.0
205
+     */
206
+    public function setShareType($shareType) {
207
+        $this->share['shareType'] = $shareType;
208
+    }
209 209
 
210
-	/**
211
-	 * get the whole share, ready to send out
212
-	 *
213
-	 * @return array
214
-	 *
215
-	 * @since 14.0.0
216
-	 */
217
-	public function getShare() {
218
-		return $this->share;
219
-	}
210
+    /**
211
+     * get the whole share, ready to send out
212
+     *
213
+     * @return array
214
+     *
215
+     * @since 14.0.0
216
+     */
217
+    public function getShare() {
218
+        return $this->share;
219
+    }
220 220
 
221
-	/**
222
-	 * get uid of the recipient
223
-	 *
224
-	 * @return string
225
-	 *
226
-	 * @since 14.0.0
227
-	 */
228
-	public function getShareWith() {
229
-		return $this->share['shareWith'];
230
-	}
221
+    /**
222
+     * get uid of the recipient
223
+     *
224
+     * @return string
225
+     *
226
+     * @since 14.0.0
227
+     */
228
+    public function getShareWith() {
229
+        return $this->share['shareWith'];
230
+    }
231 231
 
232
-	/**
233
-	 * get resource name (e.g. file, calendar, contact,...)
234
-	 *
235
-	 * @return string
236
-	 *
237
-	 * @since 14.0.0
238
-	 */
239
-	public function getResourceName() {
240
-		return $this->share['name'];
241
-	}
232
+    /**
233
+     * get resource name (e.g. file, calendar, contact,...)
234
+     *
235
+     * @return string
236
+     *
237
+     * @since 14.0.0
238
+     */
239
+    public function getResourceName() {
240
+        return $this->share['name'];
241
+    }
242 242
 
243
-	/**
244
-	 * get resource type (e.g. file, calendar, contact,...)
245
-	 *
246
-	 * @return string
247
-	 *
248
-	 * @since 14.0.0
249
-	 */
250
-	public function getResourceType() {
251
-		return $this->share['resourceType'];
252
-	}
243
+    /**
244
+     * get resource type (e.g. file, calendar, contact,...)
245
+     *
246
+     * @return string
247
+     *
248
+     * @since 14.0.0
249
+     */
250
+    public function getResourceType() {
251
+        return $this->share['resourceType'];
252
+    }
253 253
 
254
-	/**
255
-	 * get resource description (optional)
256
-	 *
257
-	 * @return string
258
-	 *
259
-	 * @since 14.0.0
260
-	 */
261
-	public function getDescription() {
262
-		return $this->share['description'];
263
-	}
254
+    /**
255
+     * get resource description (optional)
256
+     *
257
+     * @return string
258
+     *
259
+     * @since 14.0.0
260
+     */
261
+    public function getDescription() {
262
+        return $this->share['description'];
263
+    }
264 264
 
265
-	/**
266
-	 * get provider ID (e.g. file ID)
267
-	 *
268
-	 * @return string
269
-	 *
270
-	 * @since 14.0.0
271
-	 */
272
-	public function getProviderId() {
273
-		return $this->share['providerId'];
274
-	}
265
+    /**
266
+     * get provider ID (e.g. file ID)
267
+     *
268
+     * @return string
269
+     *
270
+     * @since 14.0.0
271
+     */
272
+    public function getProviderId() {
273
+        return $this->share['providerId'];
274
+    }
275 275
 
276
-	/**
277
-	 * get owner UID
278
-	 *
279
-	 * @return string
280
-	 *
281
-	 * @since 14.0.0
282
-	 */
283
-	public function getOwner() {
284
-		return $this->share['owner'];
285
-	}
276
+    /**
277
+     * get owner UID
278
+     *
279
+     * @return string
280
+     *
281
+     * @since 14.0.0
282
+     */
283
+    public function getOwner() {
284
+        return $this->share['owner'];
285
+    }
286 286
 
287
-	/**
288
-	 * get owner display name
289
-	 *
290
-	 * @return string
291
-	 *
292
-	 * @since 14.0.0
293
-	 */
294
-	public function getOwnerDisplayName() {
295
-		return $this->share['ownerDisplayName'];
296
-	}
287
+    /**
288
+     * get owner display name
289
+     *
290
+     * @return string
291
+     *
292
+     * @since 14.0.0
293
+     */
294
+    public function getOwnerDisplayName() {
295
+        return $this->share['ownerDisplayName'];
296
+    }
297 297
 
298
-	/**
299
-	 * get UID of the user who sends the share
300
-	 *
301
-	 * @return string
302
-	 *
303
-	 * @since 14.0.0
304
-	 */
305
-	public function getSharedBy() {
306
-		return $this->share['sharedBy'];
307
-	}
298
+    /**
299
+     * get UID of the user who sends the share
300
+     *
301
+     * @return string
302
+     *
303
+     * @since 14.0.0
304
+     */
305
+    public function getSharedBy() {
306
+        return $this->share['sharedBy'];
307
+    }
308 308
 
309
-	/**
310
-	 * get display name of the user who sends the share
311
-	 *
312
-	 * @return string
313
-	 *
314
-	 * @since 14.0.0
315
-	 */
316
-	public function getSharedByDisplayName() {
317
-		return $this->share['sharedByDisplayName'];
318
-	}
309
+    /**
310
+     * get display name of the user who sends the share
311
+     *
312
+     * @return string
313
+     *
314
+     * @since 14.0.0
315
+     */
316
+    public function getSharedByDisplayName() {
317
+        return $this->share['sharedByDisplayName'];
318
+    }
319 319
 
320
-	/**
321
-	 * get share type (group or user)
322
-	 *
323
-	 * @return string
324
-	 *
325
-	 * @since 14.0.0
326
-	 */
327
-	public function getShareType() {
328
-		return $this->share['shareType'];
329
-	}
320
+    /**
321
+     * get share type (group or user)
322
+     *
323
+     * @return string
324
+     *
325
+     * @since 14.0.0
326
+     */
327
+    public function getShareType() {
328
+        return $this->share['shareType'];
329
+    }
330 330
 
331
-	/**
332
-	 * get share Secret
333
-	 *
334
-	 * @return string
335
-	 *
336
-	 * @since 14.0.0
337
-	 */
338
-	public function getShareSecret() {
339
-		return $this->share['protocol']['options']['sharedSecret'];
340
-	}
331
+    /**
332
+     * get share Secret
333
+     *
334
+     * @return string
335
+     *
336
+     * @since 14.0.0
337
+     */
338
+    public function getShareSecret() {
339
+        return $this->share['protocol']['options']['sharedSecret'];
340
+    }
341 341
 
342
-	/**
343
-	 * get protocol specification
344
-	 *
345
-	 * @return array
346
-	 *
347
-	 * @since 14.0.0
348
-	 */
349
-	public function getProtocol() {
350
-		return $this->share['protocol'];
351
-	}
342
+    /**
343
+     * get protocol specification
344
+     *
345
+     * @return array
346
+     *
347
+     * @since 14.0.0
348
+     */
349
+    public function getProtocol() {
350
+        return $this->share['protocol'];
351
+    }
352 352
 }
Please login to merge, or discard this patch.
lib/public/Federation/ICloudFederationProvider.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -39,51 +39,51 @@
 block discarded – undo
39 39
 
40 40
 interface ICloudFederationProvider {
41 41
 
42
-	/**
43
-	 * get the name of the share type, handled by this provider
44
-	 *
45
-	 * @return string
46
-	 *
47
-	 * @since 14.0.0
48
-	 */
49
-	public function getShareType();
42
+    /**
43
+     * get the name of the share type, handled by this provider
44
+     *
45
+     * @return string
46
+     *
47
+     * @since 14.0.0
48
+     */
49
+    public function getShareType();
50 50
 
51
-	/**
52
-	 * share received from another server
53
-	 *
54
-	 * @param ICloudFederationShare $share
55
-	 * @return string provider specific unique ID of the share
56
-	 *
57
-	 * @throws ProviderCouldNotAddShareException
58
-	 *
59
-	 * @since 14.0.0
60
-	 */
61
-	public function shareReceived(ICloudFederationShare $share);
51
+    /**
52
+     * share received from another server
53
+     *
54
+     * @param ICloudFederationShare $share
55
+     * @return string provider specific unique ID of the share
56
+     *
57
+     * @throws ProviderCouldNotAddShareException
58
+     *
59
+     * @since 14.0.0
60
+     */
61
+    public function shareReceived(ICloudFederationShare $share);
62 62
 
63
-	/**
64
-	 * notification received from another server
65
-	 *
66
-	 * @param string $notificationType (e.g SHARE_ACCEPTED)
67
-	 * @param string $providerId share ID
68
-	 * @param array $notification provider specific notification
69
-	 * @return array $data send back to sender
70
-	 *
71
-	 * @throws ShareNotFound
72
-	 * @throws ActionNotSupportedException
73
-	 * @throws BadRequestException
74
-	 * @throws AuthenticationFailedException
75
-	 *
76
-	 * @since 14.0.0
77
-	 */
78
-	public function notificationReceived($notificationType, $providerId, array $notification);
63
+    /**
64
+     * notification received from another server
65
+     *
66
+     * @param string $notificationType (e.g SHARE_ACCEPTED)
67
+     * @param string $providerId share ID
68
+     * @param array $notification provider specific notification
69
+     * @return array $data send back to sender
70
+     *
71
+     * @throws ShareNotFound
72
+     * @throws ActionNotSupportedException
73
+     * @throws BadRequestException
74
+     * @throws AuthenticationFailedException
75
+     *
76
+     * @since 14.0.0
77
+     */
78
+    public function notificationReceived($notificationType, $providerId, array $notification);
79 79
 
80
-	/**
81
-	 * get the supported share types, e.g. "user", "group", etc.
82
-	 *
83
-	 * @return array
84
-	 *
85
-	 * @since 14.0.0
86
-	 */
87
-	public function getSupportedShareTypes();
80
+    /**
81
+     * get the supported share types, e.g. "user", "group", etc.
82
+     *
83
+     * @return array
84
+     *
85
+     * @since 14.0.0
86
+     */
87
+    public function getSupportedShareTypes();
88 88
 
89 89
 }
Please login to merge, or discard this patch.