| Conditions | 29 |
| Paths | 1 |
| Total Lines | 726 |
| Code Lines | 509 |
| Lines | 32 |
| Ratio | 4.41 % |
| 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 |
||
| 118 | public function __construct($webRoot, \OC\Config $config) { |
||
| 119 | parent::__construct(); |
||
| 120 | $this->webRoot = $webRoot; |
||
| 121 | |||
| 122 | $this->registerService('ContactsManager', function ($c) { |
||
|
|
|||
| 123 | return new ContactsManager(); |
||
| 124 | }); |
||
| 125 | |||
| 126 | $this->registerService('PreviewManager', function (Server $c) { |
||
| 127 | return new PreviewManager( |
||
| 128 | $c->getConfig(), |
||
| 129 | $c->getRootFolder(), |
||
| 130 | $c->getAppDataDir('preview'), |
||
| 131 | $c->getEventDispatcher(), |
||
| 132 | $c->getSession()->get('user_id') |
||
| 133 | ); |
||
| 134 | }); |
||
| 135 | |||
| 136 | $this->registerService(\OC\Preview\Watcher::class, function (Server $c) { |
||
| 137 | return new \OC\Preview\Watcher( |
||
| 138 | $c->getAppDataDir('preview') |
||
| 139 | ); |
||
| 140 | }); |
||
| 141 | |||
| 142 | $this->registerService('EncryptionManager', function (Server $c) { |
||
| 143 | $view = new View(); |
||
| 144 | $util = new Encryption\Util( |
||
| 145 | $view, |
||
| 146 | $c->getUserManager(), |
||
| 147 | $c->getGroupManager(), |
||
| 148 | $c->getConfig() |
||
| 149 | ); |
||
| 150 | return new Encryption\Manager( |
||
| 151 | $c->getConfig(), |
||
| 152 | $c->getLogger(), |
||
| 153 | $c->getL10N('core'), |
||
| 154 | new View(), |
||
| 155 | $util, |
||
| 156 | new ArrayCache() |
||
| 157 | ); |
||
| 158 | }); |
||
| 159 | |||
| 160 | $this->registerService('EncryptionFileHelper', function (Server $c) { |
||
| 161 | $util = new Encryption\Util( |
||
| 162 | new View(), |
||
| 163 | $c->getUserManager(), |
||
| 164 | $c->getGroupManager(), |
||
| 165 | $c->getConfig() |
||
| 166 | ); |
||
| 167 | return new Encryption\File($util); |
||
| 168 | }); |
||
| 169 | |||
| 170 | $this->registerService('EncryptionKeyStorage', function (Server $c) { |
||
| 171 | $view = new View(); |
||
| 172 | $util = new Encryption\Util( |
||
| 173 | $view, |
||
| 174 | $c->getUserManager(), |
||
| 175 | $c->getGroupManager(), |
||
| 176 | $c->getConfig() |
||
| 177 | ); |
||
| 178 | |||
| 179 | return new Encryption\Keys\Storage($view, $util); |
||
| 180 | }); |
||
| 181 | $this->registerService('TagMapper', function (Server $c) { |
||
| 182 | return new TagMapper($c->getDatabaseConnection()); |
||
| 183 | }); |
||
| 184 | $this->registerService('TagManager', function (Server $c) { |
||
| 185 | $tagMapper = $c->query('TagMapper'); |
||
| 186 | return new TagManager($tagMapper, $c->getUserSession()); |
||
| 187 | }); |
||
| 188 | View Code Duplication | $this->registerService('SystemTagManagerFactory', function (Server $c) { |
|
| 189 | $config = $c->getConfig(); |
||
| 190 | $factoryClass = $config->getSystemValue('systemtags.managerFactory', '\OC\SystemTag\ManagerFactory'); |
||
| 191 | /** @var \OC\SystemTag\ManagerFactory $factory */ |
||
| 192 | $factory = new $factoryClass($this); |
||
| 193 | return $factory; |
||
| 194 | }); |
||
| 195 | $this->registerService('SystemTagManager', function (Server $c) { |
||
| 196 | return $c->query('SystemTagManagerFactory')->getManager(); |
||
| 197 | }); |
||
| 198 | $this->registerService('SystemTagObjectMapper', function (Server $c) { |
||
| 199 | return $c->query('SystemTagManagerFactory')->getObjectMapper(); |
||
| 200 | }); |
||
| 201 | $this->registerService('RootFolder', function (Server $c) { |
||
| 202 | $manager = \OC\Files\Filesystem::getMountManager(null); |
||
| 203 | $view = new View(); |
||
| 204 | $root = new Root( |
||
| 205 | $manager, |
||
| 206 | $view, |
||
| 207 | null, |
||
| 208 | $c->getUserMountCache(), |
||
| 209 | $this->getLogger(), |
||
| 210 | $this->getUserManager() |
||
| 211 | ); |
||
| 212 | $connector = new HookConnector($root, $view); |
||
| 213 | $connector->viewToNode(); |
||
| 214 | |||
| 215 | $previewConnector = new \OC\Preview\WatcherConnector($root, $c->getSystemConfig()); |
||
| 216 | $previewConnector->connectWatcher(); |
||
| 217 | |||
| 218 | return $root; |
||
| 219 | }); |
||
| 220 | $this->registerService('LazyRootFolder', function(Server $c) { |
||
| 221 | return new LazyRoot(function() use ($c) { |
||
| 222 | return $c->query('RootFolder'); |
||
| 223 | }); |
||
| 224 | }); |
||
| 225 | $this->registerService('UserManager', function (Server $c) { |
||
| 226 | $config = $c->getConfig(); |
||
| 227 | return new \OC\User\Manager($config); |
||
| 228 | }); |
||
| 229 | $this->registerService('GroupManager', function (Server $c) { |
||
| 230 | $groupManager = new \OC\Group\Manager($this->getUserManager()); |
||
| 231 | $groupManager->listen('\OC\Group', 'preCreate', function ($gid) { |
||
| 232 | \OC_Hook::emit('OC_Group', 'pre_createGroup', array('run' => true, 'gid' => $gid)); |
||
| 233 | }); |
||
| 234 | $groupManager->listen('\OC\Group', 'postCreate', function (\OC\Group\Group $gid) { |
||
| 235 | \OC_Hook::emit('OC_User', 'post_createGroup', array('gid' => $gid->getGID())); |
||
| 236 | }); |
||
| 237 | $groupManager->listen('\OC\Group', 'preDelete', function (\OC\Group\Group $group) { |
||
| 238 | \OC_Hook::emit('OC_Group', 'pre_deleteGroup', array('run' => true, 'gid' => $group->getGID())); |
||
| 239 | }); |
||
| 240 | $groupManager->listen('\OC\Group', 'postDelete', function (\OC\Group\Group $group) { |
||
| 241 | \OC_Hook::emit('OC_User', 'post_deleteGroup', array('gid' => $group->getGID())); |
||
| 242 | }); |
||
| 243 | $groupManager->listen('\OC\Group', 'preAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 244 | \OC_Hook::emit('OC_Group', 'pre_addToGroup', array('run' => true, 'uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 245 | }); |
||
| 246 | $groupManager->listen('\OC\Group', 'postAddUser', function (\OC\Group\Group $group, \OC\User\User $user) { |
||
| 247 | \OC_Hook::emit('OC_Group', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 248 | //Minimal fix to keep it backward compatible TODO: clean up all the GroupManager hooks |
||
| 249 | \OC_Hook::emit('OC_User', 'post_addToGroup', array('uid' => $user->getUID(), 'gid' => $group->getGID())); |
||
| 250 | }); |
||
| 251 | return $groupManager; |
||
| 252 | }); |
||
| 253 | $this->registerService(Store::class, function(Server $c) { |
||
| 254 | $session = $c->getSession(); |
||
| 255 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 256 | $tokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
||
| 257 | } else { |
||
| 258 | $tokenProvider = null; |
||
| 259 | } |
||
| 260 | $logger = $c->getLogger(); |
||
| 261 | return new Store($session, $logger, $tokenProvider); |
||
| 262 | }); |
||
| 263 | $this->registerAlias(IStore::class, Store::class); |
||
| 264 | $this->registerService('OC\Authentication\Token\DefaultTokenMapper', function (Server $c) { |
||
| 265 | $dbConnection = $c->getDatabaseConnection(); |
||
| 266 | return new Authentication\Token\DefaultTokenMapper($dbConnection); |
||
| 267 | }); |
||
| 268 | $this->registerService('OC\Authentication\Token\DefaultTokenProvider', function (Server $c) { |
||
| 269 | $mapper = $c->query('OC\Authentication\Token\DefaultTokenMapper'); |
||
| 270 | $crypto = $c->getCrypto(); |
||
| 271 | $config = $c->getConfig(); |
||
| 272 | $logger = $c->getLogger(); |
||
| 273 | $timeFactory = new TimeFactory(); |
||
| 274 | return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); |
||
| 275 | }); |
||
| 276 | $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); |
||
| 277 | $this->registerService('UserSession', function (Server $c) { |
||
| 278 | $manager = $c->getUserManager(); |
||
| 279 | $session = new \OC\Session\Memory(''); |
||
| 280 | $timeFactory = new TimeFactory(); |
||
| 281 | // Token providers might require a working database. This code |
||
| 282 | // might however be called when ownCloud is not yet setup. |
||
| 283 | View Code Duplication | if (\OC::$server->getSystemConfig()->getValue('installed', false)) { |
|
| 284 | $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); |
||
| 285 | } else { |
||
| 286 | $defaultTokenProvider = null; |
||
| 287 | } |
||
| 288 | |||
| 289 | $userSession = new \OC\User\Session($manager, $session, $timeFactory, $defaultTokenProvider, $c->getConfig(), $c->getSecureRandom()); |
||
| 290 | $userSession->listen('\OC\User', 'preCreateUser', function ($uid, $password) { |
||
| 291 | \OC_Hook::emit('OC_User', 'pre_createUser', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 292 | }); |
||
| 293 | $userSession->listen('\OC\User', 'postCreateUser', function ($user, $password) { |
||
| 294 | /** @var $user \OC\User\User */ |
||
| 295 | \OC_Hook::emit('OC_User', 'post_createUser', array('uid' => $user->getUID(), 'password' => $password)); |
||
| 296 | }); |
||
| 297 | $userSession->listen('\OC\User', 'preDelete', function ($user) { |
||
| 298 | /** @var $user \OC\User\User */ |
||
| 299 | \OC_Hook::emit('OC_User', 'pre_deleteUser', array('run' => true, 'uid' => $user->getUID())); |
||
| 300 | }); |
||
| 301 | $userSession->listen('\OC\User', 'postDelete', function ($user) { |
||
| 302 | /** @var $user \OC\User\User */ |
||
| 303 | \OC_Hook::emit('OC_User', 'post_deleteUser', array('uid' => $user->getUID())); |
||
| 304 | }); |
||
| 305 | View Code Duplication | $userSession->listen('\OC\User', 'preSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 306 | /** @var $user \OC\User\User */ |
||
| 307 | \OC_Hook::emit('OC_User', 'pre_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 308 | }); |
||
| 309 | View Code Duplication | $userSession->listen('\OC\User', 'postSetPassword', function ($user, $password, $recoveryPassword) { |
|
| 310 | /** @var $user \OC\User\User */ |
||
| 311 | \OC_Hook::emit('OC_User', 'post_setPassword', array('run' => true, 'uid' => $user->getUID(), 'password' => $password, 'recoveryPassword' => $recoveryPassword)); |
||
| 312 | }); |
||
| 313 | $userSession->listen('\OC\User', 'preLogin', function ($uid, $password) { |
||
| 314 | \OC_Hook::emit('OC_User', 'pre_login', array('run' => true, 'uid' => $uid, 'password' => $password)); |
||
| 315 | }); |
||
| 316 | $userSession->listen('\OC\User', 'postLogin', function ($user, $password) { |
||
| 317 | /** @var $user \OC\User\User */ |
||
| 318 | \OC_Hook::emit('OC_User', 'post_login', array('run' => true, 'uid' => $user->getUID(), 'password' => $password)); |
||
| 319 | }); |
||
| 320 | $userSession->listen('\OC\User', 'logout', function () { |
||
| 321 | \OC_Hook::emit('OC_User', 'logout', array()); |
||
| 322 | }); |
||
| 323 | $userSession->listen('\OC\User', 'changeUser', function ($user, $feature, $value) { |
||
| 324 | /** @var $user \OC\User\User */ |
||
| 325 | \OC_Hook::emit('OC_User', 'changeUser', array('run' => true, 'user' => $user, 'feature' => $feature, 'value' => $value)); |
||
| 326 | }); |
||
| 327 | return $userSession; |
||
| 328 | }); |
||
| 329 | |||
| 330 | $this->registerService(\OC\Authentication\TwoFactorAuth\Manager::class, function (Server $c) { |
||
| 331 | return new \OC\Authentication\TwoFactorAuth\Manager($c->getAppManager(), $c->getSession(), $c->getConfig(), $c->getActivityManager(), $c->getLogger()); |
||
| 332 | }); |
||
| 333 | |||
| 334 | $this->registerService('NavigationManager', function (Server $c) { |
||
| 335 | return new \OC\NavigationManager($c->getAppManager(), |
||
| 336 | $c->getURLGenerator(), |
||
| 337 | $c->getL10NFactory(), |
||
| 338 | $c->getUserSession(), |
||
| 339 | $c->getGroupManager()); |
||
| 340 | }); |
||
| 341 | $this->registerService('AllConfig', function (Server $c) { |
||
| 342 | return new \OC\AllConfig( |
||
| 343 | $c->getSystemConfig() |
||
| 344 | ); |
||
| 345 | }); |
||
| 346 | $this->registerService('SystemConfig', function ($c) use ($config) { |
||
| 347 | return new \OC\SystemConfig($config); |
||
| 348 | }); |
||
| 349 | $this->registerService('AppConfig', function (Server $c) { |
||
| 350 | return new \OC\AppConfig($c->getDatabaseConnection()); |
||
| 351 | }); |
||
| 352 | $this->registerService('L10NFactory', function (Server $c) { |
||
| 353 | return new \OC\L10N\Factory( |
||
| 354 | $c->getConfig(), |
||
| 355 | $c->getRequest(), |
||
| 356 | $c->getUserSession(), |
||
| 357 | \OC::$SERVERROOT |
||
| 358 | ); |
||
| 359 | }); |
||
| 360 | $this->registerService('URLGenerator', function (Server $c) { |
||
| 361 | $config = $c->getConfig(); |
||
| 362 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 363 | return new \OC\URLGenerator( |
||
| 364 | $config, |
||
| 365 | $cacheFactory |
||
| 366 | ); |
||
| 367 | }); |
||
| 368 | $this->registerService('AppHelper', function ($c) { |
||
| 369 | return new \OC\AppHelper(); |
||
| 370 | }); |
||
| 371 | $this->registerService('AppFetcher', function ($c) { |
||
| 372 | return new AppFetcher( |
||
| 373 | $this->getAppDataDir('appstore'), |
||
| 374 | $this->getHTTPClientService(), |
||
| 375 | $this->query(TimeFactory::class), |
||
| 376 | $this->getConfig() |
||
| 377 | ); |
||
| 378 | }); |
||
| 379 | $this->registerService('CategoryFetcher', function ($c) { |
||
| 380 | return new CategoryFetcher( |
||
| 381 | $this->getAppDataDir('appstore'), |
||
| 382 | $this->getHTTPClientService(), |
||
| 383 | $this->query(TimeFactory::class), |
||
| 384 | $this->getConfig() |
||
| 385 | ); |
||
| 386 | }); |
||
| 387 | $this->registerService('UserCache', function ($c) { |
||
| 388 | return new Cache\File(); |
||
| 389 | }); |
||
| 390 | $this->registerService('MemCacheFactory', function (Server $c) { |
||
| 391 | $config = $c->getConfig(); |
||
| 392 | |||
| 393 | if ($config->getSystemValue('installed', false) && !(defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 394 | $v = \OC_App::getAppVersions(); |
||
| 395 | $v['core'] = md5(file_get_contents(\OC::$SERVERROOT . '/version.php')); |
||
| 396 | $version = implode(',', $v); |
||
| 397 | $instanceId = \OC_Util::getInstanceId(); |
||
| 398 | $path = \OC::$SERVERROOT; |
||
| 399 | $prefix = md5($instanceId . '-' . $version . '-' . $path . '-' . \OC::$WEBROOT); |
||
| 400 | return new \OC\Memcache\Factory($prefix, $c->getLogger(), |
||
| 401 | $config->getSystemValue('memcache.local', null), |
||
| 402 | $config->getSystemValue('memcache.distributed', null), |
||
| 403 | $config->getSystemValue('memcache.locking', null) |
||
| 404 | ); |
||
| 405 | } |
||
| 406 | |||
| 407 | return new \OC\Memcache\Factory('', $c->getLogger(), |
||
| 408 | '\\OC\\Memcache\\ArrayCache', |
||
| 409 | '\\OC\\Memcache\\ArrayCache', |
||
| 410 | '\\OC\\Memcache\\ArrayCache' |
||
| 411 | ); |
||
| 412 | }); |
||
| 413 | $this->registerService('RedisFactory', function (Server $c) { |
||
| 414 | $systemConfig = $c->getSystemConfig(); |
||
| 415 | return new RedisFactory($systemConfig); |
||
| 416 | }); |
||
| 417 | $this->registerService('ActivityManager', function (Server $c) { |
||
| 418 | return new \OC\Activity\Manager( |
||
| 419 | $c->getRequest(), |
||
| 420 | $c->getUserSession(), |
||
| 421 | $c->getConfig(), |
||
| 422 | $c->query(IValidator::class) |
||
| 423 | ); |
||
| 424 | }); |
||
| 425 | $this->registerService(\OCP\Activity\IEventMerger::class, function (Server $c) { |
||
| 426 | return new \OC\Activity\EventMerger( |
||
| 427 | $c->getL10N('lib') |
||
| 428 | ); |
||
| 429 | }); |
||
| 430 | $this->registerAlias(IValidator::class, Validator::class); |
||
| 431 | $this->registerService('AvatarManager', function (Server $c) { |
||
| 432 | return new AvatarManager( |
||
| 433 | $c->getUserManager(), |
||
| 434 | $c->getAppDataDir('avatar'), |
||
| 435 | $c->getL10N('lib'), |
||
| 436 | $c->getLogger(), |
||
| 437 | $c->getConfig() |
||
| 438 | ); |
||
| 439 | }); |
||
| 440 | $this->registerService('Logger', function (Server $c) { |
||
| 441 | $logType = $c->query('AllConfig')->getSystemValue('log_type', 'file'); |
||
| 442 | $logger = Log::getLogClass($logType); |
||
| 443 | call_user_func(array($logger, 'init')); |
||
| 444 | |||
| 445 | return new Log($logger); |
||
| 446 | }); |
||
| 447 | $this->registerService('JobList', function (Server $c) { |
||
| 448 | $config = $c->getConfig(); |
||
| 449 | return new \OC\BackgroundJob\JobList( |
||
| 450 | $c->getDatabaseConnection(), |
||
| 451 | $config, |
||
| 452 | new TimeFactory() |
||
| 453 | ); |
||
| 454 | }); |
||
| 455 | $this->registerService('Router', function (Server $c) { |
||
| 456 | $cacheFactory = $c->getMemCacheFactory(); |
||
| 457 | $logger = $c->getLogger(); |
||
| 458 | if ($cacheFactory->isAvailable()) { |
||
| 459 | $router = new \OC\Route\CachingRouter($cacheFactory->create('route'), $logger); |
||
| 460 | } else { |
||
| 461 | $router = new \OC\Route\Router($logger); |
||
| 462 | } |
||
| 463 | return $router; |
||
| 464 | }); |
||
| 465 | $this->registerService('Search', function ($c) { |
||
| 466 | return new Search(); |
||
| 467 | }); |
||
| 468 | $this->registerService('SecureRandom', function ($c) { |
||
| 469 | return new SecureRandom(); |
||
| 470 | }); |
||
| 471 | $this->registerService('Crypto', function (Server $c) { |
||
| 472 | return new Crypto($c->getConfig(), $c->getSecureRandom()); |
||
| 473 | }); |
||
| 474 | $this->registerService('Hasher', function (Server $c) { |
||
| 475 | return new Hasher($c->getConfig()); |
||
| 476 | }); |
||
| 477 | $this->registerService('CredentialsManager', function (Server $c) { |
||
| 478 | return new CredentialsManager($c->getCrypto(), $c->getDatabaseConnection()); |
||
| 479 | }); |
||
| 480 | $this->registerService('DatabaseConnection', function (Server $c) { |
||
| 481 | $systemConfig = $c->getSystemConfig(); |
||
| 482 | $factory = new \OC\DB\ConnectionFactory($c->getConfig()); |
||
| 483 | $type = $systemConfig->getValue('dbtype', 'sqlite'); |
||
| 484 | if (!$factory->isValidType($type)) { |
||
| 485 | throw new \OC\DatabaseException('Invalid database type'); |
||
| 486 | } |
||
| 487 | $connectionParams = $factory->createConnectionParams($systemConfig); |
||
| 488 | $connection = $factory->getConnection($type, $connectionParams); |
||
| 489 | $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); |
||
| 490 | return $connection; |
||
| 491 | }); |
||
| 492 | $this->registerService('HTTPHelper', function (Server $c) { |
||
| 493 | $config = $c->getConfig(); |
||
| 494 | return new HTTPHelper( |
||
| 495 | $config, |
||
| 496 | $c->getHTTPClientService() |
||
| 497 | ); |
||
| 498 | }); |
||
| 499 | $this->registerService('HttpClientService', function (Server $c) { |
||
| 500 | $user = \OC_User::getUser(); |
||
| 501 | $uid = $user ? $user : null; |
||
| 502 | return new ClientService( |
||
| 503 | $c->getConfig(), |
||
| 504 | new \OC\Security\CertificateManager($uid, new View(), $c->getConfig(), $c->getLogger()) |
||
| 505 | ); |
||
| 506 | }); |
||
| 507 | $this->registerService('EventLogger', function (Server $c) { |
||
| 508 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 509 | return new EventLogger(); |
||
| 510 | } else { |
||
| 511 | return new NullEventLogger(); |
||
| 512 | } |
||
| 513 | }); |
||
| 514 | $this->registerService('QueryLogger', function (Server $c) { |
||
| 515 | if ($c->getSystemConfig()->getValue('debug', false)) { |
||
| 516 | return new QueryLogger(); |
||
| 517 | } else { |
||
| 518 | return new NullQueryLogger(); |
||
| 519 | } |
||
| 520 | }); |
||
| 521 | $this->registerService('TempManager', function (Server $c) { |
||
| 522 | return new TempManager( |
||
| 523 | $c->getLogger(), |
||
| 524 | $c->getConfig() |
||
| 525 | ); |
||
| 526 | }); |
||
| 527 | $this->registerService('AppManager', function (Server $c) { |
||
| 528 | return new \OC\App\AppManager( |
||
| 529 | $c->getUserSession(), |
||
| 530 | $c->getAppConfig(), |
||
| 531 | $c->getGroupManager(), |
||
| 532 | $c->getMemCacheFactory(), |
||
| 533 | $c->getEventDispatcher() |
||
| 534 | ); |
||
| 535 | }); |
||
| 536 | $this->registerService('DateTimeZone', function (Server $c) { |
||
| 537 | return new DateTimeZone( |
||
| 538 | $c->getConfig(), |
||
| 539 | $c->getSession() |
||
| 540 | ); |
||
| 541 | }); |
||
| 542 | $this->registerService('DateTimeFormatter', function (Server $c) { |
||
| 543 | $language = $c->getConfig()->getUserValue($c->getSession()->get('user_id'), 'core', 'lang', null); |
||
| 544 | |||
| 545 | return new DateTimeFormatter( |
||
| 546 | $c->getDateTimeZone()->getTimeZone(), |
||
| 547 | $c->getL10N('lib', $language) |
||
| 548 | ); |
||
| 549 | }); |
||
| 550 | $this->registerService('UserMountCache', function (Server $c) { |
||
| 551 | $mountCache = new UserMountCache($c->getDatabaseConnection(), $c->getUserManager(), $c->getLogger()); |
||
| 552 | $listener = new UserMountCacheListener($mountCache); |
||
| 553 | $listener->listen($c->getUserManager()); |
||
| 554 | return $mountCache; |
||
| 555 | }); |
||
| 556 | $this->registerService('MountConfigManager', function (Server $c) { |
||
| 557 | $loader = \OC\Files\Filesystem::getLoader(); |
||
| 558 | $mountCache = $c->query('UserMountCache'); |
||
| 559 | $manager = new \OC\Files\Config\MountProviderCollection($loader, $mountCache); |
||
| 560 | |||
| 561 | // builtin providers |
||
| 562 | |||
| 563 | $config = $c->getConfig(); |
||
| 564 | $manager->registerProvider(new CacheMountProvider($config)); |
||
| 565 | $manager->registerHomeProvider(new LocalHomeMountProvider()); |
||
| 566 | $manager->registerHomeProvider(new ObjectHomeMountProvider($config)); |
||
| 567 | |||
| 568 | return $manager; |
||
| 569 | }); |
||
| 570 | $this->registerService('IniWrapper', function ($c) { |
||
| 571 | return new IniGetWrapper(); |
||
| 572 | }); |
||
| 573 | $this->registerService('AsyncCommandBus', function (Server $c) { |
||
| 574 | $jobList = $c->getJobList(); |
||
| 575 | return new AsyncBus($jobList); |
||
| 576 | }); |
||
| 577 | $this->registerService('TrustedDomainHelper', function ($c) { |
||
| 578 | return new TrustedDomainHelper($this->getConfig()); |
||
| 579 | }); |
||
| 580 | $this->registerService('Throttler', function(Server $c) { |
||
| 581 | return new Throttler( |
||
| 582 | $c->getDatabaseConnection(), |
||
| 583 | new TimeFactory(), |
||
| 584 | $c->getLogger(), |
||
| 585 | $c->getConfig() |
||
| 586 | ); |
||
| 587 | }); |
||
| 588 | $this->registerService('IntegrityCodeChecker', function (Server $c) { |
||
| 589 | // IConfig and IAppManager requires a working database. This code |
||
| 590 | // might however be called when ownCloud is not yet setup. |
||
| 591 | if(\OC::$server->getSystemConfig()->getValue('installed', false)) { |
||
| 592 | $config = $c->getConfig(); |
||
| 593 | $appManager = $c->getAppManager(); |
||
| 594 | } else { |
||
| 595 | $config = null; |
||
| 596 | $appManager = null; |
||
| 597 | } |
||
| 598 | |||
| 599 | return new Checker( |
||
| 600 | new EnvironmentHelper(), |
||
| 601 | new FileAccessHelper(), |
||
| 602 | new AppLocator(), |
||
| 603 | $config, |
||
| 604 | $c->getMemCacheFactory(), |
||
| 605 | $appManager, |
||
| 606 | $c->getTempManager() |
||
| 607 | ); |
||
| 608 | }); |
||
| 609 | $this->registerService('Request', function ($c) { |
||
| 610 | if (isset($this['urlParams'])) { |
||
| 611 | $urlParams = $this['urlParams']; |
||
| 612 | } else { |
||
| 613 | $urlParams = []; |
||
| 614 | } |
||
| 615 | |||
| 616 | if (defined('PHPUNIT_RUN') && PHPUNIT_RUN |
||
| 617 | && in_array('fakeinput', stream_get_wrappers()) |
||
| 618 | ) { |
||
| 619 | $stream = 'fakeinput://data'; |
||
| 620 | } else { |
||
| 621 | $stream = 'php://input'; |
||
| 622 | } |
||
| 623 | |||
| 624 | return new Request( |
||
| 625 | [ |
||
| 626 | 'get' => $_GET, |
||
| 627 | 'post' => $_POST, |
||
| 628 | 'files' => $_FILES, |
||
| 629 | 'server' => $_SERVER, |
||
| 630 | 'env' => $_ENV, |
||
| 631 | 'cookies' => $_COOKIE, |
||
| 632 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 633 | ? $_SERVER['REQUEST_METHOD'] |
||
| 634 | : null, |
||
| 635 | 'urlParams' => $urlParams, |
||
| 636 | ], |
||
| 637 | $this->getSecureRandom(), |
||
| 638 | $this->getConfig(), |
||
| 639 | $this->getCsrfTokenManager(), |
||
| 640 | $stream |
||
| 641 | ); |
||
| 642 | }); |
||
| 643 | $this->registerService('Mailer', function (Server $c) { |
||
| 644 | return new Mailer( |
||
| 645 | $c->getConfig(), |
||
| 646 | $c->getLogger(), |
||
| 647 | $c->getThemingDefaults() |
||
| 648 | ); |
||
| 649 | }); |
||
| 650 | $this->registerService('LDAPProvider', function(Server $c) { |
||
| 651 | $config = $c->getConfig(); |
||
| 652 | $factoryClass = $config->getSystemValue('ldapProviderFactory', null); |
||
| 653 | if(is_null($factoryClass)) { |
||
| 654 | throw new \Exception('ldapProviderFactory not set'); |
||
| 655 | } |
||
| 656 | /** @var \OCP\LDAP\ILDAPProviderFactory $factory */ |
||
| 657 | $factory = new $factoryClass($this); |
||
| 658 | return $factory->getLDAPProvider(); |
||
| 659 | }); |
||
| 660 | $this->registerService('LockingProvider', function (Server $c) { |
||
| 661 | $ini = $c->getIniWrapper(); |
||
| 662 | $config = $c->getConfig(); |
||
| 663 | $ttl = $config->getSystemValue('filelocking.ttl', max(3600, $ini->getNumeric('max_execution_time'))); |
||
| 664 | if ($config->getSystemValue('filelocking.enabled', true) or (defined('PHPUNIT_RUN') && PHPUNIT_RUN)) { |
||
| 665 | /** @var \OC\Memcache\Factory $memcacheFactory */ |
||
| 666 | $memcacheFactory = $c->getMemCacheFactory(); |
||
| 667 | $memcache = $memcacheFactory->createLocking('lock'); |
||
| 668 | if (!($memcache instanceof \OC\Memcache\NullCache)) { |
||
| 669 | return new MemcacheLockingProvider($memcache, $ttl); |
||
| 670 | } |
||
| 671 | return new DBLockingProvider($c->getDatabaseConnection(), $c->getLogger(), new TimeFactory(), $ttl); |
||
| 672 | } |
||
| 673 | return new NoopLockingProvider(); |
||
| 674 | }); |
||
| 675 | $this->registerService('MountManager', function () { |
||
| 676 | return new \OC\Files\Mount\Manager(); |
||
| 677 | }); |
||
| 678 | $this->registerService('MimeTypeDetector', function (Server $c) { |
||
| 679 | return new \OC\Files\Type\Detection( |
||
| 680 | $c->getURLGenerator(), |
||
| 681 | \OC::$configDir, |
||
| 682 | \OC::$SERVERROOT . '/resources/config/' |
||
| 683 | ); |
||
| 684 | }); |
||
| 685 | $this->registerService('MimeTypeLoader', function (Server $c) { |
||
| 686 | return new \OC\Files\Type\Loader( |
||
| 687 | $c->getDatabaseConnection() |
||
| 688 | ); |
||
| 689 | }); |
||
| 690 | $this->registerService('NotificationManager', function (Server $c) { |
||
| 691 | return new Manager( |
||
| 692 | $c->query(IValidator::class) |
||
| 693 | ); |
||
| 694 | }); |
||
| 695 | $this->registerService('CapabilitiesManager', function (Server $c) { |
||
| 696 | $manager = new \OC\CapabilitiesManager($c->getLogger()); |
||
| 697 | $manager->registerCapability(function () use ($c) { |
||
| 698 | return new \OC\OCS\CoreCapabilities($c->getConfig()); |
||
| 699 | }); |
||
| 700 | return $manager; |
||
| 701 | }); |
||
| 702 | View Code Duplication | $this->registerService('CommentsManager', function(Server $c) { |
|
| 703 | $config = $c->getConfig(); |
||
| 704 | $factoryClass = $config->getSystemValue('comments.managerFactory', '\OC\Comments\ManagerFactory'); |
||
| 705 | /** @var \OCP\Comments\ICommentsManagerFactory $factory */ |
||
| 706 | $factory = new $factoryClass($this); |
||
| 707 | return $factory->getManager(); |
||
| 708 | }); |
||
| 709 | $this->registerService('ThemingDefaults', function(Server $c) { |
||
| 710 | /* |
||
| 711 | * Dark magic for autoloader. |
||
| 712 | * If we do a class_exists it will try to load the class which will |
||
| 713 | * make composer cache the result. Resulting in errors when enabling |
||
| 714 | * the theming app. |
||
| 715 | */ |
||
| 716 | $prefixes = \OC::$composerAutoloader->getPrefixesPsr4(); |
||
| 717 | if (isset($prefixes['OCA\\Theming\\'])) { |
||
| 718 | $classExists = true; |
||
| 719 | } else { |
||
| 720 | $classExists = false; |
||
| 721 | } |
||
| 722 | |||
| 723 | if ($classExists && $c->getConfig()->getSystemValue('installed', false) && $c->getAppManager()->isInstalled('theming')) { |
||
| 724 | return new ThemingDefaults( |
||
| 725 | $c->getConfig(), |
||
| 726 | $c->getL10N('theming'), |
||
| 727 | $c->getURLGenerator(), |
||
| 728 | new \OC_Defaults(), |
||
| 729 | $c->getLazyRootFolder(), |
||
| 730 | $c->getMemCacheFactory() |
||
| 731 | ); |
||
| 732 | } |
||
| 733 | return new \OC_Defaults(); |
||
| 734 | }); |
||
| 735 | $this->registerService('EventDispatcher', function () { |
||
| 736 | return new EventDispatcher(); |
||
| 737 | }); |
||
| 738 | $this->registerService('CryptoWrapper', function (Server $c) { |
||
| 739 | // FIXME: Instantiiated here due to cyclic dependency |
||
| 740 | $request = new Request( |
||
| 741 | [ |
||
| 742 | 'get' => $_GET, |
||
| 743 | 'post' => $_POST, |
||
| 744 | 'files' => $_FILES, |
||
| 745 | 'server' => $_SERVER, |
||
| 746 | 'env' => $_ENV, |
||
| 747 | 'cookies' => $_COOKIE, |
||
| 748 | 'method' => (isset($_SERVER) && isset($_SERVER['REQUEST_METHOD'])) |
||
| 749 | ? $_SERVER['REQUEST_METHOD'] |
||
| 750 | : null, |
||
| 751 | ], |
||
| 752 | $c->getSecureRandom(), |
||
| 753 | $c->getConfig() |
||
| 754 | ); |
||
| 755 | |||
| 756 | return new CryptoWrapper( |
||
| 757 | $c->getConfig(), |
||
| 758 | $c->getCrypto(), |
||
| 759 | $c->getSecureRandom(), |
||
| 760 | $request |
||
| 761 | ); |
||
| 762 | }); |
||
| 763 | $this->registerService('CsrfTokenManager', function (Server $c) { |
||
| 764 | $tokenGenerator = new CsrfTokenGenerator($c->getSecureRandom()); |
||
| 765 | |||
| 766 | return new CsrfTokenManager( |
||
| 767 | $tokenGenerator, |
||
| 768 | $c->query(SessionStorage::class) |
||
| 769 | ); |
||
| 770 | }); |
||
| 771 | $this->registerService(SessionStorage::class, function (Server $c) { |
||
| 772 | return new SessionStorage($c->getSession()); |
||
| 773 | }); |
||
| 774 | $this->registerService('ContentSecurityPolicyManager', function (Server $c) { |
||
| 775 | return new ContentSecurityPolicyManager(); |
||
| 776 | }); |
||
| 777 | $this->registerService('ContentSecurityPolicyNonceManager', function(Server $c) { |
||
| 778 | return new ContentSecurityPolicyNonceManager( |
||
| 779 | $c->getCsrfTokenManager(), |
||
| 780 | $c->getRequest() |
||
| 781 | ); |
||
| 782 | }); |
||
| 783 | $this->registerService('ShareManager', function(Server $c) { |
||
| 784 | $config = $c->getConfig(); |
||
| 785 | $factoryClass = $config->getSystemValue('sharing.managerFactory', '\OC\Share20\ProviderFactory'); |
||
| 786 | /** @var \OCP\Share\IProviderFactory $factory */ |
||
| 787 | $factory = new $factoryClass($this); |
||
| 788 | |||
| 789 | $manager = new \OC\Share20\Manager( |
||
| 790 | $c->getLogger(), |
||
| 791 | $c->getConfig(), |
||
| 792 | $c->getSecureRandom(), |
||
| 793 | $c->getHasher(), |
||
| 794 | $c->getMountManager(), |
||
| 795 | $c->getGroupManager(), |
||
| 796 | $c->getL10N('core'), |
||
| 797 | $factory, |
||
| 798 | $c->getUserManager(), |
||
| 799 | $c->getLazyRootFolder(), |
||
| 800 | $c->getEventDispatcher() |
||
| 801 | ); |
||
| 802 | |||
| 803 | return $manager; |
||
| 804 | }); |
||
| 805 | $this->registerService('SettingsManager', function(Server $c) { |
||
| 806 | $manager = new \OC\Settings\Manager( |
||
| 807 | $c->getLogger(), |
||
| 808 | $c->getDatabaseConnection(), |
||
| 809 | $c->getL10N('lib'), |
||
| 810 | $c->getConfig(), |
||
| 811 | $c->getEncryptionManager(), |
||
| 812 | $c->getUserManager(), |
||
| 813 | $c->getLockingProvider(), |
||
| 814 | new \OC\Settings\Mapper($c->getDatabaseConnection()), |
||
| 815 | $c->getURLGenerator() |
||
| 816 | ); |
||
| 817 | return $manager; |
||
| 818 | }); |
||
| 819 | $this->registerService(\OC\Files\AppData\Factory::class, function (Server $c) { |
||
| 820 | return new \OC\Files\AppData\Factory( |
||
| 821 | $c->getRootFolder(), |
||
| 822 | $c->getSystemConfig() |
||
| 823 | ); |
||
| 824 | }); |
||
| 825 | |||
| 826 | $this->registerService('LockdownManager', function (Server $c) { |
||
| 827 | return new LockdownManager(); |
||
| 828 | }); |
||
| 829 | |||
| 830 | $this->registerService(ICloudIdManager::class, function (Server $c) { |
||
| 831 | return new CloudIdManager(); |
||
| 832 | }); |
||
| 833 | |||
| 834 | /* To trick DI since we don't extend the DIContainer here */ |
||
| 835 | $this->registerService(CleanPreviewsBackgroundJob::class, function (Server $c) { |
||
| 836 | return new CleanPreviewsBackgroundJob( |
||
| 837 | $c->getRootFolder(), |
||
| 838 | $c->getLogger(), |
||
| 839 | $c->getJobList(), |
||
| 840 | new TimeFactory() |
||
| 841 | ); |
||
| 842 | }); |
||
| 843 | } |
||
| 844 | |||
| 1587 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.