| Conditions | 33 |
| Paths | 1 |
| Total Lines | 994 |
| Code Lines | 675 |
| Lines | 66 |
| Ratio | 6.64 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 157 | public function __construct($webRoot, \OC\Config $config) { |
||
| 158 | parent::__construct(); |
||
| 159 | $this->webRoot = $webRoot; |
||
| 160 | |||
| 161 | $this->registerService(\OCP\IServerContainer::class, function (IServerContainer $c) { |
||
| 162 | return $c; |
||
| 163 | }); |
||
| 164 | |||
| 165 | $this->registerAlias(\OCP\Calendar\IManager::class, \OC\Calendar\Manager::class); |
||
| 166 | $this->registerAlias('CalendarManager', \OC\Calendar\Manager::class); |
||
| 167 | |||
| 168 | $this->registerAlias(\OCP\Contacts\IManager::class, \OC\ContactsManager::class); |
||
| 169 | $this->registerAlias('ContactsManager', \OCP\Contacts\IManager::class); |
||
| 170 | |||
| 171 | $this->registerAlias(IActionFactory::class, ActionFactory::class); |
||
| 172 | |||
| 173 | |||
| 174 | $this->registerService(\OCP\IPreview::class, function (Server $c) { |
||
| 175 | return new PreviewManager( |
||
| 176 | $c->getConfig(), |
||
| 177 | $c->getRootFolder(), |
||
| 178 | $c->getAppDataDir('preview'), |
||
| 179 | $c->getEventDispatcher(), |
||
| 180 | $c->getSession()->get('user_id') |
||
| 181 | ); |
||
| 182 | }); |
||
| 183 | $this->registerAlias('PreviewManager', \OCP\IPreview::class); |
||
| 184 | |||
| 185 | $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
||
| 186 | return new \OC\Preview\Watcher( |
||
| 187 | $c->getAppDataDir('preview') |
||
| 188 | ); |
||
| 189 | }); |
||
| 190 | |||
| 191 | $this->registerService('EncryptionManager', function (Server $c) { |
||
| 192 | $view = new View(); |
||
| 193 | $util = new Encryption\Util( |
||
| 194 | $view, |
||
| 195 | $c->getUserManager(), |
||
| 196 | $c->getGroupManager(), |
||
| 197 | $c->getConfig() |
||
| 198 | ); |
||
| 199 | return new Encryption\Manager( |
||
| 200 | $c->getConfig(), |
||
| 201 | $c->getLogger(), |
||
| 202 | $c->getL10N('core'), |
||
| 203 | new View(), |
||
| 204 | $util, |
||
| 205 | new ArrayCache() |
||
| 206 | ); |
||
| 207 | }); |
||
| 208 | |||
| 209 | View Code Duplication | $this->registerService('EncryptionFileHelper', function (Server $c) { |
|
| 210 | $util = new Encryption\Util( |
||
| 211 | new View(), |
||
| 212 | $c->getUserManager(), |
||
| 213 | $c->getGroupManager(), |
||
| 214 | $c->getConfig() |
||
| 215 | ); |
||
| 216 | return new Encryption\File( |
||
| 217 | $util, |
||
| 218 | $c->getRootFolder(), |
||
| 219 | $c->getShareManager() |
||
| 220 | ); |
||
| 221 | }); |
||
| 222 | |||
| 223 | View Code Duplication | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
|
| 224 | $view = new View(); |
||
| 225 | $util = new Encryption\Util( |
||
| 226 | $view, |
||
| 227 | $c->getUserManager(), |
||
| 228 | $c->getGroupManager(), |
||
| 229 | $c->getConfig() |
||
| 230 | ); |
||
| 231 | |||
| 232 | return new Encryption\Keys\Storage($view, $util); |
||
| 233 | }); |
||
| 234 | $this->registerService('TagMapper', function (Server $c) { |
||
| 235 | return new TagMapper($c->getDatabaseConnection()); |
||
| 236 | }); |
||
| 237 | |||
| 238 | $this->registerService(\OCP\ITagManager::class, function (Server $c) { |
||
| 239 | $tagMapper = $c->query('TagMapper'); |
||
| 240 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 241 | }); |
||
| 242 | $this->registerAlias('TagManager', \OCP\ITagManager::class); |
||
| 243 | |||
| 244 | $this->registerService('SystemTagManagerFactory', function (Server $c) { |
||
| 245 | $config = $c->getConfig(); |
||
| 246 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
||
| 247 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
||
| 248 | $factory = new $factoryClass($this); |
||
| 249 | return $factory; |
||
| 250 | }); |
||
| 251 | $this->registerService(\OCP\SystemTag\ISystemTagManager::class, function (Server $c) { |
||
| 252 | return $c->query('SystemTagManagerFactory')->getManager(); |
||
| 253 | }); |
||
| 254 | $this->registerAlias('SystemTagManager', \OCP\SystemTag\ISystemTagManager::class); |
||
| 255 | |||
| 256 | $this->registerService(\OCP\SystemTag\ISystemTagObjectMapper::class, function (Server $c) { |
||
| 257 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
||
| 258 | }); |
||
| 259 | $this->registerService('RootFolder', function (Server $c) { |
||
| 260 | $manager = \OC\Files\Filesystem::getMountManager(null); |
||
| 261 | $view = new View(); |
||
| 262 | $root = new Root( |
||
| 263 | $manager, |
||
| 264 | $view, |
||
| 265 | null, |
||
| 266 | $c->getUserMountCache(), |
||
| 267 | $this->getLogger(), |
||
| 268 | $this->getUserManager() |
||
| 269 | ); |
||
| 270 | $connector = new HookConnector($root, $view); |
||
| 271 | $connector->viewToNode(); |
||
| 272 | |||
| 273 | $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
||
| 274 | $previewConnector->connectWatcher(); |
||
| 275 | |||
| 276 | return $root; |
||
| 277 | }); |
||
| 278 | $this->registerAlias('SystemTagObjectMapper', \OCP\SystemTag\ISystemTagObjectMapper::class); |
||
| 279 | |||
| 280 | $this->registerService(\OCP\Files\IRootFolder::class, function (Server $c) { |
||
| 281 | return new LazyRoot(function () use ($c) { |
||
| 282 | return $c->query('RootFolder'); |
||
| 283 | }); |
||
| 284 | }); |
||
| 285 | $this->registerAlias('LazyRootFolder', \OCP\Files\IRootFolder::class); |
||
| 286 | |||
| 287 | $this->registerService(\OCP\IUserManager::class, function (Server $c) { |
||
| 288 | $config = $c->getConfig(); |
||
| 289 | return new \OC\User\Manager($config); |
||
| 290 | }); |
||
| 291 | $this->registerAlias('UserManager', \OCP\IUserManager::class); |
||
| 292 | |||
| 293 | $this->registerService(\OCP\IGroupManager::class, function (Server $c) { |
||
| 294 | $groupManager = new \OC\Group\Manager($this->getUserManager(), $this->getLogger()); |
||
| 295 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 296 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
||
| 297 | }); |
||
| 298 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 299 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
||
| 300 | }); |
||
| 301 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 302 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
||
| 303 | }); |
||
| 304 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 305 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
||
| 306 | }); |
||
| 307 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 308 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 309 | }); |
||
| 310 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 311 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 312 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 313 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 314 | }); |
||
| 315 | return $groupManager; |
||
| 316 | }); |
||
| 317 | $this->registerAlias('GroupManager', \OCP\IGroupManager::class); |
||
| 318 | |||
| 319 | $this->registerService(Store::class, function (Server $c) { |
||
| 320 | $session = $c->getSession(); |
||
| 321 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 322 | $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
||
| 323 | } else { |
||
| 324 | $tokenProvider = null; |
||
| 325 | } |
||
| 326 | $logger = $c->getLogger(); |
||
| 327 | return new Store($session, $logger, $tokenProvider); |
||
| 328 | }); |
||
| 329 | $this->registerAlias(IStore::class, Store::class); |
||
| 330 | $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
||
| 331 | $dbConnection = $c->getDatabaseConnection(); |
||
| 332 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
||
| 333 | }); |
||
| 334 | $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
||
| 335 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
||
| 336 | $crypto = $c->getCrypto(); |
||
| 337 | $config = $c->getConfig(); |
||
| 338 | $logger = $c->getLogger(); |
||
| 339 | $timeFactory = new TimeFactory(); |
||
| 340 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
||
| 341 | }); |
||
| 342 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
||
| 343 | |||
| 344 | $this->registerService(\OCP\IUserSession::class, function (Server $c) { |
||
| 345 | $manager = $c->getUserManager(); |
||
| 346 | $session = new \OC\Session\Memory(''); |
||
| 347 | $timeFactory = new TimeFactory(); |
||
| 348 | // Token providers might require a working database. This code |
||
| 349 | // might however be called when ownCloud is not yet setup. |
||
| 350 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 351 | $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
||
| 352 | } else { |
||
| 353 | $defaultTokenProvider = null; |
||
| 354 | } |
||
| 355 | |||
| 356 | $dispatcher = $c->getEventDispatcher(); |
||
| 357 | |||
| 358 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom(), $c->getLockdownManager()); |
||
| 359 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 360 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 361 | }); |
||
| 362 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 363 | /** @var $user \OC\User\User */ |
||
| 364 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
||
| 365 | }); |
||
| 366 | $userSession->listen('\OC\User', 'preDelete', function ($user) use ($dispatcher) { |
||
| 367 | /** @var $user \OC\User\User */ |
||
| 368 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
||
| 369 | $dispatcher->dispatch('OCP\IUser::preDelete', new GenericEvent($user)); |
||
| 370 | }); |
||
| 371 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 372 | /** @var $user \OC\User\User */ |
||
| 373 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
||
| 374 | }); |
||
| 375 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 376 | /** @var $user \OC\User\User */ |
||
| 377 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 378 | }); |
||
| 379 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 380 | /** @var $user \OC\User\User */ |
||
| 381 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 382 | }); |
||
| 383 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 384 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 385 | }); |
||
| 386 | View Code Duplication | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
|
| 387 | /** @var $user \OC\User\User */ |
||
| 388 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 389 | }); |
||
| 390 | View Code Duplication | $userSession->listen('\OC\User', 'postRememberedLogin', function ($user, $password) { |
|
| 391 | /** @var $user \OC\User\User */ |
||
| 392 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 393 | }); |
||
| 394 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 395 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
| 396 | }); |
||
| 397 | $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value, $oldValue) use ($dispatcher) { |
||
| 398 | /** @var $user \OC\User\User */ |
||
| 399 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value, 'old_value' => $oldValue)); |
||
| 400 | $dispatcher->dispatch('OCP\IUser::changeUser', new GenericEvent($user, ['feature' => $feature, 'oldValue' => $oldValue, 'value' => $value])); |
||
| 401 | }); |
||
| 402 | return $userSession; |
||
| 403 | }); |
||
| 404 | $this->registerAlias('UserSession', \OCP\IUserSession::class); |
||
| 405 | |||
| 406 | $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
||
| 407 | return new \OC\Authentication\TwoFactorAuth\Manager( |
||
| 408 | $c->getAppManager(), |
||
| 409 | $c->getSession(), |
||
| 410 | $c->getConfig(), |
||
| 411 | $c->getActivityManager(), |
||
| 412 | $c->getLogger(), |
||
| 413 | $c->query(\OC\Authentication\Token\IProvider::class), |
||
| 414 | $c->query(ITimeFactory::class) |
||
| 415 | ); |
||
| 416 | }); |
||
| 417 | |||
| 418 | $this->registerAlias(\OCP\INavigationManager::class, \OC\NavigationManager::class); |
||
| 419 | $this->registerAlias('NavigationManager', \OCP\INavigationManager::class); |
||
| 420 | |||
| 421 | $this->registerService(\OC\AllConfig::class, function (Server $c) { |
||
| 422 | return new \OC\AllConfig( |
||
| 423 | $c->getSystemConfig() |
||
| 424 | ); |
||
| 425 | }); |
||
| 426 | $this->registerAlias('AllConfig', \OC\AllConfig::class); |
||
| 427 | $this->registerAlias(\OCP\IConfig::class, \OC\AllConfig::class); |
||
| 428 | |||
| 429 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
| 430 | return new \OC\SystemConfig($config); |
||
| 431 | }); |
||
| 432 | |||
| 433 | $this->registerService(\OC\AppConfig::class, function (Server $c) { |
||
| 434 | return new \OC\AppConfig($c->getDatabaseConnection()); |
||
| 435 | }); |
||
| 436 | $this->registerAlias('AppConfig', \OC\AppConfig::class); |
||
| 437 | $this->registerAlias(\OCP\IAppConfig::class, \OC\AppConfig::class); |
||
| 438 | |||
| 439 | $this->registerService(\OCP\L10N\IFactory::class, function (Server $c) { |
||
| 440 | return new \OC\L10N\Factory( |
||
| 441 | $c->getConfig(), |
||
| 442 | $c->getRequest(), |
||
| 443 | $c->getUserSession(), |
||
| 444 | \OC::$SERVERROOT |
||
| 445 | ); |
||
| 446 | }); |
||
| 447 | $this->registerAlias('L10NFactory', \OCP\L10N\IFactory::class); |
||
| 448 | |||
| 449 | $this->registerService(\OCP\IURLGenerator::class, function (Server $c) { |
||
| 450 | $config = $c->getConfig(); |
||
| 451 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 452 | $request = $c->getRequest(); |
||
| 453 | return new \OC\URLGenerator( |
||
| 454 | $config, |
||
| 455 | $cacheFactory, |
||
| 456 | $request |
||
| 457 | ); |
||
| 458 | }); |
||
| 459 | $this->registerAlias('URLGenerator', \OCP\IURLGenerator::class); |
||
| 460 | |||
| 461 | $this->registerService('AppHelper', function ($c) { |
||
| 462 | return new \OC\AppHelper(); |
||
| 463 | }); |
||
| 464 | $this->registerAlias('AppFetcher', AppFetcher::class); |
||
| 465 | $this->registerAlias('CategoryFetcher', CategoryFetcher::class); |
||
| 466 | |||
| 467 | $this->registerService(\OCP\ICache::class, function ($c) { |
||
| 468 | return new Cache\File(); |
||
| 469 | }); |
||
| 470 | $this->registerAlias('UserCache', \OCP\ICache::class); |
||
| 471 | |||
| 472 | $this->registerService(Factory::class, function (Server $c) { |
||
| 473 | |||
| 474 | $arrayCacheFactory = new \OC\Memcache\Factory('', $c->getLogger(), |
||
| 475 | '\\OC\\Memcache\\ArrayCache', |
||
| 476 | '\\OC\\Memcache\\ArrayCache', |
||
| 477 | '\\OC\\Memcache\\ArrayCache' |
||
| 478 | ); |
||
| 479 | $config = $c->getConfig(); |
||
| 480 | $request = $c->getRequest(); |
||
| 481 | $urlGenerator = new URLGenerator($config, $arrayCacheFactory, $request); |
||
| 482 | |||
| 483 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 484 | $v = \OC_App::getAppVersions(); |
||
| 485 | $v['core'] = implode(',', \OC_Util::getVersion()); |
||
| 486 | $version = implode(',', $v); |
||
| 487 | $instanceId = \OC_Util::getInstanceId(); |
||
| 488 | $path = \OC::$SERVERROOT; |
||
| 489 | $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . $urlGenerator->getBaseUrl()); |
||
| 490 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
| 491 | $config->getSystemValue('memcache.local', null), |
||
| 492 | $config->getSystemValue('memcache.distributed', null), |
||
| 493 | $config->getSystemValue('memcache.locking', null) |
||
| 494 | ); |
||
| 495 | } |
||
| 496 | return $arrayCacheFactory; |
||
| 497 | |||
| 498 | }); |
||
| 499 | $this->registerAlias('MemCacheFactory', Factory::class); |
||
| 500 | $this->registerAlias(ICacheFactory::class, Factory::class); |
||
| 501 | |||
| 502 | $this->registerService('RedisFactory', function (Server $c) { |
||
| 503 | $systemConfig = $c->getSystemConfig(); |
||
| 504 | return new RedisFactory($systemConfig); |
||
| 505 | }); |
||
| 506 | |||
| 507 | $this->registerService(\OCP\Activity\IManager::class, function (Server $c) { |
||
| 508 | return new \OC\Activity\Manager( |
||
| 509 | $c->getRequest(), |
||
| 510 | $c->getUserSession(), |
||
| 511 | $c->getConfig(), |
||
| 512 | $c->query(IValidator::class) |
||
| 513 | ); |
||
| 514 | }); |
||
| 515 | $this->registerAlias('ActivityManager', \OCP\Activity\IManager::class); |
||
| 516 | |||
| 517 | $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
||
| 518 | return new \OC\Activity\EventMerger( |
||
| 519 | $c->getL10N('lib') |
||
| 520 | ); |
||
| 521 | }); |
||
| 522 | $this->registerAlias(IValidator::class, Validator::class); |
||
| 523 | |||
| 524 | $this->registerService(\OCP\IAvatarManager::class, function (Server $c) { |
||
| 525 | return new AvatarManager( |
||
| 526 | $c->getUserManager(), |
||
| 527 | $c->getAppDataDir('avatar'), |
||
| 528 | $c->getL10N('lib'), |
||
| 529 | $c->getLogger(), |
||
| 530 | $c->getConfig() |
||
| 531 | ); |
||
| 532 | }); |
||
| 533 | $this->registerAlias('AvatarManager', \OCP\IAvatarManager::class); |
||
| 534 | |||
| 535 | $this->registerAlias(\OCP\Support\CrashReport\IRegistry::class, \OC\Support\CrashReport\Registry::class); |
||
| 536 | |||
| 537 | $this->registerService(\OCP\ILogger::class, function (Server $c) { |
||
| 538 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
||
| 539 | $logger = Log::getLogClass($logType); |
||
| 540 | call_user_func(array($logger, 'init')); |
||
| 541 | $config = $this->getSystemConfig(); |
||
| 542 | $registry = $c->query(\OCP\Support\CrashReport\IRegistry::class); |
||
| 543 | |||
| 544 | return new Log($logger, $config, null, $registry); |
||
| 545 | }); |
||
| 546 | $this->registerAlias('Logger', \OCP\ILogger::class); |
||
| 547 | |||
| 548 | $this->registerService(\OCP\BackgroundJob\IJobList::class, function (Server $c) { |
||
| 549 | $config = $c->getConfig(); |
||
| 550 | return new \OC\BackgroundJob\JobList( |
||
| 551 | $c->getDatabaseConnection(), |
||
| 552 | $config, |
||
| 553 | new TimeFactory() |
||
| 554 | ); |
||
| 555 | }); |
||
| 556 | $this->registerAlias('JobList', \OCP\BackgroundJob\IJobList::class); |
||
| 557 | |||
| 558 | $this->registerService(\OCP\Route\IRouter::class, function (Server $c) { |
||
| 559 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 560 | $logger = $c->getLogger(); |
||
| 561 | if ($cacheFactory->isAvailableLowLatency()) { |
||
| 562 | $router = new \OC\Route\CachingRouter($cacheFactory->createLocal('route'), $logger); |
||
| 563 | } else { |
||
| 564 | $router = new \OC\Route\Router($logger); |
||
| 565 | } |
||
| 566 | return $router; |
||
| 567 | }); |
||
| 568 | $this->registerAlias('Router', \OCP\Route\IRouter::class); |
||
| 569 | |||
| 570 | $this->registerService(\OCP\ISearch::class, function ($c) { |
||
| 571 | return new Search(); |
||
| 572 | }); |
||
| 573 | $this->registerAlias('Search', \OCP\ISearch::class); |
||
| 574 | |||
| 575 | $this->registerService(\OC\Security\RateLimiting\Limiter::class, function ($c) { |
||
| 576 | return new \OC\Security\RateLimiting\Limiter( |
||
| 577 | $this->getUserSession(), |
||
| 578 | $this->getRequest(), |
||
| 579 | new \OC\AppFramework\Utility\TimeFactory(), |
||
| 580 | $c->query(\OC\Security\RateLimiting\Backend\IBackend::class) |
||
| 581 | ); |
||
| 582 | }); |
||
| 583 | $this->registerService(\OC\Security\RateLimiting\Backend\IBackend::class, function ($c) { |
||
| 584 | return new \OC\Security\RateLimiting\Backend\MemoryCache( |
||
| 585 | $this->getMemCacheFactory(), |
||
| 586 | new \OC\AppFramework\Utility\TimeFactory() |
||
| 587 | ); |
||
| 588 | }); |
||
| 589 | |||
| 590 | $this->registerService(\OCP\Security\ISecureRandom::class, function ($c) { |
||
| 591 | return new SecureRandom(); |
||
| 592 | }); |
||
| 593 | $this->registerAlias('SecureRandom', \OCP\Security\ISecureRandom::class); |
||
| 594 | |||
| 595 | $this->registerService(\OCP\Security\ICrypto::class, function (Server $c) { |
||
| 596 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 597 | }); |
||
| 598 | $this->registerAlias('Crypto', \OCP\Security\ICrypto::class); |
||
| 599 | |||
| 600 | $this->registerService(\OCP\Security\IHasher::class, function (Server $c) { |
||
| 601 | return new Hasher($c->getConfig()); |
||
| 602 | }); |
||
| 603 | $this->registerAlias('Hasher', \OCP\Security\IHasher::class); |
||
| 604 | |||
| 605 | $this->registerService(\OCP\Security\ICredentialsManager::class, function (Server $c) { |
||
| 606 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
||
| 607 | }); |
||
| 608 | $this->registerAlias('CredentialsManager', \OCP\Security\ICredentialsManager::class); |
||
| 609 | |||
| 610 | $this->registerService(IDBConnection::class, function (Server $c) { |
||
| 611 | $systemConfig = $c->getSystemConfig(); |
||
| 612 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
||
| 613 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 614 | if (!$factory->isValidType($type)) { |
||
| 615 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 616 | } |
||
| 617 | $connectionParams = $factory->createConnectionParams(); |
||
| 618 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 619 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 620 | return $connection; |
||
| 621 | }); |
||
| 622 | $this->registerAlias('DatabaseConnection', IDBConnection::class); |
||
| 623 | |||
| 624 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 625 | $config = $c->getConfig(); |
||
| 626 | return new HTTPHelper( |
||
| 627 | $config, |
||
| 628 | $c->getHTTPClientService() |
||
| 629 | ); |
||
| 630 | }); |
||
| 631 | |||
| 632 | $this->registerService(\OCP\Http\Client\IClientService::class, function (Server $c) { |
||
| 633 | $user = \OC_User::getUser(); |
||
| 634 | $uid = $user ? $user : null; |
||
| 635 | return new ClientService( |
||
| 636 | $c->getConfig(), |
||
| 637 | new \OC\Security\CertificateManager( |
||
| 638 | $uid, |
||
| 639 | new View(), |
||
| 640 | $c->getConfig(), |
||
| 641 | $c->getLogger(), |
||
| 642 | $c->getSecureRandom() |
||
| 643 | ) |
||
| 644 | ); |
||
| 645 | }); |
||
| 646 | $this->registerAlias('HttpClientService', \OCP\Http\Client\IClientService::class); |
||
| 647 | View Code Duplication | $this->registerService(\OCP\Diagnostics\IEventLogger::class, function (Server $c) { |
|
| 648 | $eventLogger = new EventLogger(); |
||
| 649 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 650 | // In debug mode, module is being activated by default |
||
| 651 | $eventLogger->activate(); |
||
| 652 | } |
||
| 653 | return $eventLogger; |
||
| 654 | }); |
||
| 655 | $this->registerAlias('EventLogger', \OCP\Diagnostics\IEventLogger::class); |
||
| 656 | |||
| 657 | View Code Duplication | $this->registerService(\OCP\Diagnostics\IQueryLogger::class, function (Server $c) { |
|
| 658 | $queryLogger = new QueryLogger(); |
||
| 659 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 660 | // In debug mode, module is being activated by default |
||
| 661 | $queryLogger->activate(); |
||
| 662 | } |
||
| 663 | return $queryLogger; |
||
| 664 | }); |
||
| 665 | $this->registerAlias('QueryLogger', \OCP\Diagnostics\IQueryLogger::class); |
||
| 666 | |||
| 667 | $this->registerService(TempManager::class, function (Server $c) { |
||
| 668 | return new TempManager( |
||
| 669 | $c->getLogger(), |
||
| 670 | $c->getConfig() |
||
| 671 | ); |
||
| 672 | }); |
||
| 673 | $this->registerAlias('TempManager', TempManager::class); |
||
| 674 | $this->registerAlias(ITempManager::class, TempManager::class); |
||
| 675 | |||
| 676 | $this->registerService(AppManager::class, function (Server $c) { |
||
| 677 | return new \OC\App\AppManager( |
||
| 678 | $c->getUserSession(), |
||
| 679 | $c->getAppConfig(), |
||
| 680 | $c->getGroupManager(), |
||
| 681 | $c->getMemCacheFactory(), |
||
| 682 | $c->getEventDispatcher() |
||
| 683 | ); |
||
| 684 | }); |
||
| 685 | $this->registerAlias('AppManager', AppManager::class); |
||
| 686 | $this->registerAlias(IAppManager::class, AppManager::class); |
||
| 687 | |||
| 688 | $this->registerService(\OCP\IDateTimeZone::class, function (Server $c) { |
||
| 689 | return new DateTimeZone( |
||
| 690 | $c->getConfig(), |
||
| 691 | $c->getSession() |
||
| 692 | ); |
||
| 693 | }); |
||
| 694 | $this->registerAlias('DateTimeZone', \OCP\IDateTimeZone::class); |
||
| 695 | |||
| 696 | $this->registerService(\OCP\IDateTimeFormatter::class, function (Server $c) { |
||
| 697 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 698 | |||
| 699 | return new DateTimeFormatter( |
||
| 700 | $c->getDateTimeZone()->getTimeZone(), |
||
| 701 | $c->getL10N('lib', $language) |
||
| 702 | ); |
||
| 703 | }); |
||
| 704 | $this->registerAlias('DateTimeFormatter', \OCP\IDateTimeFormatter::class); |
||
| 705 | |||
| 706 | $this->registerService(\OCP\Files\Config\IUserMountCache::class, function (Server $c) { |
||
| 707 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
||
| 708 | $listener = new UserMountCacheListener($mountCache); |
||
| 709 | $listener->listen($c->getUserManager()); |
||
| 710 | return $mountCache; |
||
| 711 | }); |
||
| 712 | $this->registerAlias('UserMountCache', \OCP\Files\Config\IUserMountCache::class); |
||
| 713 | |||
| 714 | $this->registerService(\OCP\Files\Config\IMountProviderCollection::class, function (Server $c) { |
||
| 715 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 716 | $mountCache = $c->query('UserMountCache'); |
||
| 717 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
||
| 718 | |||
| 719 | // builtin providers |
||
| 720 | |||
| 721 | $config = $c->getConfig(); |
||
| 722 | $manager->registerProvider(new CacheMountProvider($config)); |
||
| 723 | $manager->registerHomeProvider(new LocalHomeMountProvider()); |
||
| 724 | $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
||
| 725 | |||
| 726 | return $manager; |
||
| 727 | }); |
||
| 728 | $this->registerAlias('MountConfigManager', \OCP\Files\Config\IMountProviderCollection::class); |
||
| 729 | |||
| 730 | $this->registerService('IniWrapper', function ($c) { |
||
| 731 | return new IniGetWrapper(); |
||
| 732 | }); |
||
| 733 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
| 734 | $busClass = $c->getConfig()->getSystemValue('commandbus'); |
||
| 735 | if ($busClass) { |
||
| 736 | list($app, $class) = explode('::', $busClass, 2); |
||
| 737 | if ($c->getAppManager()->isInstalled($app)) { |
||
| 738 | \OC_App::loadApp($app); |
||
| 739 | return $c->query($class); |
||
| 740 | } else { |
||
| 741 | throw new ServiceUnavailableException("The app providing the command bus ($app) is not enabled"); |
||
| 742 | } |
||
| 743 | } else { |
||
| 744 | $jobList = $c->getJobList(); |
||
| 745 | return new CronBus($jobList); |
||
| 746 | } |
||
| 747 | }); |
||
| 748 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
| 749 | return new TrustedDomainHelper($this->getConfig()); |
||
| 750 | }); |
||
| 751 | $this->registerService('Throttler', function (Server $c) { |
||
| 752 | return new Throttler( |
||
| 753 | $c->getDatabaseConnection(), |
||
| 754 | new TimeFactory(), |
||
| 755 | $c->getLogger(), |
||
| 756 | $c->getConfig() |
||
| 757 | ); |
||
| 758 | }); |
||
| 759 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
| 760 | // IConfig and IAppManager requires a working database. This code |
||
| 761 | // might however be called when ownCloud is not yet setup. |
||
| 762 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 763 | $config = $c->getConfig(); |
||
| 764 | $appManager = $c->getAppManager(); |
||
| 765 | } else { |
||
| 766 | $config = null; |
||
| 767 | $appManager = null; |
||
| 768 | } |
||
| 769 | |||
| 770 | return new Checker( |
||
| 771 | new EnvironmentHelper(), |
||
| 772 | new FileAccessHelper(), |
||
| 773 | new AppLocator(), |
||
| 774 | $config, |
||
| 775 | $c->getMemCacheFactory(), |
||
| 776 | $appManager, |
||
| 777 | $c->getTempManager() |
||
| 778 | ); |
||
| 779 | }); |
||
| 780 | $this->registerService(\OCP\IRequest::class, function ($c) { |
||
| 781 | if (isset($this['urlParams'])) { |
||
| 782 | $urlParams = $this['urlParams']; |
||
| 783 | } else { |
||
| 784 | $urlParams = []; |
||
| 785 | } |
||
| 786 | |||
| 787 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 788 | && in_array('fakeinput', stream_get_wrappers()) |
||
| 789 | ) { |
||
| 790 | $stream = 'fakeinput://data'; |
||
| 791 | } else { |
||
| 792 | $stream = 'php://input'; |
||
| 793 | } |
||
| 794 | |||
| 795 | return new Request( |
||
| 796 | [ |
||
| 797 | 'get' => $_GET, |
||
| 798 | 'post' => $_POST, |
||
| 799 | 'files' => $_FILES, |
||
| 800 | 'server' => $_SERVER, |
||
| 801 | 'env' => $_ENV, |
||
| 802 | 'cookies' => $_COOKIE, |
||
| 803 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 804 | ? $_SERVER['REQUEST_METHOD'] |
||
| 805 | : null, |
||
| 806 | 'urlParams' => $urlParams, |
||
| 807 | ], |
||
| 808 | $this->getSecureRandom(), |
||
| 809 | $this->getConfig(), |
||
| 810 | $this->getCsrfTokenManager(), |
||
| 811 | $stream |
||
| 812 | ); |
||
| 813 | }); |
||
| 814 | $this->registerAlias('Request', \OCP\IRequest::class); |
||
| 815 | |||
| 816 | $this->registerService(\OCP\Mail\IMailer::class, function (Server $c) { |
||
| 817 | return new Mailer( |
||
| 818 | $c->getConfig(), |
||
| 819 | $c->getLogger(), |
||
| 820 | $c->query(Defaults::class), |
||
| 821 | $c->getURLGenerator(), |
||
| 822 | $c->getL10N('lib') |
||
| 823 | ); |
||
| 824 | }); |
||
| 825 | $this->registerAlias('Mailer', \OCP\Mail\IMailer::class); |
||
| 826 | |||
| 827 | $this->registerService('LDAPProvider', function (Server $c) { |
||
| 828 | $config = $c->getConfig(); |
||
| 829 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
||
| 830 | if (is_null($factoryClass)) { |
||
| 831 | throw new \Exception('ldapProviderFactory not set'); |
||
| 832 | } |
||
| 833 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
||
| 834 | $factory = new $factoryClass($this); |
||
| 835 | return $factory->getLDAPProvider(); |
||
| 836 | }); |
||
| 837 | $this->registerService(ILockingProvider::class, function (Server $c) { |
||
| 838 | $ini = $c->getIniWrapper(); |
||
| 839 | $config = $c->getConfig(); |
||
| 840 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
||
| 841 | if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 842 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
| 843 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 844 | $memcache = $memcacheFactory->createLocking('lock'); |
||
| 845 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
||
| 846 | return new MemcacheLockingProvider($memcache, $ttl); |
||
| 847 | } |
||
| 848 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
||
| 849 | } |
||
| 850 | return new NoopLockingProvider(); |
||
| 851 | }); |
||
| 852 | $this->registerAlias('LockingProvider', ILockingProvider::class); |
||
| 853 | |||
| 854 | $this->registerService(\OCP\Files\Mount\IMountManager::class, function () { |
||
| 855 | return new \OC\Files\Mount\Manager(); |
||
| 856 | }); |
||
| 857 | $this->registerAlias('MountManager', \OCP\Files\Mount\IMountManager::class); |
||
| 858 | |||
| 859 | $this->registerService(\OCP\Files\IMimeTypeDetector::class, function (Server $c) { |
||
| 860 | return new \OC\Files\Type\Detection( |
||
| 861 | $c->getURLGenerator(), |
||
| 862 | \OC::$configDir, |
||
| 863 | \OC::$SERVERROOT . '/resources/config/' |
||
| 864 | ); |
||
| 865 | }); |
||
| 866 | $this->registerAlias('MimeTypeDetector', \OCP\Files\IMimeTypeDetector::class); |
||
| 867 | |||
| 868 | $this->registerService(\OCP\Files\IMimeTypeLoader::class, function (Server $c) { |
||
| 869 | return new \OC\Files\Type\Loader( |
||
| 870 | $c->getDatabaseConnection() |
||
| 871 | ); |
||
| 872 | }); |
||
| 873 | $this->registerAlias('MimeTypeLoader', \OCP\Files\IMimeTypeLoader::class); |
||
| 874 | $this->registerService(BundleFetcher::class, function () { |
||
| 875 | return new BundleFetcher($this->getL10N('lib')); |
||
| 876 | }); |
||
| 877 | $this->registerService(\OCP\Notification\IManager::class, function (Server $c) { |
||
| 878 | return new Manager( |
||
| 879 | $c->query(IValidator::class) |
||
| 880 | ); |
||
| 881 | }); |
||
| 882 | $this->registerAlias('NotificationManager', \OCP\Notification\IManager::class); |
||
| 883 | |||
| 884 | $this->registerService(\OC\CapabilitiesManager::class, function (Server $c) { |
||
| 885 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
||
| 886 | $manager->registerCapability(function () use ($c) { |
||
| 887 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
| 888 | }); |
||
| 889 | $manager->registerCapability(function () use ($c) { |
||
| 890 | return $c->query(\OC\Security\Bruteforce\Capabilities::class); |
||
| 891 | }); |
||
| 892 | return $manager; |
||
| 893 | }); |
||
| 894 | $this->registerAlias('CapabilitiesManager', \OC\CapabilitiesManager::class); |
||
| 895 | |||
| 896 | $this->registerService(\OCP\Comments\ICommentsManager::class, function (Server $c) { |
||
| 897 | $config = $c->getConfig(); |
||
| 898 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
||
| 899 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
| 900 | $factory = new $factoryClass($this); |
||
| 901 | $manager = $factory->getManager(); |
||
| 902 | |||
| 903 | $manager->registerDisplayNameResolver('user', function($id) use ($c) { |
||
| 904 | $manager = $c->getUserManager(); |
||
| 905 | $user = $manager->get($id); |
||
| 906 | if(is_null($user)) { |
||
| 907 | $l = $c->getL10N('core'); |
||
| 908 | $displayName = $l->t('Unknown user'); |
||
| 909 | } else { |
||
| 910 | $displayName = $user->getDisplayName(); |
||
| 911 | } |
||
| 912 | return $displayName; |
||
| 913 | }); |
||
| 914 | |||
| 915 | return $manager; |
||
| 916 | }); |
||
| 917 | $this->registerAlias('CommentsManager', \OCP\Comments\ICommentsManager::class); |
||
| 918 | |||
| 919 | $this->registerService('ThemingDefaults', function (Server $c) { |
||
| 920 | /* |
||
| 921 | * Dark magic for autoloader. |
||
| 922 | * If we do a class_exists it will try to load the class which will |
||
| 923 | * make composer cache the result. Resulting in errors when enabling |
||
| 924 | * the theming app. |
||
| 925 | */ |
||
| 926 | $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
||
| 927 | if (isset($prefixes['OCA\\Theming\\'])) { |
||
| 928 | $classExists = true; |
||
| 929 | } else { |
||
| 930 | $classExists = false; |
||
| 931 | } |
||
| 932 | |||
| 933 | if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming') && $c->getTrustedDomainHelper()->isTrustedDomain($c->getRequest()->getInsecureServerHost())) { |
||
| 934 | return new ThemingDefaults( |
||
| 935 | $c->getConfig(), |
||
| 936 | $c->getL10N('theming'), |
||
| 937 | $c->getURLGenerator(), |
||
| 938 | $c->getAppDataDir('theming'), |
||
| 939 | $c->getMemCacheFactory(), |
||
| 940 | new Util($c->getConfig(), $this->getAppManager(), $this->getAppDataDir('theming')), |
||
| 941 | $this->getAppManager() |
||
| 942 | ); |
||
| 943 | } |
||
| 944 | return new \OC_Defaults(); |
||
| 945 | }); |
||
| 946 | $this->registerService(SCSSCacher::class, function (Server $c) { |
||
| 947 | /** @var Factory $cacheFactory */ |
||
| 948 | $cacheFactory = $c->query(Factory::class); |
||
| 949 | return new SCSSCacher( |
||
| 950 | $c->getLogger(), |
||
| 951 | $c->query(\OC\Files\AppData\Factory::class), |
||
| 952 | $c->getURLGenerator(), |
||
| 953 | $c->getConfig(), |
||
| 954 | $c->getThemingDefaults(), |
||
| 955 | \OC::$SERVERROOT, |
||
| 956 | $cacheFactory->createDistributed('SCSS') |
||
| 957 | ); |
||
| 958 | }); |
||
| 959 | $this->registerService(EventDispatcher::class, function () { |
||
| 960 | return new EventDispatcher(); |
||
| 961 | }); |
||
| 962 | $this->registerAlias('EventDispatcher', EventDispatcher::class); |
||
| 963 | $this->registerAlias(EventDispatcherInterface::class, EventDispatcher::class); |
||
| 964 | |||
| 965 | $this->registerService('CryptoWrapper', function (Server $c) { |
||
| 966 | // FIXME: Instantiiated here due to cyclic dependency |
||
| 967 | $request = new Request( |
||
| 968 | [ |
||
| 969 | 'get' => $_GET, |
||
| 970 | 'post' => $_POST, |
||
| 971 | 'files' => $_FILES, |
||
| 972 | 'server' => $_SERVER, |
||
| 973 | 'env' => $_ENV, |
||
| 974 | 'cookies' => $_COOKIE, |
||
| 975 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 976 | ? $_SERVER['REQUEST_METHOD'] |
||
| 977 | : null, |
||
| 978 | ], |
||
| 979 | $c->getSecureRandom(), |
||
| 980 | $c->getConfig() |
||
| 981 | ); |
||
| 982 | |||
| 983 | return new CryptoWrapper( |
||
| 984 | $c->getConfig(), |
||
| 985 | $c->getCrypto(), |
||
| 986 | $c->getSecureRandom(), |
||
| 987 | $request |
||
| 988 | ); |
||
| 989 | }); |
||
| 990 | $this->registerService('CsrfTokenManager', function (Server $c) { |
||
| 991 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
||
| 992 | |||
| 993 | return new CsrfTokenManager( |
||
| 994 | $tokenGenerator, |
||
| 995 | $c->query(SessionStorage::class) |
||
| 996 | ); |
||
| 997 | }); |
||
| 998 | $this->registerService(SessionStorage::class, function (Server $c) { |
||
| 999 | return new SessionStorage($c->getSession()); |
||
| 1000 | }); |
||
| 1001 | $this->registerService(\OCP\Security\IContentSecurityPolicyManager::class, function (Server $c) { |
||
| 1002 | return new ContentSecurityPolicyManager(); |
||
| 1003 | }); |
||
| 1004 | $this->registerAlias('ContentSecurityPolicyManager', \OCP\Security\IContentSecurityPolicyManager::class); |
||
| 1005 | |||
| 1006 | $this->registerService('ContentSecurityPolicyNonceManager', function (Server $c) { |
||
| 1007 | return new ContentSecurityPolicyNonceManager( |
||
| 1008 | $c->getCsrfTokenManager(), |
||
| 1009 | $c->getRequest() |
||
| 1010 | ); |
||
| 1011 | }); |
||
| 1012 | |||
| 1013 | $this->registerService(\OCP\Share\IManager::class, function (Server $c) { |
||
| 1014 | $config = $c->getConfig(); |
||
| 1015 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
||
| 1016 | /** @var \OCP\Share\IProviderFactory $factory */ |
||
| 1017 | $factory = new $factoryClass($this); |
||
| 1018 | |||
| 1019 | $manager = new \OC\Share20\Manager( |
||
| 1020 | $c->getLogger(), |
||
| 1021 | $c->getConfig(), |
||
| 1022 | $c->getSecureRandom(), |
||
| 1023 | $c->getHasher(), |
||
| 1024 | $c->getMountManager(), |
||
| 1025 | $c->getGroupManager(), |
||
| 1026 | $c->getL10N('lib'), |
||
| 1027 | $c->getL10NFactory(), |
||
| 1028 | $factory, |
||
| 1029 | $c->getUserManager(), |
||
| 1030 | $c->getLazyRootFolder(), |
||
| 1031 | $c->getEventDispatcher(), |
||
| 1032 | $c->getMailer(), |
||
| 1033 | $c->getURLGenerator(), |
||
| 1034 | $c->getThemingDefaults() |
||
| 1035 | ); |
||
| 1036 | |||
| 1037 | return $manager; |
||
| 1038 | }); |
||
| 1039 | $this->registerAlias('ShareManager', \OCP\Share\IManager::class); |
||
| 1040 | |||
| 1041 | $this->registerService(\OCP\Collaboration\Collaborators\ISearch::class, function(Server $c) { |
||
| 1042 | $instance = new Collaboration\Collaborators\Search($c); |
||
| 1043 | |||
| 1044 | // register default plugins |
||
| 1045 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_USER', 'class' => UserPlugin::class]); |
||
| 1046 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_GROUP', 'class' => GroupPlugin::class]); |
||
| 1047 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_EMAIL', 'class' => MailPlugin::class]); |
||
| 1048 | $instance->registerPlugin(['shareType' => 'SHARE_TYPE_REMOTE', 'class' => RemotePlugin::class]); |
||
| 1049 | |||
| 1050 | return $instance; |
||
| 1051 | }); |
||
| 1052 | $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); |
||
| 1053 | |||
| 1054 | $this->registerAlias(\OCP\Collaboration\AutoComplete\IManager::class, \OC\Collaboration\AutoComplete\Manager::class); |
||
| 1055 | |||
| 1056 | $this->registerService('SettingsManager', function (Server $c) { |
||
| 1057 | $manager = new \OC\Settings\Manager( |
||
| 1058 | $c->getLogger(), |
||
| 1059 | $c->getDatabaseConnection(), |
||
| 1060 | $c->getL10N('lib'), |
||
| 1061 | $c->getConfig(), |
||
| 1062 | $c->getEncryptionManager(), |
||
| 1063 | $c->getUserManager(), |
||
| 1064 | $c->getLockingProvider(), |
||
| 1065 | $c->getRequest(), |
||
| 1066 | new \OC\Settings\Mapper($c->getDatabaseConnection()), |
||
| 1067 | $c->getURLGenerator(), |
||
| 1068 | $c->query(AccountManager::class), |
||
| 1069 | $c->getGroupManager(), |
||
| 1070 | $c->getL10NFactory(), |
||
| 1071 | $c->getThemingDefaults(), |
||
| 1072 | $c->getAppManager() |
||
| 1073 | ); |
||
| 1074 | return $manager; |
||
| 1075 | }); |
||
| 1076 | $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
||
| 1077 | return new \OC\Files\AppData\Factory( |
||
| 1078 | $c->getRootFolder(), |
||
| 1079 | $c->getSystemConfig() |
||
| 1080 | ); |
||
| 1081 | }); |
||
| 1082 | |||
| 1083 | $this->registerService('LockdownManager', function (Server $c) { |
||
| 1084 | return new LockdownManager(function () use ($c) { |
||
| 1085 | return $c->getSession(); |
||
| 1086 | }); |
||
| 1087 | }); |
||
| 1088 | |||
| 1089 | $this->registerService(\OCP\OCS\IDiscoveryService::class, function (Server $c) { |
||
| 1090 | return new DiscoveryService($c->getMemCacheFactory(), $c->getHTTPClientService()); |
||
| 1091 | }); |
||
| 1092 | |||
| 1093 | $this->registerService(ICloudIdManager::class, function (Server $c) { |
||
| 1094 | return new CloudIdManager(); |
||
| 1095 | }); |
||
| 1096 | |||
| 1097 | $this->registerAlias(\OCP\AppFramework\Utility\IControllerMethodReflector::class, \OC\AppFramework\Utility\ControllerMethodReflector::class); |
||
| 1098 | $this->registerAlias('ControllerMethodReflector', \OCP\AppFramework\Utility\IControllerMethodReflector::class); |
||
| 1099 | |||
| 1100 | $this->registerAlias(\OCP\AppFramework\Utility\ITimeFactory::class, \OC\AppFramework\Utility\TimeFactory::class); |
||
| 1101 | $this->registerAlias('TimeFactory', \OCP\AppFramework\Utility\ITimeFactory::class); |
||
| 1102 | |||
| 1103 | $this->registerService(Defaults::class, function (Server $c) { |
||
| 1104 | return new Defaults( |
||
| 1105 | $c->getThemingDefaults() |
||
| 1106 | ); |
||
| 1107 | }); |
||
| 1108 | $this->registerAlias('Defaults', \OCP\Defaults::class); |
||
| 1109 | |||
| 1110 | $this->registerService(\OCP\ISession::class, function (SimpleContainer $c) { |
||
| 1111 | return $c->query(\OCP\IUserSession::class)->getSession(); |
||
| 1112 | }); |
||
| 1113 | |||
| 1114 | $this->registerService(IShareHelper::class, function (Server $c) { |
||
| 1115 | return new ShareHelper( |
||
| 1116 | $c->query(\OCP\Share\IManager::class) |
||
| 1117 | ); |
||
| 1118 | }); |
||
| 1119 | |||
| 1120 | $this->registerService(Installer::class, function(Server $c) { |
||
| 1121 | return new Installer( |
||
| 1122 | $c->getAppFetcher(), |
||
| 1123 | $c->getHTTPClientService(), |
||
| 1124 | $c->getTempManager(), |
||
| 1125 | $c->getLogger(), |
||
| 1126 | $c->getConfig() |
||
| 1127 | ); |
||
| 1128 | }); |
||
| 1129 | |||
| 1130 | $this->registerService(IApiFactory::class, function(Server $c) { |
||
| 1131 | return new ApiFactory($c->getHTTPClientService()); |
||
| 1132 | }); |
||
| 1133 | |||
| 1134 | $this->registerService(IInstanceFactory::class, function(Server $c) { |
||
| 1135 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 1136 | return new InstanceFactory($memcacheFactory->createLocal('remoteinstance.'), $c->getHTTPClientService()); |
||
| 1137 | }); |
||
| 1138 | |||
| 1139 | $this->registerService(IContactsStore::class, function(Server $c) { |
||
| 1140 | return new ContactsStore( |
||
| 1141 | $c->getContactsManager(), |
||
| 1142 | $c->getConfig(), |
||
| 1143 | $c->getUserManager(), |
||
| 1144 | $c->getGroupManager() |
||
| 1145 | ); |
||
| 1146 | }); |
||
| 1147 | $this->registerAlias(IContactsStore::class, ContactsStore::class); |
||
| 1148 | |||
| 1149 | $this->connectDispatcher(); |
||
| 1150 | } |
||
| 1151 | |||
| 1972 |
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: