| Conditions | 27 |
| Paths | 1 |
| Total Lines | 767 |
| Lines | 85 |
| Ratio | 11.08 % |
| 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 |
||
| 139 | public function __construct($webRoot, \OC\Config $config) { |
||
| 140 | parent::__construct(); |
||
| 141 | $this->webRoot = $webRoot; |
||
| 142 | |||
| 143 | $this->registerService('SettingsManager', function (Server $c) { |
||
| 144 | return new SettingsManager( |
||
| 145 | $c->getL10N('lib'), |
||
| 146 | $c->getAppManager(), |
||
| 147 | $c->getUserSession(), |
||
| 148 | $c->getLogger(), |
||
| 149 | $c->getGroupManager(), |
||
| 150 | $c->getConfig(), |
||
| 151 | new \OCP\Defaults(), |
||
| 152 | $c->getURLGenerator(), |
||
| 153 | new Helper(), |
||
| 154 | $c->getLockingProvider(), |
||
| 155 | $c->getDatabaseConnection(), |
||
| 156 | $c->getCertificateManager(), |
||
|
|
|||
| 157 | $c->getL10NFactory() |
||
| 158 | |||
| 159 | ); |
||
| 160 | }); |
||
| 161 | |||
| 162 | $this->registerService('ContactsManager', function ($c) { |
||
| 163 | return new ContactsManager(); |
||
| 164 | }); |
||
| 165 | |||
| 166 | $this->registerService('PreviewManager', function (Server $c) { |
||
| 167 | return new PreviewManager($c->getConfig(), |
||
| 168 | $c->getLazyRootFolder(), |
||
| 169 | $c->getUserSession()); |
||
| 170 | }); |
||
| 171 | |||
| 172 | $this->registerService('EncryptionManager', function (Server $c) { |
||
| 173 | $view = new View(); |
||
| 174 | $util = new Encryption\Util( |
||
| 175 | $view, |
||
| 176 | $c->getUserManager(), |
||
| 177 | $c->getGroupManager(), |
||
| 178 | $c->getConfig() |
||
| 179 | ); |
||
| 180 | return new Encryption\Manager( |
||
| 181 | $c->getConfig(), |
||
| 182 | $c->getLogger(), |
||
| 183 | $c->getL10N('core'), |
||
| 184 | new View(), |
||
| 185 | $util, |
||
| 186 | new ArrayCache() |
||
| 187 | ); |
||
| 188 | }); |
||
| 189 | |||
| 190 | $this->registerService('EncryptionFileHelper', function (Server $c) { |
||
| 191 | $util = new Encryption\Util( |
||
| 192 | new View(), |
||
| 193 | $c->getUserManager(), |
||
| 194 | $c->getGroupManager(), |
||
| 195 | $c->getConfig() |
||
| 196 | ); |
||
| 197 | return new Encryption\File($util); |
||
| 198 | }); |
||
| 199 | |||
| 200 | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
||
| 201 | $view = new View(); |
||
| 202 | $util = new Encryption\Util( |
||
| 203 | $view, |
||
| 204 | $c->getUserManager(), |
||
| 205 | $c->getGroupManager(), |
||
| 206 | $c->getConfig() |
||
| 207 | ); |
||
| 208 | |||
| 209 | return new Encryption\Keys\Storage( |
||
| 210 | $view, |
||
| 211 | $util, |
||
| 212 | $c->getUserSession() |
||
| 213 | ); |
||
| 214 | }); |
||
| 215 | $this->registerService('TagMapper', function (Server $c) { |
||
| 216 | return new TagMapper($c->getDatabaseConnection()); |
||
| 217 | }); |
||
| 218 | $this->registerService('TagManager', function (Server $c) { |
||
| 219 | $tagMapper = $c->query('TagMapper'); |
||
| 220 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 221 | }); |
||
| 222 | View Code Duplication | $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 223 | $config = $c->getConfig(); |
||
| 224 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
||
| 225 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
||
| 226 | $factory = new $factoryClass($this); |
||
| 227 | return $factory; |
||
| 228 | }); |
||
| 229 | $this->registerService('SystemTagManager', function (Server $c) { |
||
| 230 | return $c->query('SystemTagManagerFactory')->getManager(); |
||
| 231 | }); |
||
| 232 | $this->registerService('SystemTagObjectMapper', function (Server $c) { |
||
| 233 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
||
| 234 | }); |
||
| 235 | $this->registerService('RootFolder', function () { |
||
| 236 | $manager = \OC\Files\Filesystem::getMountManager(null); |
||
| 237 | $view = new View(); |
||
| 238 | $root = new Root($manager, $view, null); |
||
| 239 | $connector = new HookConnector($root, $view); |
||
| 240 | $connector->viewToNode(); |
||
| 241 | return $root; |
||
| 242 | }); |
||
| 243 | $this->registerService('LazyRootFolder', function (Server $c) { |
||
| 244 | return new LazyRoot(function () use ($c) { |
||
| 245 | return $c->getRootFolder(); |
||
| 246 | }); |
||
| 247 | }); |
||
| 248 | $this->registerService('AccountMapper', function (Server $c) { |
||
| 249 | return new AccountMapper($c->getConfig(), $c->getDatabaseConnection(), new AccountTermMapper($c->getDatabaseConnection())); |
||
| 250 | }); |
||
| 251 | $this->registerService('UserManager', function (Server $c) { |
||
| 252 | return new \OC\User\Manager( |
||
| 253 | $c->getConfig(), |
||
| 254 | $c->getLogger(), |
||
| 255 | $c->getAccountMapper(), |
||
| 256 | new SyncService( |
||
| 257 | $c->getConfig(), |
||
| 258 | $c->getLogger(), |
||
| 259 | $c->getAccountMapper() |
||
| 260 | ), |
||
| 261 | new UserSearch( |
||
| 262 | $c->getConfig() |
||
| 263 | ) |
||
| 264 | ); |
||
| 265 | }); |
||
| 266 | $this->registerService('GroupManager', function (Server $c) { |
||
| 267 | $groupManager = new \OC\Group\Manager( |
||
| 268 | $this->getUserManager(), |
||
| 269 | new UserSearch( |
||
| 270 | $c->getConfig() |
||
| 271 | ), |
||
| 272 | $this->getEventDispatcher() |
||
| 273 | ); |
||
| 274 | |||
| 275 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 276 | \OC_Hook::emit('OC_Group', 'pre_createGroup', ['run' => true, 'gid' => $gid]); |
||
| 277 | }); |
||
| 278 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 279 | \OC_Hook::emit('OC_User', 'post_createGroup', ['gid' => $gid->getGID()]); |
||
| 280 | }); |
||
| 281 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 282 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', ['run' => true, 'gid' => $group->getGID()]); |
||
| 283 | }); |
||
| 284 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 285 | \OC_Hook::emit('OC_User', 'post_deleteGroup', ['gid' => $group->getGID()]); |
||
| 286 | }); |
||
| 287 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 288 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', ['run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID()]); |
||
| 289 | }); |
||
| 290 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 291 | \OC_Hook::emit('OC_Group', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
||
| 292 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 293 | \OC_Hook::emit('OC_User', 'post_addToGroup', ['uid' => $user->getUID(), 'gid' => $group->getGID()]); |
||
| 294 | }); |
||
| 295 | return $groupManager; |
||
| 296 | }); |
||
| 297 | $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
||
| 298 | $dbConnection = $c->getDatabaseConnection(); |
||
| 299 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
||
| 300 | }); |
||
| 301 | $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
||
| 302 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
||
| 303 | $crypto = $c->getCrypto(); |
||
| 304 | $config = $c->getConfig(); |
||
| 305 | $logger = $c->getLogger(); |
||
| 306 | $timeFactory = new TimeFactory(); |
||
| 307 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
||
| 308 | }); |
||
| 309 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
||
| 310 | $this->registerService('TimeFactory', function () { |
||
| 311 | return new TimeFactory(); |
||
| 312 | }); |
||
| 313 | $this->registerAlias('OCP\AppFramework\Utility\ITimeFactory', 'TimeFactory'); |
||
| 314 | $this->registerService('UserSession', function (Server $c) { |
||
| 315 | $manager = $c->getUserManager(); |
||
| 316 | $session = new Memory(); |
||
| 317 | $timeFactory = new TimeFactory(); |
||
| 318 | // Token providers might require a working database. This code |
||
| 319 | // might however be called when ownCloud is not yet setup. |
||
| 320 | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 321 | $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
||
| 322 | } else { |
||
| 323 | $defaultTokenProvider = null; |
||
| 324 | } |
||
| 325 | |||
| 326 | $userSyncService = new SyncService($c->getConfig(), $c->getLogger(), $c->getAccountMapper()); |
||
| 327 | |||
| 328 | $userSession = new Session($manager, $session, $timeFactory, |
||
| 329 | $defaultTokenProvider, $c->getConfig(), $c->getLogger(), $this, $userSyncService, $c->getEventDispatcher()); |
||
| 330 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 331 | \OC_Hook::emit('OC_User', 'pre_createUser', ['run' => true, 'uid' => $uid, 'password' => $password]); |
||
| 332 | }); |
||
| 333 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 334 | /** @var $user \OC\User\User */ |
||
| 335 | \OC_Hook::emit('OC_User', 'post_createUser', ['uid' => $user->getUID(), 'password' => $password]); |
||
| 336 | }); |
||
| 337 | $userSession->listen('\OC\User', 'preDelete', function ($user) { |
||
| 338 | /** @var $user \OC\User\User */ |
||
| 339 | \OC_Hook::emit('OC_User', 'pre_deleteUser', ['run' => true, 'uid' => $user->getUID()]); |
||
| 340 | }); |
||
| 341 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 342 | /** @var $user \OC\User\User */ |
||
| 343 | \OC_Hook::emit('OC_User', 'post_deleteUser', ['uid' => $user->getUID()]); |
||
| 344 | $this->emittingCall(function () { |
||
| 345 | return true; |
||
| 346 | }, ['before' => [], 'after' => ['uid' => $user->getUID()]], 'user', 'delete'); |
||
| 347 | }); |
||
| 348 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 349 | /** @var $user \OC\User\User */ |
||
| 350 | \OC_Hook::emit('OC_User', 'pre_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
||
| 351 | }); |
||
| 352 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 353 | /** @var $user \OC\User\User */ |
||
| 354 | \OC_Hook::emit('OC_User', 'post_setPassword', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword]); |
||
| 355 | }); |
||
| 356 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 357 | \OC_Hook::emit('OC_User', 'pre_login', ['run' => true, 'uid' => $uid, 'password' => $password]); |
||
| 358 | }); |
||
| 359 | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
||
| 360 | /** @var $user \OC\User\User */ |
||
| 361 | \OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password]); |
||
| 362 | }); |
||
| 363 | $userSession->listen('\OC\User', 'preLogout', function () { |
||
| 364 | $event = new GenericEvent(null, []); |
||
| 365 | \OC::$server->getEventDispatcher()->dispatch('\OC\User\Session::pre_logout', $event); |
||
| 366 | }); |
||
| 367 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 368 | \OC_Hook::emit('OC_User', 'logout', []); |
||
| 369 | }); |
||
| 370 | $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
||
| 371 | /** @var $user \OC\User\User */ |
||
| 372 | \OC_Hook::emit('OC_User', 'changeUser', ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value]); |
||
| 373 | $this->emittingCall(function () { |
||
| 374 | return true; |
||
| 375 | }, [ |
||
| 376 | 'before' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value], |
||
| 377 | 'after' => ['run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value] |
||
| 378 | ], 'user', 'featurechange'); |
||
| 379 | }); |
||
| 380 | return $userSession; |
||
| 381 | }); |
||
| 382 | |||
| 383 | $this->registerService('OC\Authentication\TwoFactorAuth\Manager', function (Server $c) { |
||
| 384 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig()); |
||
| 385 | }); |
||
| 386 | |||
| 387 | $this->registerService('NavigationManager', function (Server $c) { |
||
| 388 | return new \OC\NavigationManager($c->getAppManager(), |
||
| 389 | $c->getURLGenerator(), |
||
| 390 | $c->getL10NFactory(), |
||
| 391 | $c->getUserSession(), |
||
| 392 | $c->getGroupManager()); |
||
| 393 | }); |
||
| 394 | $this->registerAlias(IConfig::class, 'AllConfig'); |
||
| 395 | $this->registerService('AllConfig', function (Server $c) { |
||
| 396 | return new \OC\AllConfig( |
||
| 397 | $c->getSystemConfig(), |
||
| 398 | $c->getEventDispatcher() |
||
| 399 | ); |
||
| 400 | }); |
||
| 401 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
| 402 | return new \OC\SystemConfig($config); |
||
| 403 | }); |
||
| 404 | $this->registerService('AppConfig', function (Server $c) { |
||
| 405 | return new \OC\AppConfig($c->getDatabaseConnection()); |
||
| 406 | }); |
||
| 407 | $this->registerService('L10NFactory', function (Server $c) { |
||
| 408 | return new \OC\L10N\Factory( |
||
| 409 | $c->getConfig(), |
||
| 410 | $c->getRequest(), |
||
| 411 | $c->getThemeService(), |
||
| 412 | $c->getUserSession(), |
||
| 413 | \OC::$SERVERROOT |
||
| 414 | ); |
||
| 415 | }); |
||
| 416 | $this->registerService('URLGenerator', function (Server $c) { |
||
| 417 | $config = $c->getConfig(); |
||
| 418 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 419 | $router = $c->getRouter(); |
||
| 420 | return new URLGenerator( |
||
| 421 | $config, |
||
| 422 | $cacheFactory, |
||
| 423 | $router, |
||
| 424 | new \OC\Helper\EnvironmentHelper() |
||
| 425 | ); |
||
| 426 | }); |
||
| 427 | $this->registerService('AppHelper', function ($c) { |
||
| 428 | return new \OC\AppHelper(); |
||
| 429 | }); |
||
| 430 | $this->registerService('UserCache', function ($c) { |
||
| 431 | return new Cache\File(); |
||
| 432 | }); |
||
| 433 | $this->registerService('MemCacheFactory', function (Server $c) { |
||
| 434 | $config = $c->getConfig(); |
||
| 435 | |||
| 436 | if ($config->getSystemValue('installed', false) && !(\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 437 | $v = \OC_App::getAppVersions(); |
||
| 438 | $v['core'] = \md5(\file_get_contents(\OC::$SERVERROOT . '/version.php')); |
||
| 439 | $version = \implode(',', $v); |
||
| 440 | $instanceId = \OC_Util::getInstanceId(); |
||
| 441 | $path = \OC::$SERVERROOT; |
||
| 442 | $prefix = \md5($instanceId . '-' . $version . '-' . $path); |
||
| 443 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
| 444 | $config->getSystemValue('memcache.local', null), |
||
| 445 | $config->getSystemValue('memcache.distributed', null), |
||
| 446 | $config->getSystemValue('memcache.locking', null) |
||
| 447 | ); |
||
| 448 | } |
||
| 449 | |||
| 450 | return new \OC\Memcache\Factory('', $c->getLogger(), |
||
| 451 | '\\OC\\Memcache\\ArrayCache', |
||
| 452 | '\\OC\\Memcache\\ArrayCache', |
||
| 453 | '\\OC\\Memcache\\ArrayCache' |
||
| 454 | ); |
||
| 455 | }); |
||
| 456 | $this->registerService('RedisFactory', function (Server $c) { |
||
| 457 | $systemConfig = $c->getSystemConfig(); |
||
| 458 | return new RedisFactory($systemConfig); |
||
| 459 | }); |
||
| 460 | $this->registerService('ActivityManager', function (Server $c) { |
||
| 461 | return new \OC\Activity\Manager( |
||
| 462 | $c->getRequest(), |
||
| 463 | $c->getUserSession(), |
||
| 464 | $c->getConfig() |
||
| 465 | ); |
||
| 466 | }); |
||
| 467 | $this->registerService('AvatarManager', function (Server $c) { |
||
| 468 | return new AvatarManager( |
||
| 469 | $c->getUserManager(), |
||
| 470 | $c->getLazyRootFolder(), // initialize the root folder lazily |
||
| 471 | $c->getL10N('lib'), |
||
| 472 | $c->getLogger() |
||
| 473 | ); |
||
| 474 | }); |
||
| 475 | $this->registerAlias(ILogger::class, 'Logger'); |
||
| 476 | $this->registerService('Logger', function (Server $c) { |
||
| 477 | $logClass = $c->query('AllConfig')->getSystemValue('log_type', 'owncloud'); |
||
| 478 | $logger = 'OC\\Log\\' . \ucfirst($logClass); |
||
| 479 | \call_user_func([$logger, 'init']); |
||
| 480 | |||
| 481 | return new Log($logger); |
||
| 482 | }); |
||
| 483 | $this->registerService('JobList', function (Server $c) { |
||
| 484 | $config = $c->getConfig(); |
||
| 485 | return new \OC\BackgroundJob\JobList( |
||
| 486 | $c->getDatabaseConnection(), |
||
| 487 | $config, |
||
| 488 | new TimeFactory() |
||
| 489 | ); |
||
| 490 | }); |
||
| 491 | $this->registerService('Router', function (Server $c) { |
||
| 492 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 493 | $logger = $c->getLogger(); |
||
| 494 | if ($cacheFactory->isAvailable()) { |
||
| 495 | $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
||
| 496 | } else { |
||
| 497 | $router = new \OC\Route\Router($logger); |
||
| 498 | } |
||
| 499 | return $router; |
||
| 500 | }); |
||
| 501 | $this->registerService('Search', function ($c) { |
||
| 502 | return new Search(); |
||
| 503 | }); |
||
| 504 | $this->registerService('SecureRandom', function ($c) { |
||
| 505 | return new SecureRandom(); |
||
| 506 | }); |
||
| 507 | $this->registerService('Crypto', function (Server $c) { |
||
| 508 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 509 | }); |
||
| 510 | $this->registerAlias('OCP\Security\ICrypto', 'Crypto'); |
||
| 511 | $this->registerService('Hasher', function (Server $c) { |
||
| 512 | return new Hasher($c->getConfig()); |
||
| 513 | }); |
||
| 514 | $this->registerService('CredentialsManager', function (Server $c) { |
||
| 515 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
||
| 516 | }); |
||
| 517 | $this->registerService('DatabaseConnection', function (Server $c) { |
||
| 518 | $systemConfig = $c->getSystemConfig(); |
||
| 519 | $keys = $systemConfig->getKeys(); |
||
| 520 | if (!isset($keys['dbname']) && !isset($keys['dbhost']) && isset($keys['dbtableprefix'])) { |
||
| 521 | throw new \OC\DatabaseException('No database configured'); |
||
| 522 | } |
||
| 523 | |||
| 524 | $factory = new \OC\DB\ConnectionFactory($systemConfig); |
||
| 525 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 526 | if (!$factory->isValidType($type)) { |
||
| 527 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 528 | } |
||
| 529 | $connectionParams = $factory->createConnectionParams(); |
||
| 530 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 531 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 532 | return $connection; |
||
| 533 | }); |
||
| 534 | $this->registerAlias(IDBConnection::class, 'DatabaseConnection'); |
||
| 535 | $this->registerService('Db', function (Server $c) { |
||
| 536 | return new Db($c->getDatabaseConnection()); |
||
| 537 | }); |
||
| 538 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 539 | $config = $c->getConfig(); |
||
| 540 | return new HTTPHelper( |
||
| 541 | $config, |
||
| 542 | $c->getHTTPClientService() |
||
| 543 | ); |
||
| 544 | }); |
||
| 545 | View Code Duplication | $this->registerService('HttpClientService', function (Server $c) { |
|
| 546 | $user = \OC_User::getUser(); |
||
| 547 | $uid = $user ? $user : null; |
||
| 548 | return new ClientService( |
||
| 549 | $c->getConfig(), |
||
| 550 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()) |
||
| 551 | ); |
||
| 552 | }); |
||
| 553 | View Code Duplication | $this->registerService('WebDavClientService', function (Server $c) { |
|
| 554 | $user = \OC_User::getUser(); |
||
| 555 | $uid = $user ? $user : null; |
||
| 556 | return new WebDavClientService( |
||
| 557 | $c->getConfig(), |
||
| 558 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig()) |
||
| 559 | ); |
||
| 560 | }); |
||
| 561 | View Code Duplication | $this->registerService('EventLogger', function (Server $c) { |
|
| 562 | $eventLogger = new EventLogger(); |
||
| 563 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 564 | // In debug mode, module is being activated by default |
||
| 565 | $eventLogger->activate(); |
||
| 566 | } |
||
| 567 | return $eventLogger; |
||
| 568 | }); |
||
| 569 | View Code Duplication | $this->registerService('QueryLogger', function (Server $c) { |
|
| 570 | $queryLogger = new QueryLogger(); |
||
| 571 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 572 | // In debug mode, module is being activated by default |
||
| 573 | $queryLogger->activate(); |
||
| 574 | } |
||
| 575 | return $queryLogger; |
||
| 576 | }); |
||
| 577 | $this->registerService('TempManager', function (Server $c) { |
||
| 578 | return new TempManager( |
||
| 579 | $c->getLogger(), |
||
| 580 | $c->getConfig() |
||
| 581 | ); |
||
| 582 | }); |
||
| 583 | $this->registerService('AppManager', function (Server $c) { |
||
| 584 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 585 | $appConfig = $c->getAppConfig(); |
||
| 586 | $groupManager = $c->getGroupManager(); |
||
| 587 | } else { |
||
| 588 | $appConfig = null; |
||
| 589 | $groupManager = null; |
||
| 590 | } |
||
| 591 | return new \OC\App\AppManager( |
||
| 592 | $c->getUserSession(), |
||
| 593 | $appConfig, |
||
| 594 | $groupManager, |
||
| 595 | $c->getMemCacheFactory(), |
||
| 596 | $c->getEventDispatcher(), |
||
| 597 | $c->getConfig() |
||
| 598 | ); |
||
| 599 | }); |
||
| 600 | $this->registerService('DateTimeZone', function (Server $c) { |
||
| 601 | return new DateTimeZone( |
||
| 602 | $c->getConfig(), |
||
| 603 | $c->getSession() |
||
| 604 | ); |
||
| 605 | }); |
||
| 606 | $this->registerService('DateTimeFormatter', function (Server $c) { |
||
| 607 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 608 | |||
| 609 | return new DateTimeFormatter( |
||
| 610 | $c->getDateTimeZone()->getTimeZone(), |
||
| 611 | $c->getL10N('lib', $language) |
||
| 612 | ); |
||
| 613 | }); |
||
| 614 | $this->registerService('UserMountCache', function (Server $c) { |
||
| 615 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
||
| 616 | $listener = new UserMountCacheListener($mountCache); |
||
| 617 | $listener->listen($c->getUserManager()); |
||
| 618 | return $mountCache; |
||
| 619 | }); |
||
| 620 | $this->registerService('MountConfigManager', function (Server $c) { |
||
| 621 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 622 | $mountCache = $c->query('UserMountCache'); |
||
| 623 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
||
| 624 | |||
| 625 | // builtin providers |
||
| 626 | |||
| 627 | $config = $c->getConfig(); |
||
| 628 | $manager->registerProvider(new CacheMountProvider($config)); |
||
| 629 | $manager->registerHomeProvider(new LocalHomeMountProvider()); |
||
| 630 | $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
||
| 631 | |||
| 632 | // external storage |
||
| 633 | if ($config->getAppValue('core', 'enable_external_storage', 'no') === 'yes') { |
||
| 634 | $manager->registerProvider(new \OC\Files\External\ConfigAdapter( |
||
| 635 | $c->query('AllConfig'), |
||
| 636 | $c->query('UserStoragesService'), |
||
| 637 | $c->query('UserGlobalStoragesService'), |
||
| 638 | $c->getSession() |
||
| 639 | )); |
||
| 640 | } |
||
| 641 | |||
| 642 | return $manager; |
||
| 643 | }); |
||
| 644 | $this->registerService('IniWrapper', function ($c) { |
||
| 645 | return new IniGetWrapper(); |
||
| 646 | }); |
||
| 647 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
| 648 | $jobList = $c->getJobList(); |
||
| 649 | return new AsyncBus($jobList); |
||
| 650 | }); |
||
| 651 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
| 652 | return new TrustedDomainHelper($this->getConfig()); |
||
| 653 | }); |
||
| 654 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
| 655 | // IConfig and IAppManager requires a working database. This code |
||
| 656 | // might however be called when ownCloud is not yet setup. |
||
| 657 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 658 | $config = $c->getConfig(); |
||
| 659 | $appManager = $c->getAppManager(); |
||
| 660 | } else { |
||
| 661 | $config = null; |
||
| 662 | $appManager = null; |
||
| 663 | } |
||
| 664 | |||
| 665 | return new Checker( |
||
| 666 | new EnvironmentHelper(), |
||
| 667 | new FileAccessHelper(), |
||
| 668 | new AppLocator(), |
||
| 669 | $config, |
||
| 670 | $c->getMemCacheFactory(), |
||
| 671 | $appManager, |
||
| 672 | $c->getTempManager() |
||
| 673 | ); |
||
| 674 | }); |
||
| 675 | $this->registerService('Request', function ($c) { |
||
| 676 | if (isset($this['urlParams'])) { |
||
| 677 | $urlParams = $this['urlParams']; |
||
| 678 | } else { |
||
| 679 | $urlParams = []; |
||
| 680 | } |
||
| 681 | |||
| 682 | if (\defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 683 | && \in_array('fakeinput', \stream_get_wrappers()) |
||
| 684 | ) { |
||
| 685 | $stream = 'fakeinput://data'; |
||
| 686 | } else { |
||
| 687 | $stream = 'php://input'; |
||
| 688 | } |
||
| 689 | |||
| 690 | return new Request( |
||
| 691 | [ |
||
| 692 | 'get' => $_GET, |
||
| 693 | 'post' => $_POST, |
||
| 694 | 'files' => $_FILES, |
||
| 695 | 'server' => $_SERVER, |
||
| 696 | 'env' => $_ENV, |
||
| 697 | 'cookies' => $_COOKIE, |
||
| 698 | 'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD'])) |
||
| 699 | ? $_SERVER['REQUEST_METHOD'] |
||
| 700 | : null, |
||
| 701 | 'urlParams' => $urlParams, |
||
| 702 | ], |
||
| 703 | $this->getSecureRandom(), |
||
| 704 | $this->getConfig(), |
||
| 705 | $this->getCsrfTokenManager(), |
||
| 706 | $stream |
||
| 707 | ); |
||
| 708 | }); |
||
| 709 | $this->registerService('Mailer', function (Server $c) { |
||
| 710 | return new Mailer( |
||
| 711 | $c->getConfig(), |
||
| 712 | $c->getLogger(), |
||
| 713 | new \OC_Defaults() |
||
| 714 | ); |
||
| 715 | }); |
||
| 716 | $this->registerService('LockingProvider', function (Server $c) { |
||
| 717 | $ini = $c->getIniWrapper(); |
||
| 718 | $config = $c->getConfig(); |
||
| 719 | $ttl = $config->getSystemValue('filelocking.ttl', \max(3600, $ini->getNumeric('max_execution_time'))); |
||
| 720 | if ($config->getSystemValue('filelocking.enabled', true) or (\defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 721 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
| 722 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 723 | $memcache = $memcacheFactory->createLocking('lock'); |
||
| 724 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
||
| 725 | return new MemcacheLockingProvider($memcache, $ttl); |
||
| 726 | } |
||
| 727 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
||
| 728 | } |
||
| 729 | return new NoopLockingProvider(); |
||
| 730 | }); |
||
| 731 | $this->registerAlias('OCP\Lock\ILockingProvider', 'LockingProvider'); |
||
| 732 | $this->registerService('MountManager', function () { |
||
| 733 | return new \OC\Files\Mount\Manager(); |
||
| 734 | }); |
||
| 735 | $this->registerService('MimeTypeDetector', function (Server $c) { |
||
| 736 | return new \OC\Files\Type\Detection( |
||
| 737 | $c->getURLGenerator(), |
||
| 738 | \OC::$SERVERROOT . '/config/', |
||
| 739 | \OC::$SERVERROOT . '/resources/config/' |
||
| 740 | ); |
||
| 741 | }); |
||
| 742 | $this->registerService('MimeTypeLoader', function (Server $c) { |
||
| 743 | return new \OC\Files\Type\Loader( |
||
| 744 | $c->getDatabaseConnection() |
||
| 745 | ); |
||
| 746 | }); |
||
| 747 | $this->registerAlias('OCP\Files\IMimeTypeLoader', 'MimeTypeLoader'); |
||
| 748 | $this->registerService('NotificationManager', function (Server $c) { |
||
| 749 | return new Manager($c->getEventDispatcher()); |
||
| 750 | }); |
||
| 751 | $this->registerService('CapabilitiesManager', function (Server $c) { |
||
| 752 | $manager = new \OC\CapabilitiesManager(); |
||
| 753 | $manager->registerCapability(function () use ($c) { |
||
| 754 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
| 755 | }); |
||
| 756 | return $manager; |
||
| 757 | }); |
||
| 758 | View Code Duplication | $this->registerService('CommentsManager', function (Server $c) { |
|
| 759 | $config = $c->getConfig(); |
||
| 760 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
||
| 761 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
| 762 | $factory = new $factoryClass($this); |
||
| 763 | return $factory->getManager(); |
||
| 764 | }); |
||
| 765 | $this->registerService('EventDispatcher', function () { |
||
| 766 | return new EventDispatcher(); |
||
| 767 | }); |
||
| 768 | $this->registerService('CryptoWrapper', function (Server $c) { |
||
| 769 | // FIXME: Instantiiated here due to cyclic dependency |
||
| 770 | $request = new Request( |
||
| 771 | [ |
||
| 772 | 'get' => $_GET, |
||
| 773 | 'post' => $_POST, |
||
| 774 | 'files' => $_FILES, |
||
| 775 | 'server' => $_SERVER, |
||
| 776 | 'env' => $_ENV, |
||
| 777 | 'cookies' => $_COOKIE, |
||
| 778 | 'method' => (isset($_SERVER, $_SERVER['REQUEST_METHOD'])) |
||
| 779 | ? $_SERVER['REQUEST_METHOD'] |
||
| 780 | : null, |
||
| 781 | ], |
||
| 782 | $c->getSecureRandom(), |
||
| 783 | $c->getConfig() |
||
| 784 | ); |
||
| 785 | |||
| 786 | return new CryptoWrapper( |
||
| 787 | $c->getConfig(), |
||
| 788 | $c->getCrypto(), |
||
| 789 | $c->getSecureRandom(), |
||
| 790 | $request |
||
| 791 | ); |
||
| 792 | }); |
||
| 793 | $this->registerService('CsrfTokenManager', function (Server $c) { |
||
| 794 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
||
| 795 | $sessionStorage = new SessionStorage($c->getSession()); |
||
| 796 | |||
| 797 | return new CsrfTokenManager( |
||
| 798 | $tokenGenerator, |
||
| 799 | $sessionStorage |
||
| 800 | ); |
||
| 801 | }); |
||
| 802 | $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
||
| 803 | return new ContentSecurityPolicyManager(); |
||
| 804 | }); |
||
| 805 | $this->registerService('StoragesDBConfigService', function (Server $c) { |
||
| 806 | return new DBConfigService( |
||
| 807 | $c->getDatabaseConnection(), |
||
| 808 | $c->getCrypto() |
||
| 809 | ); |
||
| 810 | }); |
||
| 811 | $this->registerService('StoragesBackendService', function (Server $c) { |
||
| 812 | $service = new StoragesBackendService($c->query('AllConfig')); |
||
| 813 | |||
| 814 | // register auth mechanisms provided by core |
||
| 815 | $provider = new \OC\Files\External\Auth\CoreAuthMechanismProvider($c, [ |
||
| 816 | // AuthMechanism::SCHEME_NULL mechanism |
||
| 817 | 'OC\Files\External\Auth\NullMechanism', |
||
| 818 | |||
| 819 | // AuthMechanism::SCHEME_BUILTIN mechanism |
||
| 820 | 'OC\Files\External\Auth\Builtin', |
||
| 821 | |||
| 822 | // AuthMechanism::SCHEME_PASSWORD mechanisms |
||
| 823 | 'OC\Files\External\Auth\Password\Password', |
||
| 824 | ]); |
||
| 825 | |||
| 826 | $service->registerAuthMechanismProvider($provider); |
||
| 827 | |||
| 828 | // force-load the session one as it will register hooks... |
||
| 829 | // TODO: obsolete it and use the TokenProvider to get the user's password from the session |
||
| 830 | $sessionCreds = new \OC\Files\External\Auth\Password\SessionCredentials( |
||
| 831 | $c->getSession(), |
||
| 832 | $c->getCrypto() |
||
| 833 | ); |
||
| 834 | $service->registerAuthMechanism($sessionCreds); |
||
| 835 | |||
| 836 | return $service; |
||
| 837 | }); |
||
| 838 | $this->registerAlias('OCP\Files\External\IStoragesBackendService', 'StoragesBackendService'); |
||
| 839 | $this->registerService('GlobalStoragesService', function (Server $c) { |
||
| 840 | return new GlobalStoragesService( |
||
| 841 | $c->query('StoragesBackendService'), |
||
| 842 | $c->query('StoragesDBConfigService'), |
||
| 843 | $c->query('UserMountCache') |
||
| 844 | ); |
||
| 845 | }); |
||
| 846 | $this->registerAlias('OCP\Files\External\Service\IGlobalStoragesService', 'GlobalStoragesService'); |
||
| 847 | View Code Duplication | $this->registerService('UserGlobalStoragesService', function (Server $c) { |
|
| 848 | return new UserGlobalStoragesService( |
||
| 849 | $c->query('StoragesBackendService'), |
||
| 850 | $c->query('StoragesDBConfigService'), |
||
| 851 | $c->query('UserSession'), |
||
| 852 | $c->query('GroupManager'), |
||
| 853 | $c->query('UserMountCache') |
||
| 854 | ); |
||
| 855 | }); |
||
| 856 | $this->registerAlias('OCP\Files\External\Service\IUserGlobalStoragesService', 'UserGlobalStoragesService'); |
||
| 857 | View Code Duplication | $this->registerService('UserStoragesService', function (Server $c) { |
|
| 858 | return new UserStoragesService( |
||
| 859 | $c->query('StoragesBackendService'), |
||
| 860 | $c->query('StoragesDBConfigService'), |
||
| 861 | $c->query('UserSession'), |
||
| 862 | $c->query('UserMountCache') |
||
| 863 | ); |
||
| 864 | }); |
||
| 865 | $this->registerAlias('OCP\Files\External\Service\IUserStoragesService', 'UserStoragesService'); |
||
| 866 | $this->registerService('ShareManager', function (Server $c) { |
||
| 867 | $config = $c->getConfig(); |
||
| 868 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
||
| 869 | /** @var \OCP\Share\IProviderFactory $factory */ |
||
| 870 | $factory = new $factoryClass($this); |
||
| 871 | |||
| 872 | $manager = new \OC\Share20\Manager( |
||
| 873 | $c->getLogger(), |
||
| 874 | $c->getConfig(), |
||
| 875 | $c->getSecureRandom(), |
||
| 876 | $c->getHasher(), |
||
| 877 | $c->getMountManager(), |
||
| 878 | $c->getGroupManager(), |
||
| 879 | $c->getL10N('core'), |
||
| 880 | $factory, |
||
| 881 | $c->getUserManager(), |
||
| 882 | $c->getLazyRootFolder(), |
||
| 883 | $c->getEventDispatcher(), |
||
| 884 | new View('/'), |
||
| 885 | $c->getDatabaseConnection() |
||
| 886 | ); |
||
| 887 | |||
| 888 | return $manager; |
||
| 889 | }); |
||
| 890 | |||
| 891 | $this->registerService('ThemeService', function ($c) { |
||
| 892 | return new ThemeService( |
||
| 893 | $this->getSystemConfig()->getValue('theme'), |
||
| 894 | $c->getAppManager(), |
||
| 895 | new \OC\Helper\EnvironmentHelper() |
||
| 896 | ); |
||
| 897 | }); |
||
| 898 | $this->registerAlias('OCP\Theme\IThemeService', 'ThemeService'); |
||
| 899 | $this->registerAlias('OCP\IUserSession', 'UserSession'); |
||
| 900 | $this->registerAlias('OCP\Security\ICrypto', 'Crypto'); |
||
| 901 | |||
| 902 | $this->registerService(IServiceLoader::class, function () { |
||
| 903 | return $this; |
||
| 904 | }); |
||
| 905 | } |
||
| 906 | |||
| 1680 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: