Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Server often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Server, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 152 | class Server extends ServerContainer implements IServerContainer { |
||
| 153 | /** @var string */ |
||
| 154 | private $webRoot; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param string $webRoot |
||
| 158 | * @param \OC\Config $config |
||
| 159 | */ |
||
| 160 | public function __construct($webRoot, \OC\Config $config) { |
||
| 161 | parent::__construct(); |
||
| 162 | $this->webRoot = $webRoot; |
||
| 163 | |||
| 164 | $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
||
| 165 | return $c; |
||
| 166 | }); |
||
| 167 | |||
| 168 | $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
||
| 169 | $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
||
| 170 | |||
| 171 | $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
||
| 172 | $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
||
| 173 | |||
| 174 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
||
| 175 | |||
| 176 | |||
| 177 | $this->registerService(\OCP\IPreview::class, function (Server $c) { |
||
| 178 | return new PreviewManager( |
||
| 179 | $c->getConfig(), |
||
| 180 | $c->getRootFolder(), |
||
| 181 | $c->getAppDataDir('preview'), |
||
| 182 | $c->getEventDispatcher(), |
||
| 183 | $c->getSession()->get('user_id') |
||
| 184 | ); |
||
| 185 | }); |
||
| 186 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
||
| 187 | |||
| 188 | $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
||
| 189 | return new \OC\Preview\Watcher( |
||
| 190 | $c->getAppDataDir('preview') |
||
| 191 | ); |
||
| 192 | }); |
||
| 193 | |||
| 194 | $this->registerService('EncryptionManager', function (Server $c) { |
||
| 195 | $view = new View(); |
||
| 196 | $util = new Encryption\Util( |
||
| 197 | $view, |
||
| 198 | $c->getUserManager(), |
||
| 199 | $c->getGroupManager(), |
||
| 200 | $c->getConfig() |
||
| 201 | ); |
||
| 202 | return new Encryption\Manager( |
||
| 203 | $c->getConfig(), |
||
| 204 | $c->getLogger(), |
||
| 205 | $c->getL10N('core'), |
||
| 206 | new View(), |
||
| 207 | $util, |
||
| 208 | new ArrayCache() |
||
| 209 | ); |
||
| 210 | }); |
||
| 211 | |||
| 212 | View Code Duplication | $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 213 | $util = new Encryption\Util( |
||
| 214 | new View(), |
||
| 215 | $c->getUserManager(), |
||
| 216 | $c->getGroupManager(), |
||
| 217 | $c->getConfig() |
||
| 218 | ); |
||
| 219 | return new Encryption\File( |
||
| 220 | $util, |
||
| 221 | $c->getRootFolder(), |
||
| 222 | $c->getShareManager() |
||
| 223 | ); |
||
| 224 | }); |
||
| 225 | |||
| 226 | View Code Duplication | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 227 | $view = new View(); |
||
| 228 | $util = new Encryption\Util( |
||
| 229 | $view, |
||
| 230 | $c->getUserManager(), |
||
| 231 | $c->getGroupManager(), |
||
| 232 | $c->getConfig() |
||
| 233 | ); |
||
| 234 | |||
| 235 | return new Encryption\Keys\Storage($view, $util); |
||
| 236 | }); |
||
| 237 | $this->registerService('TagMapper', function (Server $c) { |
||
| 238 | return new TagMapper($c->getDatabaseConnection()); |
||
| 239 | }); |
||
| 240 | |||
| 241 | $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
||
| 242 | $tagMapper = $c->query('TagMapper'); |
||
| 243 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 244 | }); |
||
| 245 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
||
| 246 | |||
| 247 | $this->registerService('SystemTagManagerFactory', function (Server $c) { |
||
| 248 | $config = $c->getConfig(); |
||
| 249 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', SystemTagManagerFactory::class); |
||
| 250 | return new $factoryClass($this); |
||
| 251 | }); |
||
| 252 | $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
||
| 253 | return $c->query('SystemTagManagerFactory')->getManager(); |
||
| 254 | }); |
||
| 255 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
||
| 256 | |||
| 257 | $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
||
| 258 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
||
| 259 | }); |
||
| 260 | $this->registerService('RootFolder', function (Server $c) { |
||
| 261 | $manager = \OC\Files\Filesystem::getMountManager(null); |
||
| 262 | $view = new View(); |
||
| 263 | $root = new Root( |
||
| 264 | $manager, |
||
| 265 | $view, |
||
| 266 | null, |
||
| 267 | $c->getUserMountCache(), |
||
| 268 | $this->getLogger(), |
||
| 269 | $this->getUserManager() |
||
| 270 | ); |
||
| 271 | $connector = new HookConnector($root, $view); |
||
| 272 | $connector->viewToNode(); |
||
| 273 | |||
| 274 | $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
||
| 275 | $previewConnector->connectWatcher(); |
||
| 276 | |||
| 277 | return $root; |
||
| 278 | }); |
||
| 279 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
||
| 280 | |||
| 281 | $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
||
| 282 | return new LazyRoot(function () use ($c) { |
||
| 283 | return $c->query('RootFolder'); |
||
| 284 | }); |
||
| 285 | }); |
||
| 286 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
||
| 287 | |||
| 288 | $this->registerService(\OC\User\Manager::class, function (Server $c) { |
||
| 289 | $config = $c->getConfig(); |
||
| 290 | return new \OC\User\Manager($config); |
||
| 291 | }); |
||
| 292 | $this->registerAlias('UserManager', \OC\User\Manager::class); |
||
| 293 | $this->registerAlias(\OCP\IUserManager::class, \OC\User\Manager::class); |
||
| 294 | |||
| 295 | $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
||
| 296 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
||
| 297 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 298 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
||
| 299 | }); |
||
| 300 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 301 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
||
| 302 | }); |
||
| 303 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 304 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
||
| 305 | }); |
||
| 306 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 307 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
||
| 308 | }); |
||
| 309 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 310 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 311 | }); |
||
| 312 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 313 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 314 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 315 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 316 | }); |
||
| 317 | return $groupManager; |
||
| 318 | }); |
||
| 319 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
||
| 320 | |||
| 321 | $this->registerService(Store::class, function (Server $c) { |
||
| 322 | $session = $c->getSession(); |
||
| 323 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 324 | $tokenProvider = $c->query(IProvider::class); |
||
| 325 | } else { |
||
| 326 | $tokenProvider = null; |
||
| 327 | } |
||
| 328 | $logger = $c->getLogger(); |
||
| 329 | return new Store($session, $logger, $tokenProvider); |
||
| 330 | }); |
||
| 331 | $this->registerAlias(IStore::class, Store::class); |
||
| 332 | $this->registerService(Authentication\Token\DefaultTokenMapper::class, function (Server $c) { |
||
| 333 | $dbConnection = $c->getDatabaseConnection(); |
||
| 334 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
||
| 335 | }); |
||
| 336 | $this->registerService(Authentication\Token\DefaultTokenProvider::class, function (Server $c) { |
||
| 337 | $mapper = $c->query(Authentication\Token\DefaultTokenMapper::class); |
||
| 338 | $crypto = $c->getCrypto(); |
||
| 339 | $config = $c->getConfig(); |
||
| 340 | $logger = $c->getLogger(); |
||
| 341 | $timeFactory = new TimeFactory(); |
||
| 342 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
||
| 343 | }); |
||
| 344 | $this->registerAlias(IProvider::class, Authentication\Token\DefaultTokenProvider::class); |
||
| 345 | |||
| 346 | $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
||
| 347 | $manager = $c->getUserManager(); |
||
| 348 | $session = new \OC\Session\Memory(''); |
||
| 349 | $timeFactory = new TimeFactory(); |
||
| 350 | // Token providers might require a working database. This code |
||
| 351 | // might however be called when ownCloud is not yet setup. |
||
| 352 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 353 | $defaultTokenProvider = $c->query(IProvider::class); |
||
| 354 | } else { |
||
| 355 | $defaultTokenProvider = null; |
||
| 356 | } |
||
| 357 | |||
| 358 | $dispatcher = $c->getEventDispatcher(); |
||
| 359 | |||
| 360 | $userSession = new \OC\User\Session( |
||
| 361 | $manager, |
||
| 362 | $session, |
||
| 363 | $timeFactory, |
||
| 364 | $defaultTokenProvider, |
||
| 365 | $c->getConfig(), |
||
| 366 | $c->getSecureRandom(), |
||
| 367 | $c->getLockdownManager(), |
||
| 368 | $c->getLogger() |
||
| 369 | ); |
||
| 370 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 371 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 372 | }); |
||
| 373 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 374 | /** @var $user \OC\User\User */ |
||
| 375 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
||
| 376 | }); |
||
| 377 | $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
||
| 378 | /** @var $user \OC\User\User */ |
||
| 379 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
||
| 380 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
||
| 381 | }); |
||
| 382 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 383 | /** @var $user \OC\User\User */ |
||
| 384 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
||
| 385 | }); |
||
| 386 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 387 | /** @var $user \OC\User\User */ |
||
| 388 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 389 | }); |
||
| 390 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 391 | /** @var $user \OC\User\User */ |
||
| 392 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 393 | }); |
||
| 394 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 395 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 396 | }); |
||
| 397 | View Code Duplication | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 398 | /** @var $user \OC\User\User */ |
||
| 399 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 400 | }); |
||
| 401 | View Code Duplication | $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 402 | /** @var $user \OC\User\User */ |
||
| 403 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 404 | }); |
||
| 405 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 406 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
| 407 | }); |
||
| 408 | $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
||
| 409 | /** @var $user \OC\User\User */ |
||
| 410 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
||
| 411 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
||
| 412 | }); |
||
| 413 | return $userSession; |
||
| 414 | }); |
||
| 415 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
||
| 416 | |||
| 417 | $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
||
| 418 | return new \OC\Authentication\TwoFactorAuth\Manager( |
||
| 419 | $c->getAppManager(), |
||
| 420 | $c->getSession(), |
||
| 421 | $c->getConfig(), |
||
| 422 | $c->getActivityManager(), |
||
| 423 | $c->getLogger(), |
||
| 424 | $c->query(IProvider::class), |
||
| 425 | $c->query(ITimeFactory::class), |
||
| 426 | $c->query(EventDispatcherInterface::class) |
||
| 427 | ); |
||
| 428 | }); |
||
| 429 | |||
| 430 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
||
| 431 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
||
| 432 | |||
| 433 | $this->registerService(\OC\AllConfig::class, function (Server $c) { |
||
| 434 | return new \OC\AllConfig( |
||
| 435 | $c->getSystemConfig() |
||
| 436 | ); |
||
| 437 | }); |
||
| 438 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
||
| 439 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
||
| 440 | |||
| 441 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
| 442 | return new \OC\SystemConfig($config); |
||
| 443 | }); |
||
| 444 | |||
| 445 | $this->registerService(\OC\AppConfig::class, function (Server $c) { |
||
| 446 | return new \OC\AppConfig($c->getDatabaseConnection()); |
||
| 447 | }); |
||
| 448 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
||
| 449 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
||
| 450 | |||
| 451 | $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
||
| 452 | return new \OC\L10N\Factory( |
||
| 453 | $c->getConfig(), |
||
| 454 | $c->getRequest(), |
||
| 455 | $c->getUserSession(), |
||
| 456 | \OC::$SERVERROOT |
||
| 457 | ); |
||
| 458 | }); |
||
| 459 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
||
| 460 | |||
| 461 | $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
||
| 462 | $config = $c->getConfig(); |
||
| 463 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 464 | $request = $c->getRequest(); |
||
| 465 | return new \OC\URLGenerator( |
||
| 466 | $config, |
||
| 467 | $cacheFactory, |
||
| 468 | $request |
||
| 469 | ); |
||
| 470 | }); |
||
| 471 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
||
| 472 | |||
| 473 | $this->registerAlias('AppFetcher', AppFetcher::class); |
||
| 474 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
||
| 475 | |||
| 476 | $this->registerService(\OCP\ICache::class, function ($c) { |
||
| 477 | return new Cache\File(); |
||
| 478 | }); |
||
| 479 | $this->registerAlias('UserCache', \OCP\ICache::class); |
||
| 480 | |||
| 481 | $this->registerService(Factory::class, function (Server $c) { |
||
| 482 | |||
| 483 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
||
| 484 | ArrayCache::class, |
||
| 485 | ArrayCache::class, |
||
| 486 | ArrayCache::class |
||
| 487 | ); |
||
| 488 | $config = $c->getConfig(); |
||
| 489 | $request = $c->getRequest(); |
||
| 490 | $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
||
| 491 | |||
| 492 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 493 | $v = \OC_App::getAppVersions(); |
||
| 494 | $v['core'] = implode(',', \OC_Util::getVersion()); |
||
| 495 | $version = implode(',', $v); |
||
| 496 | $instanceId = \OC_Util::getInstanceId(); |
||
| 497 | $path = \OC::$SERVERROOT; |
||
| 498 | $prefix = md5($instanceId . '-' . $version . '-' . $path); |
||
| 499 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
| 500 | $config->getSystemValue('memcache.local', null), |
||
| 501 | $config->getSystemValue('memcache.distributed', null), |
||
| 502 | $config->getSystemValue('memcache.locking', null) |
||
| 503 | ); |
||
| 504 | } |
||
| 505 | return $arrayCacheFactory; |
||
| 506 | |||
| 507 | }); |
||
| 508 | $this->registerAlias('MemCacheFactory', Factory::class); |
||
| 509 | $this->registerAlias(ICacheFactory::class, Factory::class); |
||
| 510 | |||
| 511 | $this->registerService('RedisFactory', function (Server $c) { |
||
| 512 | $systemConfig = $c->getSystemConfig(); |
||
| 513 | return new RedisFactory($systemConfig); |
||
| 514 | }); |
||
| 515 | |||
| 516 | $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
||
| 517 | return new \OC\Activity\Manager( |
||
| 518 | $c->getRequest(), |
||
| 519 | $c->getUserSession(), |
||
| 520 | $c->getConfig(), |
||
| 521 | $c->query(IValidator::class) |
||
| 522 | ); |
||
| 523 | }); |
||
| 524 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
||
| 525 | |||
| 526 | $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
||
| 527 | return new \OC\Activity\EventMerger( |
||
| 528 | $c->getL10N('lib') |
||
| 529 | ); |
||
| 530 | }); |
||
| 531 | $this->registerAlias(IValidator::class, Validator::class); |
||
| 532 | |||
| 533 | $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
||
| 534 | return new AvatarManager( |
||
| 535 | $c->query(\OC\User\Manager::class), |
||
| 536 | $c->getAppDataDir('avatar'), |
||
| 537 | $c->getL10N('lib'), |
||
| 538 | $c->getLogger(), |
||
| 539 | $c->getConfig() |
||
| 540 | ); |
||
| 541 | }); |
||
| 542 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
||
| 543 | |||
| 544 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
||
| 545 | |||
| 546 | $this->registerService(\OCP\ILogger::class, function (Server $c) { |
||
| 547 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
||
| 548 | $logger = Log::getLogClass($logType); |
||
| 549 | call_user_func(array($logger, 'init')); |
||
| 550 | $config = $this->getSystemConfig(); |
||
| 551 | $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
||
| 552 | |||
| 553 | return new Log($logger, $config, null, $registry); |
||
| 554 | }); |
||
| 555 | $this->registerAlias('Logger', \OCP\ILogger::class); |
||
| 556 | |||
| 557 | $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
||
| 558 | $config = $c->getConfig(); |
||
| 559 | return new \OC\BackgroundJob\JobList( |
||
| 560 | $c->getDatabaseConnection(), |
||
| 561 | $config, |
||
| 562 | new TimeFactory() |
||
| 563 | ); |
||
| 564 | }); |
||
| 565 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
||
| 566 | |||
| 567 | $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
||
| 568 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 569 | $logger = $c->getLogger(); |
||
| 570 | if ($cacheFactory->isAvailableLowLatency()) { |
||
| 571 | $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
||
| 572 | } else { |
||
| 573 | $router = new \OC\Route\Router($logger); |
||
| 574 | } |
||
| 575 | return $router; |
||
| 576 | }); |
||
| 577 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
||
| 578 | |||
| 579 | $this->registerService(\OCP\ISearch::class, function ($c) { |
||
| 580 | return new Search(); |
||
| 581 | }); |
||
| 582 | $this->registerAlias('Search', \OCP\ISearch::class); |
||
| 583 | |||
| 584 | $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
||
| 585 | return new \OC\Security\RateLimiting\Limiter( |
||
| 586 | $this->getUserSession(), |
||
| 587 | $this->getRequest(), |
||
| 588 | new \OC\AppFramework\Utility\TimeFactory(), |
||
| 589 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
||
| 590 | ); |
||
| 591 | }); |
||
| 592 | $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
||
| 593 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
||
| 594 | $this->getMemCacheFactory(), |
||
| 595 | new \OC\AppFramework\Utility\TimeFactory() |
||
| 596 | ); |
||
| 597 | }); |
||
| 598 | |||
| 599 | $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
||
| 600 | return new SecureRandom(); |
||
| 601 | }); |
||
| 602 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
||
| 603 | |||
| 604 | $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
||
| 605 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 606 | }); |
||
| 607 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
||
| 608 | |||
| 609 | $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
||
| 610 | return new Hasher($c->getConfig()); |
||
| 611 | }); |
||
| 612 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
||
| 613 | |||
| 614 | $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
||
| 615 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
||
| 616 | }); |
||
| 617 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
||
| 618 | |||
| 619 | $this->registerService(IDBConnection::class, function (Server $c) { |
||
| 620 | $systemConfig = $c->getSystemConfig(); |
||
| 621 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
||
| 622 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 623 | if (!$factory->isValidType($type)) { |
||
| 624 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 625 | } |
||
| 626 | $connectionParams = $factory->createConnectionParams(); |
||
| 627 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 628 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 629 | return $connection; |
||
| 630 | }); |
||
| 631 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
||
| 632 | |||
| 633 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 634 | $config = $c->getConfig(); |
||
| 635 | return new HTTPHelper( |
||
| 636 | $config, |
||
| 637 | $c->getHTTPClientService() |
||
| 638 | ); |
||
| 639 | }); |
||
| 640 | |||
| 641 | $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
||
| 642 | $user = \OC_User::getUser(); |
||
| 643 | $uid = $user ? $user : null; |
||
| 644 | return new ClientService( |
||
| 645 | $c->getConfig(), |
||
| 646 | new \OC\Security\CertificateManager( |
||
| 647 | $uid, |
||
| 648 | new View(), |
||
| 649 | $c->getConfig(), |
||
| 650 | $c->getLogger(), |
||
| 651 | $c->getSecureRandom() |
||
| 652 | ) |
||
| 653 | ); |
||
| 654 | }); |
||
| 655 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
||
| 656 | View Code Duplication | $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 657 | $eventLogger = new EventLogger(); |
||
| 658 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 659 | // In debug mode, module is being activated by default |
||
| 660 | $eventLogger->activate(); |
||
| 661 | } |
||
| 662 | return $eventLogger; |
||
| 663 | }); |
||
| 664 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
||
| 665 | |||
| 666 | View Code Duplication | $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 667 | $queryLogger = new QueryLogger(); |
||
| 668 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 669 | // In debug mode, module is being activated by default |
||
| 670 | $queryLogger->activate(); |
||
| 671 | } |
||
| 672 | return $queryLogger; |
||
| 673 | }); |
||
| 674 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
||
| 675 | |||
| 676 | $this->registerService(TempManager::class, function (Server $c) { |
||
| 677 | return new TempManager( |
||
| 678 | $c->getLogger(), |
||
| 679 | $c->getConfig() |
||
| 680 | ); |
||
| 681 | }); |
||
| 682 | $this->registerAlias('TempManager', TempManager::class); |
||
| 683 | $this->registerAlias(ITempManager::class, TempManager::class); |
||
| 684 | |||
| 685 | $this->registerService(AppManager::class, function (Server $c) { |
||
| 686 | return new \OC\App\AppManager( |
||
| 687 | $c->getUserSession(), |
||
| 688 | $c->query(\OC\AppConfig::class), |
||
| 689 | $c->getGroupManager(), |
||
| 690 | $c->getMemCacheFactory(), |
||
| 691 | $c->getEventDispatcher() |
||
| 692 | ); |
||
| 693 | }); |
||
| 694 | $this->registerAlias('AppManager', AppManager::class); |
||
| 695 | $this->registerAlias(IAppManager::class, AppManager::class); |
||
| 696 | |||
| 697 | $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
||
| 698 | return new DateTimeZone( |
||
| 699 | $c->getConfig(), |
||
| 700 | $c->getSession() |
||
| 701 | ); |
||
| 702 | }); |
||
| 703 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
||
| 704 | |||
| 705 | $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
||
| 706 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 707 | |||
| 708 | return new DateTimeFormatter( |
||
| 709 | $c->getDateTimeZone()->getTimeZone(), |
||
| 710 | $c->getL10N('lib', $language) |
||
| 711 | ); |
||
| 712 | }); |
||
| 713 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
||
| 714 | |||
| 715 | $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
||
| 716 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
||
| 717 | $listener = new UserMountCacheListener($mountCache); |
||
| 718 | $listener->listen($c->getUserManager()); |
||
| 719 | return $mountCache; |
||
| 720 | }); |
||
| 721 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
||
| 722 | |||
| 723 | $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
||
| 724 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 725 | $mountCache = $c->query('UserMountCache'); |
||
| 726 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
||
| 727 | |||
| 728 | // builtin providers |
||
| 729 | |||
| 730 | $config = $c->getConfig(); |
||
| 731 | $manager->registerProvider(new CacheMountProvider($config)); |
||
| 732 | $manager->registerHomeProvider(new LocalHomeMountProvider()); |
||
| 733 | $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
||
| 734 | |||
| 735 | return $manager; |
||
| 736 | }); |
||
| 737 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
||
| 738 | |||
| 739 | $this->registerService('IniWrapper', function ($c) { |
||
| 740 | return new IniGetWrapper(); |
||
| 741 | }); |
||
| 742 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
| 743 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
||
| 744 | if ($busClass) { |
||
| 745 | list($app, $class) = explode('::', $busClass, 2); |
||
| 746 | if ($c->getAppManager()->isInstalled($app)) { |
||
| 747 | \OC_App::loadApp($app); |
||
| 748 | return $c->query($class); |
||
| 749 | } else { |
||
| 750 | throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
||
| 751 | } |
||
| 752 | } else { |
||
| 753 | $jobList = $c->getJobList(); |
||
| 754 | return new CronBus($jobList); |
||
| 755 | } |
||
| 756 | }); |
||
| 757 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
| 758 | return new TrustedDomainHelper($this->getConfig()); |
||
| 759 | }); |
||
| 760 | $this->registerService('Throttler', function (Server $c) { |
||
| 761 | return new Throttler( |
||
| 762 | $c->getDatabaseConnection(), |
||
| 763 | new TimeFactory(), |
||
| 764 | $c->getLogger(), |
||
| 765 | $c->getConfig() |
||
| 766 | ); |
||
| 767 | }); |
||
| 768 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
| 769 | // IConfig and IAppManager requires a working database. This code |
||
| 770 | // might however be called when ownCloud is not yet setup. |
||
| 771 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 772 | $config = $c->getConfig(); |
||
| 773 | $appManager = $c->getAppManager(); |
||
| 774 | } else { |
||
| 775 | $config = null; |
||
| 776 | $appManager = null; |
||
| 777 | } |
||
| 778 | |||
| 779 | return new Checker( |
||
| 780 | new EnvironmentHelper(), |
||
| 781 | new FileAccessHelper(), |
||
| 782 | new AppLocator(), |
||
| 783 | $config, |
||
| 784 | $c->getMemCacheFactory(), |
||
| 785 | $appManager, |
||
| 786 | $c->getTempManager() |
||
| 787 | ); |
||
| 788 | }); |
||
| 789 | $this->registerService(\OCP\IRequest::class, function ($c) { |
||
| 790 | if (isset($this['urlParams'])) { |
||
| 791 | $urlParams = $this['urlParams']; |
||
| 792 | } else { |
||
| 793 | $urlParams = []; |
||
| 794 | } |
||
| 795 | |||
| 796 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 797 | && in_array('fakeinput', stream_get_wrappers()) |
||
| 798 | ) { |
||
| 799 | $stream = 'fakeinput://data'; |
||
| 800 | } else { |
||
| 801 | $stream = 'php://input'; |
||
| 802 | } |
||
| 803 | |||
| 804 | return new Request( |
||
| 805 | [ |
||
| 806 | 'get' => $_GET, |
||
| 807 | 'post' => $_POST, |
||
| 808 | 'files' => $_FILES, |
||
| 809 | 'server' => $_SERVER, |
||
| 810 | 'env' => $_ENV, |
||
| 811 | 'cookies' => $_COOKIE, |
||
| 812 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 813 | ? $_SERVER['REQUEST_METHOD'] |
||
| 814 | : '', |
||
| 815 | 'urlParams' => $urlParams, |
||
| 816 | ], |
||
| 817 | $this->getSecureRandom(), |
||
| 818 | $this->getConfig(), |
||
| 819 | $this->getCsrfTokenManager(), |
||
| 820 | $stream |
||
| 821 | ); |
||
| 822 | }); |
||
| 823 | $this->registerAlias('Request', \OCP\IRequest::class); |
||
| 824 | |||
| 825 | $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
||
| 826 | return new Mailer( |
||
| 827 | $c->getConfig(), |
||
| 828 | $c->getLogger(), |
||
| 829 | $c->query(Defaults::class), |
||
| 830 | $c->getURLGenerator(), |
||
| 831 | $c->getL10N('lib') |
||
| 832 | ); |
||
| 833 | }); |
||
| 834 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
||
| 835 | |||
| 836 | $this->registerService('LDAPProvider', function (Server $c) { |
||
| 837 | $config = $c->getConfig(); |
||
| 838 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
||
| 839 | if (is_null($factoryClass)) { |
||
| 840 | throw new \Exception('ldapProviderFactory not set'); |
||
| 841 | } |
||
| 842 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
||
| 843 | $factory = new $factoryClass($this); |
||
| 844 | return $factory->getLDAPProvider(); |
||
| 845 | }); |
||
| 846 | $this->registerService(ILockingProvider::class, function (Server $c) { |
||
| 847 | $ini = $c->getIniWrapper(); |
||
| 848 | $config = $c->getConfig(); |
||
| 849 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
||
| 850 | if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 851 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
| 852 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 853 | $memcache = $memcacheFactory->createLocking('lock'); |
||
| 854 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
||
| 855 | return new MemcacheLockingProvider($memcache, $ttl); |
||
| 856 | } |
||
| 857 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
||
| 858 | } |
||
| 859 | return new NoopLockingProvider(); |
||
| 860 | }); |
||
| 861 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
||
| 862 | |||
| 863 | $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
||
| 864 | return new \OC\Files\Mount\Manager(); |
||
| 865 | }); |
||
| 866 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
||
| 867 | |||
| 868 | $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
||
| 869 | return new \OC\Files\Type\Detection( |
||
| 870 | $c->getURLGenerator(), |
||
| 871 | \OC::$configDir, |
||
| 872 | \OC::$SERVERROOT . '/resources/config/' |
||
| 873 | ); |
||
| 874 | }); |
||
| 875 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
||
| 876 | |||
| 877 | $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
||
| 878 | return new \OC\Files\Type\Loader( |
||
| 879 | $c->getDatabaseConnection() |
||
| 880 | ); |
||
| 881 | }); |
||
| 882 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
||
| 883 | $this->registerService(BundleFetcher::class, function () { |
||
| 884 | return new BundleFetcher($this->getL10N('lib')); |
||
| 885 | }); |
||
| 886 | $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
||
| 887 | return new Manager( |
||
| 888 | $c->query(IValidator::class) |
||
| 889 | ); |
||
| 890 | }); |
||
| 891 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
||
| 892 | |||
| 893 | $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
||
| 894 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
||
| 895 | $manager->registerCapability(function () use ($c) { |
||
| 896 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
| 897 | }); |
||
| 898 | $manager->registerCapability(function () use ($c) { |
||
| 899 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
||
| 900 | }); |
||
| 901 | return $manager; |
||
| 902 | }); |
||
| 903 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
||
| 904 | |||
| 905 | $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
||
| 906 | $config = $c->getConfig(); |
||
| 907 | $factoryClass = $config->getSystemValue('comments.managerFactory', CommentsManagerFactory::class); |
||
| 908 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
| 909 | $factory = new $factoryClass($this); |
||
| 910 | $manager = $factory->getManager(); |
||
| 911 | |||
| 912 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
||
| 913 | $manager = $c->getUserManager(); |
||
| 914 | $user = $manager->get($id); |
||
| 915 | if(is_null($user)) { |
||
| 916 | $l = $c->getL10N('core'); |
||
| 917 | $displayName = $l->t('Unknown user'); |
||
| 918 | } else { |
||
| 919 | $displayName = $user->getDisplayName(); |
||
| 920 | } |
||
| 921 | return $displayName; |
||
| 922 | }); |
||
| 923 | |||
| 924 | return $manager; |
||
| 925 | }); |
||
| 926 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
||
| 927 | |||
| 928 | $this->registerService('ThemingDefaults', function (Server $c) { |
||
| 929 | /* |
||
| 930 | * Dark magic for autoloader. |
||
| 931 | * If we do a class_exists it will try to load the class which will |
||
| 932 | * make composer cache the result. Resulting in errors when enabling |
||
| 933 | * the theming app. |
||
| 934 | */ |
||
| 935 | $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
||
| 936 | if (isset($prefixes['OCA\\Theming\\'])) { |
||
| 937 | $classExists = true; |
||
| 938 | } else { |
||
| 939 | $classExists = false; |
||
| 940 | } |
||
| 941 | |||
| 942 | if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
||
| 943 | return new ThemingDefaults( |
||
| 944 | $c->getConfig(), |
||
| 945 | $c->getL10N('theming'), |
||
| 946 | $c->getURLGenerator(), |
||
| 947 | $c->getAppDataDir('theming'), |
||
| 948 | $c->getMemCacheFactory(), |
||
| 949 | new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
||
| 950 | $this->getAppManager() |
||
| 951 | ); |
||
| 952 | } |
||
| 953 | return new \OC_Defaults(); |
||
| 954 | }); |
||
| 955 | $this->registerService(SCSSCacher::class, function (Server $c) { |
||
| 956 | /** @var Factory $cacheFactory */ |
||
| 957 | $cacheFactory = $c->query(Factory::class); |
||
| 958 | return new SCSSCacher( |
||
| 959 | $c->getLogger(), |
||
| 960 | $c->query(\OC\Files\AppData\Factory::class), |
||
| 961 | $c->getURLGenerator(), |
||
| 962 | $c->getConfig(), |
||
| 963 | $c->getThemingDefaults(), |
||
| 964 | \OC::$SERVERROOT, |
||
| 965 | $this->getMemCacheFactory() |
||
| 966 | ); |
||
| 967 | }); |
||
| 968 | $this->registerService(JSCombiner::class, function (Server $c) { |
||
| 969 | /** @var Factory $cacheFactory */ |
||
| 970 | $cacheFactory = $c->query(Factory::class); |
||
| 971 | return new JSCombiner( |
||
| 972 | $c->getAppDataDir('js'), |
||
| 973 | $c->getURLGenerator(), |
||
| 974 | $this->getMemCacheFactory(), |
||
| 975 | $c->getSystemConfig(), |
||
| 976 | $c->getLogger() |
||
| 977 | ); |
||
| 978 | }); |
||
| 979 | $this->registerService(EventDispatcher::class, function () { |
||
| 980 | return new EventDispatcher(); |
||
| 981 | }); |
||
| 982 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
||
| 983 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
||
| 984 | |||
| 985 | $this->registerService('CryptoWrapper', function (Server $c) { |
||
| 986 | // FIXME: Instantiiated here due to cyclic dependency |
||
| 987 | $request = new Request( |
||
| 988 | [ |
||
| 989 | 'get' => $_GET, |
||
| 990 | 'post' => $_POST, |
||
| 991 | 'files' => $_FILES, |
||
| 992 | 'server' => $_SERVER, |
||
| 993 | 'env' => $_ENV, |
||
| 994 | 'cookies' => $_COOKIE, |
||
| 995 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 996 | ? $_SERVER['REQUEST_METHOD'] |
||
| 997 | : null, |
||
| 998 | ], |
||
| 999 | $c->getSecureRandom(), |
||
| 1000 | $c->getConfig() |
||
| 1001 | ); |
||
| 1002 | |||
| 1003 | return new CryptoWrapper( |
||
| 1004 | $c->getConfig(), |
||
| 1005 | $c->getCrypto(), |
||
| 1006 | $c->getSecureRandom(), |
||
| 1007 | $request |
||
| 1008 | ); |
||
| 1009 | }); |
||
| 1010 | $this->registerService('CsrfTokenManager', function (Server $c) { |
||
| 1011 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
||
| 1012 | |||
| 1013 | return new CsrfTokenManager( |
||
| 1014 | $tokenGenerator, |
||
| 1015 | $c->query(SessionStorage::class) |
||
| 1016 | ); |
||
| 1017 | }); |
||
| 1018 | $this->registerService(SessionStorage::class, function (Server $c) { |
||
| 1019 | return new SessionStorage($c->getSession()); |
||
| 1020 | }); |
||
| 1021 | $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
||
| 1022 | return new ContentSecurityPolicyManager(); |
||
| 1023 | }); |
||
| 1024 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
||
| 1025 | |||
| 1026 | $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
||
| 1027 | return new ContentSecurityPolicyNonceManager( |
||
| 1028 | $c->getCsrfTokenManager(), |
||
| 1029 | $c->getRequest() |
||
| 1030 | ); |
||
| 1031 | }); |
||
| 1032 | |||
| 1033 | $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
||
| 1034 | $config = $c->getConfig(); |
||
| 1035 | $factoryClass = $config->getSystemValue('sharing.managerFactory', ProviderFactory::class); |
||
| 1036 | /** @var \OCP\Share\IProviderFactory $factory */ |
||
| 1037 | $factory = new $factoryClass($this); |
||
| 1038 | |||
| 1039 | $manager = new \OC\Share20\Manager( |
||
| 1040 | $c->getLogger(), |
||
| 1041 | $c->getConfig(), |
||
| 1042 | $c->getSecureRandom(), |
||
| 1043 | $c->getHasher(), |
||
| 1044 | $c->getMountManager(), |
||
| 1045 | $c->getGroupManager(), |
||
| 1046 | $c->getL10N('lib'), |
||
| 1047 | $c->getL10NFactory(), |
||
| 1048 | $factory, |
||
| 1049 | $c->getUserManager(), |
||
| 1050 | $c->getLazyRootFolder(), |
||
| 1051 | $c->getEventDispatcher(), |
||
| 1052 | $c->getMailer(), |
||
| 1053 | $c->getURLGenerator(), |
||
| 1054 | $c->getThemingDefaults() |
||
| 1055 | ); |
||
| 1056 | |||
| 1057 | return $manager; |
||
| 1058 | }); |
||
| 1059 | $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
||
| 1060 | |||
| 1061 | $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
||
| 1062 | $instance = new Collaboration\Collaborators\Search($c); |
||
| 1063 | |||
| 1064 | // register default plugins |
||
| 1065 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
||
| 1066 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
||
| 1067 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
||
| 1068 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
||
| 1069 | |||
| 1070 | return $instance; |
||
| 1071 | }); |
||
| 1072 | $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
||
| 1073 | |||
| 1074 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
||
| 1075 | |||
| 1076 | $this->registerService('SettingsManager', function (Server $c) { |
||
| 1077 | $manager = new \OC\Settings\Manager( |
||
| 1078 | $c->getLogger(), |
||
| 1079 | $c->getDatabaseConnection(), |
||
| 1080 | $c->getL10N('lib'), |
||
| 1081 | $c->getConfig(), |
||
| 1082 | $c->getEncryptionManager(), |
||
| 1083 | $c->getUserManager(), |
||
| 1084 | $c->getLockingProvider(), |
||
| 1085 | $c->getRequest(), |
||
| 1086 | $c->getURLGenerator(), |
||
| 1087 | $c->query(AccountManager::class), |
||
| 1088 | $c->getGroupManager(), |
||
| 1089 | $c->getL10NFactory(), |
||
| 1090 | $c->getAppManager() |
||
| 1091 | ); |
||
| 1092 | return $manager; |
||
| 1093 | }); |
||
| 1094 | $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
||
| 1095 | return new \OC\Files\AppData\Factory( |
||
| 1096 | $c->getRootFolder(), |
||
| 1097 | $c->getSystemConfig() |
||
| 1098 | ); |
||
| 1099 | }); |
||
| 1100 | |||
| 1101 | $this->registerService('LockdownManager', function (Server $c) { |
||
| 1102 | return new LockdownManager(function () use ($c) { |
||
| 1103 | return $c->getSession(); |
||
| 1104 | }); |
||
| 1105 | }); |
||
| 1106 | |||
| 1107 | $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
||
| 1108 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
||
| 1109 | }); |
||
| 1110 | |||
| 1111 | $this->registerService(ICloudIdManager::class, function (Server $c) { |
||
| 1112 | return new CloudIdManager(); |
||
| 1113 | }); |
||
| 1114 | |||
| 1115 | $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
||
| 1116 | $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
||
| 1117 | |||
| 1118 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
||
| 1119 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
||
| 1120 | |||
| 1121 | $this->registerService(Defaults::class, function (Server $c) { |
||
| 1122 | return new Defaults( |
||
| 1123 | $c->getThemingDefaults() |
||
| 1124 | ); |
||
| 1125 | }); |
||
| 1126 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
||
| 1127 | |||
| 1128 | $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
||
| 1129 | return $c->query(\OCP\IUserSession::class)->getSession(); |
||
| 1130 | }); |
||
| 1131 | |||
| 1132 | $this->registerService(IShareHelper::class, function (Server $c) { |
||
| 1133 | return new ShareHelper( |
||
| 1134 | $c->query(\OCP\Share\IManager::class) |
||
| 1135 | ); |
||
| 1136 | }); |
||
| 1137 | |||
| 1138 | $this->registerService(Installer::class, function(Server $c) { |
||
| 1139 | return new Installer( |
||
| 1140 | $c->getAppFetcher(), |
||
| 1141 | $c->getHTTPClientService(), |
||
| 1142 | $c->getTempManager(), |
||
| 1143 | $c->getLogger(), |
||
| 1144 | $c->getConfig() |
||
| 1145 | ); |
||
| 1146 | }); |
||
| 1147 | |||
| 1148 | $this->registerService(IApiFactory::class, function(Server $c) { |
||
| 1149 | return new ApiFactory($c->getHTTPClientService()); |
||
| 1150 | }); |
||
| 1151 | |||
| 1152 | $this->registerService(IInstanceFactory::class, function(Server $c) { |
||
| 1153 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 1154 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
||
| 1155 | }); |
||
| 1156 | |||
| 1157 | $this->registerService(IContactsStore::class, function(Server $c) { |
||
| 1158 | return new ContactsStore( |
||
| 1159 | $c->getContactsManager(), |
||
| 1160 | $c->getConfig(), |
||
| 1161 | $c->getUserManager(), |
||
| 1162 | $c->getGroupManager() |
||
| 1163 | ); |
||
| 1164 | }); |
||
| 1165 | $this->registerAlias(IContactsStore::class, ContactsStore::class); |
||
| 1166 | |||
| 1167 | $this->connectDispatcher(); |
||
| 1168 | } |
||
| 1169 | |||
| 1170 | /** |
||
| 1171 | * @return \OCP\Calendar\IManager |
||
| 1172 | */ |
||
| 1173 | public function getCalendarManager() { |
||
| 1174 | return $this->query('CalendarManager'); |
||
| 1175 | } |
||
| 1176 | |||
| 1177 | private function connectDispatcher() { |
||
| 1178 | $dispatcher = $this->getEventDispatcher(); |
||
| 1179 | |||
| 1180 | // Delete avatar on user deletion |
||
| 1181 | $dispatcher->addListener('OCP\IUser::preDelete', function(GenericEvent $e) { |
||
| 1182 | $logger = $this->getLogger(); |
||
| 1183 | $manager = $this->getAvatarManager(); |
||
| 1184 | /** @var IUser $user */ |
||
| 1185 | $user = $e->getSubject(); |
||
| 1186 | |||
| 1187 | try { |
||
| 1188 | $avatar = $manager->getAvatar($user->getUID()); |
||
| 1189 | $avatar->remove(); |
||
| 1190 | } catch (NotFoundException $e) { |
||
| 1191 | // no avatar to remove |
||
| 1192 | } catch (\Exception $e) { |
||
| 1193 | // Ignore exceptions |
||
| 1194 | $logger->info('Could not cleanup avatar of ' . $user->getUID()); |
||
| 1195 | } |
||
| 1196 | }); |
||
| 1197 | |||
| 1198 | $dispatcher->addListener('OCP\IUser::changeUser', function (GenericEvent $e) { |
||
| 1199 | $manager = $this->getAvatarManager(); |
||
| 1200 | /** @var IUser $user */ |
||
| 1201 | $user = $e->getSubject(); |
||
| 1202 | $feature = $e->getArgument('feature'); |
||
| 1203 | $oldValue = $e->getArgument('oldValue'); |
||
| 1204 | $value = $e->getArgument('value'); |
||
| 1205 | |||
| 1206 | try { |
||
| 1207 | $avatar = $manager->getAvatar($user->getUID()); |
||
| 1208 | $avatar->userChanged($feature, $oldValue, $value); |
||
| 1209 | } catch (NotFoundException $e) { |
||
| 1210 | // no avatar to remove |
||
| 1211 | } |
||
| 1212 | }); |
||
| 1213 | } |
||
| 1214 | |||
| 1215 | /** |
||
| 1216 | * @return \OCP\Contacts\IManager |
||
| 1217 | */ |
||
| 1218 | public function getContactsManager() { |
||
| 1219 | return $this->query('ContactsManager'); |
||
| 1220 | } |
||
| 1221 | |||
| 1222 | /** |
||
| 1223 | * @return \OC\Encryption\Manager |
||
| 1224 | */ |
||
| 1225 | public function getEncryptionManager() { |
||
| 1226 | return $this->query('EncryptionManager'); |
||
| 1227 | } |
||
| 1228 | |||
| 1229 | /** |
||
| 1230 | * @return \OC\Encryption\File |
||
| 1231 | */ |
||
| 1232 | public function getEncryptionFilesHelper() { |
||
| 1233 | return $this->query('EncryptionFileHelper'); |
||
| 1234 | } |
||
| 1235 | |||
| 1236 | /** |
||
| 1237 | * @return \OCP\Encryption\Keys\IStorage |
||
| 1238 | */ |
||
| 1239 | public function getEncryptionKeyStorage() { |
||
| 1240 | return $this->query('EncryptionKeyStorage'); |
||
| 1241 | } |
||
| 1242 | |||
| 1243 | /** |
||
| 1244 | * The current request object holding all information about the request |
||
| 1245 | * currently being processed is returned from this method. |
||
| 1246 | * In case the current execution was not initiated by a web request null is returned |
||
| 1247 | * |
||
| 1248 | * @return \OCP\IRequest |
||
| 1249 | */ |
||
| 1250 | public function getRequest() { |
||
| 1251 | return $this->query('Request'); |
||
| 1252 | } |
||
| 1253 | |||
| 1254 | /** |
||
| 1255 | * Returns the preview manager which can create preview images for a given file |
||
| 1256 | * |
||
| 1257 | * @return \OCP\IPreview |
||
| 1258 | */ |
||
| 1259 | public function getPreviewManager() { |
||
| 1260 | return $this->query('PreviewManager'); |
||
| 1261 | } |
||
| 1262 | |||
| 1263 | /** |
||
| 1264 | * Returns the tag manager which can get and set tags for different object types |
||
| 1265 | * |
||
| 1266 | * @see \OCP\ITagManager::load() |
||
| 1267 | * @return \OCP\ITagManager |
||
| 1268 | */ |
||
| 1269 | public function getTagManager() { |
||
| 1270 | return $this->query('TagManager'); |
||
| 1271 | } |
||
| 1272 | |||
| 1273 | /** |
||
| 1274 | * Returns the system-tag manager |
||
| 1275 | * |
||
| 1276 | * @return \OCP\SystemTag\ISystemTagManager |
||
| 1277 | * |
||
| 1278 | * @since 9.0.0 |
||
| 1279 | */ |
||
| 1280 | public function getSystemTagManager() { |
||
| 1281 | return $this->query('SystemTagManager'); |
||
| 1282 | } |
||
| 1283 | |||
| 1284 | /** |
||
| 1285 | * Returns the system-tag object mapper |
||
| 1286 | * |
||
| 1287 | * @return \OCP\SystemTag\ISystemTagObjectMapper |
||
| 1288 | * |
||
| 1289 | * @since 9.0.0 |
||
| 1290 | */ |
||
| 1291 | public function getSystemTagObjectMapper() { |
||
| 1292 | return $this->query('SystemTagObjectMapper'); |
||
| 1293 | } |
||
| 1294 | |||
| 1295 | /** |
||
| 1296 | * Returns the avatar manager, used for avatar functionality |
||
| 1297 | * |
||
| 1298 | * @return \OCP\IAvatarManager |
||
| 1299 | */ |
||
| 1300 | public function getAvatarManager() { |
||
| 1301 | return $this->query('AvatarManager'); |
||
| 1302 | } |
||
| 1303 | |||
| 1304 | /** |
||
| 1305 | * Returns the root folder of ownCloud's data directory |
||
| 1306 | * |
||
| 1307 | * @return \OCP\Files\IRootFolder |
||
| 1308 | */ |
||
| 1309 | public function getRootFolder() { |
||
| 1310 | return $this->query('LazyRootFolder'); |
||
| 1311 | } |
||
| 1312 | |||
| 1313 | /** |
||
| 1314 | * Returns the root folder of ownCloud's data directory |
||
| 1315 | * This is the lazy variant so this gets only initialized once it |
||
| 1316 | * is actually used. |
||
| 1317 | * |
||
| 1318 | * @return \OCP\Files\IRootFolder |
||
| 1319 | */ |
||
| 1320 | public function getLazyRootFolder() { |
||
| 1321 | return $this->query('LazyRootFolder'); |
||
| 1322 | } |
||
| 1323 | |||
| 1324 | /** |
||
| 1325 | * Returns a view to ownCloud's files folder |
||
| 1326 | * |
||
| 1327 | * @param string $userId user ID |
||
| 1328 | * @return \OCP\Files\Folder|null |
||
| 1329 | */ |
||
| 1330 | public function getUserFolder($userId = null) { |
||
| 1331 | View Code Duplication | if ($userId === null) { |
|
| 1332 | $user = $this->getUserSession()->getUser(); |
||
| 1333 | if (!$user) { |
||
| 1334 | return null; |
||
| 1335 | } |
||
| 1336 | $userId = $user->getUID(); |
||
| 1337 | } |
||
| 1338 | $root = $this->getRootFolder(); |
||
| 1339 | return $root->getUserFolder($userId); |
||
| 1340 | } |
||
| 1341 | |||
| 1342 | /** |
||
| 1343 | * Returns an app-specific view in ownClouds data directory |
||
| 1344 | * |
||
| 1345 | * @return \OCP\Files\Folder |
||
| 1346 | * @deprecated since 9.2.0 use IAppData |
||
| 1347 | */ |
||
| 1348 | public function getAppFolder() { |
||
| 1349 | $dir = '/' . \OC_App::getCurrentApp(); |
||
| 1350 | $root = $this->getRootFolder(); |
||
| 1351 | if (!$root->nodeExists($dir)) { |
||
| 1352 | $folder = $root->newFolder($dir); |
||
| 1353 | } else { |
||
| 1354 | $folder = $root->get($dir); |
||
| 1355 | } |
||
| 1356 | return $folder; |
||
| 1357 | } |
||
| 1358 | |||
| 1359 | /** |
||
| 1360 | * @return \OC\User\Manager |
||
| 1361 | */ |
||
| 1362 | public function getUserManager() { |
||
| 1363 | return $this->query('UserManager'); |
||
| 1364 | } |
||
| 1365 | |||
| 1366 | /** |
||
| 1367 | * @return \OC\Group\Manager |
||
| 1368 | */ |
||
| 1369 | public function getGroupManager() { |
||
| 1370 | return $this->query('GroupManager'); |
||
| 1371 | } |
||
| 1372 | |||
| 1373 | /** |
||
| 1374 | * @return \OC\User\Session |
||
| 1375 | */ |
||
| 1376 | public function getUserSession() { |
||
| 1377 | return $this->query('UserSession'); |
||
| 1378 | } |
||
| 1379 | |||
| 1380 | /** |
||
| 1381 | * @return \OCP\ISession |
||
| 1382 | */ |
||
| 1383 | public function getSession() { |
||
| 1384 | return $this->query('UserSession')->getSession(); |
||
| 1385 | } |
||
| 1386 | |||
| 1387 | /** |
||
| 1388 | * @param \OCP\ISession $session |
||
| 1389 | */ |
||
| 1390 | public function setSession(\OCP\ISession $session) { |
||
| 1391 | $this->query(SessionStorage::class)->setSession($session); |
||
| 1392 | $this->query('UserSession')->setSession($session); |
||
| 1393 | $this->query(Store::class)->setSession($session); |
||
| 1394 | } |
||
| 1395 | |||
| 1396 | /** |
||
| 1397 | * @return \OC\Authentication\TwoFactorAuth\Manager |
||
| 1398 | */ |
||
| 1399 | public function getTwoFactorAuthManager() { |
||
| 1400 | return $this->query('\OC\Authentication\TwoFactorAuth\Manager'); |
||
| 1401 | } |
||
| 1402 | |||
| 1403 | /** |
||
| 1404 | * @return \OC\NavigationManager |
||
| 1405 | */ |
||
| 1406 | public function getNavigationManager() { |
||
| 1407 | return $this->query('NavigationManager'); |
||
| 1408 | } |
||
| 1409 | |||
| 1410 | /** |
||
| 1411 | * @return \OCP\IConfig |
||
| 1412 | */ |
||
| 1413 | public function getConfig() { |
||
| 1414 | return $this->query('AllConfig'); |
||
| 1415 | } |
||
| 1416 | |||
| 1417 | /** |
||
| 1418 | * @return \OC\SystemConfig |
||
| 1419 | */ |
||
| 1420 | public function getSystemConfig() { |
||
| 1421 | return $this->query('SystemConfig'); |
||
| 1422 | } |
||
| 1423 | |||
| 1424 | /** |
||
| 1425 | * Returns the app config manager |
||
| 1426 | * |
||
| 1427 | * @return \OCP\IAppConfig |
||
| 1428 | */ |
||
| 1429 | public function getAppConfig() { |
||
| 1430 | return $this->query('AppConfig'); |
||
| 1431 | } |
||
| 1432 | |||
| 1433 | /** |
||
| 1434 | * @return \OCP\L10N\IFactory |
||
| 1435 | */ |
||
| 1436 | public function getL10NFactory() { |
||
| 1437 | return $this->query('L10NFactory'); |
||
| 1438 | } |
||
| 1439 | |||
| 1440 | /** |
||
| 1441 | * get an L10N instance |
||
| 1442 | * |
||
| 1443 | * @param string $app appid |
||
| 1444 | * @param string $lang |
||
| 1445 | * @return IL10N |
||
| 1446 | */ |
||
| 1447 | public function getL10N($app, $lang = null) { |
||
| 1448 | return $this->getL10NFactory()->get($app, $lang); |
||
| 1449 | } |
||
| 1450 | |||
| 1451 | /** |
||
| 1452 | * @return \OCP\IURLGenerator |
||
| 1453 | */ |
||
| 1454 | public function getURLGenerator() { |
||
| 1455 | return $this->query('URLGenerator'); |
||
| 1456 | } |
||
| 1457 | |||
| 1458 | /** |
||
| 1459 | * @return AppFetcher |
||
| 1460 | */ |
||
| 1461 | public function getAppFetcher() { |
||
| 1464 | |||
| 1465 | /** |
||
| 1466 | * Returns an ICache instance. Since 8.1.0 it returns a fake cache. Use |
||
| 1467 | * getMemCacheFactory() instead. |
||
| 1468 | * |
||
| 1469 | * @return \OCP\ICache |
||
| 1470 | * @deprecated 8.1.0 use getMemCacheFactory to obtain a proper cache |
||
| 1471 | */ |
||
| 1472 | public function getCache() { |
||
| 1475 | |||
| 1476 | /** |
||
| 1477 | * Returns an \OCP\CacheFactory instance |
||
| 1478 | * |
||
| 1479 | * @return \OCP\ICacheFactory |
||
| 1480 | */ |
||
| 1481 | public function getMemCacheFactory() { |
||
| 1484 | |||
| 1485 | /** |
||
| 1486 | * Returns an \OC\RedisFactory instance |
||
| 1487 | * |
||
| 1488 | * @return \OC\RedisFactory |
||
| 1489 | */ |
||
| 1490 | public function getGetRedisFactory() { |
||
| 1493 | |||
| 1494 | |||
| 1495 | /** |
||
| 1496 | * Returns the current session |
||
| 1497 | * |
||
| 1498 | * @return \OCP\IDBConnection |
||
| 1499 | */ |
||
| 1500 | public function getDatabaseConnection() { |
||
| 1503 | |||
| 1504 | /** |
||
| 1505 | * Returns the activity manager |
||
| 1506 | * |
||
| 1507 | * @return \OCP\Activity\IManager |
||
| 1508 | */ |
||
| 1509 | public function getActivityManager() { |
||
| 1512 | |||
| 1513 | /** |
||
| 1514 | * Returns an job list for controlling background jobs |
||
| 1515 | * |
||
| 1516 | * @return \OCP\BackgroundJob\IJobList |
||
| 1517 | */ |
||
| 1518 | public function getJobList() { |
||
| 1521 | |||
| 1522 | /** |
||
| 1523 | * Returns a logger instance |
||
| 1524 | * |
||
| 1525 | * @return \OCP\ILogger |
||
| 1526 | */ |
||
| 1527 | public function getLogger() { |
||
| 1530 | |||
| 1531 | /** |
||
| 1532 | * Returns a router for generating and matching urls |
||
| 1533 | * |
||
| 1534 | * @return \OCP\Route\IRouter |
||
| 1535 | */ |
||
| 1536 | public function getRouter() { |
||
| 1539 | |||
| 1540 | /** |
||
| 1541 | * Returns a search instance |
||
| 1542 | * |
||
| 1543 | * @return \OCP\ISearch |
||
| 1544 | */ |
||
| 1545 | public function getSearch() { |
||
| 1548 | |||
| 1549 | /** |
||
| 1550 | * Returns a SecureRandom instance |
||
| 1551 | * |
||
| 1552 | * @return \OCP\Security\ISecureRandom |
||
| 1553 | */ |
||
| 1554 | public function getSecureRandom() { |
||
| 1557 | |||
| 1558 | /** |
||
| 1559 | * Returns a Crypto instance |
||
| 1560 | * |
||
| 1561 | * @return \OCP\Security\ICrypto |
||
| 1562 | */ |
||
| 1563 | public function getCrypto() { |
||
| 1566 | |||
| 1567 | /** |
||
| 1568 | * Returns a Hasher instance |
||
| 1569 | * |
||
| 1570 | * @return \OCP\Security\IHasher |
||
| 1571 | */ |
||
| 1572 | public function getHasher() { |
||
| 1575 | |||
| 1576 | /** |
||
| 1577 | * Returns a CredentialsManager instance |
||
| 1578 | * |
||
| 1579 | * @return \OCP\Security\ICredentialsManager |
||
| 1580 | */ |
||
| 1581 | public function getCredentialsManager() { |
||
| 1584 | |||
| 1585 | /** |
||
| 1586 | * Returns an instance of the HTTP helper class |
||
| 1587 | * |
||
| 1588 | * @deprecated Use getHTTPClientService() |
||
| 1589 | * @return \OC\HTTPHelper |
||
| 1590 | */ |
||
| 1591 | public function getHTTPHelper() { |
||
| 1594 | |||
| 1595 | /** |
||
| 1596 | * Get the certificate manager for the user |
||
| 1597 | * |
||
| 1598 | * @param string $userId (optional) if not specified the current loggedin user is used, use null to get the system certificate manager |
||
| 1599 | * @return \OCP\ICertificateManager | null if $uid is null and no user is logged in |
||
| 1600 | */ |
||
| 1601 | public function getCertificateManager($userId = '') { |
||
| 1618 | |||
| 1619 | /** |
||
| 1620 | * Returns an instance of the HTTP client service |
||
| 1621 | * |
||
| 1622 | * @return \OCP\Http\Client\IClientService |
||
| 1623 | */ |
||
| 1624 | public function getHTTPClientService() { |
||
| 1627 | |||
| 1628 | /** |
||
| 1629 | * Create a new event source |
||
| 1630 | * |
||
| 1631 | * @return \OCP\IEventSource |
||
| 1632 | */ |
||
| 1633 | public function createEventSource() { |
||
| 1636 | |||
| 1637 | /** |
||
| 1638 | * Get the active event logger |
||
| 1639 | * |
||
| 1640 | * The returned logger only logs data when debug mode is enabled |
||
| 1641 | * |
||
| 1642 | * @return \OCP\Diagnostics\IEventLogger |
||
| 1643 | */ |
||
| 1644 | public function getEventLogger() { |
||
| 1647 | |||
| 1648 | /** |
||
| 1649 | * Get the active query logger |
||
| 1650 | * |
||
| 1651 | * The returned logger only logs data when debug mode is enabled |
||
| 1652 | * |
||
| 1653 | * @return \OCP\Diagnostics\IQueryLogger |
||
| 1654 | */ |
||
| 1655 | public function getQueryLogger() { |
||
| 1658 | |||
| 1659 | /** |
||
| 1660 | * Get the manager for temporary files and folders |
||
| 1661 | * |
||
| 1662 | * @return \OCP\ITempManager |
||
| 1663 | */ |
||
| 1664 | public function getTempManager() { |
||
| 1667 | |||
| 1668 | /** |
||
| 1669 | * Get the app manager |
||
| 1670 | * |
||
| 1671 | * @return \OCP\App\IAppManager |
||
| 1672 | */ |
||
| 1673 | public function getAppManager() { |
||
| 1676 | |||
| 1677 | /** |
||
| 1678 | * Creates a new mailer |
||
| 1679 | * |
||
| 1680 | * @return \OCP\Mail\IMailer |
||
| 1681 | */ |
||
| 1682 | public function getMailer() { |
||
| 1685 | |||
| 1686 | /** |
||
| 1687 | * Get the webroot |
||
| 1688 | * |
||
| 1689 | * @return string |
||
| 1690 | */ |
||
| 1691 | public function getWebRoot() { |
||
| 1694 | |||
| 1695 | /** |
||
| 1696 | * @return \OC\OCSClient |
||
| 1697 | */ |
||
| 1698 | public function getOcsClient() { |
||
| 1701 | |||
| 1702 | /** |
||
| 1703 | * @return \OCP\IDateTimeZone |
||
| 1704 | */ |
||
| 1705 | public function getDateTimeZone() { |
||
| 1708 | |||
| 1709 | /** |
||
| 1710 | * @return \OCP\IDateTimeFormatter |
||
| 1711 | */ |
||
| 1712 | public function getDateTimeFormatter() { |
||
| 1715 | |||
| 1716 | /** |
||
| 1717 | * @return \OCP\Files\Config\IMountProviderCollection |
||
| 1718 | */ |
||
| 1719 | public function getMountProviderCollection() { |
||
| 1722 | |||
| 1723 | /** |
||
| 1724 | * Get the IniWrapper |
||
| 1725 | * |
||
| 1726 | * @return IniGetWrapper |
||
| 1727 | */ |
||
| 1728 | public function getIniWrapper() { |
||
| 1731 | |||
| 1732 | /** |
||
| 1733 | * @return \OCP\Command\IBus |
||
| 1734 | */ |
||
| 1735 | public function getCommandBus() { |
||
| 1738 | |||
| 1739 | /** |
||
| 1740 | * Get the trusted domain helper |
||
| 1741 | * |
||
| 1742 | * @return TrustedDomainHelper |
||
| 1743 | */ |
||
| 1744 | public function getTrustedDomainHelper() { |
||
| 1747 | |||
| 1748 | /** |
||
| 1749 | * Get the locking provider |
||
| 1750 | * |
||
| 1751 | * @return \OCP\Lock\ILockingProvider |
||
| 1752 | * @since 8.1.0 |
||
| 1753 | */ |
||
| 1754 | public function getLockingProvider() { |
||
| 1757 | |||
| 1758 | /** |
||
| 1759 | * @return \OCP\Files\Mount\IMountManager |
||
| 1760 | **/ |
||
| 1761 | function getMountManager() { |
||
| 1764 | |||
| 1765 | /** @return \OCP\Files\Config\IUserMountCache */ |
||
| 1766 | function getUserMountCache() { |
||
| 1769 | |||
| 1770 | /** |
||
| 1771 | * Get the MimeTypeDetector |
||
| 1772 | * |
||
| 1773 | * @return \OCP\Files\IMimeTypeDetector |
||
| 1774 | */ |
||
| 1775 | public function getMimeTypeDetector() { |
||
| 1778 | |||
| 1779 | /** |
||
| 1780 | * Get the MimeTypeLoader |
||
| 1781 | * |
||
| 1782 | * @return \OCP\Files\IMimeTypeLoader |
||
| 1783 | */ |
||
| 1784 | public function getMimeTypeLoader() { |
||
| 1787 | |||
| 1788 | /** |
||
| 1789 | * Get the manager of all the capabilities |
||
| 1790 | * |
||
| 1791 | * @return \OC\CapabilitiesManager |
||
| 1792 | */ |
||
| 1793 | public function getCapabilitiesManager() { |
||
| 1796 | |||
| 1797 | /** |
||
| 1798 | * Get the EventDispatcher |
||
| 1799 | * |
||
| 1800 | * @return EventDispatcherInterface |
||
| 1801 | * @since 8.2.0 |
||
| 1802 | */ |
||
| 1803 | public function getEventDispatcher() { |
||
| 1806 | |||
| 1807 | /** |
||
| 1808 | * Get the Notification Manager |
||
| 1809 | * |
||
| 1810 | * @return \OCP\Notification\IManager |
||
| 1811 | * @since 8.2.0 |
||
| 1812 | */ |
||
| 1813 | public function getNotificationManager() { |
||
| 1816 | |||
| 1817 | /** |
||
| 1818 | * @return \OCP\Comments\ICommentsManager |
||
| 1819 | */ |
||
| 1820 | public function getCommentsManager() { |
||
| 1823 | |||
| 1824 | /** |
||
| 1825 | * @return \OCA\Theming\ThemingDefaults |
||
| 1826 | */ |
||
| 1827 | public function getThemingDefaults() { |
||
| 1830 | |||
| 1831 | /** |
||
| 1832 | * @return \OC\IntegrityCheck\Checker |
||
| 1833 | */ |
||
| 1834 | public function getIntegrityCodeChecker() { |
||
| 1837 | |||
| 1838 | /** |
||
| 1839 | * @return \OC\Session\CryptoWrapper |
||
| 1840 | */ |
||
| 1841 | public function getSessionCryptoWrapper() { |
||
| 1844 | |||
| 1845 | /** |
||
| 1846 | * @return CsrfTokenManager |
||
| 1847 | */ |
||
| 1848 | public function getCsrfTokenManager() { |
||
| 1851 | |||
| 1852 | /** |
||
| 1853 | * @return Throttler |
||
| 1854 | */ |
||
| 1855 | public function getBruteForceThrottler() { |
||
| 1858 | |||
| 1859 | /** |
||
| 1860 | * @return IContentSecurityPolicyManager |
||
| 1861 | */ |
||
| 1862 | public function getContentSecurityPolicyManager() { |
||
| 1865 | |||
| 1866 | /** |
||
| 1867 | * @return ContentSecurityPolicyNonceManager |
||
| 1868 | */ |
||
| 1869 | public function getContentSecurityPolicyNonceManager() { |
||
| 1872 | |||
| 1873 | /** |
||
| 1874 | * Not a public API as of 8.2, wait for 9.0 |
||
| 1875 | * |
||
| 1876 | * @return \OCA\Files_External\Service\BackendService |
||
| 1877 | */ |
||
| 1878 | public function getStoragesBackendService() { |
||
| 1881 | |||
| 1882 | /** |
||
| 1883 | * Not a public API as of 8.2, wait for 9.0 |
||
| 1884 | * |
||
| 1885 | * @return \OCA\Files_External\Service\GlobalStoragesService |
||
| 1886 | */ |
||
| 1887 | public function getGlobalStoragesService() { |
||
| 1890 | |||
| 1891 | /** |
||
| 1892 | * Not a public API as of 8.2, wait for 9.0 |
||
| 1893 | * |
||
| 1894 | * @return \OCA\Files_External\Service\UserGlobalStoragesService |
||
| 1895 | */ |
||
| 1896 | public function getUserGlobalStoragesService() { |
||
| 1899 | |||
| 1900 | /** |
||
| 1901 | * Not a public API as of 8.2, wait for 9.0 |
||
| 1902 | * |
||
| 1903 | * @return \OCA\Files_External\Service\UserStoragesService |
||
| 1904 | */ |
||
| 1905 | public function getUserStoragesService() { |
||
| 1908 | |||
| 1909 | /** |
||
| 1910 | * @return \OCP\Share\IManager |
||
| 1911 | */ |
||
| 1912 | public function getShareManager() { |
||
| 1915 | |||
| 1916 | /** |
||
| 1917 | * @return \OCP\Collaboration\Collaborators\ISearch |
||
| 1918 | */ |
||
| 1919 | public function getCollaboratorSearch() { |
||
| 1922 | |||
| 1923 | /** |
||
| 1924 | * @return \OCP\Collaboration\AutoComplete\IManager |
||
| 1925 | */ |
||
| 1926 | public function getAutoCompleteManager(){ |
||
| 1929 | |||
| 1930 | /** |
||
| 1931 | * Returns the LDAP Provider |
||
| 1932 | * |
||
| 1933 | * @return \OCP\LDAP\ILDAPProvider |
||
| 1934 | */ |
||
| 1935 | public function getLDAPProvider() { |
||
| 1938 | |||
| 1939 | /** |
||
| 1940 | * @return \OCP\Settings\IManager |
||
| 1941 | */ |
||
| 1942 | public function getSettingsManager() { |
||
| 1945 | |||
| 1946 | /** |
||
| 1947 | * @return \OCP\Files\IAppData |
||
| 1948 | */ |
||
| 1949 | public function getAppDataDir($app) { |
||
| 1954 | |||
| 1955 | /** |
||
| 1956 | * @return \OCP\Lockdown\ILockdownManager |
||
| 1957 | */ |
||
| 1958 | public function getLockdownManager() { |
||
| 1961 | |||
| 1962 | /** |
||
| 1963 | * @return \OCP\Federation\ICloudIdManager |
||
| 1964 | */ |
||
| 1965 | public function getCloudIdManager() { |
||
| 1968 | |||
| 1969 | /** |
||
| 1970 | * @return \OCP\Remote\Api\IApiFactory |
||
| 1971 | */ |
||
| 1972 | public function getRemoteApiFactory() { |
||
| 1975 | |||
| 1976 | /** |
||
| 1977 | * @return \OCP\Remote\IInstanceFactory |
||
| 1978 | */ |
||
| 1979 | public function getRemoteInstanceFactory() { |
||
| 1982 | } |
||
| 1983 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: